Skip to content

Commit

Permalink
debug 14.2 (#2814)
Browse files Browse the repository at this point in the history
* debug 14.2

* big fixes rights

* bug template add

* updater tos enable false

* Replaced presence confirm modal with alert
  • Loading branch information
WolfyWin authored Jul 8, 2024
1 parent 211e8ca commit aa051b2
Show file tree
Hide file tree
Showing 16 changed files with 206 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ const TemplateDetails = (props) =>
]}
routes={[
{
path: '/form',
component: TemplateForm,
onEnter: () => props.openForm(props.templateType, props.defaultLocale),
onLeave: () => props.resetForm(props.templateType, props.defaultLocale)
}, {
path: '/:id',
component: TemplateForm,
onEnter: (params) => props.openForm(props.templateType, props.defaultLocale, params.id || null),
Expand Down
2 changes: 2 additions & 0 deletions src/main/privacy/Installation/ClarolinePrivacyInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Claroline\InstallationBundle\Additional\AdditionalInstaller;
use Claroline\PrivacyBundle\Installation\Updater\Updater141000;
use Claroline\PrivacyBundle\Installation\Updater\Updater142000;

class ClarolinePrivacyInstaller extends AdditionalInstaller
{
Expand All @@ -21,6 +22,7 @@ public static function getUpdaters(): array
{
return [
'14.1.0' => Updater141000::class,
'14.2.0' => Updater142000::class,
];
}
}
41 changes: 41 additions & 0 deletions src/main/privacy/Installation/Updater/Updater142000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Claroline\PrivacyBundle\Installation\Updater;

use Claroline\AppBundle\Persistence\ObjectManager;
use Claroline\CoreBundle\Library\Configuration\PlatformConfigurationHandler;
use Claroline\InstallationBundle\Updater\Updater;
use Claroline\PrivacyBundle\Manager\PrivacyManager;

class Updater142000 extends Updater
{
private PlatformConfigurationHandler $config;
private PrivacyManager $privacyManager;
private ObjectManager $om;

public function __construct(
PlatformConfigurationHandler $config,
PrivacyManager $privacyManager,
ObjectManager $om
) {
$this->config = $config;
$this->privacyManager = $privacyManager;
$this->om = $om;
}

public function postUpdate(): void
{
$privacyParameters = $this->privacyManager->getParameters();
$template = $privacyParameters->getTosTemplate();

if (null === $template || $template->isSystem()) {
$privacyParameters->setTosEnabled(false);
}

$this->privacyManager->updateParameters($privacyParameters);

$this->config->setParameter('tos.enabled', false);

$this->om->flush();
}
}
6 changes: 6 additions & 0 deletions src/main/privacy/Resources/config/services/updater.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ services:
- '@Claroline\CoreBundle\Library\Configuration\PlatformConfigurationHandler'
- '@Claroline\PrivacyBundle\Manager\PrivacyManager'
- '@Claroline\AppBundle\Persistence\ObjectManager'

Claroline\PrivacyBundle\Installation\Updater\Updater142000:
arguments:
- '@Claroline\CoreBundle\Library\Configuration\PlatformConfigurationHandler'
- '@Claroline\PrivacyBundle\Manager\PrivacyManager'
- '@Claroline\AppBundle\Persistence\ObjectManager'
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const TermsOfServiceModal = props =>
title={trans('terms_of_service',{},'privacy')}
size="lg"
backdrop="static"
closeButton={false}
closeButton={true}
onEntering={() => {
if (!props.loaded) {
props.fetch()
Expand Down
153 changes: 88 additions & 65 deletions src/plugin/cursus/Controller/EventPresenceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,94 @@ public function __construct(
$this->authorization = $authorization;
}

/**
* Updates the status of a EventPresence for current user.
*
* @Route("/sign", name="apiv2_cursus_event_presence_sign", methods={"PUT"})
*/
public function signStatusAction(Request $request): JsonResponse
{
$data = $this->decodeRequest($request);
if (empty($data)) {
throw new InvalidDataException('Invalid data');
}

$event = $data['event'];
$signature = trim($data['signature']);

$eventObject = $this->om->getRepository(Event::class)->findOneBy([
'uuid' => $event['id'],
]);

$presence = $this->om->getRepository(EventPresence::class)->findOneBy([
'event' => $eventObject,
'user' => $this->tokenStorage->getToken()->getUser(),
]);

if (!$presence) {
return new JsonResponse(null, 404);
}

if (EventPresence::PRESENT === $presence->getStatus()) {
return new JsonResponse(['success' => false]);
}

$presenceData = $this->serializer->serialize($presence);
$presenceData['status'] = EventPresence::PRESENT;
$presenceData['signature'] = $signature;

$this->crud->update($presence, $presenceData);

return new JsonResponse(['success' => true]);
}

/**
* Confirm the status of a EventPresence for current user.
*
* @Route("/confirm", name="apiv2_cursus_event_presence_confirm", methods={"PUT"})
*/
public function confirmStatusAction(Request $request): JsonResponse
{
$data = $this->decodeRequest($request);
if (empty($data)) {
throw new InvalidDataException('Invalid data');
}

$presences = $this->om->getRepository(EventPresence::class)->findBy(['uuid' => $data]);
$this->om->startFlushSuite();
foreach ($presences as $presence) {
$this->checkPermission('ADMINISTRATE', $presence, [], true);

$this->manager->setValidationDate([$presence], new \DateTime());
}
$this->om->endFlushSuite();

return new JsonResponse();
}

/**
* @Route("/check/{code}", name="apiv2_cursus_event_presence_check", methods={"GET"})
*/
public function getEventPresenceByCodeAction(string $code): JsonResponse
{
$event = $this->om->getRepository(Event::class)->findOneBy(['code' => $code]);
if (!$event) {
return new JsonResponse(null, 404);
}

$user = $this->tokenStorage->getToken()->getUser();
if (!$user || 'anon.' === $user) {
return new JsonResponse(null, 401);
}

$presence = $this->om->getRepository(EventPresence::class)->findOneBy([
'event' => $event,
'user' => $user,
]);

return new JsonResponse($this->serializer->serialize($presence));
}

/**
* @Route("/{id}", name="apiv2_cursus_event_presence_list", methods={"GET"})
*
Expand Down Expand Up @@ -132,71 +220,6 @@ public function updateStatusAction(string $status, Request $request): JsonRespon
}, $presences));
}

/**
* Updates the status of a EventPresence for current user.
*
* @Route("/sign", name="apiv2_cursus_event_presence_sign", methods={"PUT"})
*/
public function signStatusAction(Request $request): JsonResponse
{
$data = $this->decodeRequest($request);
if (empty($data)) {
throw new InvalidDataException('Invalid data');
}

$event = $data['event'];
$signature = trim($data['signature']);

$eventObject = $this->om->getRepository(Event::class)->findOneBy([
'uuid' => $event['id'],
]);

$presence = $this->om->getRepository(EventPresence::class)->findOneBy([
'event' => $eventObject,
'user' => $this->tokenStorage->getToken()->getUser(),
]);

if (!$presence) {
return new JsonResponse(null, 404);
}

if (EventPresence::PRESENT === $presence->getStatus()) {
return new JsonResponse(['success' => false]);
}

$presenceData = $this->serializer->serialize($presence);
$presenceData['status'] = EventPresence::PRESENT;
$presenceData['signature'] = $signature;

$this->crud->update($presence, $presenceData);

return new JsonResponse(['success' => true]);
}

/**
* Confirm the status of a EventPresence for current user.
*
* @Route("/confirm", name="apiv2_cursus_event_presence_confirm", methods={"PUT"})
*/
public function confirmStatusAction(Request $request): JsonResponse
{
$data = $this->decodeRequest($request);
if (empty($data)) {
throw new InvalidDataException('Invalid data');
}

$presences = $this->om->getRepository(EventPresence::class)->findBy(['uuid' => $data]);
$this->om->startFlushSuite();
foreach ($presences as $presence) {
$this->checkPermission('ADMINISTRER', $presence, [], true);

$this->manager->setValidationDate([$presence], new \DateTime());
}
$this->om->endFlushSuite();

return new JsonResponse();
}

/**
* @Route("/{id}/download/{filled}", name="apiv2_cursus_event_presence_download", methods={"GET"})
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {MODAL_BUTTON} from '#/main/app/buttons'
import {trans} from '#/main/app/intl'
import {hasPermission} from '#/main/app/security'
import {MODAL_EVIDENCE} from '#/plugin/cursus/modals/presence/evidences'
import {constants} from '#/plugin/cursus/constants'

export default (presences, refresher) => {
const processable = presences.filter(presence => hasPermission('edit', presence))
Expand All @@ -16,7 +17,7 @@ export default (presences, refresher) => {
onSuccess: refresher.update,
editable: true
}],
displayed: 0 !== processable.length,
displayed: 0 !== processable.length && [constants.PRESENCE_STATUS_ABSENT_UNJUSTIFIED, constants.PRESENCE_STATUS_ABSENT_JUSTIFIED].includes(processable[0].status),
group: trans('validation', {}, 'presence'),
scope: ['object']
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const CourseDetails = (props) =>
contextType={props.contextType}
path={props.path}
course={props.course}
registration={props.registrations}
registrations={props.registrations}
reload={props.reload}
register={props.register}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const EventsTool = (props) =>
<Routes
path={props.path}
redirect={[
{from: '/', exact: true, to: props.course ? '/about/' + props.course.slug : '/about'}
{from: '/', exact: true, to: props.course ? '/about/' + props.course.slug + '/sessions' : '/about'}
]}
routes={[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,27 @@ import {selectors, actions} from '#/plugin/cursus/tools/presence/store'
import {selectors as securitySelectors} from '#/main/app/security/store/selectors'

const SignPresenceComponent = (props) =>
<ContentSizing size="md" className="d-flex flex-column align-items-center">
{ props.currentUser && props.eventLoaded && props.currentEvent &&
<Form
className="mt-5"
<ContentSizing size="md" className="d-flex flex-column align-items-center mt-5">
{props.currentUser && props.eventLoaded && props.currentEvent && props.eventSigned &&
<Alert
type="success"
className="content-md"
title={trans('presence_confirm_title', {}, 'presence')}
>
{trans('presence_confirm_desc', {event_title: props.currentEvent.name}, 'presence')}
<div className="btn-toolbar gap-1 mt-3 justify-content-end">
<Button
className="btn btn-success"
label={trans('presence_confirm_other', {}, 'presence')}
type={CALLBACK_BUTTON}
callback={() => props.history.push(`${props.path}`)}
/>
</div>
</Alert>
}

{ props.currentUser && props.eventLoaded && props.currentEvent && !props.eventSigned &&
<Form>
<div className="bg-body-secondary rounded-2 p-4">
<ContentHtml className="text-center mb-3">
{trans('presence_info', {
Expand Down Expand Up @@ -53,6 +69,7 @@ const SignPresenceComponent = (props) =>
{ !props.currentUser && props.eventLoaded && props.currentEvent &&
<Alert
type="warning"
className="content-md"
title={trans('not_registered', {}, 'presence')}
>
{trans('not_registered_desc', {}, 'presence')}
Expand All @@ -74,6 +91,7 @@ const SignPresenceComponent = (props) =>
{ props.eventLoaded && !props.currentEvent &&
<Alert
type="warning"
className="content-md"
title={trans('event_not_found', {}, 'presence')}
>
{trans('event_not_found_desc', {}, 'presence')}
Expand All @@ -95,7 +113,8 @@ const SignPresence = connect(
currentUser: securitySelectors.currentUser(state),
currentEvent: selectors.currentEvent(state),
eventLoaded: selectors.eventLoaded(state),
signature: selectors.signature(state)
signature: selectors.signature(state),
eventSigned: selectors.eventSigned(state)
}),
(dispatch) => ({
signPresence: (event, signature) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const PresenceToolComponent = (props) =>
component: SignPresence
}, {
path: '/',
onEnter: () => props.resetEvent(),
component: EventPresence
}
]}
Expand All @@ -32,6 +33,11 @@ const PresenceTool = connect(
(dispatch) => ({
getEventByCode(code = null) {
dispatch(actions.getEventByCode(code))
},
resetEvent() {
dispatch(actions.setCode(''))
dispatch(actions.setCurrentEvent(null))
dispatch(actions.setEventLoaded(false))
}
})
)(PresenceToolComponent)
Expand Down
Loading

0 comments on commit aa051b2

Please sign in to comment.