feat: view and edit comments of uploaded documents
addresses #869eg7tv1
This commit is contained in:
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller\Administrative\Document;
|
||||||
|
|
||||||
|
use App\Controller\Traits\ReturnUrlTrait;
|
||||||
|
use App\Entity\Upload;
|
||||||
|
use App\Htmx\HxRedirectResponse;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||||
|
|
||||||
|
class CommentController extends AbstractController
|
||||||
|
{
|
||||||
|
use ReturnUrlTrait;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly EntityManagerInterface $entityManager,
|
||||||
|
private readonly LoggerInterface $logger,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/administrative/document/comment/{uuid}', name: 'app_administrative_document_comment')]
|
||||||
|
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||||
|
#[IsGranted('COMMENT', subject: 'document')]
|
||||||
|
public function index(Upload $document, Request $request): Response
|
||||||
|
{
|
||||||
|
$form = $this
|
||||||
|
->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,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ class UploadVoter extends Voter
|
|||||||
public const DELETE = 'DELETE';
|
public const DELETE = 'DELETE';
|
||||||
public const DOWNLOAD = 'DOWNLOAD';
|
public const DOWNLOAD = 'DOWNLOAD';
|
||||||
public const CHECK = 'CHECK';
|
public const CHECK = 'CHECK';
|
||||||
|
public const COMMENT = 'COMMENT';
|
||||||
|
|
||||||
public function __construct(private readonly Security $security)
|
public function __construct(private readonly Security $security)
|
||||||
{
|
{
|
||||||
@@ -25,7 +26,7 @@ class UploadVoter extends Voter
|
|||||||
return false;
|
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
|
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
|
||||||
@@ -35,7 +36,7 @@ class UploadVoter extends Voter
|
|||||||
|
|
||||||
// Administrative users have full access
|
// Administrative users have full access
|
||||||
if (true === $this->security->isGranted('ROLE_ADMINISTRATIVE')) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,6 +90,16 @@
|
|||||||
{{ icon('delete') }}
|
{{ icon('delete') }}
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if is_granted('COMMENT', upload) %}
|
||||||
|
<button type="button"
|
||||||
|
class="{{ html_classes({ 'text-gray-300': not upload.comment }) }}"
|
||||||
|
title="{{ upload.comment ? 'Kommentar bearbeiten' : 'Kommentar hinzufügen' }}"
|
||||||
|
hx-get="{{ path('app_administrative_document_comment', { 'uuid': upload.uuid, 'r': return_url() }) }}"
|
||||||
|
hx-target="body"
|
||||||
|
hx-swap="beforeend">
|
||||||
|
{{ icon('feedback') }}
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
<a href="{{ path('app_common_download', { 'uuid': upload.uuid, 'inline': false }) }}"
|
<a href="{{ path('app_common_download', { 'uuid': upload.uuid, 'inline': false }) }}"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
title="Download und Markierung">
|
title="Download und Markierung">
|
||||||
|
|||||||
@@ -99,6 +99,16 @@
|
|||||||
{{ icon('delete') }}
|
{{ icon('delete') }}
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if is_granted('COMMENT', upload) %}
|
||||||
|
<button type="button"
|
||||||
|
class="{{ html_classes({ 'text-gray-300': not upload.comment }) }}"
|
||||||
|
title="{{ upload.comment ? 'Kommentar bearbeiten' : 'Kommentar hinzufügen' }}"
|
||||||
|
hx-get="{{ path('app_administrative_document_comment', { 'uuid': upload.uuid, 'r': return_url() }) }}"
|
||||||
|
hx-target="body"
|
||||||
|
hx-swap="beforeend">
|
||||||
|
{{ icon('feedback') }}
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
{% if is_granted('CHECK', upload) %}
|
{% if is_granted('CHECK', upload) %}
|
||||||
<button type="button"
|
<button type="button"
|
||||||
hx-get="{{ path('app_administrative_document_check', { 'uuid': upload.uuid, 'r': return_url() }) }}"
|
hx-get="{{ path('app_administrative_document_check', { 'uuid': upload.uuid, 'r': return_url() }) }}"
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
{% extends 'htmx_modal.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Kommentar{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<a href="{{ path('app_common_download', { 'uuid': document.uuid, 'inline': true }) }}"
|
||||||
|
target="_blank"
|
||||||
|
class="flex justify-between items-center pb-4"
|
||||||
|
title="Dokument öffnen">
|
||||||
|
<h2 class="font-bold text-lg">
|
||||||
|
{{ ('label.document.type.' ~ document.type)|trans }} {{ document.disposition.teamer }} vom {{ document.createdAt|date('d.m.Y') }}
|
||||||
|
</h2>
|
||||||
|
{{ icon('eye') }}
|
||||||
|
</a>
|
||||||
|
{{ form_start(form) }}
|
||||||
|
<div class="pb-4">
|
||||||
|
{{ form_row(form.comment) }}
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn">
|
||||||
|
Aktualisieren
|
||||||
|
</button>
|
||||||
|
{{ form_rest(form) }}
|
||||||
|
{{ form_end(form) }}
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user