2024-03-20 23:48:18 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Wallabag\Security\Voter;
|
|
|
|
|
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
|
|
|
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
|
|
|
use Symfony\Component\Security\Core\Security;
|
|
|
|
use Wallabag\Entity\IgnoreOriginInstanceRule;
|
|
|
|
|
|
|
|
class IgnoreOriginInstanceRuleVoter extends Voter
|
|
|
|
{
|
|
|
|
public const EDIT = 'EDIT';
|
|
|
|
public const DELETE = 'DELETE';
|
|
|
|
|
2025-04-05 13:54:27 +02:00
|
|
|
public function __construct(
|
2025-04-05 13:59:36 +02:00
|
|
|
private readonly Security $security,
|
2025-04-05 13:54:27 +02:00
|
|
|
) {
|
2024-03-20 23:48:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function supports(string $attribute, $subject): bool
|
|
|
|
{
|
|
|
|
if (!$subject instanceof IgnoreOriginInstanceRule) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!\in_array($attribute, [self::EDIT, self::DELETE], true)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
|
|
|
|
{
|
2025-04-05 13:56:56 +02:00
|
|
|
return match ($attribute) {
|
|
|
|
self::EDIT, self::DELETE => $this->security->isGranted('ROLE_SUPER_ADMIN'),
|
|
|
|
default => false,
|
|
|
|
};
|
2024-03-20 23:48:18 +01:00
|
|
|
}
|
|
|
|
}
|