mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-20 04:02:50 +00:00
use event to override vote on task
Now, the bundle dispatch an event `chill_task.vote` to override the authorization on voting on a task. If a subscriber or listener emits a vote on the event, this vote override the logic defined for the default task.
This commit is contained in:
@@ -29,6 +29,8 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Chill\TaskBundle\Security\Authorization\AuthorizationEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -66,14 +68,22 @@ class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterf
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
protected $eventDispatcher;
|
||||
|
||||
public function __construct(
|
||||
AccessDecisionManagerInterface $accessDecisionManager,
|
||||
AuthorizationHelper $authorizationHelper,
|
||||
EventDispatcherInterface $eventDispatcher,
|
||||
LoggerInterface $logger
|
||||
) {
|
||||
$this->accessDecisionManager = $accessDecisionManager;
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
@@ -101,6 +111,21 @@ class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterf
|
||||
if (!$token->getUser() instanceof User) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$event = new AuthorizationEvent($subject, $attribute, $token);
|
||||
|
||||
$this->eventDispatcher->dispatch(AuthorizationEvent::VOTE, $event);
|
||||
|
||||
if ($event->hasVote()) {
|
||||
|
||||
$this->logger->debug("The TaskVoter is overriding by "
|
||||
.AuthorizationEvent::VOTE, [
|
||||
'vote' => $event->getVote(),
|
||||
'task_id' => $subject->getId()
|
||||
]);
|
||||
|
||||
return $event->getVote();
|
||||
}
|
||||
|
||||
if ($subject instanceof AbstractTask) {
|
||||
if ($subject->getPerson() === null) {
|
||||
|
Reference in New Issue
Block a user