mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add missing roles and adapt role voter for exports houshold and activity
This commit is contained in:
parent
78ea990189
commit
d716e0c2c2
@ -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()
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -318,6 +318,7 @@ CHILL_PERSON_ACCOMPANYING_PERIOD_FULL: Voir les détails, créer, supprimer et m
|
||||
CHILL_PERSON_ACCOMPANYING_COURSE_REASSIGN_BULK: Réassigner les parcours en lot
|
||||
CHILL_PERSON_ACCOMPANYING_PERIOD_SEE_DETAILS: Voir les détails d'une période d'accompagnement
|
||||
CHILL_PERSON_ACCOMPANYING_PERIOD_STATS: Statistiques sur les parcours d'accompagnement
|
||||
CHILL_PERSON_HOUSEHOLD_STATS: Statistiques sur les ménages
|
||||
|
||||
#period
|
||||
Period closed!: Période clôturée!
|
||||
|
Loading…
x
Reference in New Issue
Block a user