custom_email: Add manage_preferences block to the plaintext version.

Earlier, the content of the "manage_preferences" block that includes
the unsubscribe_link, personal settings link, etc was missing in the
plaintext version of the custom emails.

This commit updates the logic to include the manage_preferences block
content in the plaintext version.
This commit is contained in:
Prakhar Pratyush 2024-09-05 14:59:39 +05:30 committed by Tim Abbott
parent e967226f8c
commit e8349aa5d7
3 changed files with 31 additions and 1 deletions

View File

@ -0,0 +1,15 @@
---
{% if remote_server_email %}
You are receiving this email to update you about important changes to Zulip's Terms of Service.
Unsubscribe: {{ unsubscribe_link }}
{% elif unsubscribe_link %}
{{ _("Manage email preferences") }}:
{{ realm_url }}/#settings/notifications
{{ _("Unsubscribe from marketing emails") }}:
{{ unsubscribe_link }}
{% endif %}

View File

@ -560,6 +560,16 @@ def custom_email_sender(
# vary user-to-user # vary user-to-user
f.write(base_template.read().replace("{{ rendered_input }}", rendered_input)) f.write(base_template.read().replace("{{ rendered_input }}", rendered_input))
# Add the manage_preferences block content in the plain_text template.
manage_preferences_block_template_path = (
"templates/zerver/emails/custom_email_base.pre.manage_preferences_block.txt"
)
with (
open(plain_text_template_path, "a") as f,
open(manage_preferences_block_template_path) as manage_preferences_block,
):
f.write(manage_preferences_block.read())
with open(subject_path, "w") as f: with open(subject_path, "w") as f:
f.write(get_header(subject, parsed_email_template.get("subject"), "subject")) f.write(get_header(subject, parsed_email_template.get("subject"), "subject"))

View File

@ -90,6 +90,11 @@ class TestCustomEmails(ZulipTestCase):
str(msg.alternatives[0][0]), str(msg.alternatives[0][0]),
) )
self.assertIn("Unsubscribe", str(msg.alternatives[0][0])) self.assertIn("Unsubscribe", str(msg.alternatives[0][0]))
# Verify that the Text version contains the footer.
self.assertIn(
"You are receiving this email to update you about important changes to Zulip", msg.body
)
self.assertIn("Unsubscribe", msg.body)
def test_send_custom_email_headers(self) -> None: def test_send_custom_email_headers(self) -> None:
hamlet = self.example_user("hamlet") hamlet = self.example_user("hamlet")
@ -107,7 +112,7 @@ class TestCustomEmails(ZulipTestCase):
msg = mail.outbox[0] msg = mail.outbox[0]
self.assertEqual(msg.subject, "Test subject") self.assertEqual(msg.subject, "Test subject")
self.assertFalse(msg.reply_to) self.assertFalse(msg.reply_to)
self.assertEqual("Test body", msg.body) self.assertIn("Test body", msg.body)
def test_send_custom_email_context(self) -> None: def test_send_custom_email_context(self) -> None:
hamlet = self.example_user("hamlet") hamlet = self.example_user("hamlet")