feat: prevent editing of assignments with applications or dispositions

This commit is contained in:
Björn Fromme
2024-01-10 12:26:01 +01:00
parent d994a6fa5f
commit 33d8d9ad26
3 changed files with 14 additions and 8 deletions
+8 -5
View File
@@ -30,18 +30,21 @@ class AssignmentVoter extends Voter
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
/** @var Assignment $assignment */
$assignment = $subject;
// All authenticated users may view assignments
if (static::VIEW === $attribute && null !== $token->getUser()) {
return true;
}
// Only users with administrative role may edit assignments
// Only users with administrative role may edit assignments without applications or dispositions
if (static::EDIT === $attribute && in_array('ROLE_ADMINISTRATIVE', $token->getRoleNames())) {
return true;
}
$assignmentCount = $assignment->getApplications()->count();
$dispositionCount = $assignment->getDispositions()->count();
/** @var Assignment $assignment */
$assignment = $subject;
return 0 === $assignmentCount && 0 === $dispositionCount;
}
// Only allow applications to open assignments
if (Assignment::STATUS_CLOSED === $assignment->getStatus()) {