From a125c8d90b4de6766f181ca744f2c266c7e673ed Mon Sep 17 00:00:00 2001 From: Tomas Hermanek Date: Wed, 14 Aug 2024 10:26:59 +0200 Subject: [PATCH] Refactor business logic vote handling in AbstractVoter --- src/Security/Voter/AbstractVoter.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Security/Voter/AbstractVoter.php b/src/Security/Voter/AbstractVoter.php index 87fef08..2cfe048 100644 --- a/src/Security/Voter/AbstractVoter.php +++ b/src/Security/Voter/AbstractVoter.php @@ -38,17 +38,18 @@ protected function voteOnAttribute(string $attribute, mixed $subject, TokenInter return true; } - // If specific business logic allows, grant access - if ($this->businessLogicVote($attribute, $subject, $user)) { - return true; + // Allow to define custom business logic vote + $vote = $this->businessLogicVote($attribute, $subject, $user); + if (false === (null === $vote)) { + return $vote; } return $this->permissionVote($attribute, $subject, $user); } - protected function businessLogicVote(string $attribute, mixed $subject, AnzuUser $user): bool + protected function businessLogicVote(string $attribute, mixed $subject, AnzuUser $user): ?bool { - return false; + return null; } protected function permissionVote(string $attribute, mixed $subject, AnzuUser $user): bool