327 pinned comment

This commit is contained in:
2022-01-10 20:55:37 +00:00
committed by Julien Fastré
parent 01d51da7e1
commit b153fc19f6
10 changed files with 328 additions and 136 deletions

View File

@@ -0,0 +1,42 @@
<?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");
}
}
}