src/Bundles/EpidemiologicalSurveillanceBundle/Security/Voter/SurveillanceCaseVoter.php line 13

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Bundles\EpidemiologicalSurveillanceBundle\Security\Voter;
  4. use App\Bundles\EpidemiologicalSurveillanceBundle\Entity\SurveillanceCase;
  5. use App\Bundles\OrganizationBundle\Service\Organization\OrganizationService;
  6. use App\Bundles\UserBundle\Enum\SystemPermissionEnum;
  7. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  8. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  9. class SurveillanceCaseVoter extends Voter
  10. {
  11.     public function __construct(
  12.         private readonly OrganizationService $organizationService,
  13.     ) {
  14.     }
  15.     /**
  16.      * @param string           $attribute
  17.      * @param SurveillanceCase $subject
  18.      *
  19.      * @return bool
  20.      */
  21.     protected function supports(string $attribute$subject): bool
  22.     {
  23.         return $attribute === SystemPermissionEnum::EPIDEMIOLOGICAL_SURVEILLANCE_CASE_VIEW->value;
  24.     }
  25.     /**
  26.      * @param string           $attribute
  27.      * @param SurveillanceCase $subject
  28.      * @param TokenInterface   $token
  29.      *
  30.      * @return bool
  31.      */
  32.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  33.     {
  34.         return $this->organizationService->hasPermissionByLocation($subject->getLocation());
  35.     }
  36. }