diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.py index a9c56cf297..f01fc1b584 100644 --- a/zerver/lib/markdown/__init__.py +++ b/zerver/lib/markdown/__init__.py @@ -1957,6 +1957,9 @@ class UserGroupMentionPattern(CompiledInlineProcessor): if db_data is not None: user_group = db_data.mention_data.get_user_group(name) if user_group: + if user_group.deactivated: + silent = True + if not silent: self.zmd.zulip_rendering_result.mentions_user_group_ids.add(user_group.id) name = user_group.name diff --git a/zerver/tests/test_markdown.py b/zerver/tests/test_markdown.py index ee0a7bec88..83911b547f 100644 --- a/zerver/tests/test_markdown.py +++ b/zerver/tests/test_markdown.py @@ -19,7 +19,7 @@ from zerver.actions.alert_words import do_add_alert_words from zerver.actions.create_realm import do_create_realm from zerver.actions.realm_emoji import do_remove_realm_emoji from zerver.actions.realm_settings import do_set_realm_property -from zerver.actions.user_groups import check_add_user_group +from zerver.actions.user_groups import check_add_user_group, do_deactivate_user_group from zerver.actions.user_settings import do_change_user_setting from zerver.actions.users import change_user_is_active from zerver.lib.alert_words import get_alert_word_automaton @@ -2898,6 +2898,27 @@ class MarkdownMentionTest(ZulipTestCase): self.assertEqual(rendering_result.mentions_user_group_ids, set()) + def test_deactivated_user_group_mention(self) -> None: + sender_user_profile = self.example_user("othello") + msg = Message( + sender=sender_user_profile, + sending_client=get_client("test"), + realm=sender_user_profile.realm, + ) + support = self.create_user_group_for_test("support") + do_deactivate_user_group(support, acting_user=None) + + content = "We'll add you to @*support* user group." + rendering_result = render_message_markdown(msg, content) + self.assertEqual( + rendering_result.rendered_content, + "

We'll add you to " + f'support' + " user group.

", + ) + + self.assertEqual(rendering_result.mentions_user_group_ids, set()) + def test_user_group_mention_in_quotes(self) -> None: user_profile = self.example_user("othello") message = Message(