src/Security/Voter/QaAdminVoter.php line 12

Open in your IDE?
  1. <?php
  2. namespace MedBrief\MSR\Security\Voter;
  3. use EasyCorp\Bundle\EasyAdminBundle\Security\Permission;
  4. use Override;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  7. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. class QaAdminVoter extends Voter
  10. {
  11. public function __construct(private readonly AuthorizationCheckerInterface $authorizationChecker)
  12. {
  13. }
  14. #[Override]
  15. protected function supports($attribute, $subject): bool
  16. {
  17. // replace with your own logic
  18. // https://symfony.com/doc/current/security/voters.html
  19. return $attribute == Permission::EA_EXECUTE_ACTION;
  20. }
  21. #[Override]
  22. protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
  23. {
  24. $user = $token->getUser();
  25. // if the user is anonymous, do not grant access
  26. if (!$user instanceof UserInterface) {
  27. return false;
  28. }
  29. // Any QA Admin Permission is Granted to Super Admins
  30. return $this->authorizationChecker->isGranted('ROLE_SUPER_ADMIN');
  31. }
  32. }