From 70ab893d34b299f9541f9ad7afa7b7e5e3b50ff8 Mon Sep 17 00:00:00 2001
From: Lauryn Menard
Date: Fri, 4 Oct 2024 16:54:16 +0200
Subject: [PATCH] urls: Generate narrow links in backend with "channel"
operator.
---
zerver/lib/markdown/__init__.py | 4 +--
zerver/lib/url_decoding.py | 4 +--
zerver/lib/url_encoding.py | 6 ++--
.../tests/fixtures/markdown_test_cases.json | 16 +++++-----
.../fixtures/message_link_test_cases.json | 6 ++--
zerver/tests/test_auth_backends.py | 6 ++--
zerver/tests/test_digest.py | 2 +-
zerver/tests/test_markdown.py | 32 +++++++++----------
.../tests/test_message_notification_emails.py | 10 +++---
zerver/tests/test_outgoing_webhook_system.py | 16 +++++-----
zerver/tests/test_push_notifications.py | 2 +-
zerver/tests/test_subs.py | 2 +-
12 files changed, 53 insertions(+), 53 deletions(-)
diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.py
index f01fc1b584..f23532bd4c 100644
--- a/zerver/lib/markdown/__init__.py
+++ b/zerver/lib/markdown/__init__.py
@@ -2008,7 +2008,7 @@ class StreamPattern(CompiledInlineProcessor):
# provide more clarity to API clients.
# Also do the same for StreamTopicPattern.
stream_url = encode_stream(stream_id, name)
- el.set("href", f"/#narrow/stream/{stream_url}")
+ el.set("href", f"/#narrow/channel/{stream_url}")
text = f"#{name}"
el.text = markdown.util.AtomicString(text)
return el, m.start(), m.end()
@@ -2037,7 +2037,7 @@ class StreamTopicPattern(CompiledInlineProcessor):
el.set("data-stream-id", str(stream_id))
stream_url = encode_stream(stream_id, stream_name)
topic_url = hash_util_encode(topic_name)
- link = f"/#narrow/stream/{stream_url}/topic/{topic_url}"
+ link = f"/#narrow/channel/{stream_url}/topic/{topic_url}"
el.set("href", link)
text = f"#{stream_name} > {topic_name}"
el.text = markdown.util.AtomicString(text)
diff --git a/zerver/lib/url_decoding.py b/zerver/lib/url_decoding.py
index 4a5aff455e..bff76444b7 100644
--- a/zerver/lib/url_decoding.py
+++ b/zerver/lib/url_decoding.py
@@ -11,7 +11,7 @@ def is_same_server_message_link(url: str) -> bool:
if hostname not in {None, settings.EXTERNAL_HOST_WITHOUT_PORT}:
return False
- # A message link always has category `narrow`, section `stream`
+ # A message link always has category `narrow`, section `channel`
# or `dm`, and ends with `/near/`, where
# is a sequence of digits. The URL fragment of a message link has
# at least 5 parts. e.g. '#narrow/dm/9,15-dm/near/43'
@@ -23,4 +23,4 @@ def is_same_server_message_link(url: str) -> bool:
section = fragment_parts[1]
ends_with_near_message_id = fragment_parts[-2] == "near" and fragment_parts[-1].isdigit()
- return category == "narrow" and section in {"stream", "dm"} and ends_with_near_message_id
+ return category == "narrow" and section in {"channel", "dm"} and ends_with_near_message_id
diff --git a/zerver/lib/url_encoding.py b/zerver/lib/url_encoding.py
index ca112ab70b..25fe4e6c61 100644
--- a/zerver/lib/url_encoding.py
+++ b/zerver/lib/url_encoding.py
@@ -39,12 +39,12 @@ def direct_message_group_narrow_url(
def stream_narrow_url(realm: Realm, stream: Stream) -> str:
- base_url = f"{realm.url}/#narrow/stream/"
+ base_url = f"{realm.url}/#narrow/channel/"
return base_url + encode_stream(stream.id, stream.name)
def topic_narrow_url(*, realm: Realm, stream: Stream, topic_name: str) -> str:
- base_url = f"{realm.url}/#narrow/stream/"
+ base_url = f"{realm.url}/#narrow/channel/"
return f"{base_url}{encode_stream(stream.id, stream.name)}/topic/{hash_util_encode(topic_name)}"
@@ -74,7 +74,7 @@ def near_stream_message_url(realm: Realm, message: dict[str, Any]) -> str:
parts = [
realm.url,
"#narrow",
- "stream",
+ "channel",
encoded_stream,
"topic",
encoded_topic_name,
diff --git a/zerver/tests/fixtures/markdown_test_cases.json b/zerver/tests/fixtures/markdown_test_cases.json
index 2e2b3c6fd1..593e7fc505 100644
--- a/zerver/tests/fixtures/markdown_test_cases.json
+++ b/zerver/tests/fixtures/markdown_test_cases.json
@@ -488,9 +488,9 @@
},
{
"name": "fragment_link",
- "input": "[foo](http://zulip.testserver/#narrow/stream/1-Denmark)",
- "expected_output": "foo
",
- "marked_expected_output": "foo
"
+ "input": "[foo](http://zulip.testserver/#narrow/channel/1-Denmark)",
+ "expected_output": "foo
",
+ "marked_expected_output": "foo
"
},
{
"name": "not_fragment_link",
@@ -1050,9 +1050,9 @@
},
{
"name": "normal_quote_and_reply",
- "input": "@_**Zoe|7** [said](http://zulip.testserver/#narrow/stream/13-social/topic/party/near/103):\n```quote\nHow are you?\n```\n\nGreat",
- "expected_output": "Zoe said:
\n\nHow are you?
\n
\nGreat
",
- "marked_expected_output": "Zoe said:
\n\nHow are you?
\n
\nGreat
",
+ "input": "@_**Zoe|7** [said](http://zulip.testserver/#narrow/channel/13-social/topic/party/near/103):\n```quote\nHow are you?\n```\n\nGreat",
+ "expected_output": "Zoe said:
\n\nHow are you?
\n
\nGreat
",
+ "marked_expected_output": "Zoe said:
\n\nHow are you?
\n
\nGreat
",
"text_content": "[…]\nGreat"
},
{
@@ -1316,8 +1316,8 @@
""
],
[
- "http://zulip.testserver/#narrow/stream/1-Denmark",
- "http://zulip.testserver/#narrow/stream/1-Denmark
",
+ "http://zulip.testserver/#narrow/channel/1-Denmark",
+ "http://zulip.testserver/#narrow/channel/1-Denmark
",
""
],
[
diff --git a/zerver/tests/fixtures/message_link_test_cases.json b/zerver/tests/fixtures/message_link_test_cases.json
index 6cdfad33ff..10c578a50c 100644
--- a/zerver/tests/fixtures/message_link_test_cases.json
+++ b/zerver/tests/fixtures/message_link_test_cases.json
@@ -11,17 +11,17 @@
},
{
"name": "stream_message_link",
- "message_link": "#narrow/stream/8-design/topic/desktop/near/82",
+ "message_link": "#narrow/channel/8-design/topic/desktop/near/82",
"expected_output": true
},
{
"name": "stream_link",
- "message_link": "#narrow/stream/8-design",
+ "message_link": "#narrow/channel/8-design",
"expected_output": false
},
{
"name": "topic_link",
- "message_link": "#narrow/stream/8-design/topic/desktop",
+ "message_link": "#narrow/channel/8-design/topic/desktop",
"expected_output": false
},
{
diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py
index 8a4117ccde..ae77b5f1ea 100644
--- a/zerver/tests/test_auth_backends.py
+++ b/zerver/tests/test_auth_backends.py
@@ -4747,9 +4747,9 @@ class GoogleAuthBackendTest(SocialAuthBase):
self.assertEqual(res.status_code, 302)
self.assertEqual(res["Location"], "http://zulip.testserver/user_uploads/path_to_image")
- res = test_redirect_to_next_url("/#narrow/stream/7-test-here")
+ res = test_redirect_to_next_url("/#narrow/channel/7-test-here")
self.assertEqual(res.status_code, 302)
- self.assertEqual(res["Location"], "http://zulip.testserver/#narrow/stream/7-test-here")
+ self.assertEqual(res["Location"], "http://zulip.testserver/#narrow/channel/7-test-here")
def test_log_into_subdomain_when_token_is_malformed(self) -> None:
data: ExternalAuthDataDict = {
@@ -5600,7 +5600,7 @@ class TestDevAuthBackend(ZulipTestCase):
# to the backend. Rather we depend upon the browser's behaviour of persisting
# hash anchors in between redirect requests. See below stackoverflow conversation
# https://stackoverflow.com/questions/5283395/url-hash-is-persisting-between-redirects
- res = do_local_login("/accounts/login/local/?next=#narrow/stream/7-test-here")
+ res = do_local_login("/accounts/login/local/?next=#narrow/channel/7-test-here")
self.assertEqual(res.status_code, 302)
self.assertEqual(res["Location"], "http://zulip.testserver")
diff --git a/zerver/tests/test_digest.py b/zerver/tests/test_digest.py
index a4e7f4fff5..569c0f1feb 100644
--- a/zerver/tests/test_digest.py
+++ b/zerver/tests/test_digest.py
@@ -509,7 +509,7 @@ class TestDigestEmailMessages(ZulipTestCase):
realm, recently_created_streams, can_access_public=True
)
self.assertEqual(stream_count, 1)
- expected_html = f"New stream"
+ expected_html = f"New stream"
self.assertEqual(stream_info["html"][0], expected_html)
# guests don't see our stream
diff --git a/zerver/tests/test_markdown.py b/zerver/tests/test_markdown.py
index 3eee89c099..74caf860a3 100644
--- a/zerver/tests/test_markdown.py
+++ b/zerver/tests/test_markdown.py
@@ -588,10 +588,10 @@ class MarkdownLinkTest(ZulipTestCase):
sender_user_profile = self.example_user("othello")
message = Message(sender=sender_user_profile, sending_client=get_client("test"))
- msg = "http://zulip.testserver/#narrow/stream/999-hello"
+ msg = "http://zulip.testserver/#narrow/channel/999-hello"
self.assertEqual(
markdown_convert(msg, message_realm=realm, message=message).rendered_content,
- 'http://zulip.testserver/#narrow/stream/999-hello
',
+ 'http://zulip.testserver/#narrow/channel/999-hello
',
)
msg = f"http://zulip.testserver/user_uploads/{realm.id}/ff/file.txt"
@@ -622,10 +622,10 @@ class MarkdownLinkTest(ZulipTestCase):
sender_user_profile = self.example_user("othello")
message = Message(sender=sender_user_profile, sending_client=get_client("test"))
- msg = "[hello](http://zulip.testserver/#narrow/stream/999-hello)"
+ msg = "[hello](http://zulip.testserver/#narrow/channel/999-hello)"
self.assertEqual(
markdown_convert(msg, message_realm=realm, message=message).rendered_content,
- 'hello
',
+ 'hello
',
)
msg = f"[hello](http://zulip.testserver/user_uploads/{realm.id}/ff/file.txt)"
@@ -2984,7 +2984,7 @@ class MarkdownStreamMentionTests(ZulipTestCase):
content = "#**Denmark**"
self.assertEqual(
render_message_markdown(msg, content).rendered_content,
- f'#{denmark.name}
',
+ f'#{denmark.name}
',
)
def test_invalid_stream_followed_by_valid_mention(self) -> None:
@@ -2998,7 +2998,7 @@ class MarkdownStreamMentionTests(ZulipTestCase):
content = "#**Invalid** and #**Denmark**"
self.assertEqual(
render_message_markdown(msg, content).rendered_content,
- f'#Invalid and #{denmark.name}
',
+ f'#Invalid and #{denmark.name}
',
)
def test_stream_multiple(self) -> None:
@@ -3017,10 +3017,10 @@ class MarkdownStreamMentionTests(ZulipTestCase):
"Look to "
'#{denmark.name} and '
+ f'href="/#narrow/channel/{denmark.id}-Denmark">#{denmark.name} and '
'#{scotland.name}, '
+ f'href="/#narrow/channel/{scotland.id}-Scotland">#{scotland.name}, '
"there something
",
)
@@ -3032,7 +3032,7 @@ class MarkdownStreamMentionTests(ZulipTestCase):
content = "#**CaseSens**"
self.assertEqual(
render_message_markdown(msg, content).rendered_content,
- f'#{case_sens.name}
',
+ f'#{case_sens.name}
',
)
def test_stream_case_sensitivity_nonmatching(self) -> None:
@@ -3060,7 +3060,7 @@ class MarkdownStreamMentionTests(ZulipTestCase):
content = "#**Denmark>some topic**"
self.assertEqual(
render_message_markdown(msg, content).rendered_content,
- f'#{denmark.name} > some topic
',
+ f'#{denmark.name} > some topic
',
)
def test_topic_atomic_string(self) -> None:
@@ -3082,7 +3082,7 @@ class MarkdownStreamMentionTests(ZulipTestCase):
content = "#**Denmark>#1234**"
self.assertEqual(
render_message_markdown(msg, content).rendered_content,
- f'#{denmark.name} > #1234
',
+ f'#{denmark.name} > #1234
',
)
def test_topic_multiple(self) -> None:
@@ -3099,11 +3099,11 @@ class MarkdownStreamMentionTests(ZulipTestCase):
render_message_markdown(msg, content).rendered_content,
"This has two links: "
f''
+ f'href="/#narrow/channel/{denmark.id}-{denmark.name}/topic/some.20topic">'
f"#{denmark.name} > some topic"
" and "
f''
+ f'href="/#narrow/channel/{scotland.id}-{scotland.name}/topic/other.20topic">'
f"#{scotland.name} > other topic"
".
",
)
@@ -3125,7 +3125,7 @@ class MarkdownStreamMentionTests(ZulipTestCase):
msg = Message(sender=sender_user_profile, sending_client=get_client("test"), realm=realm)
content = "#**привет**"
quoted_name = ".D0.BF.D1.80.D0.B8.D0.B2.D0.B5.D1.82"
- href = f"/#narrow/stream/{uni.id}-{quoted_name}"
+ href = f"/#narrow/channel/{uni.id}-{quoted_name}"
self.assertEqual(
render_message_markdown(msg, content).rendered_content,
f'#{uni.name}
',
@@ -3148,7 +3148,7 @@ class MarkdownStreamMentionTests(ZulipTestCase):
stream = self.make_stream(stream_name="Stream #1234", realm=realm)
msg = Message(sender=sender_user_profile, sending_client=get_client("test"), realm=realm)
content = "#**Stream #1234**"
- href = f"/#narrow/stream/{stream.id}-Stream-.231234"
+ href = f"/#narrow/channel/{stream.id}-Stream-.231234"
self.assertEqual(
render_message_markdown(msg, content).rendered_content,
f'#{stream.name}
',
@@ -3290,7 +3290,7 @@ class MarkdownApiTests(ZulipTestCase):
stream_id = get_stream("Denmark", get_realm("zulip")).id
self.assertEqual(
response_dict["rendered"],
- f'This mentions #Denmark and @King Hamlet.
',
+ f'This mentions #Denmark and @King Hamlet.
',
)
diff --git a/zerver/tests/test_message_notification_emails.py b/zerver/tests/test_message_notification_emails.py
index 2d25a4efcc..6006efc7f0 100644
--- a/zerver/tests/test_message_notification_emails.py
+++ b/zerver/tests/test_message_notification_emails.py
@@ -1220,7 +1220,7 @@ class TestMessageNotificationEmails(ZulipTestCase):
"Come and join us in #**Verona**.",
)
stream_id = get_stream("Verona", get_realm("zulip")).id
- href = f"http://zulip.testserver/#narrow/stream/{stream_id}-Verona"
+ href = f"http://zulip.testserver/#narrow/channel/{stream_id}-Verona"
verify_body_include = [
f'#VeronaConversation
'
+ 'Conversation
'
)
actual_output = convert(test_data)
expected_output = (
- ''
+ ''
)
self.assertEqual(actual_output, expected_output)
diff --git a/zerver/tests/test_outgoing_webhook_system.py b/zerver/tests/test_outgoing_webhook_system.py
index 8cd98e2d02..470c29c901 100644
--- a/zerver/tests/test_outgoing_webhook_system.py
+++ b/zerver/tests/test_outgoing_webhook_system.py
@@ -132,13 +132,13 @@ class DoRestCallTests(ZulipTestCase):
self.assertEqual(
m.output,
[
- f'WARNING:root:Message http://zulip.testserver/#narrow/stream/999-Verona/topic/Foo/near/ triggered an outgoing webhook, returning status code 500.\n Content of response (in quotes): "{final_response.text}"'
+ f'WARNING:root:Message http://zulip.testserver/#narrow/channel/999-Verona/topic/Foo/near/ triggered an outgoing webhook, returning status code 500.\n Content of response (in quotes): "{final_response.text}"'
],
)
bot_owner_notification = self.get_last_message()
self.assertEqual(
bot_owner_notification.content,
- """[A message](http://zulip.testserver/#narrow/stream/999-Verona/topic/Foo/near/) to your bot @_**Outgoing Webhook** triggered an outgoing webhook.
+ """[A message](http://zulip.testserver/#narrow/channel/999-Verona/topic/Foo/near/) to your bot @_**Outgoing Webhook** triggered an outgoing webhook.
The webhook got a response with status code *500*.""",
)
@@ -196,7 +196,7 @@ The webhook got a response with status code *500*.""",
self.assertEqual(
m.output,
[
- f'WARNING:root:Message http://zulip.testserver/#narrow/stream/999-Verona/topic/Foo/near/ triggered an outgoing webhook, returning status code 400.\n Content of response (in quotes): "{final_response.text}"'
+ f'WARNING:root:Message http://zulip.testserver/#narrow/channel/999-Verona/topic/Foo/near/ triggered an outgoing webhook, returning status code 400.\n Content of response (in quotes): "{final_response.text}"'
],
)
@@ -205,7 +205,7 @@ The webhook got a response with status code *500*.""",
bot_owner_notification = self.get_last_message()
self.assertEqual(
bot_owner_notification.content,
- """[A message](http://zulip.testserver/#narrow/stream/999-Verona/topic/Foo/near/) to your bot @_**Outgoing Webhook** triggered an outgoing webhook.
+ """[A message](http://zulip.testserver/#narrow/channel/999-Verona/topic/Foo/near/) to your bot @_**Outgoing Webhook** triggered an outgoing webhook.
The webhook got a response with status code *400*.""",
)
@@ -291,7 +291,7 @@ The webhook got a response with status code *400*.""",
bot_owner_notification = self.get_last_message()
self.assertEqual(
bot_owner_notification.content,
- """[A message](http://zulip.testserver/#narrow/stream/999-Verona/topic/Foo/near/) to your bot @_**Outgoing Webhook** triggered an outgoing webhook.
+ """[A message](http://zulip.testserver/#narrow/channel/999-Verona/topic/Foo/near/) to your bot @_**Outgoing Webhook** triggered an outgoing webhook.
When trying to send a request to the webhook service, an exception of type RequestException occurred:
```
I'm a generic exception :(
@@ -322,7 +322,7 @@ I'm a generic exception :(
bot_owner_notification = self.get_last_message()
self.assertEqual(
bot_owner_notification.content,
- """[A message](http://zulip.testserver/#narrow/stream/999-Verona/topic/Foo/near/) to your bot @_**Outgoing Webhook** triggered an outgoing webhook.
+ """[A message](http://zulip.testserver/#narrow/channel/999-Verona/topic/Foo/near/) to your bot @_**Outgoing Webhook** triggered an outgoing webhook.
The outgoing webhook server attempted to send a message in Zulip, but that request resulted in the following error:
> Widgets: API programmer sent invalid JSON content\nThe response contains the following payload:\n```\n'{"content": "whatever", "widget_content": "test"}'\n```""",
)
@@ -349,7 +349,7 @@ The outgoing webhook server attempted to send a message in Zulip, but that reque
bot_owner_notification = self.get_last_message()
self.assertEqual(
bot_owner_notification.content,
- """[A message](http://zulip.testserver/#narrow/stream/999-Verona/topic/Foo/near/) to your bot @_**Outgoing Webhook** triggered an outgoing webhook.
+ """[A message](http://zulip.testserver/#narrow/channel/999-Verona/topic/Foo/near/) to your bot @_**Outgoing Webhook** triggered an outgoing webhook.
The outgoing webhook server attempted to send a message in Zulip, but that request resulted in the following error:
> Invalid response format\nThe response contains the following payload:\n```\n'true'\n```""",
)
@@ -378,7 +378,7 @@ The outgoing webhook server attempted to send a message in Zulip, but that reque
bot_owner_notification = self.get_last_message()
self.assertEqual(
bot_owner_notification.content,
- """[A message](http://zulip.testserver/#narrow/stream/999-Verona/topic/Foo/near/) to your bot @_**Outgoing Webhook** triggered an outgoing webhook.
+ """[A message](http://zulip.testserver/#narrow/channel/999-Verona/topic/Foo/near/) to your bot @_**Outgoing Webhook** triggered an outgoing webhook.
The outgoing webhook server attempted to send a message in Zulip, but that request resulted in the following error:
> Invalid JSON in response\nThe response contains the following payload:\n```\n"this isn't valid json"\n```""",
)
diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py
index fb1fe0eb7d..ccbf4be4c4 100644
--- a/zerver/tests/test_push_notifications.py
+++ b/zerver/tests/test_push_notifications.py
@@ -5124,7 +5124,7 @@ class TestPushNotificationsContent(ZulipTestCase):
},
{
"name": "stream_names",
- "rendered_content": f'Testing stream names #Verona.
',
+ "rendered_content": f'Testing stream names #Verona.
',
"expected_output": "Testing stream names #Verona.",
},
]
diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py
index 36465cb655..2d27da6f49 100644
--- a/zerver/tests/test_subs.py
+++ b/zerver/tests/test_subs.py
@@ -4352,7 +4352,7 @@ class SubscriptionAPITest(ZulipTestCase):
self.assertEqual(msg.recipient.type_id, new_stream_announcements_stream.id)
self.assertEqual(msg.sender_id, self.notification_bot(realm).id)
stream_id = Stream.objects.latest("id").id
- expected_rendered_msg = f'{user.full_name} created a new channel #{invite_streams[0]}.
'
+ expected_rendered_msg = f'{user.full_name} created a new channel #{invite_streams[0]}.
'
self.assertEqual(msg.rendered_content, expected_rendered_msg)
def test_successful_subscriptions_notifies_with_escaping(self) -> None: