src/Voters/AppointmentVoter.php line 9

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