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')]
|
#[Route('/admin/assignment/edit/{uuid}', name: 'app_admin_assignment_edit')]
|
||||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||||
|
#[IsGranted('EDIT', subject: 'assignment')]
|
||||||
public function index(Assignment $assignment, Request $request): Response
|
public function index(Assignment $assignment, Request $request): Response
|
||||||
{
|
{
|
||||||
$form = $this->createForm(AssignmentType::class, $assignment);
|
$form = $this->createForm(AssignmentType::class, $assignment);
|
||||||
|
|||||||
@@ -30,18 +30,21 @@ class AssignmentVoter extends Voter
|
|||||||
|
|
||||||
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
|
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
|
||||||
{
|
{
|
||||||
|
/** @var Assignment $assignment */
|
||||||
|
$assignment = $subject;
|
||||||
|
|
||||||
// All authenticated users may view assignments
|
// All authenticated users may view assignments
|
||||||
if (static::VIEW === $attribute && null !== $token->getUser()) {
|
if (static::VIEW === $attribute && null !== $token->getUser()) {
|
||||||
return true;
|
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())) {
|
if (static::EDIT === $attribute && in_array('ROLE_ADMINISTRATIVE', $token->getRoleNames())) {
|
||||||
return true;
|
$assignmentCount = $assignment->getApplications()->count();
|
||||||
}
|
$dispositionCount = $assignment->getDispositions()->count();
|
||||||
|
|
||||||
/** @var Assignment $assignment */
|
return 0 === $assignmentCount && 0 === $dispositionCount;
|
||||||
$assignment = $subject;
|
}
|
||||||
|
|
||||||
// Only allow applications to open assignments
|
// Only allow applications to open assignments
|
||||||
if (Assignment::STATUS_CLOSED === $assignment->getStatus()) {
|
if (Assignment::STATUS_CLOSED === $assignment->getStatus()) {
|
||||||
|
|||||||
@@ -113,9 +113,11 @@
|
|||||||
<a href="{{ path('app_admin_assignment_duplicate', { 'uuid': assignment.uuid, 'r': return_url() }) }}">
|
<a href="{{ path('app_admin_assignment_duplicate', { 'uuid': assignment.uuid, 'r': return_url() }) }}">
|
||||||
{{ icon('copy', 'w-5 h-5') }}
|
{{ icon('copy', 'w-5 h-5') }}
|
||||||
</a>
|
</a>
|
||||||
<a href="{{ path('app_admin_assignment_edit', { 'uuid': assignment.uuid, 'r': return_url() }) }}">
|
{% if is_granted('EDIT', assignment) %}
|
||||||
{{ icon('edit', 'w-5 h-5') }}
|
<a href="{{ path('app_admin_assignment_edit', { 'uuid': assignment.uuid, 'r': return_url() }) }}">
|
||||||
</a>
|
{{ icon('edit', 'w-5 h-5') }}
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user