add a button 'new task' in page head and improve voter

This commit is contained in:
2018-07-05 15:33:35 +02:00
parent 9852430b13
commit 066efdc042
3 changed files with 43 additions and 27 deletions

View File

@@ -27,6 +27,7 @@ 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\Person;
/**
*
@@ -77,8 +78,9 @@ class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterf
public function supports($attribute, $subject)
{
return $subject instanceof AbstractTask
&& in_array($attribute, self::ROLES);
return ($subject instanceof AbstractTask && in_array($attribute, self::ROLES))
||
($subject instanceof Person && $attribute === self::CREATE);
}
/**
@@ -96,12 +98,18 @@ class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterf
return false;
}
if ($subject->getPerson() === null) {
throw new \LogicException("You should associate a person with task "
. "in order to check autorizations");
if ($subject instanceof AbstractTask) {
if ($subject->getPerson() === null) {
throw new \LogicException("You should associate a person with task "
. "in order to check autorizations");
}
$person = $subject->getPerson();
} else {
$person = $subject;
}
if (!$this->accessDecisionManager->decide($token, [PersonVoter::SEE], $subject->getPerson())) {
if (!$this->accessDecisionManager->decide($token, [PersonVoter::SEE], $person)) {
return false;
}