src/Security/ModuleVoter.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Security;
  3. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  4. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  5. use Symfony\Component\Security\Core\User\UserInterface;
  6. use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
  7. use Symfony\Component\DependencyInjection\ContainerInterface;
  8. class ModuleVoter extends Voter
  9. {
  10.     private $container;
  11.     public function __construct(ContainerInterface $container)
  12.     {
  13.         $this->container $container;
  14.     }
  15.     protected function supports($attribute$subject)
  16.     {
  17.         return in_array($attribute, ['MODULE_ACCESS']);
  18.     }
  19.     protected function voteOnAttribute($attribute$objectTokenInterface $token)
  20.     {
  21.         $module $object;
  22.         $user $token->getUser();
  23.         $suiteUtils $this->container->get('strategic_plan_utils');
  24.         //check the Access permission for the roles this user belongs to, grant or deny access based on that
  25.         $result_access=$suiteUtils->hasAccessToRole($user->getID(), $module'access');
  26.         foreach($result_access as $row){
  27.             if($row['access_override'] >= 0){
  28.                 return true;
  29.             }
  30.         }
  31.         return false;
  32.     }
  33. }