From 45bc220796ded574ab81e1add2e07c4e3debf6a2 Mon Sep 17 00:00:00 2001 From: Harshit Bansal Date: Fri, 14 Jul 2017 23:07:52 +0000 Subject: [PATCH] notifications: Fix relative stream links in missed message emails. Fixes: #5310. --- zerver/lib/notifications.py | 7 +++++++ zerver/tests/test_notifications.py | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/zerver/lib/notifications.py b/zerver/lib/notifications.py index d677345dcc..a8d200a392 100644 --- a/zerver/lib/notifications.py +++ b/zerver/lib/notifications.py @@ -119,6 +119,13 @@ def build_message_list(user_profile, messages): r"/user_avatars/(\d+)/emoji/", user_profile.realm.uri + r"/user_avatars/\1/emoji/", content) + # Stream links need to be converted from relative to absolute. They + # have href values in the form of "/#narrow/stream/...". + content = re.sub( + r"/#narrow/stream/", + user_profile.realm.uri + r"/#narrow/stream/", + content) + return content def fix_plaintext_image_urls(content): diff --git a/zerver/tests/test_notifications.py b/zerver/tests/test_notifications.py index 6f9e7ad201..6f05005e60 100644 --- a/zerver/tests/test_notifications.py +++ b/zerver/tests/test_notifications.py @@ -349,3 +349,16 @@ class TestMissedMessages(ZulipTestCase): body = ':test_emoji:' subject = 'Othello, the Moor of Venice sent you a message' self._test_cases(tokens, msg_id, body, subject, send_as_user=False, verify_html_body=True) + + @patch('zerver.lib.email_mirror.generate_random_token') + def test_stream_link_in_missed_message(self, mock_random_token): + # type: (MagicMock) -> None + tokens = self._get_tokens() + mock_random_token.side_effect = tokens + + msg_id = self.send_message(self.example_email('othello'), self.example_email('hamlet'), + Recipient.PERSONAL, + 'Come and join us in #**Verona**.') + body = '#Verona