mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
url_encoding: Use user name instead of email in personal_narrow_url.
This commit updates the urls for personal narrow sent in email
notifications to be of form "{user_id}-{encoded_full_name}" to
make it consistent with the urls that we use for such narrows
in webapp which were recently updated in b4eddad for improving
performance. We encode the full name in the same way that we do in
webapp by replacing the url characters encoded by browser with "-".
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
from email.headerregistry import Address
|
|
||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List
|
||||||
from urllib.parse import quote, urlsplit
|
from urllib.parse import quote, urlsplit
|
||||||
|
|
||||||
|
import re2
|
||||||
|
|
||||||
from zerver.lib.topic import get_topic_from_message_info
|
from zerver.lib.topic import get_topic_from_message_info
|
||||||
from zerver.models import Realm, Stream, UserProfile
|
from zerver.models import Realm, Stream, UserProfile
|
||||||
|
|
||||||
@@ -21,8 +22,8 @@ def encode_stream(stream_id: int, stream_name: str) -> str:
|
|||||||
|
|
||||||
def personal_narrow_url(realm: Realm, sender: UserProfile) -> str:
|
def personal_narrow_url(realm: Realm, sender: UserProfile) -> str:
|
||||||
base_url = f"{realm.uri}/#narrow/pm-with/"
|
base_url = f"{realm.uri}/#narrow/pm-with/"
|
||||||
email_user = Address(addr_spec=sender.email).username.lower()
|
encoded_user_name = re2.sub(r'[ "%\/<>`\p{C}]+', "-", sender.full_name)
|
||||||
pm_slug = str(sender.id) + "-" + hash_util_encode(email_user)
|
pm_slug = str(sender.id) + "-" + encoded_user_name
|
||||||
return base_url + pm_slug
|
return base_url + pm_slug
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1183,6 +1183,21 @@ class TestMissedMessages(ZulipTestCase):
|
|||||||
msg_id, verify_body_include, email_subject, send_as_user=False, verify_html_body=True
|
msg_id, verify_body_include, email_subject, send_as_user=False, verify_html_body=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_pm_link_in_missed_message_header(self) -> None:
|
||||||
|
cordelia = self.example_user("cordelia")
|
||||||
|
msg_id = self.send_personal_message(
|
||||||
|
cordelia,
|
||||||
|
self.example_user("hamlet"),
|
||||||
|
"Let's test PM link in email notifications",
|
||||||
|
)
|
||||||
|
|
||||||
|
encoded_name = "Cordelia,-Lear's-daughter"
|
||||||
|
verify_body_include = [
|
||||||
|
f"view it in Zulip Dev Zulip: http://zulip.testserver/#narrow/pm-with/{cordelia.id}-{encoded_name}"
|
||||||
|
]
|
||||||
|
email_subject = "PMs with Cordelia, Lear's daughter"
|
||||||
|
self._test_cases(msg_id, verify_body_include, email_subject, send_as_user=False)
|
||||||
|
|
||||||
def test_sender_name_in_missed_message(self) -> None:
|
def test_sender_name_in_missed_message(self) -> None:
|
||||||
hamlet = self.example_user("hamlet")
|
hamlet = self.example_user("hamlet")
|
||||||
msg_id_1 = self.send_stream_message(
|
msg_id_1 = self.send_stream_message(
|
||||||
|
|||||||
Reference in New Issue
Block a user