notification: add show action

This commit is contained in:
2021-12-28 22:35:15 +01:00
parent f453dbb543
commit 1ad6a958e2
5 changed files with 133 additions and 13 deletions

View File

@@ -0,0 +1,51 @@
<?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\MainBundle\Security\Authorization;
use Chill\MainBundle\Entity\Notification;
use Chill\MainBundle\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use UnexpectedValueException;
final class NotificationVoter extends Voter
{
public const SEE = 'chill_main_notification_see';
public const UPDATE = 'chill_main_notification_update';
protected function supports($attribute, $subject): bool
{
return $subject instanceof Notification;
}
/**
* @param string $attribute
* @param Notification $subject
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
$user = $token->getUser();
if (!$user instanceof User) {
return false;
}
switch ($attribute) {
case self::SEE:
return $subject->getSender() === $user || $subject->getAddressees()->contains($user);
default:
throw new UnexpectedValueException("this subject {$subject} is not implemented");
}
}
}