add DELETE to the TaskVoter

This commit is contained in:
nobohan 2018-04-26 11:46:01 +02:00
parent d251074430
commit 0d9e80eb72

View File

@ -29,7 +29,7 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Chill\MainBundle\Entity\User;
/**
*
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
@ -38,31 +38,33 @@ class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterf
const CREATE = 'CHILL_TASK_TASK_CREATE';
const UPDATE = 'CHILL_TASK_TASK_UPDATE';
const SHOW = 'CHILL_TASK_TASK_SHOW';
const DELETE = 'CHILL_TASK_TASK_DELETE';
const ROLES = [
self::CREATE,
self::UPDATE,
self::SHOW
self::SHOW,
self::DELETE
];
/**
*
* @var AuthorizationHelper
*/
protected $authorizationHelper;
/**
*
* @var AccessDecisionManagerInterface
*/
protected $accessDecisionManager;
/**
*
* @var LoggerInterface
*/
protected $logger;
public function __construct(
AccessDecisionManagerInterface $accessDecisionManager,
AuthorizationHelper $authorizationHelper,
@ -72,15 +74,15 @@ class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterf
$this->authorizationHelper = $authorizationHelper;
$this->logger = $logger;
}
public function supports($attribute, $subject)
{
return $subject instanceof AbstractTask
return $subject instanceof AbstractTask
&& in_array($attribute, self::ROLES);
}
/**
*
*
* @param string $attribute
* @param AbstractTask $subject
* @param TokenInterface $token
@ -89,28 +91,28 @@ class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterf
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
$this->logger->debug(sprintf("Voting from %s class", self::class));
if (!$token->getUser() instanceof User) {
return false;
}
if ($subject->getPerson() === null) {
throw new \LogicException("You should associate a person with task "
. "in order to check autorizations");
}
if (!$this->accessDecisionManager->decide($token, [PersonVoter::SEE], $subject->getPerson())) {
return false;
}
return $this->authorizationHelper->userHasAccess(
$token->getUser(),
$subject,
$token->getUser(),
$subject,
$attribute
);
}
public function getRoles()
{
return self::ROLES;
@ -122,7 +124,7 @@ class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterf
'Task' => self::ROLES
];
}
public function getRolesWithoutScope()
{
return [];