Fix: Add dedicated process for withdrawal of applications by teamer

This commit is contained in:
Björn Fromme
2023-10-21 10:20:24 +02:00
parent e3dc2b22fd
commit 0fce77fbb7
3 changed files with 22 additions and 15 deletions
+17 -10
View File
@@ -11,6 +11,7 @@ class ApplicationVoter extends Voter
{
public const VIEW = 'VIEW';
public const DELETE = 'DELETE';
public const WITHDRAW = 'WITHDRAW';
public const DISPOSE = 'DISPOSE';
public const STATUS = 'STATUS';
@@ -20,7 +21,7 @@ class ApplicationVoter extends Voter
return false;
}
return in_array($attribute, [static::VIEW, static::DELETE, static::DISPOSE, static::STATUS]);
return in_array($attribute, [static::VIEW, static::WITHDRAW, static::DELETE, static::DISPOSE, static::STATUS]);
}
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
@@ -30,24 +31,30 @@ class ApplicationVoter extends Voter
/** @var Application $application */
$application = $subject;
$status = $application->getStatus();
if ($user->hasRole('ROLE_ADMINISTRATIVE')) {
$adminAttributes = [static::VIEW, static::DELETE, static::DISPOSE, static::STATUS];
$teamerAttributes = [static::VIEW, static::WITHDRAW, static::DELETE, static::STATUS];
if ($user->hasRole('ROLE_ADMINISTRATIVE') && in_array($attribute, $adminAttributes)) {
$assignment = $application->getAssignment();
return match ($attribute) {
static::VIEW, static::STATUS => Application::STATUS_REJECTED !== $application->getStatus(),
static::DELETE => Application::STATUS_REJECTED === $application->getStatus(),
static::DISPOSE => Application::STATUS_REJECTED !== $application->getStatus()
static::VIEW, static::STATUS => Application::STATUS_REJECTED !== $status,
static::DELETE => Application::STATUS_REJECTED === $status,
static::DISPOSE => Application::STATUS_REJECTED !== $status
&& $assignment->getAvailableDispositions() > $assignment->getDispositions()->count(),
default => false,
};
}
if ($user->hasRole('ROLE_TEAMER')) {
if ($user->hasRole('ROLE_TEAMER') && in_array($attribute, $teamerAttributes)) {
$teamer = $user->getTeamer();
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::WITHDRAW => $teamer === $application->getTeamer(),
static::DELETE => $teamer === $application->getTeamer()
&& Application::STATUS_REJECTED === $status,
static::VIEW => $teamer === $application->getTeamer()
&& Application::STATUS_REJECTED !== $status,
default => false,
};
}