From 6e672ebbee0e7f0258f3f184d49f47efa5697395 Mon Sep 17 00:00:00 2001 From: sahil839 Date: Sun, 2 May 2021 13:26:58 +0530 Subject: [PATCH] settings: Add moderators option for wildcard_mention_policy. --- templates/zerver/api/changelog.md | 4 ++++ version.py | 2 +- zerver/lib/message.py | 3 +++ zerver/models.py | 2 ++ zerver/openapi/zulip.yaml | 8 ++++++-- zerver/tests/test_events.py | 2 +- zerver/tests/test_message_send.py | 10 ++++++++++ zerver/tests/test_realm.py | 1 + 8 files changed, 28 insertions(+), 4 deletions(-) diff --git a/templates/zerver/api/changelog.md b/templates/zerver/api/changelog.md index 42e7183ef9..b13b198e3a 100644 --- a/templates/zerver/api/changelog.md +++ b/templates/zerver/api/changelog.md @@ -10,6 +10,10 @@ below features are supported. ## Changes in Zulip 4.0 +**Feature level 62** + +* Added `moderators only` option for `wildcard_mention_policy`. + **Feature level 61** * Added support for inviting users as moderators to the invitation diff --git a/version.py b/version.py index 4b6e13f6aa..b01c311854 100644 --- a/version.py +++ b/version.py @@ -30,7 +30,7 @@ DESKTOP_WARNING_VERSION = "5.2.0" # # Changes should be accompanied by documentation explaining what the # new level means in templates/zerver/api/changelog.md. -API_FEATURE_LEVEL = 61 +API_FEATURE_LEVEL = 62 # Bump the minor PROVISION_VERSION to indicate that folks should provision # only when going from an old version of the code to a newer version. Bump diff --git a/zerver/lib/message.py b/zerver/lib/message.py index 0a4cbed9c5..f279a1c6d2 100644 --- a/zerver/lib/message.py +++ b/zerver/lib/message.py @@ -1398,6 +1398,9 @@ def wildcard_mention_allowed(sender: UserProfile, stream: Stream) -> bool: if realm.wildcard_mention_policy == Realm.WILDCARD_MENTION_POLICY_ADMINS: return sender.is_realm_admin + if realm.wildcard_mention_policy == Realm.WILDCARD_MENTION_POLICY_MODERATORS: + return sender.is_realm_admin or sender.is_moderator + if realm.wildcard_mention_policy == Realm.WILDCARD_MENTION_POLICY_STREAM_ADMINS: # TODO: Change this when we implement stream administrators return sender.is_realm_admin diff --git a/zerver/models.py b/zerver/models.py index b8b9e717fb..35f2975e63 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -305,6 +305,7 @@ class Realm(models.Model): WILDCARD_MENTION_POLICY_STREAM_ADMINS = 4 WILDCARD_MENTION_POLICY_ADMINS = 5 WILDCARD_MENTION_POLICY_NOBODY = 6 + WILDCARD_MENTION_POLICY_MODERATORS = 7 wildcard_mention_policy: int = models.PositiveSmallIntegerField( default=WILDCARD_MENTION_POLICY_STREAM_ADMINS, ) @@ -315,6 +316,7 @@ class Realm(models.Model): WILDCARD_MENTION_POLICY_STREAM_ADMINS, WILDCARD_MENTION_POLICY_ADMINS, WILDCARD_MENTION_POLICY_NOBODY, + WILDCARD_MENTION_POLICY_MODERATORS, ] # Who in the organization has access to users' actual email diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml index e594b33bd5..aa34d94c52 100644 --- a/zerver/openapi/zulip.yaml +++ b/zerver/openapi/zulip.yaml @@ -3257,11 +3257,13 @@ paths: * 4 => Only stream and organization administrators can use wildcard mentions in large streams. * 5 => Only organization administrators can use wildcard mentions in large streams. * 6 => Nobody can use wildcard mentions in large streams. + * 7 => Only organization adminstartors and moderators can use wildcard mentions in large streams. All users will receive a warning/reminder when using mentions in large streams, even when permitted to do so. - **Changes**: New in Zulip 4.0 (feature level 33). + **Changes**: New in Zulip 4.0 (feature level 33). Moderators option added in + Zulip 4.0 (feature level 62). default_language: type: string description: | @@ -8208,11 +8210,13 @@ paths: * 4 => Only stream and organization administrators can use wildcard mentions in large streams. * 5 => Only organization administrators can use wildcard mentions in large streams. * 6 => Nobody can use wildcard mentions in large streams. + * 7 => Only organization adminstartors and moderators can use wildcard mentions in large streams. All users will receive a warning/reminder when using mentions in large streams, even when permitted to do so. - **Changes**: New in Zulip 4.0 (feature level 33). + **Changes**: New in Zulip 4.0 (feature level 33). Moderators option added in + Zulip 4.0 (feature level 62). realm_default_language: type: string description: | diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py index 6b8e4c6cc4..eb75b8760c 100644 --- a/zerver/tests/test_events.py +++ b/zerver/tests/test_events.py @@ -1979,7 +1979,7 @@ class RealmPropertyActionTest(BaseAction): invite_to_stream_policy=[4, 3, 2, 1], private_message_policy=[2, 1], user_group_edit_policy=[1, 2], - wildcard_mention_policy=[6, 5, 4, 3, 2, 1], + wildcard_mention_policy=[7, 6, 5, 4, 3, 2, 1], email_address_visibility=[Realm.EMAIL_ADDRESS_VISIBILITY_ADMINS], bot_creation_policy=[Realm.BOT_CREATION_EVERYONE], video_chat_provider=[ diff --git a/zerver/tests/test_message_send.py b/zerver/tests/test_message_send.py index 203dc7d138..ae45a202e2 100644 --- a/zerver/tests/test_message_send.py +++ b/zerver/tests/test_message_send.py @@ -1827,6 +1827,16 @@ class StreamMessagesTest(ZulipTestCase): self.send_and_verify_wildcard_mention_message("cordelia", sub_count=10) self.send_and_verify_wildcard_mention_message("iago") + do_set_realm_property( + realm, + "wildcard_mention_policy", + Realm.WILDCARD_MENTION_POLICY_MODERATORS, + acting_user=None, + ) + self.send_and_verify_wildcard_mention_message("cordelia", test_fails=True) + self.send_and_verify_wildcard_mention_message("cordelia", sub_count=10) + self.send_and_verify_wildcard_mention_message("shiva") + cordelia.date_joined = timezone_now() cordelia.save() do_set_realm_property( diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.py index 8f28541a99..28fc2f73c9 100644 --- a/zerver/tests/test_realm.py +++ b/zerver/tests/test_realm.py @@ -892,6 +892,7 @@ class RealmAPITest(ZulipTestCase): Realm.WILDCARD_MENTION_POLICY_STREAM_ADMINS, Realm.WILDCARD_MENTION_POLICY_ADMINS, Realm.WILDCARD_MENTION_POLICY_NOBODY, + Realm.WILDCARD_MENTION_POLICY_MODERATORS, ], bot_creation_policy=[1, 2], email_address_visibility=[