fix: Strict types interfaces: VoterHelperInterface, ProvideRoleHierarchyInterface and ProvideRoleInterface.

This commit is contained in:
Pol Dellaiera
2021-11-23 10:40:34 +01:00
parent 05dda33a7a
commit 328b4c4596
21 changed files with 187 additions and 255 deletions

View File

@@ -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;
}