mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-21 17:54:24 +00:00
43 lines
1.2 KiB
PHP
43 lines
1.2 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\Comment;
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
|
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
|
use UnexpectedValueException;
|
|
|
|
class AccompanyingPeriodCommentVoter extends Voter
|
|
{
|
|
public const DELETE = 'CHILL_PERSON_ACCOMPANYING_PERIOD_COMMENT_DELETE';
|
|
|
|
public const EDIT = 'CHILL_PERSON_ACCOMPANYING_PERIOD_COMMENT_EDIT';
|
|
|
|
protected function supports($attribute, $subject)
|
|
{
|
|
return $subject instanceof Comment;
|
|
}
|
|
|
|
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
|
|
{
|
|
/** @var Comment $subject */
|
|
switch ($attribute) {
|
|
case self::EDIT:
|
|
case self::DELETE:
|
|
return $subject->getCreator() === $token->getUser();
|
|
|
|
default:
|
|
throw new UnexpectedValueException("This attribute {$attribute} is not supported");
|
|
}
|
|
}
|
|
}
|