src/Bundles/ReportBundle/Security/ReportTemplateShareVoter.php line 14

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Bundles\ReportBundle\Security;
  4. use App\Bundles\ReportBundle\Entity\ReportTemplate;
  5. use App\Bundles\UserBundle\Entity\User;
  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. use Symfony\Component\Security\Core\Security;
  10. class ReportTemplateShareVoter extends Voter
  11. {
  12.     public function __construct(private readonly Security $security)
  13.     {
  14.     }
  15.     protected function supports(string $attribute$subject): bool
  16.     {
  17.         return $attribute === SystemPermissionEnum::SINGLE_REPORT_TEMPLATE_SHARE->value;
  18.     }
  19.     /** @param ReportTemplate $subject */
  20.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  21.     {
  22.         $user $this->security->getUser();
  23.         if (!$user instanceof User) {
  24.             return false;
  25.         }
  26.         if ($subject->getUser() === $user) {
  27.             return true;
  28.         }
  29.         return false;
  30.     }
  31. }