Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
demo-orgs: Check owner email for missed message emails.
Lauryn Menard2fac27afb9ba
diff --git a/zerver/lib/email_notifications.py b/zerver/lib/email_notifications.pyindex c99d06788fe..afd0b9a95ad 100644--- a/zerver/lib/email_notifications.py+++ b/zerver/lib/email_notifications.py@@ -621,6 +621,18 @@ def handle_missedmessage_emails(# BUG: Investigate why it's possible to get here.return # nocoverage+ if user_profile.delivery_email == "":+ # The assertions here are to help document the only circumstance under which+ # this condition should be possible.+ assert (+ user_profile.realm.demo_organization_scheduled_deletion_date is not None+ and user_profile.is_realm_owner+ )+ # Because demo organizations are created without setting an email, we can't+ # send any missed message emails until they add an email to their account,+ # e.g., they receive a direct message from the Welcome or Notification bot.+ return+# Note: This query structure automatically filters out any# messages that were permanently deleted, since those would now be# in the ArchivedMessage table, not the Message table.diff --git a/zerver/tests/test_message_notification_emails.py b/zerver/tests/test_message_notification_emails.pyindex bc158ae836e..70a2ce3ce15 100644--- a/zerver/tests/test_message_notification_emails.py+++ b/zerver/tests/test_message_notification_emails.py@@ -1,6 +1,7 @@import randomimport refrom collections.abc import Sequence+from datetime import timedeltafrom email.headerregistry import Addressfrom unittest import mockfrom unittest.mock import patch@@ -11,9 +12,11 @@ from django.conf import settingsfrom django.core import mailfrom django.core.mail.message import EmailMultiAlternativesfrom django.test import override_settings+from django.utils.timezone import now as timezone_nowfrom django_stubs_ext import StrPromisefrom zerver.actions.create_user import do_create_user+from zerver.actions.message_send import internal_send_private_messagefrom zerver.actions.user_groups import add_subgroups_to_user_group, check_add_user_groupfrom zerver.actions.user_settings import do_change_user_settingfrom zerver.actions.user_topics import do_set_user_topic_visibility_policy@@ -89,6 +92,35 @@ class TestMessageNotificationEmails(ZulipTestCase):)m.assert_not_called()+ def test_demo_organization_owner_email_not_set(self) -> None:+ realm = get_realm("zulip")+ realm.demo_organization_scheduled_deletion_date = timezone_now() + timedelta(days=30)+ realm.save()++ # Demo organization owner's don't have an email address set initially+ desdemona = self.example_user("desdemona")+ desdemona.delivery_email = ""+ desdemona.save()++ notification_bot = self.notification_bot(realm)+ internal_send_private_message(+ sender=notification_bot,+ recipient_user=desdemona,+ content="Notification bot message",+ )+ message = self.get_last_message()+ self.assertEqual(message.sender.id, notification_bot.id)+ self.assertEqual(message.content, "Notification bot message")++ with mock.patch(+ "zerver.lib.email_notifications.do_send_missedmessage_events_reply_in_zulip"+ ) as m:+ handle_missedmessage_emails(+ desdemona.id,+ {message.id: MissedMessageData(trigger=NotificationTriggers.DIRECT_MESSAGE)},+ )+ m.assert_not_called()+def normalize_string(self, s: str | StrPromise) -> str:s = s.strip()return re.sub(r"\s+", " ", s)