mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-05 12:59:44 +00:00
56 lines
1.8 KiB
PHP
56 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
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 implements ChillVoterInterface
|
|
{
|
|
final public const ALL = [
|
|
self::SEE,
|
|
self::STATS,
|
|
];
|
|
|
|
final public const SEE = 'CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_EVALUATION_SHOW';
|
|
|
|
final public const STATS = 'CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_EVALUATION_STATS';
|
|
|
|
public function __construct(private readonly Security $security)
|
|
{
|
|
}
|
|
|
|
protected function supports($attribute, $subject)
|
|
{
|
|
return $subject instanceof AccompanyingPeriodWorkEvaluation
|
|
&& in_array($attribute, self::ALL, true);
|
|
}
|
|
|
|
/**
|
|
* @param string $attribute
|
|
* @param AccompanyingPeriodWorkEvaluation $subject
|
|
*/
|
|
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
|
|
{
|
|
return match ($attribute) {
|
|
self::STATS => $this->security->isGranted(AccompanyingPeriodVoter::STATS, $subject),
|
|
self::SEE => $this->security->isGranted(AccompanyingPeriodWorkVoter::SEE, $subject->getAccompanyingPeriodWork()),
|
|
default => throw new UnexpectedValueException("attribute {$attribute} is not supported"),
|
|
};
|
|
}
|
|
}
|