mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
52 lines
1.6 KiB
PHP
52 lines
1.6 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\Resource;
|
|
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;
|
|
|
|
class AccompanyingPeriodResourceVoter extends Voter
|
|
{
|
|
public const EDIT = 'CHILL_PERSON_ACCOMPANYING_PERIOD_RESOURCE_EDIT';
|
|
|
|
private AccessDecisionManagerInterface $accessDecisionManager;
|
|
|
|
public function __construct(AccessDecisionManagerInterface $accessDecisionManager)
|
|
{
|
|
$this->accessDecisionManager = $accessDecisionManager;
|
|
}
|
|
|
|
protected function supports($attribute, $subject)
|
|
{
|
|
return $subject instanceof Resource && self::EDIT === $attribute;
|
|
}
|
|
|
|
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
|
|
{
|
|
/** @var \Chill\PersonBundle\Entity\AccompanyingPeriod\Resource $subject */
|
|
switch ($attribute) {
|
|
case self::EDIT:
|
|
return $this->accessDecisionManager->decide(
|
|
$token,
|
|
[AccompanyingPeriodVoter::EDIT],
|
|
$subject->getAccompanyingPeriod()
|
|
);
|
|
|
|
default:
|
|
throw new UnexpectedValueException("attribute not supported: {$attribute}");
|
|
}
|
|
}
|
|
}
|