From 104139657ba7948c6d67e5e2fb20547951b89efe Mon Sep 17 00:00:00 2001 From: Mateusz Mandera Date: Sun, 7 Mar 2021 20:35:35 +0100 Subject: [PATCH] bots: Pass realm to get_system_bot calls in email_mirror. --- zerver/lib/email_mirror.py | 8 +++++--- zerver/tests/test_email_mirror.py | 10 ++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/zerver/lib/email_mirror.py b/zerver/lib/email_mirror.py index b01ccea286..0fa16a085c 100644 --- a/zerver/lib/email_mirror.py +++ b/zerver/lib/email_mirror.py @@ -228,7 +228,9 @@ def send_mm_reply_to_stream( stream=stream.name, error=error.msg ) internal_send_private_message( - get_system_bot(settings.NOTIFICATION_BOT), user_profile, error_message + get_system_bot(settings.NOTIFICATION_BOT, user_profile.realm_id), + user_profile, + error_message, ) @@ -326,7 +328,7 @@ def filter_footer(text: str) -> str: def extract_and_upload_attachments(message: EmailMessage, realm: Realm) -> str: - user_profile = get_system_bot(settings.EMAIL_GATEWAY_BOT) + user_profile = get_system_bot(settings.EMAIL_GATEWAY_BOT, realm.id) attachment_links = [] for part in message.walk(): @@ -422,7 +424,7 @@ def process_stream_message(to: str, message: EmailMessage) -> None: options["include_quotes"] = is_forwarded(subject_header) body = construct_zulip_body(message, stream.realm, **options) - send_zulip(get_system_bot(settings.EMAIL_GATEWAY_BOT), stream, subject, body) + send_zulip(get_system_bot(settings.EMAIL_GATEWAY_BOT, stream.realm_id), stream, subject, body) logger.info( "Successfully processed email to %s (%s)", stream.name, diff --git a/zerver/tests/test_email_mirror.py b/zerver/tests/test_email_mirror.py index ca8187d1e0..427c320fdc 100644 --- a/zerver/tests/test_email_mirror.py +++ b/zerver/tests/test_email_mirror.py @@ -528,7 +528,7 @@ class TestEmailMirrorMessagesWithAttachments(ZulipTestCase): len(image_bytes), "image/png", image_bytes, - get_system_bot(settings.EMAIL_GATEWAY_BOT), + get_system_bot(settings.EMAIL_GATEWAY_BOT, stream.realm_id), target_realm=user_profile.realm, ) @@ -571,7 +571,7 @@ class TestEmailMirrorMessagesWithAttachments(ZulipTestCase): len(image_bytes), "image/png", image_bytes, - get_system_bot(settings.EMAIL_GATEWAY_BOT), + get_system_bot(settings.EMAIL_GATEWAY_BOT, stream.realm_id), target_realm=user_profile.realm, ) @@ -617,7 +617,7 @@ class TestEmailMirrorMessagesWithAttachments(ZulipTestCase): len(image_bytes), "image/png", image_bytes, - get_system_bot(settings.EMAIL_GATEWAY_BOT), + get_system_bot(settings.EMAIL_GATEWAY_BOT, stream.realm_id), target_realm=user_profile.realm, ) @@ -977,7 +977,9 @@ class TestMissedMessageEmailMessages(ZulipTestCase): message.content, "Error sending message to stream announce via message notification email reply:\nOnly organization administrators can send to this stream.", ) - self.assertEqual(message.sender, get_system_bot(settings.NOTIFICATION_BOT)) + self.assertEqual( + message.sender, get_system_bot(settings.NOTIFICATION_BOT, user_profile.realm_id) + ) def test_missed_stream_message_email_response_tracks_topic_change(self) -> None: self.subscribe(self.example_user("hamlet"), "Denmark")