feat: prevent editing of assignments with applications or dispositions
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -113,9 +113,11 @@
|
||||
<a href="{{ path('app_admin_assignment_duplicate', { 'uuid': assignment.uuid, 'r': return_url() }) }}">
|
||||
{{ icon('copy', 'w-5 h-5') }}
|
||||
</a>
|
||||
<a href="{{ path('app_admin_assignment_edit', { 'uuid': assignment.uuid, 'r': return_url() }) }}">
|
||||
{{ icon('edit', 'w-5 h-5') }}
|
||||
</a>
|
||||
{% if is_granted('EDIT', assignment) %}
|
||||
<a href="{{ path('app_admin_assignment_edit', { 'uuid': assignment.uuid, 'r': return_url() }) }}">
|
||||
{{ icon('edit', 'w-5 h-5') }}
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user