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

@@ -9,13 +9,13 @@ use Chill\MainBundle\Security\Authorization\AbstractChillVoter;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\User;
use Symfony\Component\Security\Core\Role\Role;
/**
* Voter for Third Party
*
*
*
*
*
*/
class ThirdPartyVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterface
@@ -29,13 +29,13 @@ class ThirdPartyVoter extends AbstractChillVoter implements ProvideRoleHierarchy
public const CREATE = 'CHILL_3PARTY_3PARTY_CREATE';
public const UPDATE = 'CHILL_3PARTY_3PARTY_UPDATE';
public const SHOW = 'CHILL_3PARTY_3PARTY_SHOW';
public function __construct(AuthorizationHelper $authorizationHelper)
{
$this->authorizationHelper = $authorizationHelper;
}
protected function supports($attribute, $subject)
{
if ($subject instanceof ThirdParty) {
@@ -43,42 +43,41 @@ class ThirdPartyVoter extends AbstractChillVoter implements ProvideRoleHierarchy
} elseif ($subject === NULL) {
return $attribute === self::CREATE || $attribute === self::SHOW ;
}
return false;
}
/**
*
*
* @param string $attribute
* @param ThirdParty|null $subject
* @param TokenInterface $token
* @return type
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
return true;
$user = $token->getUser();
if (!$user instanceof User) {
return false;
}
return true;
$centers = $this->authorizationHelper
->getReachableCenters($user, new Role($attribute));
if ($subject === NULL) {
return count($centers) > 0;
} elseif ($subject instanceof ThirdParty) {
return count(\array_intersect($centers, $subject->getCenters()->toArray())) > 0;
}
return false;
}
public function getRoles(): array
public function getRoles(): array
{
return [
self::CREATE, self::UPDATE, self::SHOW