mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
notification: add comment in show and append comment
This commit is contained in:
@@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\MainBundle\Security\Authorization;
|
||||
|
||||
use Chill\MainBundle\Entity\Notification;
|
||||
use Chill\MainBundle\Entity\NotificationComment;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
||||
@@ -19,18 +20,20 @@ use UnexpectedValueException;
|
||||
|
||||
final class NotificationVoter extends Voter
|
||||
{
|
||||
public const COMMENT_EDIT = 'CHILL_MAIN_NOTIFICATION_COMMENT_EDIT';
|
||||
|
||||
public const SEE = 'chill_main_notification_see';
|
||||
|
||||
public const UPDATE = 'chill_main_notification_update';
|
||||
|
||||
protected function supports($attribute, $subject): bool
|
||||
{
|
||||
return $subject instanceof Notification;
|
||||
return $subject instanceof Notification || $subject instanceof NotificationComment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $attribute
|
||||
* @param Notification $subject
|
||||
* @param mixed $subject
|
||||
*/
|
||||
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
|
||||
{
|
||||
@@ -40,12 +43,24 @@ final class NotificationVoter extends Voter
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ($attribute) {
|
||||
case self::SEE:
|
||||
return $subject->getSender() === $user || $subject->getAddressees()->contains($user);
|
||||
if ($subject instanceof Notification) {
|
||||
switch ($attribute) {
|
||||
case self::SEE:
|
||||
return $subject->getSender() === $user || $subject->getAddressees()->contains($user);
|
||||
|
||||
default:
|
||||
throw new UnexpectedValueException("this subject {$subject} is not implemented");
|
||||
default:
|
||||
throw new UnexpectedValueException("this subject {$attribute} is not implemented");
|
||||
}
|
||||
} elseif ($subject instanceof NotificationComment) {
|
||||
switch ($attribute) {
|
||||
case self::COMMENT_EDIT:
|
||||
return $subject->getCreatedBy() === $user;
|
||||
|
||||
default:
|
||||
throw new UnexpectedValueException("this subject {$attribute} is not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
throw new UnexpectedValueException();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user