mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-19 00:34:24 +00:00
63 lines
1.9 KiB
PHP
63 lines
1.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Chill\PersonBundle\Security\Authorization;
|
|
|
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument;
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
|
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
|
|
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
|
use UnexpectedValueException;
|
|
|
|
/**
|
|
* Voter for AccompanyingPeriodWorkEvaluationDocument.
|
|
*
|
|
* Delegates to the sames authorization than for Evalution
|
|
*/
|
|
class AccompanyingPeriodWorkEvaluationDocumentVoter extends Voter
|
|
{
|
|
public const SEE = 'CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_EVALUATION_DOCUMENT_SHOW';
|
|
|
|
private AccessDecisionManagerInterface $accessDecisionManager;
|
|
|
|
public function __construct(AccessDecisionManagerInterface $accessDecisionManager)
|
|
{
|
|
$this->accessDecisionManager = $accessDecisionManager;
|
|
}
|
|
|
|
protected function supports($attribute, $subject)
|
|
{
|
|
return $subject instanceof AccompanyingPeriodWorkEvaluationDocument
|
|
&& self::SEE === $attribute;
|
|
}
|
|
|
|
/**
|
|
* @param string $attribute
|
|
* @param AccompanyingPeriodWorkEvaluationDocument $subject
|
|
*
|
|
* @return bool|void
|
|
*/
|
|
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
|
|
{
|
|
switch ($attribute) {
|
|
case self::SEE:
|
|
return $this->accessDecisionManager->decide(
|
|
$token,
|
|
[AccompanyingPeriodWorkEvaluationVoter::SEE],
|
|
$subject->getAccompanyingPeriodWorkEvaluation()
|
|
);
|
|
|
|
default:
|
|
throw new UnexpectedValueException("The attribute {$attribute} is not supported");
|
|
}
|
|
}
|
|
}
|