From 936baf19a58024eb6f825845e49eaea023ef19ca Mon Sep 17 00:00:00 2001 From: Tobias Werth Date: Mon, 18 Apr 2022 13:43:54 +0200 Subject: [PATCH] Allow deletion of individual files in executable. Part of #1526. --- .../Controller/Jury/ExecutableController.php | 25 +++++++++++++++++++ .../jury/executable_edit_content.html.twig | 6 +++++ 2 files changed, 31 insertions(+) diff --git a/webapp/src/Controller/Jury/ExecutableController.php b/webapp/src/Controller/Jury/ExecutableController.php index 6fe8608d105..923eca00a0c 100644 --- a/webapp/src/Controller/Jury/ExecutableController.php +++ b/webapp/src/Controller/Jury/ExecutableController.php @@ -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") */ diff --git a/webapp/templates/jury/executable_edit_content.html.twig b/webapp/templates/jury/executable_edit_content.html.twig index 352851914c3..c0d70714764 100644 --- a/webapp/templates/jury/executable_edit_content.html.twig +++ b/webapp/templates/jury/executable_edit_content.html.twig @@ -33,6 +33,12 @@ href="{{ path('jury_executable_download_single', {execId: executable.execid, rank: ranks[idx]}) }}"> Download + {% if is_granted('ROLE_ADMIN') %} + + Delete + + {% endif %} {{ files[idx] | codeEditor(idx, null, true, 'form_source' ~ idx, aceFilenames[idx]) }}