new/show/edit/delete/list functionality added for accompanyingperiod task

This commit is contained in:
2021-09-17 14:33:42 +02:00
parent a156bd0863
commit 01ae50aca7
15 changed files with 243 additions and 119 deletions

View File

@@ -27,7 +27,9 @@ use Psr\Log\LoggerInterface;
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Symfony\Component\Security\Core\Role\Role;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Chill\TaskBundle\Security\Authorization\AuthorizationEvent;
@@ -128,14 +130,13 @@ class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterf
}
if ($subject instanceof AbstractTask) {
if ($subject->getPerson() === null) {
$associated = $subject->getPerson() ?? $subject->getCourse();
if ($associated === null) {
throw new \LogicException("You should associate a person with task "
. "in order to check autorizations");
}
$person = $subject->getPerson();
} elseif ($subject instanceof Person) {
$person = $subject;
$associated = $subject;
} else {
// subject is null. We check that at least one center is reachable
$centers = $this->authorizationHelper->getReachableCenters($token->getUser(), new Role($attribute));
@@ -143,8 +144,10 @@ class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterf
return count($centers) > 0;
}
if (!$this->accessDecisionManager->decide($token, [PersonVoter::SEE], $person)) {
if ($associated instanceof Person && !$this->accessDecisionManager->decide($token, [PersonVoter::SEE], $associated)) {
return false;
} elseif ($associated instanceof AccompanyingPeriod && !$this->accessDecisionManager->decide($token, [AccompanyingPeriodVoter::SEE], $associated)) {
return false;
}