src/Voters/SuperAdminVoter.php line 9

Open in your IDE?
  1. <?php
  2. namespace App\Voters;
  3. use App\Entity\Person\SuperClinicAdmin;
  4. use App\Entity\Person\User;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. class SuperAdminVoter extends AppVoter
  7. {
  8.     protected function supports($attribute$subject)
  9.     {
  10.         return $subject instanceof SuperClinicAdmin && $attribute == self::EDIT;
  11.     }
  12.     protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  13.     {
  14.         /** @var User $user */
  15.         $user $token->getUser();
  16.         return $this->decisionManager->decide($token,
  17.             [User::ROLE_CONSENTZ_ADMIN]) || ($user instanceof SuperClinicAdmin && $user->getOrganisation() === $subject->getOrganisation());
  18.     }
  19. }