From 51b3ef8ee3f66606ceb6ba3e3fcfe9c507737483 Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Tue, 16 Apr 2024 20:45:02 +0200 Subject: [PATCH] streams-events: Update notifications for stream to channel rename. Updates notification messages that are sent to "stream events" topic when a permission or policy setting is changed to use channel instead of stream. Also, updates some strings that were not marked for translation in the message that was sent when the retention policy was changed. Updates notification messages that are sent when a stream/channel is created. Updates notification messages that are sent when a user is subscribed to stream/channel(s). Part of stream to channel rename project. --- tools/lib/capitalization.py | 2 +- zerver/actions/streams.py | 37 +++++++++++++---------- zerver/tests/test_subs.py | 58 +++++++++++++++++-------------------- zerver/views/streams.py | 12 ++++---- 4 files changed, 56 insertions(+), 53 deletions(-) diff --git a/tools/lib/capitalization.py b/tools/lib/capitalization.py index 41ab6479fd..cb6f403f19 100644 --- a/tools/lib/capitalization.py +++ b/tools/lib/capitalization.py @@ -102,7 +102,7 @@ IGNORED_PHRASES = [ r"in 20 minutes", r"in 3 hours", # these are used as topics - r"^new streams$", + r"^new channels$", r"^stream events$", # These are used as example short names (e.g. an uncapitalized context): r"^marketing$", diff --git a/zerver/actions/streams.py b/zerver/actions/streams.py index 618ba1ca88..e9ea206f8b 100644 --- a/zerver/actions/streams.py +++ b/zerver/actions/streams.py @@ -312,7 +312,7 @@ def do_unarchive_stream( sender, stream, str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC_NAME), - _("Stream {channel_name} un-archived.").format(channel_name=new_name), + _("Channel {channel_name} un-archived.").format(channel_name=new_name), ) @@ -1176,11 +1176,12 @@ def send_change_stream_permission_notification( with override_language(stream.realm.default_language): notification_string = _( - "{user} changed the [access permissions](/help/stream-permissions) " - "for this stream from **{old_policy}** to **{new_policy}**." + "{user} changed the [access permissions]({help_link}) " + "for this channel from **{old_policy}** to **{new_policy}**." ) notification_string = notification_string.format( user=user_mention, + help_link="/help/stream-permissions", old_policy=old_policy_name, new_policy=new_policy_name, ) @@ -1351,13 +1352,14 @@ def send_change_stream_post_policy_notification( with override_language(stream.realm.default_language): notification_string = _( - "{user} changed the [posting permissions](/help/stream-sending-policy) " - "for this stream:\n\n" + "{user} changed the [posting permissions]({help_link}) " + "for this channel:\n\n" "* **Old permissions**: {old_policy}.\n" "* **New permissions**: {new_policy}.\n" ) notification_string = notification_string.format( user=user_mention, + help_link="/help/stream-sending-policy", old_policy=Stream.POST_POLICIES[old_post_policy], new_policy=Stream.POST_POLICIES[new_post_policy], ) @@ -1467,7 +1469,7 @@ def do_rename_stream(stream: Stream, new_name: str, user_profile: UserProfile) - sender, stream, str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC_NAME), - _("{user_name} renamed stream {old_channel_name} to {new_channel_name}.").format( + _("{user_name} renamed channel {old_channel_name} to {new_channel_name}.").format( user_name=silent_mention_syntax_for_user(user_profile), old_channel_name=f"**{old_name}**", new_channel_name=f"**{new_name}**", @@ -1488,7 +1490,7 @@ def send_change_stream_description_notification( old_description = "*" + _("No description.") + "*" notification_string = ( - _("{user} changed the description for this stream.").format(user=user_mention) + _("{user} changed the description for this channel.").format(user=user_mention) + "\n\n* **" + _("Old description") + ":**" @@ -1561,24 +1563,29 @@ def send_change_stream_message_retention_days_notification( with override_language(stream.realm.default_language): if old_value == Stream.MESSAGE_RETENTION_SPECIAL_VALUES_MAP["unlimited"]: old_retention_period = _("Forever") - new_retention_period = f"{new_value} days" - summary_line = f"Messages in this stream will now be automatically deleted {new_value} days after they are sent." + new_retention_period = _("{number_of_days} days").format(number_of_days=new_value) + summary_line = _( + "Messages in this channel will now be automatically deleted {number_of_days} days after they are sent." + ).format(number_of_days=new_value) elif new_value == Stream.MESSAGE_RETENTION_SPECIAL_VALUES_MAP["unlimited"]: - old_retention_period = f"{old_value} days" + old_retention_period = _("{number_of_days} days").format(number_of_days=old_value) new_retention_period = _("Forever") - summary_line = _("Messages in this stream will now be retained forever.") + summary_line = _("Messages in this channel will now be retained forever.") else: - old_retention_period = f"{old_value} days" - new_retention_period = f"{new_value} days" - summary_line = f"Messages in this stream will now be automatically deleted {new_value} days after they are sent." + old_retention_period = _("{number_of_days} days").format(number_of_days=old_value) + new_retention_period = _("{number_of_days} days").format(number_of_days=new_value) + summary_line = _( + "Messages in this channel will now be automatically deleted {number_of_days} days after they are sent." + ).format(number_of_days=new_value) notification_string = _( - "{user} has changed the [message retention period](/help/message-retention-policy) for this stream:\n" + "{user} has changed the [message retention period]({help_link}) for this channel:\n" "* **Old retention period**: {old_retention_period}\n" "* **New retention period**: {new_retention_period}\n\n" "{summary_line}" ) notification_string = notification_string.format( user=user_mention, + help_link="/help/message-retention-policy", old_retention_period=old_retention_period, new_retention_period=new_retention_period, summary_line=summary_line, diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py index 3a562fc707..ebb1ba7847 100644 --- a/zerver/tests/test_subs.py +++ b/zerver/tests/test_subs.py @@ -675,7 +675,7 @@ class StreamAdminTest(ZulipTestCase): self.assert_length(messages, 1) expected_notification = ( f"@_**King Hamlet|{user_profile.id}** changed the [access permissions](/help/stream-permissions) " - "for this stream from **Private, protected history** to **Public**." + "for this channel from **Private, protected history** to **Public**." ) self.assertEqual(messages[0].content, expected_notification) @@ -736,7 +736,7 @@ class StreamAdminTest(ZulipTestCase): self.assert_length(messages, 1) expected_notification = ( f"@_**King Hamlet|{user_profile.id}** changed the [access permissions](/help/stream-permissions) " - "for this stream from **Public** to **Private, protected history**." + "for this channel from **Public** to **Private, protected history**." ) self.assertEqual(messages[0].content, expected_notification) @@ -853,7 +853,7 @@ class StreamAdminTest(ZulipTestCase): self.assert_length(messages, 1) expected_notification = ( f"@_**{user_profile.full_name}|{user_profile.id}** changed the [access permissions](/help/stream-permissions) " - "for this stream from **Private, protected history** to **Public, protected history**." + "for this channel from **Private, protected history** to **Public, protected history**." ) self.assertEqual(messages[0].content, expected_notification) @@ -892,7 +892,7 @@ class StreamAdminTest(ZulipTestCase): self.assert_length(messages, 1) expected_notification = ( f"@_**King Hamlet|{user_profile.id}** changed the [access permissions](/help/stream-permissions) " - "for this stream from **Public** to **Private, shared history**." + "for this channel from **Public** to **Private, shared history**." ) self.assertEqual(messages[0].content, expected_notification) @@ -931,7 +931,7 @@ class StreamAdminTest(ZulipTestCase): self.assert_length(messages, 1) expected_notification = ( f"@_**King Hamlet|{user_profile.id}** changed the [access permissions](/help/stream-permissions) " - "for this stream from **Private, protected history** to **Private, shared history**." + "for this channel from **Private, protected history** to **Private, shared history**." ) self.assertEqual(messages[0].content, expected_notification) @@ -1014,7 +1014,7 @@ class StreamAdminTest(ZulipTestCase): self.assert_length(messages, 1) expected_notification = ( f"@_**King Hamlet|{user_profile.id}** changed the [access permissions](/help/stream-permissions) " - "for this stream from **Public** to **Web-public**." + "for this channel from **Public** to **Web-public**." ) self.assertEqual(messages[0].content, expected_notification) @@ -1051,7 +1051,7 @@ class StreamAdminTest(ZulipTestCase): self.assert_length(messages, 1) expected_notification = ( f"@_**Iago|{user_profile.id}** changed the [access permissions](/help/stream-permissions) " - "for this stream from **Private, protected history** to **Private, shared history**." + "for this channel from **Private, protected history** to **Private, shared history**." ) self.assertEqual(messages[0].content, expected_notification) @@ -1081,7 +1081,7 @@ class StreamAdminTest(ZulipTestCase): self.assert_length(messages, 2) expected_notification = ( f"@_**Iago|{user_profile.id}** changed the [access permissions](/help/stream-permissions) " - "for this stream from **Private, shared history** to **Private, protected history**." + "for this channel from **Private, shared history** to **Private, protected history**." ) self.assertEqual(messages[1].content, expected_notification) @@ -1746,7 +1746,7 @@ class StreamAdminTest(ZulipTestCase): # Inspect the notification message sent message = self.get_last_message() actual_stream = Stream.objects.get(id=message.recipient.type_id) - message_content = f"@_**King Hamlet|{user_profile.id}** renamed stream **stream_name1** to **stream_name2**." + message_content = f"@_**King Hamlet|{user_profile.id}** renamed channel **stream_name1** to **stream_name2**." self.assertEqual(actual_stream.name, "stream_name2") self.assertEqual(actual_stream.realm_id, user_profile.realm_id) self.assertEqual(message.recipient.type, Recipient.STREAM) @@ -1873,7 +1873,7 @@ class StreamAdminTest(ZulipTestCase): messages = get_topic_messages(user_profile, stream, "stream events") expected_notification = ( - f"@_**{user_profile.full_name}|{user_profile.id}** changed the description for this stream.\n\n" + f"@_**{user_profile.full_name}|{user_profile.id}** changed the description for this channel.\n\n" "* **Old description:**\n" "```` quote\n" "Test description\n" @@ -1895,7 +1895,7 @@ class StreamAdminTest(ZulipTestCase): messages = get_topic_messages(user_profile, stream, "stream events") expected_notification = ( - f"@_**{user_profile.full_name}|{user_profile.id}** changed the description for this stream.\n\n" + f"@_**{user_profile.full_name}|{user_profile.id}** changed the description for this channel.\n\n" "* **Old description:**\n" "```` quote\n" "*No description.*\n" @@ -1917,7 +1917,7 @@ class StreamAdminTest(ZulipTestCase): messages = get_topic_messages(user_profile, stream, "stream events") expected_notification = ( - f"@_**{user_profile.full_name}|{user_profile.id}** changed the description for this stream.\n\n" + f"@_**{user_profile.full_name}|{user_profile.id}** changed the description for this channel.\n\n" "* **Old description:**\n" "```` quote\n" "Test description\n" @@ -1985,7 +1985,7 @@ class StreamAdminTest(ZulipTestCase): messages = get_topic_messages(user_profile, stream, "stream events") expected_notification = ( f"@_**{user_profile.full_name}|{user_profile.id}** changed the " - "[posting permissions](/help/stream-sending-policy) for this stream:\n\n" + "[posting permissions](/help/stream-sending-policy) for this channel:\n\n" "* **Old permissions**: All stream members can post.\n" "* **New permissions**: Only organization administrators can post." ) @@ -2048,7 +2048,7 @@ class StreamAdminTest(ZulipTestCase): messages = get_topic_messages(user_profile, stream, "stream events") expected_notification = ( f"@_**{user_profile.full_name}|{user_profile.id}** changed the " - "[posting permissions](/help/stream-sending-policy) for this stream:\n\n" + "[posting permissions](/help/stream-sending-policy) for this channel:\n\n" f"* **Old permissions**: {Stream.POST_POLICIES[old_post_policy]}.\n" f"* **New permissions**: {Stream.POST_POLICIES[policy]}." ) @@ -2082,10 +2082,10 @@ class StreamAdminTest(ZulipTestCase): messages = get_topic_messages(user_profile, stream, "stream events") self.assert_length(messages, 1) expected_notification = ( - f"@_**Desdemona|{user_profile.id}** has changed the [message retention period](/help/message-retention-policy) for this stream:\n" + f"@_**Desdemona|{user_profile.id}** has changed the [message retention period](/help/message-retention-policy) for this channel:\n" "* **Old retention period**: Forever\n" "* **New retention period**: 2 days\n\n" - "Messages in this stream will now be automatically deleted 2 days after they are sent." + "Messages in this channel will now be automatically deleted 2 days after they are sent." ) self.assertEqual(messages[0].content, expected_notification) realm_audit_log = RealmAuditLog.objects.filter( @@ -2103,10 +2103,10 @@ class StreamAdminTest(ZulipTestCase): messages = get_topic_messages(user_profile, stream, "stream events") self.assert_length(messages, 2) expected_notification = ( - f"@_**Desdemona|{user_profile.id}** has changed the [message retention period](/help/message-retention-policy) for this stream:\n" + f"@_**Desdemona|{user_profile.id}** has changed the [message retention period](/help/message-retention-policy) for this channel:\n" "* **Old retention period**: 2 days\n" "* **New retention period**: 8 days\n\n" - "Messages in this stream will now be automatically deleted 8 days after they are sent." + "Messages in this channel will now be automatically deleted 8 days after they are sent." ) self.assertEqual(messages[1].content, expected_notification) realm_audit_log = RealmAuditLog.objects.filter( @@ -2125,10 +2125,10 @@ class StreamAdminTest(ZulipTestCase): messages = get_topic_messages(user_profile, stream, "stream events") self.assert_length(messages, 3) expected_notification = ( - f"@_**Desdemona|{user_profile.id}** has changed the [message retention period](/help/message-retention-policy) for this stream:\n" + f"@_**Desdemona|{user_profile.id}** has changed the [message retention period](/help/message-retention-policy) for this channel:\n" "* **Old retention period**: 8 days\n" "* **New retention period**: Forever\n\n" - "Messages in this stream will now be retained forever." + "Messages in this channel will now be retained forever." ) self.assertEqual(messages[2].content, expected_notification) realm_audit_log = RealmAuditLog.objects.filter( @@ -4229,9 +4229,7 @@ class SubscriptionAPITest(ZulipTestCase): self.assertEqual(msg.recipient.type, Recipient.STREAM) self.assertEqual(msg.recipient.type_id, new_stream_announcements_stream.id) self.assertEqual(msg.sender_id, self.notification_bot(self.test_realm).id) - expected_msg = ( - f"@_**{invitee_full_name}|{invitee.id}** created a new stream #**{invite_streams[0]}**." - ) + expected_msg = f"@_**{invitee_full_name}|{invitee.id}** created a new channel #**{invite_streams[0]}**." self.assertEqual(msg.content, expected_msg) msg = self.get_last_message() @@ -4239,7 +4237,7 @@ class SubscriptionAPITest(ZulipTestCase): self.assertEqual(msg.recipient.type_id, target_stream.id) self.assertEqual(msg.sender_id, self.notification_bot(self.test_realm).id) expected_msg = ( - f"**Public** stream created by @_**{invitee_full_name}|{invitee.id}**. **Description:**\n" + f"**Public** channel created by @_**{invitee_full_name}|{invitee.id}**. **Description:**\n" "```` quote\n*No description.*\n````" ) self.assertEqual(msg.content, expected_msg) @@ -4275,7 +4273,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 stream #{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: @@ -4304,9 +4302,7 @@ class SubscriptionAPITest(ZulipTestCase): self.assertEqual( msg.sender_id, self.notification_bot(new_stream_announcements_stream.realm).id ) - expected_msg = ( - f"@_**{invitee_full_name}|{invitee.id}** created a new stream #**{invite_streams[0]}**." - ) + expected_msg = f"@_**{invitee_full_name}|{invitee.id}** created a new channel #**{invite_streams[0]}**." self.assertEqual(msg.content, expected_msg) def test_non_ascii_stream_subscription(self) -> None: @@ -4641,7 +4637,7 @@ class SubscriptionAPITest(ZulipTestCase): self.assertEqual(msg.topic_name(), "stream events") self.assertEqual(msg.sender.email, settings.NOTIFICATION_BOT) self.assertIn( - f"**{policy_name}** stream created by @_**{self.test_user.full_name}|{self.test_user.id}**. **Description:**\n" + f"**{policy_name}** channel created by @_**{self.test_user.full_name}|{self.test_user.id}**. **Description:**\n" "```` quote", msg.content, ) @@ -5973,7 +5969,7 @@ class GetSubscribersTest(ZulipTestCase): ) msg = f""" - @**King Hamlet|{hamlet.id}** subscribed you to the following streams: + @**King Hamlet|{hamlet.id}** subscribed you to the following channels: * #**stream_0** * #**stream_1** @@ -6008,7 +6004,7 @@ class GetSubscribersTest(ZulipTestCase): ) msg = f""" - @**King Hamlet|{hamlet.id}** subscribed you to the stream #**stream_invite_only_1**. + @**King Hamlet|{hamlet.id}** subscribed you to the channel #**stream_invite_only_1**. """ for user in [cordelia, othello, polonius]: self.assert_user_got_subscription_notification(user, msg) diff --git a/zerver/views/streams.py b/zerver/views/streams.py index b45ac7583c..f9eba6922b 100644 --- a/zerver/views/streams.py +++ b/zerver/views/streams.py @@ -514,13 +514,13 @@ def you_were_just_subscribed_message( subscriptions = sorted(stream_names) if len(subscriptions) == 1: with override_language(recipient_user.default_language): - return _("{user_full_name} subscribed you to the stream {channel_name}.").format( + return _("{user_full_name} subscribed you to the channel {channel_name}.").format( user_full_name=f"@**{acting_user.full_name}|{acting_user.id}**", channel_name=f"#**{subscriptions[0]}**", ) with override_language(recipient_user.default_language): - message = _("{user_full_name} subscribed you to the following streams:").format( + message = _("{user_full_name} subscribed you to the following channels:").format( user_full_name=f"@**{acting_user.full_name}|{acting_user.id}**", ) message += "\n\n" @@ -761,10 +761,10 @@ def send_messages_for_new_subscribers( if new_stream_announcements_stream is not None: with override_language(new_stream_announcements_stream.realm.default_language): if len(created_streams) > 1: - content = _("{user_name} created the following streams: {new_channels}.") + content = _("{user_name} created the following channels: {new_channels}.") else: - content = _("{user_name} created a new stream {new_channels}.") - topic_name = _("new streams") + content = _("{user_name} created a new channel {new_channels}.") + topic_name = _("new channels") content = content.format( user_name=silent_mention_syntax_for_user(user_profile), @@ -798,7 +798,7 @@ def send_messages_for_new_subscribers( stream=stream, topic_name=str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC_NAME), content=_( - "**{policy}** stream created by {user_name}. **Description:**" + "**{policy}** channel created by {user_name}. **Description:**" ).format( user_name=silent_mention_syntax_for_user(user_profile), policy=get_stream_permission_policy_name(