Implement voting logic: separation of concerns

A separate AccompanyingCourseDocumentStoredObjectVoter was\
created to handle the specific access to a Stored object\
related to an Accompanying Course Document.
This commit is contained in:
2024-06-20 15:17:56 +02:00
parent 427f232ab8
commit d26fa6bde6
3 changed files with 67 additions and 3 deletions

View File

@@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Security\Authorization;
use Chill\DocStoreBundle\Security\Authorization\StoredObjectVoterInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
@@ -21,13 +22,13 @@ use Symfony\Component\Security\Core\Authorization\Voter\Voter;
*
* Delegates to the sames authorization than for Evalution
*/
class AccompanyingPeriodWorkEvaluationDocumentVoter extends Voter
class AccompanyingPeriodWorkEvaluationDocumentVoter extends Voter implements StoredObjectVoterInterface
{
final public const SEE = 'CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_EVALUATION_DOCUMENT_SHOW';
public function __construct(private readonly AccessDecisionManagerInterface $accessDecisionManager) {}
protected function supports($attribute, $subject)
public function supports($attribute, $subject): bool
{
return $subject instanceof AccompanyingPeriodWorkEvaluationDocument
&& self::SEE === $attribute;
@@ -39,7 +40,7 @@ class AccompanyingPeriodWorkEvaluationDocumentVoter extends Voter
*
* @return bool|void
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
public function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
return match ($attribute) {
self::SEE => $this->accessDecisionManager->decide(