diff --git a/src/Controller/Admin/AccommodationBooking/GenerateAccessLinkController.php b/src/Controller/Admin/AccommodationBooking/GenerateAccessLinkController.php
index 22ff510..786870b 100644
--- a/src/Controller/Admin/AccommodationBooking/GenerateAccessLinkController.php
+++ b/src/Controller/Admin/AccommodationBooking/GenerateAccessLinkController.php
@@ -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.');
diff --git a/src/Controller/Admin/AccommodationBooking/SendAccessLinkController.php b/src/Controller/Admin/AccommodationBooking/SendAccessLinkController.php
index c8fcefa..65b6d59 100644
--- a/src/Controller/Admin/AccommodationBooking/SendAccessLinkController.php
+++ b/src/Controller/Admin/AccommodationBooking/SendAccessLinkController.php
@@ -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()]);
}
diff --git a/src/Controller/Groups/OfferController.php b/src/Controller/Groups/OfferController.php
index 96d47c5..3ec954a 100644
--- a/src/Controller/Groups/OfferController.php
+++ b/src/Controller/Groups/OfferController.php
@@ -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();
}
/**
diff --git a/src/Entity/Groups/AccommodationBooking.php b/src/Entity/Groups/AccommodationBooking.php
index 2c93be4..c034221 100644
--- a/src/Entity/Groups/AccommodationBooking.php
+++ b/src/Entity/Groups/AccommodationBooking.php
@@ -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;
diff --git a/src/Service/AccommodationBookingService.php b/src/Service/AccommodationBookingService.php
index c10d061..c77f324 100644
--- a/src/Service/AccommodationBookingService.php
+++ b/src/Service/AccommodationBookingService.php
@@ -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);
diff --git a/templates/admin/accommodation_booking/show.html.twig b/templates/admin/accommodation_booking/show.html.twig
index a0f8a5f..bb6e0ff 100644
--- a/templates/admin/accommodation_booking/show.html.twig
+++ b/templates/admin/accommodation_booking/show.html.twig
@@ -212,42 +212,48 @@
Zugangslink
- {% if accessLink %}
-
-
- Gültig bis {{ accessLinkExpiresAt | date('d.m.Y') }}
- {% if accessLinkExpiresAt < date() %}
- (abgelaufen)
- {% endif %}
+ {% if not booking.customerAccessible %}
+
+ Ein Zugangslink wird beim Versand des Angebots erzeugt und kann erst danach erneuert werden.