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
@@ -8,7 +8,7 @@ tk = pytest.importorskip("tkinter")
|
||||
from ccma.config import AppConfig # noqa: E402
|
||||
from ccma.domain.mail_templates import placeholder_entries # noqa: E402
|
||||
from ccma.services.welcome_mail import generate_and_send_welcome_mail # noqa: E402
|
||||
from ccma.storage.repository import MemberRepository # noqa: E402
|
||||
from ccma.storage.repository import MemberRepository, RepositoryError # noqa: E402
|
||||
|
||||
|
||||
# One root for the whole session: the icon library binds its images to the first
|
||||
@@ -136,3 +136,42 @@ def test_edited_template_survives_saving_and_produces_real_lines_in_the_mail(
|
||||
).get_content()
|
||||
assert "Aufnahmegebühr (fällig 17.09.2026): 15.00 Euro" in content
|
||||
assert "…" not in content
|
||||
|
||||
|
||||
def test_the_dialog_refuses_to_save_an_unbalanced_block(tk_root, repository):
|
||||
stored = repository.mail_templates_root / "willkommen.txt"
|
||||
before = stored.read_text(encoding="utf-8")
|
||||
|
||||
dialog = _open_options(tk_root, repository)
|
||||
try:
|
||||
dialog.mail_template_body.delete("1.0", "end")
|
||||
dialog.mail_template_body.insert("1.0", "Offen sind aktuell:\n{{#claims}}\n{{claim.title}}")
|
||||
with pytest.raises(RepositoryError, match="wird nicht geschlossen"):
|
||||
dialog._save_mail_templates()
|
||||
finally:
|
||||
dialog.grab_release()
|
||||
dialog.destroy()
|
||||
|
||||
assert stored.read_text(encoding="utf-8") == before
|
||||
|
||||
|
||||
def test_a_broken_template_does_not_half_save_the_others(tk_root, repository):
|
||||
reminder_file = repository.mail_templates_root / "mahnung.txt"
|
||||
before = reminder_file.read_text(encoding="utf-8")
|
||||
|
||||
dialog = _open_options(tk_root, repository)
|
||||
try:
|
||||
# Edit a valid template first, then break the second one.
|
||||
dialog.mail_template_var.set("Mahnung")
|
||||
dialog._select_mail_template()
|
||||
dialog.mail_template_body.insert("end", "\nP.S. Bitte Mitgliedsnummer angeben.")
|
||||
dialog.mail_template_var.set("Willkommen & Erstrechnung")
|
||||
dialog._select_mail_template()
|
||||
dialog.mail_template_body.insert("end", "\n{{#claims}}\n{{claim.title}}")
|
||||
with pytest.raises(RepositoryError, match="wird nicht geschlossen"):
|
||||
dialog._save_mail_templates()
|
||||
finally:
|
||||
dialog.grab_release()
|
||||
dialog.destroy()
|
||||
|
||||
assert reminder_file.read_text(encoding="utf-8") == before
|
||||
|
||||
Reference in New Issue
Block a user