src/StartPlatz/Bundle/GruendungsstipendiumBundle/Security/GsApplicationVoter.php line 10

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\StartPlatz\Bundle\GruendungsstipendiumBundle\Security;
  3. use App\StartPlatz\Bundle\StartupBundle\Entity\Application;
  4. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  6. use Symfony\Component\Security\Core\Security;
  7. class GsApplicationVoter extends Voter
  8. {
  9.     public const APPROVE 'GS_APPROVE';
  10.     public const REJECT 'GS_REJECT';
  11.     public const ADMIT_JURY 'GS_ADMIT_JURY';
  12.     public const START_FUNDING 'GS_START_FUNDING';
  13.     public const CLOSE_PARTICIPATION 'GS_CLOSE_PARTICIPATION';
  14.     public const FINALIZE 'GS_FINALIZE';
  15.     public const LINK_MEMBER 'GS_LINK_MEMBER';
  16.     public const LINK_TEAM 'GS_LINK_TEAM';
  17.     public const RESET 'GS_RESET';
  18.     public const DELETE 'GS_DELETE';
  19.     private const SUPPORTED = [
  20.         self::APPROVE,
  21.         self::REJECT,
  22.         self::ADMIT_JURY,
  23.         self::START_FUNDING,
  24.         self::CLOSE_PARTICIPATION,
  25.         self::FINALIZE,
  26.         self::LINK_MEMBER,
  27.         self::LINK_TEAM,
  28.         self::RESET,
  29.         self::DELETE,
  30.     ];
  31.     public function __construct(
  32.         private readonly Security $security
  33.     ) {}
  34.     protected function supports(string $attribute$subject): bool
  35.     {
  36.         return in_array($attributeself::SUPPORTEDtrue)
  37.             && $subject instanceof Application;
  38.     }
  39.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  40.     {
  41.         if (!$this->security->isGranted('ROLE_ADMIN')) {
  42.             return false;
  43.         }
  44.         return match ($attribute) {
  45.             self::RESETself::DELETE => $this->security->isGranted('ROLE_MASTER'),
  46.             default => true,
  47.         };
  48.     }
  49. }