transition added + attempt voter

This commit is contained in:
Julie Lenaerts 2021-11-19 08:37:56 +01:00
parent e9e3b85518
commit a20d7222a8
3 changed files with 19 additions and 6 deletions

View File

@ -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');
}
}

View File

@ -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();

View File

@ -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: