mirror of
https://git.hiabuto.net/C3MA/CCMA.git
synced 2026-09-06 03:20:49 +02:00
Reject unbalanced repeat markers in mail templates
validate_mail_template() only looked at placeholder names, and "{{#claims}}" is
not a placeholder -- so an unclosed block or a stray "{{/claims}}" passed the
check and rendered as itself: the member would read the marker in their mail.
Repeat markers are now checked structurally: every one names a block the template
actually has, openers and closers pair up in order, blocks do not nest (the
renderer does not support it either), and the subject takes no markers at all.
Each case explains what is wrong and what is missing.
The same check runs before sending, not just before saving: the templates are
plain files in the store and can be edited outside CCMA, where refusing to send
beats mailing a marker. Saving several edited templates now validates all of
them before writing the first, so a mistake in one no longer leaves the others
half-saved.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
d3dbb5e96d
commit
c46662561e
@@ -5,7 +5,13 @@ from email.message import EmailMessage
|
||||
from email.policy import SMTP
|
||||
from email.utils import format_datetime, make_msgid
|
||||
|
||||
from ccma.domain.mail_templates import MailTemplate, MailTemplateError, render_mail_template
|
||||
from ccma.domain.mail_templates import (
|
||||
MailTemplate,
|
||||
MailTemplateError,
|
||||
render_mail_template,
|
||||
template_spec,
|
||||
validate_block_markers,
|
||||
)
|
||||
from ccma.domain.models import Member
|
||||
from ccma.domain.placeholders import base_placeholder_values
|
||||
from ccma.storage.repository import MemberRepository, RepositoryError
|
||||
@@ -61,10 +67,17 @@ def render_template(
|
||||
values: dict[str, str],
|
||||
repeats: dict[str, list[dict[str, str]]] | None = None,
|
||||
) -> MailTemplate:
|
||||
template = repository.get_mail_template(key)
|
||||
try:
|
||||
return render_mail_template(repository.get_mail_template(key), values, repeats)
|
||||
# The templates are plain files in the store and may have been edited outside
|
||||
# CCMA, so the structural check runs again here: refusing to send beats
|
||||
# sending a mail with "{{#claims}}" in its text.
|
||||
validate_block_markers(key, template.subject, template.body)
|
||||
return render_mail_template(template, values, repeats)
|
||||
except MailTemplateError as exc:
|
||||
raise RepositoryError(str(exc)) from exc
|
||||
raise RepositoryError(
|
||||
f"Die E-Mail-Vorlage „{template_spec(key).label}“ ist fehlerhaft: {exc}"
|
||||
) from exc
|
||||
|
||||
|
||||
def compose_mail(
|
||||
|
||||
Reference in New Issue
Block a user