diff --git a/src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodWorkEvaluationDocumentVoter.php b/src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodWorkEvaluationDocumentVoter.php new file mode 100644 index 000000000..b3b6dab56 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodWorkEvaluationDocumentVoter.php @@ -0,0 +1,51 @@ +accessDecisionManager = $accessDecisionManager; + } + + protected function supports($attribute, $subject) + { + return $subject instanceof AccompanyingPeriodWorkEvaluationDocument + && $attribute === self::SEE; + } + + /** + * @param string $attribute + * @param AccompanyingPeriodWorkEvaluationDocument $subject + * @param TokenInterface $token + * @return bool|void + */ + protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool + { + switch ($attribute){ + case self::SEE: + return $this->accessDecisionManager->decide($token, [AccompanyingPeriodWorkEvaluationVoter::SEE], + $subject->getAccompanyingPeriodWorkEvaluation()); + + default: + throw new \UnexpectedValueException("The attribute $attribute is not supported"); + } + } + + +} diff --git a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php index 1465f345c..32c71b9f0 100644 --- a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php +++ b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php @@ -16,6 +16,7 @@ use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Workflow\EntityWorkflowHandlerInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument; use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocumentRepository; +use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkEvaluationDocumentVoter; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkEvaluationVoter; use Symfony\Contracts\Translation\TranslatorInterface; @@ -51,7 +52,7 @@ class AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler implements EntityW $doc = $this->getRelatedEntity($entityWorkflow); return $this->translator->trans( - 'workflow.Evaluation (n°%eval%)', + 'workflow.Doc for evaluation (n°%eval%)', ['%eval%' => $entityWorkflow->getRelatedEntityId()] ) . ' - ' . $this->translatableStringHelper->localize($doc->getAccompanyingPeriodWorkEvaluation() ->getEvaluation()->getTitle()); @@ -64,7 +65,7 @@ class AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler implements EntityW public function getRoleShow(EntityWorkflow $entityWorkflow): ?string { - return AccompanyingPeriodWorkEvaluationVoter::SEE; + return AccompanyingPeriodWorkEvaluationDocumentVoter::SEE; } public function getTemplate(EntityWorkflow $entityWorkflow, array $options = []): string diff --git a/src/Bundle/ChillPersonBundle/config/services/security.yaml b/src/Bundle/ChillPersonBundle/config/services/security.yaml index ca719b0b6..af81b42e2 100644 --- a/src/Bundle/ChillPersonBundle/config/services/security.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/security.yaml @@ -34,6 +34,10 @@ services: autowire: true autoconfigure: true + Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkEvaluationDocumentVoter: + autowire: true + autoconfigure: true + Chill\PersonBundle\Security\Authorization\HouseholdVoter: autowire: true autoconfigure: true diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index c4d163a16..3b1aea377 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -571,3 +571,6 @@ Linked evaluations: Évaluations associées # Accompanying period per user My accompanying periods: Mes parcours My accompanying periods in draft: Mes parcours brouillons + +workflow: + Doc for evaluation (n°%eval%): Document de l'évaluation n°%eval%