vendor/datenwerk/ginger-bundle/Security/IntergartionVoter.php line 11

Open in your IDE?
  1. <?php
  2. namespace DW\GingerBundle\Security;
  3. use DW\GingerBundle\Entity\Integration;
  4. use DW\GingerBundle\Entity\User;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  7. use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
  8. class IntergartionVoter extends Voter
  9. {
  10.     const VIEW 'view';
  11.     const EDIT 'edit';
  12.     const CREATE 'create';
  13.     const DELETE 'delete';
  14.     private AccessDecisionManagerInterface $decisionManager;
  15.     public function __construct(AccessDecisionManagerInterface $decisionManager)
  16.     {
  17.         $this->decisionManager $decisionManager;
  18.     }
  19.     protected function supports($attribute$subject): bool
  20.     {
  21.         // if the attribute isn't one we support, return false
  22.         if (!in_array($attribute, array(self::VIEWself::EDITself::CREATEself::DELETE))) {
  23.             return false;
  24.         }
  25.         // only vote on integration objects inside this voter
  26.         if (!$subject instanceof Integration) {
  27.             return false;
  28.         }
  29.         return true;
  30.     }
  31.     protected function voteOnAttribute($attribute$subjectTokenInterface $token): bool
  32.     {
  33.         $user $token->getUser();
  34.         if (!$user instanceof User) {
  35.             // the user must be logged in; if not, deny access
  36.             return false;
  37.         }
  38.         return $this->decisionManager->decide($token, ['ROLE_GINGER_INTEGRATION_ADMIN']);
  39.     }
  40. }