fix: prevent generating offer links while booking is in draft

This commit is contained in:
Björn Fromme
2026-08-19 13:00:43 +02:00
parent 2601e46ec4
commit 8617bf6c86
11 changed files with 442 additions and 36 deletions
@@ -26,6 +26,11 @@ class GenerateAccessLinkController extends AbstractController
#[Route('/admin/accommodation-booking/{id}/generate-access-link', name: 'app_admin_accommodationbooking_generate_access_link')]
public function index(AccommodationBooking $booking, Request $request): Response
{
// A draft has not been offered to anyone yet, so there is nothing a link could show.
if (!$booking->isCustomerAccessible()) {
return $this->redirectToRoute('app_admin_accommodationbooking_show', ['id' => $booking->getId()]);
}
if ($request->isMethod(Request::METHOD_POST)) {
if (!$this->isCsrfTokenValid('generate_accommodation_booking_access_link_'.$booking->getId(), $request->request->getString('_token'))) {
throw $this->createAccessDeniedException('Invalid CSRF token.');
@@ -26,7 +26,7 @@ class SendAccessLinkController extends AbstractController
#[Route('/admin/accommodation-booking/{id}/send-access-link', name: 'app_admin_accommodationbooking_send_access_link')]
public function index(AccommodationBooking $booking, Request $request): Response
{
if (null === $booking->getAccessLinkIssuedAt()) {
if (!$booking->isCustomerAccessible() || null === $booking->getAccessLinkIssuedAt()) {
return $this->redirectToRoute('app_admin_accommodationbooking_show', ['id' => $booking->getId()]);
}
+1 -1
View File
@@ -128,7 +128,7 @@ class OfferController extends AbstractController
*/
private function isCustomerVisible(AccommodationBooking $booking): bool
{
return !$booking->isDraft() && !$booking->isRequested() && !$booking->isDiscarded();
return $booking->isCustomerAccessible() && !$booking->isRequested() && !$booking->isDiscarded();
}
/**
@@ -402,6 +402,17 @@ class AccommodationBooking implements BlameableEntityInterface, TimestampableEnt
return AccommodationBookingStatus::Discarded === $this->status;
}
/**
* Whether the record may be put in front of the customer at all. A draft is the office's
* own workbench — nothing has been offered yet, so an access link would point the customer
* at a half-prepared record. Every access link action (issuing, regenerating, sending)
* hangs off this, so the rule lives in one place rather than in each caller.
*/
public function isCustomerAccessible(): bool
{
return !$this->isDraft();
}
public function getOrigin(): AccommodationBookingOrigin
{
return $this->origin;
+18 -4
View File
@@ -436,12 +436,18 @@ class AccommodationBookingService
}
/**
* Sets accessLinkIssuedAt if the booking doesn't have one yet, whatever its status.
* No email side effect — the confirmation email is always sent separately via
* sendCustomerConfirmationEmail(), regardless of whether a link exists.
* Sets accessLinkIssuedAt if the booking doesn't have one yet. No email side effect — the
* confirmation email is always sent separately via sendCustomerConfirmationEmail(),
* regardless of whether a link exists.
* A no-op while the record is not customer accessible: a draft has nothing to show yet, so
* publishing the offer (sendOffer()) moves it out of Entwurf before asking for a link.
*/
public function issueAccessLink(AccommodationBooking $booking): void
{
if (!$booking->isCustomerAccessible()) {
return;
}
if (null !== $booking->getAccessLinkIssuedAt()) {
return;
}
@@ -489,9 +495,15 @@ class AccommodationBookingService
* Explicit admin action: (re)issues the access link, invalidating any previously issued
* link for this booking. No email side effect — sending is a separate, explicit admin
* action via sendCustomerConfirmationEmail().
* A no-op for a record that is not customer accessible yet, for the same reason as
* issueAccessLink().
*/
public function regenerateAccessLink(AccommodationBooking $booking): void
{
if (!$booking->isCustomerAccessible()) {
return;
}
$booking->setAccessLinkIssuedAt(new \DateTimeImmutable());
$this->entityManager->flush();
}
@@ -509,8 +521,10 @@ class AccommodationBookingService
return;
}
$this->issueAccessLink($booking);
// Offen first: the status is what makes the record customer accessible, and only then
// will issueAccessLink() hand out a link (it flushes both changes together).
$booking->setStatus(AccommodationBookingStatus::Open);
$this->issueAccessLink($booking);
$this->entityManager->flush();
$this->sendCustomerConfirmationEmail($booking);