<?php
namespace App\Security;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ModuleVoter extends Voter
{
private $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
protected function supports($attribute, $subject)
{
return in_array($attribute, ['MODULE_ACCESS']);
}
protected function voteOnAttribute($attribute, $object, TokenInterface $token)
{
$module = $object;
$user = $token->getUser();
$suiteUtils = $this->container->get('strategic_plan_utils');
//check the Access permission for the roles this user belongs to, grant or deny access based on that
$result_access=$suiteUtils->hasAccessToRole($user->getID(), $module, 'access');
foreach($result_access as $row){
if($row['access_override'] >= 0){
return true;
}
}
return false;
}
}