mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
add missing roles and adapt role voter for exports houshold and activity
This commit is contained in:
@@ -13,10 +13,10 @@ namespace Chill\ActivityBundle\Security\Authorization;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Security\Authorization\AbstractChillVoter;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\MainBundle\Security\Authorization\VoterHelperFactoryInterface;
|
||||
use Chill\MainBundle\Security\Authorization\VoterHelperInterface;
|
||||
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
|
||||
|
||||
use function in_array;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
|
||||
class ActivityStatsVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterface
|
||||
{
|
||||
@@ -24,14 +24,14 @@ class ActivityStatsVoter extends AbstractChillVoter implements ProvideRoleHierar
|
||||
|
||||
public const STATS = 'CHILL_ACTIVITY_STATS';
|
||||
|
||||
/**
|
||||
* @var AuthorizationHelper
|
||||
*/
|
||||
protected $helper;
|
||||
protected VoterHelperInterface $helper;
|
||||
|
||||
public function __construct(AuthorizationHelper $helper)
|
||||
public function __construct(VoterHelperFactoryInterface $voterHelperFactory)
|
||||
{
|
||||
$this->helper = $helper;
|
||||
$this->helper = $voterHelperFactory
|
||||
->generate(self::class)
|
||||
->addCheckFor(Center::class, [self::STATS, self::LISTS])
|
||||
->build();
|
||||
}
|
||||
|
||||
public function getRoles(): array
|
||||
@@ -49,30 +49,14 @@ class ActivityStatsVoter extends AbstractChillVoter implements ProvideRoleHierar
|
||||
return $this->getAttributes();
|
||||
}
|
||||
|
||||
protected function getSupportedClasses()
|
||||
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
|
||||
{
|
||||
return [Center::class];
|
||||
}
|
||||
|
||||
protected function isGranted($attribute, $object, $user = null)
|
||||
{
|
||||
if (!$user instanceof \Symfony\Component\Security\Core\User\UserInterface) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->helper->userHasAccess($user, $object, $attribute);
|
||||
return $this->helper->voteOnAttribute($attribute, $subject, $token);
|
||||
}
|
||||
|
||||
protected function supports($attribute, $subject)
|
||||
{
|
||||
if (
|
||||
$subject instanceof Center
|
||||
&& in_array($attribute, $this->getAttributes(), true)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return $this->helper->supports($attribute, $subject);
|
||||
}
|
||||
|
||||
private function getAttributes()
|
||||
|
Reference in New Issue
Block a user