From 6c48a22f8673e19c2b0fcdb7b5cb6f2a4809d85e Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 19 Nov 2021 08:37:56 +0100 Subject: [PATCH] transition added + attempt voter --- .../Controller/AccompanyingCourseController.php | 12 +++++++++++- .../Authorization/AccompanyingPeriodVoter.php | 6 ++++++ .../config/services/controller.yaml | 7 ++----- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php index 1f4262034..c9b9cee35 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php @@ -23,6 +23,7 @@ use Symfony\Component\Serializer\SerializerInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Validator\Validator\ValidatorInterface; +use Symfony\Component\Workflow\Registry; /** * Class AccompanyingCourseController @@ -39,16 +40,20 @@ class AccompanyingCourseController extends Controller private AccompanyingPeriodWorkRepository $workRepository; + private Registry $registry; + public function __construct( SerializerInterface $serializer, EventDispatcherInterface $dispatcher, ValidatorInterface $validator, - AccompanyingPeriodWorkRepository $workRepository + AccompanyingPeriodWorkRepository $workRepository, + Registry $registry ) { $this->serializer = $serializer; $this->dispatcher = $dispatcher; $this->validator = $validator; $this->workRepository = $workRepository; + $this->registry = $registry; } /** @@ -175,6 +180,11 @@ class AccompanyingCourseController extends Controller if ($form->isSubmitted() && $form->isValid()) { $this->getDoctrine()->getManager()->flush(); + $workflow = $this->registry->get($accompanyingCourse); + + if ($workflow->can($accompanyingCourse, 'close')) { + $workflow->apply($accompanyingCourse, 'close'); + } } diff --git a/src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodVoter.php b/src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodVoter.php index 5247df505..49847d114 100644 --- a/src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodVoter.php +++ b/src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodVoter.php @@ -78,6 +78,12 @@ class AccompanyingPeriodVoter extends AbstractChillVoter implements ProvideRole return false; } + if (AccompanyingPeriod::STEP_CLOSED === $subject->getStep()) { + if($this->security->isGranted(self::EDIT, $subject)) { + return false; + } + } + // if confidential, only the referent can see it if ($subject->isConfidential()) { return $token->getUser() === $subject->getUser(); diff --git a/src/Bundle/ChillPersonBundle/config/services/controller.yaml b/src/Bundle/ChillPersonBundle/config/services/controller.yaml index 369fe63bb..fb31e8ee9 100644 --- a/src/Bundle/ChillPersonBundle/config/services/controller.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/controller.yaml @@ -32,11 +32,8 @@ services: tags: ['controller.service_arguments'] Chill\PersonBundle\Controller\AccompanyingCourseController: - arguments: - $serializer: '@Symfony\Component\Serializer\SerializerInterface' - $dispatcher: '@Symfony\Contracts\EventDispatcher\EventDispatcherInterface' - $validator: '@Symfony\Component\Validator\Validator\ValidatorInterface' - $workRepository: '@Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository' + autoconfigure: true + autowire: true tags: ['controller.service_arguments'] Chill\PersonBundle\Controller\AccompanyingCourseApiController: