add default voter
Some checks failed
ci/woodpecker/push/woodpecker/2 Pipeline failed
ci/woodpecker/push/woodpecker/1 Pipeline failed

This commit is contained in:
Simon Vieille 2024-03-25 15:46:53 +01:00
parent e81b11c5ec
commit fcecf74f90
Signed by: deblan
GPG key ID: 579388D585F70417

View file

@ -0,0 +1,51 @@
<?php
namespace App\Security\Voter;
use App\Core\Entity\EntityInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\User\UserInterface;
class EntityVoter extends Voter
{
public const EDIT = 'edit';
public const VIEW = 'show';
public const DELETE = 'delete';
protected function supports(string $attribute, mixed $subject): bool
{
// replace with your own logic
// https://symfony.com/doc/current/security/voters.html
return in_array($attribute, [self::EDIT, self::VIEW, self::DELETE])
&& $subject instanceof EntityInterface;
}
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
$user = $token->getUser();
if (!$user instanceof UserInterface) {
return false;
}
switch ($attribute) {
case self::EDIT:
return true;
break;
case self::VIEW:
return true;
break;
case self::DELETE:
return true;
break;
}
return false;
}
}