63 lines
2.7 KiB
PHP
63 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Controller\Admin\AccommodationBooking;
|
|
|
|
use App\Entity\Groups\AccommodationBooking;
|
|
use App\Htmx\HxRedirectResponse;
|
|
use App\Service\AccommodationBookingService;
|
|
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 SendAccessLinkController extends AbstractController
|
|
{
|
|
public function __construct(
|
|
private readonly AccommodationBookingService $bookingService,
|
|
private readonly LoggerInterface $logger,
|
|
) {
|
|
}
|
|
|
|
#[Route('/admin/accommodation-booking/{id}/send-access-link', name: 'app_admin_accommodationbooking_send_access_link')]
|
|
public function index(AccommodationBooking $booking, Request $request): Response
|
|
{
|
|
if (!$booking->isCustomerAccessible() || null === $booking->getAccessLinkIssuedAt()) {
|
|
return $this->redirectToRoute('app_admin_accommodationbooking_show', ['id' => $booking->getId()]);
|
|
}
|
|
|
|
if ($request->isMethod(Request::METHOD_POST)) {
|
|
if (!$this->isCsrfTokenValid('send_accommodation_booking_access_link_'.$booking->getId(), $request->request->getString('_token'))) {
|
|
throw $this->createAccessDeniedException('Invalid CSRF token.');
|
|
}
|
|
|
|
// Older bookings can still be missing their contact data. Sending would be
|
|
// silently skipped further down, so say so instead of reporting success.
|
|
if (null === $booking->getEmail() || '' === trim($booking->getEmail())) {
|
|
$this->addFlash('error', 'Für diese Buchung ist keine E-Mail-Adresse hinterlegt. Bitte ergänze sie, um den Zugangslink zu senden.');
|
|
|
|
return new HxRedirectResponse($this->generateUrl('app_admin_accommodationbooking_edit', ['id' => $booking->getId()]));
|
|
}
|
|
|
|
$this->bookingService->sendAccessLink($booking);
|
|
|
|
$this->addFlash('success', 'Ein neuer Zugangslink wurde dem Kunden per E-Mail zugestellt.');
|
|
|
|
$this->logger->info('Sent accommodation booking access link', [
|
|
'id' => $booking->getId(),
|
|
]);
|
|
|
|
return new HxRedirectResponse($this->generateUrl('app_admin_accommodationbooking_show', ['id' => $booking->getId()]));
|
|
}
|
|
|
|
return $this->render('admin/accommodation_booking/modal_send_access_link.html.twig', [
|
|
'booking' => $booking,
|
|
'csrf_token_id' => 'send_accommodation_booking_access_link_'.$booking->getId(),
|
|
]);
|
|
}
|
|
}
|