mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
rename voter helepers
This commit is contained in:
@@ -22,6 +22,8 @@ namespace Chill\PersonBundle\Security\Authorization;
|
||||
use Chill\MainBundle\Security\Authorization\AbstractChillVoter;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\MainBundle\Security\Authorization\VoterHelperFactoryInterface;
|
||||
use Chill\MainBundle\Security\Authorization\VoterHelperInterface;
|
||||
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
@@ -42,52 +44,32 @@ class PersonVoter extends AbstractChillVoter implements ProvideRoleHierarchyInte
|
||||
|
||||
protected CenterResolverDispatcher $centerResolverDispatcher;
|
||||
|
||||
protected VoterHelperInterface $voter;
|
||||
|
||||
public function __construct(
|
||||
AuthorizationHelper $helper,
|
||||
CenterResolverDispatcher $centerResolverDispatcher
|
||||
CenterResolverDispatcher $centerResolverDispatcher,
|
||||
VoterHelperFactoryInterface $voterFactory
|
||||
) {
|
||||
$this->helper = $helper;
|
||||
$this->centerResolverDispatcher = $centerResolverDispatcher;
|
||||
$this->voter = $voterFactory
|
||||
->generate(self::class)
|
||||
->addCheckFor(Center::class, [self::STATS, self::LISTS, self::DUPLICATE])
|
||||
->addCheckFor(Person::class, [self::CREATE, self::UPDATE, self::SEE, self::DUPLICATE])
|
||||
->addCheckFor(null, [self::CREATE] )
|
||||
->build()
|
||||
;
|
||||
}
|
||||
|
||||
protected function supports($attribute, $subject)
|
||||
{
|
||||
if ($subject instanceof Person) {
|
||||
return \in_array($attribute, [
|
||||
self::CREATE, self::UPDATE, self::SEE, self::DUPLICATE
|
||||
]);
|
||||
} elseif ($subject instanceof Center) {
|
||||
return \in_array($attribute, [
|
||||
self::STATS, self::LISTS, self::DUPLICATE
|
||||
]);
|
||||
} elseif ($subject === null) {
|
||||
return $attribute === self::CREATE;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return $this->voter->supports($attribute, $subject);
|
||||
}
|
||||
|
||||
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
|
||||
{
|
||||
if (!$token->getUser() instanceof User) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($subject === null) {
|
||||
$centers = $this->helper->getReachableCenters($token->getUser(),
|
||||
new Role($attribute));
|
||||
|
||||
return count($centers) > 0;
|
||||
}
|
||||
|
||||
$center = $this->centerResolverDispatcher->resolveCenter($subject);
|
||||
|
||||
if (NULL === $center && $subject instanceof Person) {
|
||||
// person without any center are seen by everybody
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->helper->userHasAccess($token->getUser(), $subject, $attribute);
|
||||
return $this->voter->voteOnAttribute($attribute, $subject, $token);
|
||||
}
|
||||
|
||||
private function getAttributes()
|
||||
|
Reference in New Issue
Block a user