Feat: Consider availability of dispositions in voter

This commit is contained in:
Björn Fromme
2023-10-12 14:57:30 +02:00
parent e188ec2bf0
commit be3633c39a
+8 -3
View File
@@ -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,
};
}