diff --git a/src/Controller/Admin/Assignment/EditController.php b/src/Controller/Admin/Assignment/EditController.php
index 233a6a5..c3af15e 100644
--- a/src/Controller/Admin/Assignment/EditController.php
+++ b/src/Controller/Admin/Assignment/EditController.php
@@ -22,6 +22,7 @@ class EditController extends AbstractController
#[Route('/admin/assignment/edit/{uuid}', name: 'app_admin_assignment_edit')]
#[IsGranted('ROLE_ADMINISTRATIVE')]
+ #[IsGranted('EDIT', subject: 'assignment')]
public function index(Assignment $assignment, Request $request): Response
{
$form = $this->createForm(AssignmentType::class, $assignment);
diff --git a/src/Security/Voter/AssignmentVoter.php b/src/Security/Voter/AssignmentVoter.php
index 54e7369..66d1115 100644
--- a/src/Security/Voter/AssignmentVoter.php
+++ b/src/Security/Voter/AssignmentVoter.php
@@ -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()) {
diff --git a/templates/admin/assignment/index.html.twig b/templates/admin/assignment/index.html.twig
index 3d23d02..8709e64 100644
--- a/templates/admin/assignment/index.html.twig
+++ b/templates/admin/assignment/index.html.twig
@@ -113,9 +113,11 @@
{{ icon('copy', 'w-5 h-5') }}
-
- {{ icon('edit', 'w-5 h-5') }}
-
+ {% if is_granted('EDIT', assignment) %}
+
+ {{ icon('edit', 'w-5 h-5') }}
+
+ {% endif %}