feat: delete accommodation bookings in draft

This commit is contained in:
Björn Fromme
2026-08-20 12:39:45 +02:00
parent 3db1850e4f
commit 98a303e941
4 changed files with 264 additions and 0 deletions
@@ -0,0 +1,68 @@
<?php
declare(strict_types=1);
namespace App\Controller\Admin\AccommodationBooking;
use App\Controller\Traits\ReturnUrlTrait;
use App\Entity\Groups\AccommodationBooking;
use App\Htmx\HxTrait;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
#[IsGranted('ROLE_GROUPS_MANAGER')]
class DeleteController extends AbstractController
{
use HxTrait;
use ReturnUrlTrait;
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly LoggerInterface $logger,
) {
}
#[Route('/admin/accommodation-booking/{id}/delete', name: 'app_admin_accommodationbooking_delete')]
public function index(AccommodationBooking $booking, Request $request): Response
{
// Only a scratch record may be removed outright. Everything else has been in contact
// with the customer and has to stay on the books — an Absage is how those are closed,
// and it keeps the record readable afterwards.
if (!$booking->isDraft()) {
$this->addFlash('error', 'Nur ein Entwurf lässt sich löschen. Eine Buchung, die bereits beim Kunden war, wird abgesagt.');
return $this->htmxRedirect($request, $this->getReturnUrl($request, 'app_admin_accommodationbooking'));
}
if ($request->isMethod(Request::METHOD_POST)) {
if (!$this->isCsrfTokenValid('delete_accommodation_booking_'.$booking->getId(), $request->request->getString('_token'))) {
throw $this->createAccessDeniedException('Invalid CSRF token.');
}
$this->logger->info('Deleted accommodation booking draft', [
'id' => $booking->getId(),
'groupName' => $booking->getGroupName(),
'accommodation' => $booking->getAccommodation()?->getName(),
]);
$this->entityManager->remove($booking);
$this->entityManager->flush();
$this->addFlash('success', 'Der Entwurf wurde gelöscht');
// Back to the list the delete was started from, so the filter and the page the
// manager was on survive the round trip.
return $this->htmxRedirect($request, $this->getReturnUrl($request, 'app_admin_accommodationbooking'));
}
return $this->render('admin/accommodation_booking/modal_delete.html.twig', [
'booking' => $booking,
'csrf_token_id' => 'delete_accommodation_booking_'.$booking->getId(),
]);
}
}