Skip to content

Commit

Permalink
Allow deletion of individual files in executable.
Browse files Browse the repository at this point in the history
Part of DOMjudge#1526.
  • Loading branch information
meisterT committed Apr 18, 2022
1 parent e8c95c5 commit 936baf1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
25 changes: 25 additions & 0 deletions webapp/src/Controller/Jury/ExecutableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,31 @@ public function downloadAction(string $execId): Response
return Utils::streamAsBinaryFile($zipFileContent, $filename, 'zip');
}

/**
* @Route("/{execId}/delete/{rank}", name="jury_executable_delete_single")
* @IsGranted("ROLE_ADMIN")
*/
public function deleteSingleAction(string $execId, int $rank): Response
{
/** @var Executable $executable */
$executable = $this->em->getRepository(Executable::class)->find($execId);
if (!$executable) {
throw new NotFoundHttpException(sprintf('Executable with ID %s not found.', $execId));
}

/** @var ExecutableFile[] $files */
$files = array_values($executable->getImmutableExecutable()->getFiles()->toArray());
foreach ($files as $file) {
if ($file->getRank() == $rank) {
$this->em->remove($file);
$this->em->flush();
return $this->redirectToRoute('jury_executable_edit_files', ['execId' => $execId]);
}
}

throw new NotFoundHttpException(sprintf('No file with rank %d found.', $rank));
}

/**
* @Route("/{execId}/download/{rank}", name="jury_executable_download_single")
*/
Expand Down
6 changes: 6 additions & 0 deletions webapp/templates/jury/executable_edit_content.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
href="{{ path('jury_executable_download_single', {execId: executable.execid, rank: ranks[idx]}) }}">
<i class="fas fa-download"></i> Download
</a>
{% if is_granted('ROLE_ADMIN') %}
<a class="btn btn-secondary btn-sm"
href="{{ path('jury_executable_delete_single', {execId: executable.execid, rank: ranks[idx]}) }}">
<i class="fas fa-trash"></i> Delete
</a>
{% endif %}
</div>

{{ files[idx] | codeEditor(idx, null, true, 'form_source' ~ idx, aceFilenames[idx]) }}
Expand Down

0 comments on commit 936baf1

Please sign in to comment.