mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
fix: Strict types interfaces: VoterHelperInterface
, ProvideRoleHierarchyInterface
and ProvideRoleInterface
.
This commit is contained in:
@@ -12,7 +12,7 @@ use Chill\MainBundle\Entity\User;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
@@ -22,56 +22,56 @@ class BudgetElementVoter extends AbstractChillVoter implements ProvideRoleHierar
|
||||
const DELETE = 'CHILL_BUDGET_ELEMENT_DELETE';
|
||||
const UPDATE = 'CHILL_BUDGET_ELEMENT_UPDATE';
|
||||
const SHOW = 'CHILL_BUDGET_ELEMENT_SHOW';
|
||||
|
||||
|
||||
const ROLES = [
|
||||
self::CREATE,
|
||||
self::DELETE,
|
||||
self::SHOW,
|
||||
self::UPDATE
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var AuthorizationHelper
|
||||
*/
|
||||
protected $authorizationHelper;
|
||||
|
||||
|
||||
public function __construct(AuthorizationHelper $authorizationHelper)
|
||||
{
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected function supports($attribute, $subject)
|
||||
{
|
||||
return (\in_array($attribute, self::ROLES) && $subject instanceof AbstractElement)
|
||||
or
|
||||
($subject instanceof Person && \in_array($attribute, [ self::SHOW, self::CREATE ]));
|
||||
}
|
||||
|
||||
|
||||
protected function voteOnAttribute($attribute, $subject, \Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token)
|
||||
{
|
||||
$user = $token->getUser();
|
||||
|
||||
|
||||
if (FALSE === $user instanceof User) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return $this->authorizationHelper
|
||||
->userHasAccess($user, $subject, new Role($attribute));
|
||||
}
|
||||
|
||||
public function getRoles()
|
||||
|
||||
public function getRoles(): array
|
||||
{
|
||||
return self::ROLES;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getRolesWithHierarchy(): array
|
||||
{
|
||||
return [ 'Budget elements' => self::ROLES ];
|
||||
}
|
||||
|
||||
public function getRolesWithoutScope()
|
||||
return ['Budget elements' => self::ROLES];
|
||||
}
|
||||
|
||||
public function getRolesWithoutScope(): array
|
||||
{
|
||||
return self::ROLES;
|
||||
}
|
||||
|
Reference in New Issue
Block a user