mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-29 11:03:50 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,47 +1,44 @@
|
||||
<?php
|
||||
/*
|
||||
*
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\TaskBundle\Security\Authorization;
|
||||
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class AuthorizationEvent extends Event
|
||||
{
|
||||
public const VOTE = 'chill_task.vote';
|
||||
|
||||
/**
|
||||
* @var Chill\TaskBundle\Entity\AbstractTask|\Chill\PersonBundle\Entity\Person|null
|
||||
*/
|
||||
protected $subject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $attribute;
|
||||
|
||||
|
||||
/**
|
||||
* @var \Chill\PersonBundle\Entity\Person|Chill\TaskBundle\Entity\AbstractTask|null
|
||||
*/
|
||||
protected $subject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TokenInterface
|
||||
*/
|
||||
protected $token;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $vote;
|
||||
|
||||
const VOTE = 'chill_task.vote';
|
||||
|
||||
|
||||
public function __construct(
|
||||
$subject,
|
||||
$attribute,
|
||||
$subject,
|
||||
$attribute,
|
||||
TokenInterface $token
|
||||
) {
|
||||
$this->subject = $subject;
|
||||
@@ -49,40 +46,40 @@ class AuthorizationEvent extends Event
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
public function getSubject()
|
||||
{
|
||||
return $this->subject;
|
||||
}
|
||||
|
||||
public function getAttribute()
|
||||
{
|
||||
return $this->attribute;
|
||||
}
|
||||
|
||||
public function getSubject()
|
||||
{
|
||||
return $this->subject;
|
||||
}
|
||||
|
||||
public function getToken(): TokenInterface
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
|
||||
public function getVote()
|
||||
{
|
||||
return $this->vote;
|
||||
}
|
||||
|
||||
public function setVote($vote)
|
||||
{
|
||||
$this->vote = $vote;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasVote()
|
||||
{
|
||||
return $this->vote !== NULL;
|
||||
return null !== $this->vote;
|
||||
}
|
||||
|
||||
|
||||
public function removeVote()
|
||||
{
|
||||
$this->vote = NULL;
|
||||
$this->vote = null;
|
||||
}
|
||||
|
||||
public function setVote($vote)
|
||||
{
|
||||
$this->vote = $vote;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -1,31 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\TaskBundle\Security\Authorization;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Security\Authorization\AbstractChillVoter;
|
||||
use Chill\MainBundle\Security\Authorization\VoterHelperFactoryInterface;
|
||||
use Chill\MainBundle\Security\Authorization\VoterHelperInterface;
|
||||
use Chill\TaskBundle\Entity\AbstractTask;
|
||||
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
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 Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Chill\TaskBundle\Entity\AbstractTask;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
|
||||
use function in_array;
|
||||
|
||||
final class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterface
|
||||
{
|
||||
public const CREATE_COURSE = 'CHILL_TASK_TASK_CREATE_FOR_COURSE';
|
||||
|
||||
public const CREATE_PERSON = 'CHILL_TASK_TASK_CREATE_FOR_PERSON';
|
||||
public const DELETE = 'CHILL_TASK_TASK_DELETE';
|
||||
public const SHOW = 'CHILL_TASK_TASK_SHOW';
|
||||
public const UPDATE = 'CHILL_TASK_TASK_UPDATE';
|
||||
|
||||
public const DELETE = 'CHILL_TASK_TASK_DELETE';
|
||||
|
||||
public const ROLES = [
|
||||
self::CREATE_COURSE,
|
||||
@@ -35,12 +43,16 @@ final class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchy
|
||||
self::UPDATE,
|
||||
];
|
||||
|
||||
public const SHOW = 'CHILL_TASK_TASK_SHOW';
|
||||
|
||||
public const UPDATE = 'CHILL_TASK_TASK_UPDATE';
|
||||
|
||||
private AccessDecisionManagerInterface $accessDecisionManager;
|
||||
|
||||
private LoggerInterface $logger;
|
||||
|
||||
private EventDispatcherInterface $eventDispatcher;
|
||||
|
||||
private LoggerInterface $logger;
|
||||
|
||||
private VoterHelperInterface $voter;
|
||||
|
||||
public function __construct(
|
||||
@@ -62,6 +74,23 @@ final class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchy
|
||||
->build();
|
||||
}
|
||||
|
||||
public function getRoles(): array
|
||||
{
|
||||
return self::ROLES;
|
||||
}
|
||||
|
||||
public function getRolesWithHierarchy(): array
|
||||
{
|
||||
return [
|
||||
'Task' => self::ROLES,
|
||||
];
|
||||
}
|
||||
|
||||
public function getRolesWithoutScope(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function supports($attribute, $subject)
|
||||
{
|
||||
return $this->voter->supports($attribute, $subject);
|
||||
@@ -69,7 +98,7 @@ final class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchy
|
||||
|
||||
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
|
||||
{
|
||||
$this->logger->debug(sprintf("Voting from %s class", self::class));
|
||||
$this->logger->debug(sprintf('Voting from %s class', self::class));
|
||||
|
||||
if (!$token->getUser() instanceof User) {
|
||||
return false;
|
||||
@@ -80,10 +109,10 @@ final class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchy
|
||||
$this->eventDispatcher->dispatch(AuthorizationEvent::VOTE, $event);
|
||||
|
||||
if ($event->hasVote()) {
|
||||
$this->logger->debug("The TaskVoter is overriding by "
|
||||
.AuthorizationEvent::VOTE, [
|
||||
$this->logger->debug('The TaskVoter is overriding by '
|
||||
. AuthorizationEvent::VOTE, [
|
||||
'vote' => $event->getVote(),
|
||||
'task_id' => $subject->getId()
|
||||
'task_id' => $subject->getId(),
|
||||
]);
|
||||
|
||||
return $event->getVote();
|
||||
@@ -97,11 +126,11 @@ final class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchy
|
||||
return true;
|
||||
}
|
||||
|
||||
if (NULL !== $person = $subject->getPerson()) {
|
||||
if (null !== $person = $subject->getPerson()) {
|
||||
if (!$this->accessDecisionManager->decide($token, [PersonVoter::SEE], $person)) {
|
||||
return false;
|
||||
}
|
||||
} elseif (NULL !== $period = $subject->getCourse()) {
|
||||
} elseif (null !== $period = $subject->getCourse()) {
|
||||
if (!$this->accessDecisionManager->decide($token, [AccompanyingPeriodVoter::SEE], $period)) {
|
||||
return false;
|
||||
}
|
||||
@@ -110,7 +139,7 @@ final class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchy
|
||||
|
||||
if ($subject instanceof AccompanyingPeriod) {
|
||||
if (AccompanyingPeriod::STEP_CLOSED === $subject->getStep()) {
|
||||
if (\in_array($attribute, [self::UPDATE, self::CREATE_COURSE, self::DELETE], true)) {
|
||||
if (in_array($attribute, [self::UPDATE, self::CREATE_COURSE, self::DELETE], true)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -119,21 +148,4 @@ final class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchy
|
||||
// do regular check.
|
||||
return $this->voter->voteOnAttribute($attribute, $subject, $token);
|
||||
}
|
||||
|
||||
public function getRoles(): array
|
||||
{
|
||||
return self::ROLES;
|
||||
}
|
||||
|
||||
public function getRolesWithHierarchy(): array
|
||||
{
|
||||
return [
|
||||
'Task' => self::ROLES
|
||||
];
|
||||
}
|
||||
|
||||
public function getRolesWithoutScope(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user