src/Voters/DisabledUserVoter.php line 14

  1. <?php
  2. /*
  3.  *  @author Guerby Duval <info@tranzaksyon.com>
  4.  *  @link https://tranzaksyon.com
  5.  *  @copyright You are not allowed to remove this author "Guerby Duval <info@tranzaksyon.com>", the link "https://tranzaksyon.com" neither this copyright.
  6.  */
  7. namespace App\Voters;
  8. use App\Entity\User;
  9. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  10. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  11. class DisabledUserVoter extends Voter
  12. {
  13.     protected function supports(string $attributemixed $subject): bool
  14.     {
  15.         return true;
  16.     }
  17.     protected function voteOnAttribute(string $attributemixed $subjectTokenInterface $token): bool
  18.     {
  19.         $user $token->getUser();
  20.         if (!$user instanceof User || $user->getDisabledBy() !== null || ($user->getSriInfos()->count() > && $user->getSriInfos()[0]->getDisabledBy() !== null)) {
  21.             return false;
  22.         }
  23.         return true;
  24.     }
  25. }