From 644bfa225decdd52bd953386afcbfc4deb011b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Thu, 13 Aug 2026 17:20:17 +0200 Subject: [PATCH] feat: view and edit comments of uploaded documents addresses #869eg7tv1 --- .../Document/CommentController.php | 62 +++++++++++++++++++ src/Security/Voter/UploadVoter.php | 5 +- .../document/accepted.html.twig | 10 +++ .../administrative/document/index.html.twig | 10 +++ .../document/modal_comment.html.twig | 24 +++++++ 5 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 src/Controller/Administrative/Document/CommentController.php create mode 100644 templates/administrative/document/modal_comment.html.twig diff --git a/src/Controller/Administrative/Document/CommentController.php b/src/Controller/Administrative/Document/CommentController.php new file mode 100644 index 0000000..9f9b225 --- /dev/null +++ b/src/Controller/Administrative/Document/CommentController.php @@ -0,0 +1,62 @@ +createFormBuilder($document, ['hx_post' => $request->getUri()]) + ->add('comment', TextareaType::class, [ + 'label' => 'Kommentar', + 'required' => false, + 'attr' => [ + 'rows' => 5, + ], + ]) + ->getForm() + ; + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->entityManager->flush(); + + $this->addFlash('success', 'Der Kommentar wurde aktualisiert'); + $this->logger->info('Update document comment', [ + 'document_id' => $document->getId(), + 'document_filename' => $document->getOriginalFilename(), + ]); + + return new HxRedirectResponse($this->getReturnUrl($request, 'app_administrative_document_index')); + } + + return $this->render('administrative/document/modal_comment.html.twig', [ + 'form' => $form->createView(), + 'document' => $document, + ]); + } +} diff --git a/src/Security/Voter/UploadVoter.php b/src/Security/Voter/UploadVoter.php index 5af0873..1291ff5 100644 --- a/src/Security/Voter/UploadVoter.php +++ b/src/Security/Voter/UploadVoter.php @@ -14,6 +14,7 @@ class UploadVoter extends Voter public const DELETE = 'DELETE'; public const DOWNLOAD = 'DOWNLOAD'; public const CHECK = 'CHECK'; + public const COMMENT = 'COMMENT'; public function __construct(private readonly Security $security) { @@ -25,7 +26,7 @@ class UploadVoter extends Voter return false; } - return in_array($attribute, [static::VIEW, static::DELETE, static::DOWNLOAD, static::CHECK]); + return in_array($attribute, [static::VIEW, static::DELETE, static::DOWNLOAD, static::CHECK, static::COMMENT]); } protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool @@ -35,7 +36,7 @@ class UploadVoter extends Voter // Administrative users have full access if (true === $this->security->isGranted('ROLE_ADMINISTRATIVE')) { - if (true === in_array($attribute, [static::VIEW, static::DELETE, static::DOWNLOAD])) { + if (true === in_array($attribute, [static::VIEW, static::DELETE, static::DOWNLOAD, static::COMMENT])) { return true; } diff --git a/templates/administrative/document/accepted.html.twig b/templates/administrative/document/accepted.html.twig index 76e142d..a00f5e3 100644 --- a/templates/administrative/document/accepted.html.twig +++ b/templates/administrative/document/accepted.html.twig @@ -90,6 +90,16 @@ {{ icon('delete') }} {% endif %} + {% if is_granted('COMMENT', upload) %} + + {% endif %} diff --git a/templates/administrative/document/index.html.twig b/templates/administrative/document/index.html.twig index 50a0a5f..f2beb1a 100644 --- a/templates/administrative/document/index.html.twig +++ b/templates/administrative/document/index.html.twig @@ -99,6 +99,16 @@ {{ icon('delete') }} {% endif %} + {% if is_granted('COMMENT', upload) %} + + {% endif %} {% if is_granted('CHECK', upload) %} + {{ form_rest(form) }} + {{ form_end(form) }} +{% endblock %}