Notification: add a counter for notifications

This commit is contained in:
2022-01-04 16:44:01 +01:00
parent 5bb5468198
commit 3a207b2c5d
12 changed files with 211 additions and 29 deletions

View File

@@ -20,6 +20,13 @@ use UnexpectedValueException;
final class NotificationVoter extends Voter
{
/**
* Allow to add a comment on a notification.
*
* May apply on both @see{NotificationComment::class} and @see{Notification::class}.
*/
public const COMMENT_ADD = 'CHILL_MAIN_NOTIFICATION_COMMENT_ADD';
public const COMMENT_EDIT = 'CHILL_MAIN_NOTIFICATION_COMMENT_EDIT';
public const NOTIFICATION_SEE = 'CHILL_MAIN_NOTIFICATION_SEE';
@@ -47,20 +54,30 @@ final class NotificationVoter extends Voter
if ($subject instanceof Notification) {
switch ($attribute) {
case self::COMMENT_ADD:
return false === $subject->isSystem() && (
$subject->getAddressees()->contains($user) || $subject->getSender() === $user
);
case self::NOTIFICATION_SEE:
case self::NOTIFICATION_TOGGLE_READ_STATUS:
return $subject->getSender() === $user || $subject->getAddressees()->contains($user);
case self::NOTIFICATION_UPDATE:
return $subject->getSender() === $user;
return $subject->getSender() === $user && false === $subject->isSystem();
default:
throw new UnexpectedValueException("this subject {$attribute} is not implemented");
}
} elseif ($subject instanceof NotificationComment) {
switch ($attribute) {
case self::COMMENT_ADD:
return false === $subject->getNotification()->isSystem() && (
$subject->getNotification()->getAddressees()->contains($user) || $subject->getNotification()->getSender() === $user
);
case self::COMMENT_EDIT:
return $subject->getCreatedBy() === $user;
return $subject->getCreatedBy() === $user && false === $subject->getNotification()->isSystem();
default:
throw new UnexpectedValueException("this subject {$attribute} is not implemented");