src/Bundles/TemplateBundle/Security/Voter/BaseTemplateModifyVoter.php line 13

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Bundles\TemplateBundle\Security\Voter;
  4. use App\Bundles\UserBundle\Entity\User;
  5. use App\Bundles\UserBundle\Enum\SystemPermissionEnum;
  6. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  7. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  8. use Symfony\Component\Security\Core\Security;
  9. class BaseTemplateModifyVoter extends Voter
  10. {
  11.     public function __construct(private readonly Security $security)
  12.     {
  13.     }
  14.     protected function supports(string $attribute$subject): bool
  15.     {
  16.         return $attribute === SystemPermissionEnum::SINGLE_TEMPLATE_DELETE->value ||
  17.             $attribute === SystemPermissionEnum::SINGLE_TEMPLATE_SHARE->value ||
  18.             $attribute === SystemPermissionEnum::SINGLE_TEMPLATE_EDIT->value;
  19.     }
  20.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  21.     {
  22.         /** @var User $user */
  23.         $user $this->security->getUser();
  24.         return $subject->getUser() === $user;
  25.     }
  26. }