From be3633c39a00e9d697701a02278fe53ea71676bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Thu, 12 Oct 2023 14:57:30 +0200 Subject: [PATCH] Feat: Consider availability of dispositions in voter --- src/Security/Voter/ApplicationVoter.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Security/Voter/ApplicationVoter.php b/src/Security/Voter/ApplicationVoter.php index 274f1d4..e850723 100644 --- a/src/Security/Voter/ApplicationVoter.php +++ b/src/Security/Voter/ApplicationVoter.php @@ -32,18 +32,23 @@ class ApplicationVoter extends Voter $application = $subject; if ($user->hasRole('ROLE_ADMINISTRATIVE')) { + $assignment = $application->getAssignment(); return match ($attribute) { static::VIEW => true, static::DELETE => Application::STATUS_REJECTED === $application->getStatus(), - static::DISPOSE, static::REJECT => Application::STATUS_REJECTED !== $application->getStatus(), + static::REJECT => Application::STATUS_REJECTED !== $application->getStatus(), + static::DISPOSE => Application::STATUS_REJECTED !== $application->getStatus() + && $assignment->getAvailableDispositions() > $assignment->getDispositions()->count(), default => false, }; } if ($user->hasRole('ROLE_TEAMER')) { return match ($attribute) { - static::DELETE => $user->getTeamer() === $application->getTeamer() && Application::STATUS_REJECTED === $application->getStatus(), - static::VIEW => $user->getTeamer() === $application->getTeamer() && Application::STATUS_REJECTED !== $application->getStatus(), + static::DELETE => $user->getTeamer() === $application->getTeamer() + && Application::STATUS_REJECTED === $application->getStatus(), + static::VIEW => $user->getTeamer() === $application->getTeamer() + && Application::STATUS_REJECTED !== $application->getStatus(), default => false, }; }