notification: add comment in show and append comment

This commit is contained in:
2021-12-28 23:25:12 +01:00
parent 9647785d8b
commit cb88a37885
5 changed files with 113 additions and 7 deletions

View File

@@ -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();
}
}