Fix Bestätigung email: send synchronously for immediate error feedback (STI-77)
The Bestätigung email was sent via Celery task (fire-and-forget), so the UI always showed "wird gesendet" even when the task failed silently in the worker. Now sends synchronously from the web process (matching the working test email pattern) with proper error display to the user. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -827,9 +827,9 @@ def bestaetigung_vorschau(request, pk):
|
||||
def bestaetigung_versenden(request, pk):
|
||||
"""
|
||||
Sendet das Bestätigungsschreiben per E-Mail an den Destinatär.
|
||||
POST-only (CSRF-geschützt). Startet asynchronen Celery-Task.
|
||||
POST-only (CSRF-geschützt). Sendet synchron für direktes Feedback.
|
||||
"""
|
||||
from stiftung.tasks import send_bestaetigung
|
||||
from stiftung.tasks import _send_bestaetigung_sync
|
||||
|
||||
if request.method != "POST":
|
||||
return redirect("stiftung:destinataer_detail", pk=pk)
|
||||
@@ -843,8 +843,24 @@ def bestaetigung_versenden(request, pk):
|
||||
)
|
||||
return redirect("stiftung:destinataer_detail", pk=pk)
|
||||
|
||||
base_url = request.build_absolute_uri("/").rstrip("/")
|
||||
send_bestaetigung.delay(str(destinataer.id), base_url=base_url)
|
||||
try:
|
||||
result = _send_bestaetigung_sync(str(destinataer.id))
|
||||
except Exception as exc:
|
||||
import logging
|
||||
logging.getLogger(__name__).exception("Bestätigung versenden fehlgeschlagen: %s", exc)
|
||||
messages.error(
|
||||
request,
|
||||
f"Bestätigungsschreiben konnte nicht gesendet werden: {exc}",
|
||||
)
|
||||
return redirect("stiftung:destinataer_detail", pk=pk)
|
||||
|
||||
if result and result.get("status") == "skipped":
|
||||
messages.warning(request, "Versand übersprungen: Keine E-Mail-Adresse hinterlegt.")
|
||||
return redirect("stiftung:destinataer_detail", pk=pk)
|
||||
|
||||
if result and result.get("status") == "error":
|
||||
messages.error(request, f"Fehler: {result.get('message', 'Unbekannter Fehler')}")
|
||||
return redirect("stiftung:destinataer_detail", pk=pk)
|
||||
|
||||
log_action(
|
||||
request,
|
||||
@@ -857,7 +873,7 @@ def bestaetigung_versenden(request, pk):
|
||||
|
||||
messages.success(
|
||||
request,
|
||||
f"Bestätigungsschreiben wird per E-Mail an {destinataer.email} gesendet.",
|
||||
f"Bestätigungsschreiben wurde erfolgreich an {destinataer.email} gesendet.",
|
||||
)
|
||||
return redirect("stiftung:destinataer_detail", pk=pk)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user