mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-03-05 23:09:35 +00:00
Use the new VoterHelper in voters
This commit is contained in:
parent
fc6643bd6f
commit
6be55d1837
16 changed files with 146 additions and 162 deletions
|
|
@ -24,29 +24,36 @@ namespace App\Security\Voter;
|
|||
|
||||
use App\Entity\Parts\Part;
|
||||
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;
|
||||
|
||||
/**
|
||||
* A Voter that votes on Part entities.
|
||||
*
|
||||
* See parts permissions for valid operations.
|
||||
*/
|
||||
class PartVoter extends ExtendedVoter
|
||||
final class PartVoter extends Voter
|
||||
{
|
||||
final public const READ = 'read';
|
||||
|
||||
public function __construct(private readonly VoterHelper $helper)
|
||||
{
|
||||
}
|
||||
|
||||
protected function supports($attribute, $subject): bool
|
||||
{
|
||||
if (is_a($subject, Part::class, true)) {
|
||||
return $this->resolver->isValidOperation('parts', $attribute);
|
||||
return $this->helper->isValidOperation('parts', $attribute);
|
||||
}
|
||||
|
||||
//Allow class name as subject
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function voteOnUser(string $attribute, $subject, User $user): bool
|
||||
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
|
||||
{
|
||||
//Null concealing operator means, that no
|
||||
return $this->resolver->inherit($user, 'parts', $attribute) ?? false;
|
||||
return $this->helper->isGranted($token, 'parts', $attribute);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue