mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
add missing roles and adapt role voter for exports houshold and activity
This commit is contained in:
@@ -11,6 +11,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Security\Authorization;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Security\Authorization\VoterHelperFactoryInterface;
|
||||
use Chill\MainBundle\Security\Authorization\VoterHelperInterface;
|
||||
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
@@ -19,7 +23,7 @@ use Symfony\Component\Security\Core\Security;
|
||||
use UnexpectedValueException;
|
||||
use function in_array;
|
||||
|
||||
class HouseholdVoter extends Voter
|
||||
class HouseholdVoter extends Voter implements ProvideRoleHierarchyInterface
|
||||
{
|
||||
public const EDIT = 'CHILL_PERSON_HOUSEHOLD_EDIT';
|
||||
|
||||
@@ -36,17 +40,40 @@ class HouseholdVoter extends Voter
|
||||
self::EDIT, self::SEE,
|
||||
];
|
||||
|
||||
private VoterHelperInterface $helper;
|
||||
|
||||
private Security $security;
|
||||
|
||||
public function __construct(Security $security)
|
||||
public function __construct(Security $security, VoterHelperFactoryInterface $voterHelperFactory)
|
||||
{
|
||||
$this->security = $security;
|
||||
$this->helper = $voterHelperFactory
|
||||
->generate(self::class)
|
||||
->addCheckFor(Center::class, [self::STATS])
|
||||
->build();
|
||||
}
|
||||
|
||||
public function getRolesWithHierarchy(): array
|
||||
{
|
||||
return [ 'Person' => $this->getRoles() ];
|
||||
}
|
||||
|
||||
public function getRoles(): array
|
||||
{
|
||||
return [self::STATS];
|
||||
}
|
||||
|
||||
public function getRolesWithoutScope(): array
|
||||
{
|
||||
return $this->getRoles();
|
||||
}
|
||||
|
||||
protected function supports($attribute, $subject)
|
||||
{
|
||||
return $subject instanceof Household
|
||||
&& in_array($attribute, self::ALL, true);
|
||||
return ($subject instanceof Household
|
||||
&& in_array($attribute, self::ALL, true))
|
||||
|| $this->helper->supports($attribute, $subject)
|
||||
;
|
||||
}
|
||||
|
||||
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
|
||||
@@ -58,6 +85,9 @@ class HouseholdVoter extends Voter
|
||||
case self::EDIT:
|
||||
return $this->checkAssociatedMembersRole($subject, PersonVoter::UPDATE);
|
||||
|
||||
case self::STATS:
|
||||
return $this->voteOnAttribute($attribute, $subject, $token);
|
||||
|
||||
default:
|
||||
throw new UnexpectedValueException('attribute not supported');
|
||||
}
|
||||
|
Reference in New Issue
Block a user