Feat: Add document delete functionality for admins
This commit is contained in:
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller\Admin\Document;
|
||||||
|
|
||||||
|
use App\Entity\Upload;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||||
|
|
||||||
|
class DeleteController extends AbstractController
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly EntityManagerInterface $entityManager,
|
||||||
|
private readonly LoggerInterface $logger
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/admin/document/delete/{uuid}', name: 'app_admin_document_delete')]
|
||||||
|
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||||
|
#[IsGranted('DELETE', subject: 'document')]
|
||||||
|
public function index(Upload $document): Response
|
||||||
|
{
|
||||||
|
$this->entityManager->remove($document);
|
||||||
|
$this->entityManager->flush();
|
||||||
|
|
||||||
|
$this->addFlash('success', 'Das Dokument wurde gelöscht');
|
||||||
|
$this->logger->info('Delete document', [
|
||||||
|
'document_filename' => $document->getOriginalFilename(),
|
||||||
|
'owner' => $document->getOwner()->getFullName(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->redirectToRoute('app_admin_document_index');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -66,6 +66,18 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="flex items-center space-x-2 justify-end">
|
<div class="flex items-center space-x-2 justify-end">
|
||||||
|
{% if is_granted('DELETE', upload) %}
|
||||||
|
<button type="button"
|
||||||
|
class="text-red-500"
|
||||||
|
{{ stimulus_controller('modal-button', [], [], {'confirmation-modal': '#confirmation-modal'}) }}
|
||||||
|
{{ stimulus_action('modal-button', 'confirmation', null, {
|
||||||
|
'title': 'Bist du sicher?',
|
||||||
|
'content': 'Möchtest du das Dokument wirklich löschen?',
|
||||||
|
'target-url': path('app_admin_document_delete', { 'uuid': upload.uuid })
|
||||||
|
}) }}>
|
||||||
|
{{ icon('delete') }}
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
{% if is_granted('CHECK', upload) %}
|
{% if is_granted('CHECK', upload) %}
|
||||||
<button type="button"
|
<button type="button"
|
||||||
{{ stimulus_controller('modal-button', [], [], {'ajax-modal': '#ajax-modal'}) }}
|
{{ stimulus_controller('modal-button', [], [], {'ajax-modal': '#ajax-modal'}) }}
|
||||||
|
|||||||
Reference in New Issue
Block a user