<?php
namespace MedBrief\MSR\Security\Voter;
use EasyCorp\Bundle\EasyAdminBundle\Security\Permission;
use Override;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\User\UserInterface;
class QaAdminVoter extends Voter
{
public function __construct(private readonly AuthorizationCheckerInterface $authorizationChecker)
{
}
#[Override]
protected function supports($attribute, $subject): bool
{
// replace with your own logic
// https://symfony.com/doc/current/security/voters.html
return $attribute == Permission::EA_EXECUTE_ACTION;
}
#[Override]
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
$user = $token->getUser();
// if the user is anonymous, do not grant access
if (!$user instanceof UserInterface) {
return false;
}
// Any QA Admin Permission is Granted to Super Admins
return $this->authorizationChecker->isGranted('ROLE_SUPER_ADMIN');
}
}