src/Voters/OrganisationVoter.php line 10

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