feat: answer received form submissions by mail

This commit is contained in:
fromme committed 2026-09-24 16:35:31 +02:00
1 parent 19364df2db
commit aa728ddc99
22 files changed
+974 -9

No files matched your search

@@ -0,0 +1,48 @@
<?php
namespace App\Controller\Admin\ApplicationFormSubmission;
use App\Email\ApplicationFormSubmissionMailer;
use App\Entity\ApplicationFormSubmission;
use App\Htmx\HxRedirectResponse;
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;
/**
* Sends the follow-up mail. Never automatic: a reviewer decides when a submission has waited long
* enough, and may send it again after a bounce or a wording fix - the stamp is overwritten.
*
* Unlike the receipt this one is allowed to fail loudly: somebody is watching the response.
*/
class SendFollowUpMailController extends AbstractController
{
public function __construct(private readonly ApplicationFormSubmissionMailer $mailer)
{
}
#[Route('/admin/application-form-submission/send-follow-up/{uuid}', name: 'app_admin_application_form_submission_send_follow_up')]
#[IsGranted('ROLE_TEAM_ADMIN')]
public function index(ApplicationFormSubmission $submission, Request $request): Response
{
if (true === $request->isMethod(Request::METHOD_POST)) {
$this->mailer->sendFollowUp($submission);
$this->addFlash('success', 'Die zweite E-Mail wurde versendet');
return new HxRedirectResponse($this->generateUrl('app_admin_application_form_submission_detail', [
'uuid' => $submission->getUuid(),
'r' => $request->query->get('r'),
]));
}
return $this->render('admin/application_form_submission/modal_send_follow_up.html.twig', [
'submission' => $submission,
// Named in the confirmation so a reviewer sees whether the handout the wording
// promises is actually going out.
'handout' => $this->mailer->findHandout(),
]);
}
}
@@ -0,0 +1,44 @@
<?php
namespace App\Controller\Admin\ApplicationFormSubmission;
use App\Email\ApplicationFormSubmissionMailer;
use App\Entity\ApplicationFormSubmission;
use App\Htmx\HxRedirectResponse;
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;
/**
* Sends the receipt again by hand. The endpoint sends it by itself when a submission arrives, so
* this is for the cases where that did not work: an address that was missing or wrong, or wording
* that was fixed afterwards.
*/
class SendReceiptMailController extends AbstractController
{
public function __construct(private readonly ApplicationFormSubmissionMailer $mailer)
{
}
#[Route('/admin/application-form-submission/send-receipt/{uuid}', name: 'app_admin_application_form_submission_send_receipt')]
#[IsGranted('ROLE_TEAM_ADMIN')]
public function index(ApplicationFormSubmission $submission, Request $request): Response
{
if (true === $request->isMethod(Request::METHOD_POST)) {
$this->mailer->sendReceipt($submission);
$this->addFlash('success', 'Die Eingangsbestätigung wurde erneut versendet');
return new HxRedirectResponse($this->generateUrl('app_admin_application_form_submission_detail', [
'uuid' => $submission->getUuid(),
'r' => $request->query->get('r'),
]));
}
return $this->render('admin/application_form_submission/modal_send_receipt.html.twig', [
'submission' => $submission,
]);
}
}
@@ -2,6 +2,7 @@
namespace App\Controller\Api;
use App\Email\ApplicationFormSubmissionMailer;
use App\Entity\ApplicationFormSubmission;
use App\Model\ApplicationFormSubmissionDto;
use Doctrine\ORM\EntityManagerInterface;
@@ -28,6 +29,7 @@ class ApplicationFormController extends AbstractController
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly LoggerInterface $logger,
private readonly ApplicationFormSubmissionMailer $mailer,
) {
}
@@ -45,6 +47,11 @@ class ApplicationFormController extends AbstractController
): JsonResponse {
$submission = $this->store($dto, $request);
// After the store and unable to throw: the row is safe by now, and a mail problem must
// not answer an error to a submission this application has accepted. A payload without
// an email address is normal - not every form asks for one - and is logged, not failed.
$receiptSent = $this->mailer->sendAutomaticReceipt($submission);
$this->logger->info('Application form submission received', [
'uuid' => $submission->getUuid(),
'form' => $submission->getForm(),
@@ -53,6 +60,7 @@ class ApplicationFormController extends AbstractController
'submittedAt' => $submission->getSubmittedAt()->format(\DateTimeInterface::ATOM),
// the labels and the answers are personal data (§7), their number is not
'detailCount' => count($submission->getDetails()),
'receiptSent' => $receiptSent,
]);
return new JsonResponse(