src/Security/Voter/DemandVoter.php line 8

Open in your IDE?
  1. <?php
  2. namespace App\Security\Voter;
  3. use App\Entity\Demand;
  4. use Symfony\Component\Security\Core\User\UserInterface;
  5. class DemandVoter extends AbstractDeepVoter
  6. {
  7.     public const TRANSFER 'transfer';
  8.     public static $listAttribute 'list_demands';
  9.     protected function listAttribute(): string
  10.     {
  11.         return self::$listAttribute;
  12.     }
  13.     protected function createAttribute(): string
  14.     {
  15.         return 'none';
  16.     }
  17.     protected function supports($attribute$subject): bool
  18.     {
  19.         return parent::supports($attribute$subject)
  20.             || self::TRANSFER === $attribute
  21.         ;
  22.     }
  23.     protected function isSupportedSubject(object $subject): bool
  24.     {
  25.         return $subject instanceof Demand;
  26.     }
  27.     protected function canList(UserInterface $user): bool
  28.     {
  29.         return $user->isFirstLevelOrLower()
  30.             || $user->isAnAdmin()
  31.         ;
  32.     }
  33.     protected function canCreate(UserInterface $user): bool
  34.     {
  35.         return false;
  36.     }
  37.     protected function canRead(UserInterface $user): bool
  38.     {
  39.         return $user->isFirstLevelOrLower()
  40.             || $user->isAnAdmin()
  41.         ;
  42.     }
  43.     protected function canUpdate(UserInterface $user): bool
  44.     {
  45.         return $user->isCompanyDirector()
  46.             || $user->isMainAdmin()
  47.         ;
  48.     }
  49.     protected function canDelete(UserInterface $user): bool
  50.     {
  51.         return $user->isMainAdmin();
  52.     }
  53.     protected function additionalActions(string $attributeUserInterface $user): bool
  54.     {
  55.         if (self::TRANSFER === $attribute
  56.             && $user->isFirstLevelOrLower()
  57.         ) {
  58.             return true;
  59.         }
  60.         return false;
  61.     }
  62. }