src/Security/Authorization/Voter/SecretVoter.php line 8

Open in your IDE?
  1. <?php
  2. namespace App\Security\Authorization\Voter;
  3.  
  4. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
  6.  
  7. class SecretVoter implements VoterInterface
  8. {
  9.     const VIEW 'VIEW';
  10.     const EDIT 'EDIT';
  11.     const DELETE 'DELETE';
  12.     const CREATE 'CREATE';
  13.     const LIST = 'LIST';
  14.  
  15.     public function supportsAttribute($attribute)
  16.     {
  17.  
  18.         return in_array($attribute, array(
  19.             self::VIEW,
  20.             self::EDIT,
  21.             self::DELETE,
  22.             self::CREATE,
  23.             self::LIST,
  24.         ));
  25.     }
  26.  
  27.     public function supportsClass($class)
  28.     {
  29.  
  30.         $supportedClass 'App\Entity\Secret';
  31.  
  32.         if (is_string($class)) {
  33.             if ($class === $supportedClass) {
  34.                 return true;
  35.             } else {
  36.                 return false;
  37.             }
  38.         }
  39.         if(is_null($class)) {
  40.             return true;
  41.         }
  42.         return $supportedClass === get_class($class) || is_subclass_of(get_class($class), $supportedClass);
  43.     }
  44.  
  45.  
  46.     public function vote(TokenInterface $token$entity, array $attributes)
  47.     {
  48.         $user $token->getUser();
  49.         if (!is_object($user)) {
  50.             return VoterInterface::ACCESS_DENIED;
  51.         }
  52.  
  53.         if (!$this->supportsClass($entity)) {
  54.             return VoterInterface::ACCESS_ABSTAIN;
  55.         }
  56.         $attribute $attributes[0];
  57.         if(is_array($attribute)) {
  58.             $attribute $attribute[0];
  59.         };
  60. // kalydig 2022.01.25
  61.         if($user->hasRole("SuperUsers")) {
  62.             return VoterInterface::ACCESS_GRANTED;
  63.         }
  64. //kalydi
  65.         switch($attribute) {
  66.             case self::LIST:
  67.                 return VoterInterface::ACCESS_GRANTED;
  68.                 break;
  69.             case self::VIEW:
  70.                 if($entity->getEnvironmentType()->getName() != "prod") {
  71.                     return VoterInterface::ACCESS_GRANTED;
  72.                 } elseif($user->hasRole("SuperUsers") || $user->hasRole("Deliveries") || $user->hasRole("CSMs")) {
  73.                     return VoterInterface::ACCESS_GRANTED;
  74.                 }  else {
  75.                     return VoterInterface::ACCESS_DENIED;
  76.                 }
  77.                 break;
  78.             case self::DELETE:
  79.                 if($user->hasRole("SuperUsers")) {
  80.                     return VoterInterface::ACCESS_GRANTED;
  81.                 } else {
  82.                     return VoterInterface::ACCESS_DENIED;
  83.                 }
  84.                 break;
  85.             case self::EDIT:
  86.                 if($entity->getEnvironmentType()->getName() != "prod") {
  87.                     return VoterInterface::ACCESS_GRANTED;
  88.                 } elseif($user->hasRole("SuperUsers") || $user->hasRole("Deliveries")) {
  89.                     return VoterInterface::ACCESS_GRANTED;
  90.                 }  else {
  91.                 return VoterInterface::ACCESS_DENIED;
  92.                }
  93.                 break;
  94.             case self::CREATE:
  95.                 if($user->hasRole("SuperUsers") || $user->hasRole("Deliveries")) {
  96.                     return VoterInterface::ACCESS_GRANTED;
  97.                 } else {
  98.                     return VoterInterface::ACCESS_DENIED;
  99.                 }
  100.                 break;
  101.         }
  102. // kalydig 2022.01.25
  103.         return VoterInterface::ACCESS_DENIED;
  104.     }
  105. }