mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-30 03:23:48 +00:00
Feature: Add a list export for evaluation, actions and household
This commit is contained in:
@@ -11,16 +11,25 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Security\Authorization;
|
||||
|
||||
use Chill\MainBundle\Security\Authorization\ChillVoterInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use UnexpectedValueException;
|
||||
use function in_array;
|
||||
|
||||
class AccompanyingPeriodWorkEvaluationVoter extends Voter
|
||||
class AccompanyingPeriodWorkEvaluationVoter extends Voter implements ChillVoterInterface
|
||||
{
|
||||
public const ALL = [
|
||||
self::SEE,
|
||||
self::STATS,
|
||||
];
|
||||
|
||||
public const SEE = 'CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_EVALUATION_SHOW';
|
||||
|
||||
public const STATS = 'CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_EVALUATION_STATS';
|
||||
|
||||
private Security $security;
|
||||
|
||||
public function __construct(Security $security)
|
||||
@@ -31,7 +40,7 @@ class AccompanyingPeriodWorkEvaluationVoter extends Voter
|
||||
protected function supports($attribute, $subject)
|
||||
{
|
||||
return $subject instanceof AccompanyingPeriodWorkEvaluation
|
||||
&& self::SEE === $attribute;
|
||||
&& in_array($attribute, self::ALL, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,6 +50,9 @@ class AccompanyingPeriodWorkEvaluationVoter extends Voter
|
||||
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
|
||||
{
|
||||
switch ($attribute) {
|
||||
case self::STATS:
|
||||
return $this->security->isGranted(AccompanyingPeriodWorkVoter::STATS, $subject);
|
||||
|
||||
case self::SEE:
|
||||
return $this->security->isGranted(AccompanyingPeriodWorkVoter::SEE, $subject->getAccompanyingPeriodWork());
|
||||
|
||||
|
@@ -11,8 +11,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Security\Authorization;
|
||||
|
||||
use Chill\MainBundle\Security\Authorization\ChillVoterInterface;
|
||||
use Chill\MainBundle\Security\Authorization\VoterHelperFactoryInterface;
|
||||
use Chill\MainBundle\Security\Authorization\VoterHelperInterface;
|
||||
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
@@ -20,8 +25,15 @@ use UnexpectedValueException;
|
||||
use function get_class;
|
||||
use function in_array;
|
||||
|
||||
class AccompanyingPeriodWorkVoter extends Voter
|
||||
class AccompanyingPeriodWorkVoter extends Voter implements ProvideRoleHierarchyInterface, ChillVoterInterface
|
||||
{
|
||||
public const ALL = [
|
||||
self::SEE,
|
||||
self::CREATE,
|
||||
self::UPDATE,
|
||||
self::DELETE,
|
||||
];
|
||||
|
||||
public const CREATE = 'CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_CREATE';
|
||||
|
||||
public const DELETE = 'CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_DELETE';
|
||||
@@ -32,9 +44,39 @@ class AccompanyingPeriodWorkVoter extends Voter
|
||||
|
||||
private Security $security;
|
||||
|
||||
public function __construct(Security $security)
|
||||
{
|
||||
private VoterHelperInterface $voterHelper;
|
||||
|
||||
public function __construct(
|
||||
Security $security,
|
||||
VoterHelperFactoryInterface $voterHelperFactory
|
||||
) {
|
||||
$this->security = $security;
|
||||
$this->voterHelper = $voterHelperFactory
|
||||
->generate(self::class)
|
||||
->addCheckFor(null, [self::CREATE])
|
||||
->addCheckFor(AccompanyingPeriod::class, [self::ALL])
|
||||
->addCheckFor(Person::class, [self::SEE, self::CREATE])
|
||||
->build();
|
||||
}
|
||||
|
||||
public function getRoles(): array
|
||||
{
|
||||
return [
|
||||
self::SEE,
|
||||
self::CREATE,
|
||||
self::UPDATE,
|
||||
self::DELETE,
|
||||
];
|
||||
}
|
||||
|
||||
public function getRolesWithHierarchy(): array
|
||||
{
|
||||
return ['Social actions' => $this->getRoles()];
|
||||
}
|
||||
|
||||
public function getRolesWithoutScope(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function supports($attribute, $subject): bool
|
||||
@@ -86,9 +128,4 @@ class AccompanyingPeriodWorkVoter extends Voter
|
||||
|
||||
throw new UnexpectedValueException(sprintf("attribute {$attribute} on instance %s is not supported", get_class($subject)));
|
||||
}
|
||||
|
||||
private function getRoles(): array
|
||||
{
|
||||
return [self::SEE, self::CREATE, self::UPDATE, self::DELETE];
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\PersonBundle\Security\Authorization;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Security\Authorization\ChillVoterInterface;
|
||||
use Chill\MainBundle\Security\Authorization\VoterHelperFactoryInterface;
|
||||
use Chill\MainBundle\Security\Authorization\VoterHelperInterface;
|
||||
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
|
||||
@@ -23,7 +24,7 @@ use Symfony\Component\Security\Core\Security;
|
||||
use UnexpectedValueException;
|
||||
use function in_array;
|
||||
|
||||
class HouseholdVoter extends Voter implements ProvideRoleHierarchyInterface
|
||||
class HouseholdVoter extends Voter implements ProvideRoleHierarchyInterface, ChillVoterInterface
|
||||
{
|
||||
public const EDIT = 'CHILL_PERSON_HOUSEHOLD_EDIT';
|
||||
|
||||
@@ -37,7 +38,9 @@ class HouseholdVoter extends Voter implements ProvideRoleHierarchyInterface
|
||||
public const STATS = 'CHILL_PERSON_HOUSEHOLD_STATS';
|
||||
|
||||
private const ALL = [
|
||||
self::EDIT, self::SEE,
|
||||
self::SEE,
|
||||
self::EDIT,
|
||||
self::STATS,
|
||||
];
|
||||
|
||||
private VoterHelperInterface $helper;
|
||||
@@ -60,7 +63,7 @@ class HouseholdVoter extends Voter implements ProvideRoleHierarchyInterface
|
||||
|
||||
public function getRolesWithHierarchy(): array
|
||||
{
|
||||
return ['Person' => $this->getRoles()];
|
||||
return ['Household' => $this->getRoles()];
|
||||
}
|
||||
|
||||
public function getRolesWithoutScope(): array
|
||||
|
Reference in New Issue
Block a user