notifications: Fix the if/elif order in the manage_preferences block.

The emails sent for missed messages have a text at the bottom
explaining the reason why the email was sent.

This commit reorders the conditional statements in the email
template to align with the trigger priority order defined
in the 'get_email_notification_trigger'.
This commit is contained in:
Prakhar Pratyush 2023-06-22 10:02:32 +05:30 committed by Tim Abbott
parent f7e41499fe
commit 5f6dd83696
3 changed files with 82 additions and 16 deletions

View File

@ -29,14 +29,14 @@
{% trans %}You are receiving this because you were personally mentioned.{% endtrans %}<br />
{% elif mentioned_user_group_name %}
{% trans %}You are receiving this because @{{ mentioned_user_group_name }} was mentioned.{% endtrans %}<br />
{% elif wildcard_mentioned %}
{% trans %}You are receiving this because everyone was mentioned in #{{ stream_name }}.{% endtrans %}<br />
{% elif followed_topic_wildcard_mentioned %}
{% trans %}You are receiving this because you have wildcard mention notifications enabled for topics you follow.{% endtrans %}<br />
{% elif stream_email_notify %}
{% trans %}You are receiving this because you have email notifications enabled for #{{ stream_name }}.{% endtrans %}<br />
{% elif wildcard_mentioned %}
{% trans %}You are receiving this because everyone was mentioned in #{{ stream_name }}.{% endtrans %}<br />
{% elif followed_topic_email_notify %}
{% trans %}You are receiving this because you have email notifications enabled for topics you follow.{% endtrans %}<br />
{% elif stream_email_notify %}
{% trans %}You are receiving this because you have email notifications enabled for #{{ stream_name }}.{% endtrans %}<br />
{% endif %}
{% if reply_to_zulip %}
{% trans notif_url=realm_uri + "/#settings/notifications" %}Reply to this email directly, <a href="{{ narrow_url }}">view it in {{ realm_name }} Zulip</a>, or <a href="{{ notif_url }}">manage email preferences</a>.{% endtrans %}

View File

@ -25,14 +25,14 @@ See {{ alert_notif_url }} for more details.
{% trans %}You are receiving this because you were personally mentioned.{% endtrans %}
{% elif mentioned_user_group_name %}
{% trans %}You are receiving this because @{{ mentioned_user_group_name }} was mentioned.{% endtrans %}
{% elif wildcard_mentioned %}
{% trans %}You are receiving this because everyone was mentioned in #{{ stream_name }}.{% endtrans %}
{% elif followed_topic_wildcard_mentioned %}
{% trans %}You are receiving this because you have wildcard mention notifications enabled for topics you follow.{% endtrans %}
{% elif stream_email_notify %}
{% trans %}You are receiving this because you have email notifications enabled for #{{ stream_name }}.{% endtrans %}
{% elif wildcard_mentioned %}
{% trans %}You are receiving this because everyone was mentioned in #{{ stream_name }}.{% endtrans %}
{% elif followed_topic_email_notify %}
{% trans %}You are receiving this because you have email notifications enabled for topics you follow.{% endtrans %}
{% elif stream_email_notify %}
{% trans %}You are receiving this because you have email notifications enabled for #{{ stream_name }}.{% endtrans %}
{% endif %}
{% if reply_to_zulip %}

View File

@ -1061,7 +1061,7 @@ class TestMissedMessages(ZulipTestCase):
for text in expected_email_include:
self.assertIn(text, self.normalize_string(mail.outbox[0].body))
def test_user_group_over_wildcard_mention_priority(self) -> None:
def test_user_group_over_followed_topic_wildcard_mention_priority(self) -> None:
hamlet = self.example_user("hamlet")
cordelia = self.example_user("cordelia")
othello = self.example_user("othello")
@ -1070,7 +1070,9 @@ class TestMissedMessages(ZulipTestCase):
get_realm("zulip"), "hamlet_and_cordelia", [hamlet, cordelia], acting_user=None
)
wildcard_mentioned_message_id = self.send_stream_message(othello, "Denmark", "@**all**")
followed_topic_wildcard_mentioned_message_id = self.send_stream_message(
othello, "Denmark", "@**all**"
)
user_group_mentioned_message_id = self.send_stream_message(
othello, "Denmark", "@*hamlet_and_cordelia*"
)
@ -1079,8 +1081,8 @@ class TestMissedMessages(ZulipTestCase):
hamlet.id,
[
{
"message_id": wildcard_mentioned_message_id,
"trigger": "wildcard_mentioned",
"message_id": followed_topic_wildcard_mentioned_message_id,
"trigger": "followed_topic_wildcard_mentioned",
"mentioned_user_group_id": None,
},
{
@ -1099,19 +1101,52 @@ class TestMissedMessages(ZulipTestCase):
for text in expected_email_include:
self.assertIn(text, self.normalize_string(mail.outbox[0].body))
def test_wildcard_over_stream_mention_priority(self) -> None:
def test_followed_topic_wildcard_over_wildcard_mention_priority(self) -> None:
hamlet = self.example_user("hamlet")
othello = self.example_user("othello")
stream_mentioned_message_id = self.send_stream_message(othello, "Denmark", "1")
wildcard_mentioned_message_id = self.send_stream_message(othello, "Denmark", "@**all**")
followed_topic_wildcard_mentioned_message_id = self.send_stream_message(
othello, "Denmark", "@**all**"
)
handle_missedmessage_emails(
hamlet.id,
[
{
"message_id": wildcard_mentioned_message_id,
"trigger": "wildcard_mentioned",
"mentioned_user_group_id": None,
},
{
"message_id": followed_topic_wildcard_mentioned_message_id,
"trigger": "followed_topic_wildcard_mentioned",
"mentioned_user_group_id": None,
},
],
)
expected_email_include = [
"Othello, the Moor of Venice: > @**all** > @**all** -- ",
"You are receiving this because you have wildcard mention notifications enabled for topics you follow.",
]
for text in expected_email_include:
self.assertIn(text, self.normalize_string(mail.outbox[0].body))
def test_wildcard_mention_over_followed_topic_notify_priority(self) -> None:
hamlet = self.example_user("hamlet")
othello = self.example_user("othello")
followed_topic_mentioned_message_id = self.send_stream_message(othello, "Denmark", "1")
wildcard_mentioned_message_id = self.send_stream_message(othello, "Denmark", "@**all**")
handle_missedmessage_emails(
hamlet.id,
[
{
"message_id": stream_mentioned_message_id,
"trigger": "stream_email_notify",
"message_id": followed_topic_mentioned_message_id,
"trigger": "followed_topic_email_notify",
"mentioned_user_group_id": None,
},
{
@ -1130,6 +1165,37 @@ class TestMissedMessages(ZulipTestCase):
for text in expected_email_include:
self.assertIn(text, self.normalize_string(mail.outbox[0].body))
def test_followed_topic_notify_over_stream_message_notify_priority(self) -> None:
hamlet = self.example_user("hamlet")
othello = self.example_user("othello")
stream_mentioned_message_id = self.send_stream_message(othello, "Denmark", "0")
followed_topic_mentioned_message_id = self.send_stream_message(othello, "Denmark", "1")
handle_missedmessage_emails(
hamlet.id,
[
{
"message_id": stream_mentioned_message_id,
"trigger": "stream_email_notify",
"mentioned_user_group_id": None,
},
{
"message_id": followed_topic_mentioned_message_id,
"trigger": "followed_topic_email_notify",
"mentioned_user_group_id": None,
},
],
)
expected_email_include = [
"Othello, the Moor of Venice: > 0 > 1 -- ",
"You are receiving this because you have email notifications enabled for topics you follow.",
]
for text in expected_email_include:
self.assertIn(text, self.normalize_string(mail.outbox[0].body))
def test_include_realm_name_in_missedmessage_emails_subject(self) -> None:
user = self.example_user("hamlet")