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
@@ -267,3 +267,29 @@ def test_archiving_failure_after_smtp_success_still_logs_the_sent_mail(tmp_path,
|
||||
assert event.event_type == "welcome_email_sent"
|
||||
assert event.data["archive_error"]
|
||||
assert "document" not in event.references
|
||||
|
||||
|
||||
def test_a_template_broken_outside_ccma_stops_the_send(tmp_path):
|
||||
repository, member = _new_member_repository(tmp_path)
|
||||
# The templates are plain files in the store, so they can be edited (and broken)
|
||||
# with any text editor -- the send has to notice instead of mailing the marker.
|
||||
(repository.mail_templates_root / "willkommen.txt").write_text(
|
||||
"Betreff: Willkommen\n\nHallo,\n{{#claims}}\n{{claim.title}}\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
with pytest.raises(RepositoryError, match="wird nicht geschlossen"):
|
||||
generate_and_send_welcome_mail(
|
||||
repository,
|
||||
member.member_id,
|
||||
delivery_mode="local",
|
||||
output_path=tmp_path / "Willkommen.eml",
|
||||
sender_name="Verwaltung C3MA",
|
||||
sender_email="verwaltung@example.org",
|
||||
signature="Der Vorstand",
|
||||
)
|
||||
|
||||
assert not (tmp_path / "Willkommen.eml").exists()
|
||||
archive = repository.members_root / member.member_id / "files" / "documents" / "Willkommen"
|
||||
assert not archive.exists()
|
||||
assert repository.get_events(member.member_id)[-1].event_type != "welcome_email_sent"
|
||||
|
||||
Reference in New Issue
Block a user