feat: assignment call off

This commit is contained in:
Björn Fromme
2024-11-06 21:04:33 +01:00
parent ca0c965058
commit ef7871f1d4
12 changed files with 181 additions and 23 deletions
+15 -3
View File
@@ -17,6 +17,7 @@ class AssignmentVoter extends Voter
public const EDIT = 'EDIT';
public const APPLY = 'APPLY';
public const PUBLISH = 'PUBLISH';
public const CALL_OFF = 'CALL_OFF';
public function __construct(
private readonly Security $security,
@@ -30,7 +31,7 @@ class AssignmentVoter extends Voter
return false;
}
return in_array($attribute, [static::VIEW, static::EDIT, static::APPLY, static::PUBLISH]);
return in_array($attribute, [static::VIEW, static::EDIT, static::APPLY, static::PUBLISH, static::CALL_OFF]);
}
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
@@ -54,8 +55,19 @@ class AssignmentVoter extends Voter
&& $this->security->isGranted('ROLE_ADMINISTRATIVE');
}
// Only allow applications to published assignments
if (Assignment::STATUS_DRAFT === $assignment->getStatus()) {
// Only users with administrative role may call off assignments
if (static::CALL_OFF === $attribute) {
return Assignment::STATUS_CALLED_OFF !== $assignment->getStatus()
&& $this->security->isGranted('ROLE_ADMINISTRATIVE');
}
// Only allow applications to published, not deleted and not called off assignments
if (
true === in_array($assignment->getStatus(), [
Assignment::STATUS_DRAFT,
Assignment::STATUS_DELETED,
Assignment::STATUS_CALLED_OFF,
])) {
return false;
}