src/Voters/MediaVoter.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Voters;
  3. use App\Entity\Media\Media;
  4. use App\Entity\Person\User;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. class MediaVoter extends AppVoter
  8. {
  9.     protected function supports($attribute$subject null)
  10.     {
  11.         if (!in_array($attribute, [self::CREATEself::EDIT])) {
  12.             return false;
  13.         }
  14.         if (!$subject instanceof Media && $subject != null) {
  15.             return false;
  16.         }
  17.         return true;
  18.     }
  19.     protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  20.     {
  21.         $user $token->getUser();
  22.         if (!$user instanceof UserInterface) {
  23.             return false;
  24.         }
  25.         switch ($attribute) {
  26.             case self::CREATE:
  27.                 if ($this->decisionManager->decide($token, [
  28.                     User::ROLE_CONSENTZ_ADMIN,
  29.                     User::ROLE_SUPER_CLINIC_ADMIN,
  30.                     User::ROLE_CLINIC_ADMIN
  31.                 ])
  32.                 ) {
  33.                     return true;
  34.                 }
  35.                 break;
  36.             case self::EDIT:
  37.                 if ($this->decisionManager->decide($token, [
  38.                     User::ROLE_CONSENTZ_ADMIN,
  39.                     User::ROLE_SUPER_CLINIC_ADMIN,
  40.                     User::ROLE_CLINIC_ADMIN
  41.                 ])
  42.                 ) {
  43.                     return true;
  44.                 }
  45.                 break;
  46.         }
  47.         return false;
  48.     }
  49. }