src/Security/Voter/UserRoleVoter.php line 13
<?phpdeclare(strict_types=1);namespace App\Security\Voter;use App\Entity\User;use App\Enum\BaseRoleEnum;use App\Enum\RoleEnum;use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;use Symfony\Component\Security\Core\Authorization\Voter\Voter;final class UserRoleVoter extends Voter{private const ROLE_ADMIN = BaseRoleEnum::ROLE_ADMIN;private const EXTERNAL_PARTNER = RoleEnum::EXTERNAL_PARTNER;private const EXTERNAL_STAKEHOLDER = RoleEnum::EXTERNAL_STAKEHOLDER;private const GENERAL_MANAGER = RoleEnum::GENERAL_MANAGER;private const PROJECT_EMPLOYEE = RoleEnum::PROJECT_EMPLOYEE;private const PROJECT_MANAGER = RoleEnum::PROJECT_MANAGER;protected function supports(string $attribute, $subject): bool{return in_array($attribute,[self::EXTERNAL_PARTNER,self::EXTERNAL_STAKEHOLDER,self::GENERAL_MANAGER,self::PROJECT_EMPLOYEE,self::PROJECT_MANAGER]);}protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool{/** @var ?User $loggedUser */$loggedUser = $token->getUser();if (!$loggedUser) {return false;}if (in_array(self::ROLE_ADMIN, $loggedUser->getRoles())) {return false;}$currentRole = $loggedUser->getCurrentRoleInstitution()->getRole()->getKeyName();return $attribute === $currentRole;}}