Use the new VoterHelper in voters

This commit is contained in:
Jan Böhmer 2023-08-28 22:00:25 +02:00
parent fc6643bd6f
commit 6be55d1837
16 changed files with 146 additions and 162 deletions

View file

@ -24,18 +24,26 @@ namespace App\Security\Voter;
use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User;
use App\Services\UserSystem\VoterHelper;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class GroupVoter extends ExtendedVoter
final class GroupVoter extends Voter
{
public function __construct(private readonly VoterHelper $helper)
{
}
/**
* Similar to voteOnAttribute, but checking for the anonymous user is already done.
* The current user (or the anonymous user) is passed by $user.
*
* @param string $attribute
*/
protected function voteOnUser(string $attribute, $subject, User $user): bool
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
return $this->resolver->inherit($user, 'groups', $attribute) ?? false;
return $this->helper->isGranted($token, 'groups', $attribute);
}
/**
@ -49,7 +57,7 @@ class GroupVoter extends ExtendedVoter
protected function supports(string $attribute, $subject): bool
{
if (is_a($subject, Group::class, true)) {
return $this->resolver->isValidOperation('groups', $attribute);
return $this->helper->isValidOperation('groups', $attribute);
}
return false;