From 83383090f9461b81bf718afc449bc0b2196db0cd Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Tue, 5 Jul 2022 18:05:17 +0530 Subject: [PATCH] realm: Removed WILDCARD_MENTION_POLICY_STREAM_ADMINS option. This commit removes WILDCARD_MENTION_POLICY_STREAM_ADMINS option of wildcard_mention_policy since we are not moving forward with stream administrator concept and instead working on new permssions model as per #19525. We also add a migration to change wildcard_mention_policy of existing realms to WILDCARD_MENTION_POLICY_ADMINS. This change is fine since we were already treating both the setting values as same as stream admin concept was not implemented completely. --- templates/zerver/api/changelog.md | 5 +++ zerver/lib/message.py | 4 --- ...395_alter_realm_wildcard_mention_policy.py | 32 +++++++++++++++++++ zerver/models.py | 4 +-- zerver/openapi/zulip.yaml | 8 ++--- zerver/tests/test_message_send.py | 12 ------- 6 files changed, 42 insertions(+), 23 deletions(-) create mode 100644 zerver/migrations/0395_alter_realm_wildcard_mention_policy.py diff --git a/templates/zerver/api/changelog.md b/templates/zerver/api/changelog.md index 8a436d0db3..0e5b389cfe 100644 --- a/templates/zerver/api/changelog.md +++ b/templates/zerver/api/changelog.md @@ -20,6 +20,11 @@ format used by the Zulip server that they are interacting with. ## Changes in Zulip 6.0 +**Feature level 133** + +* [`POST /register`](/api/register-queue), `PATCH /realm`: Removed + stream administrators option from `wildcard_mention_policy` setting. + **Feature level 132** * [`GET /streams/{stream_id}`](/api/get-stream-by-id): diff --git a/zerver/lib/message.py b/zerver/lib/message.py index a199bae4f3..358756b302 100644 --- a/zerver/lib/message.py +++ b/zerver/lib/message.py @@ -1605,10 +1605,6 @@ def wildcard_mention_allowed(sender: UserProfile, stream: Stream) -> bool: 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 - if realm.wildcard_mention_policy == Realm.WILDCARD_MENTION_POLICY_FULL_MEMBERS: return sender.is_realm_admin or (not sender.is_provisional_member and not sender.is_guest) diff --git a/zerver/migrations/0395_alter_realm_wildcard_mention_policy.py b/zerver/migrations/0395_alter_realm_wildcard_mention_policy.py new file mode 100644 index 0000000000..b31190588e --- /dev/null +++ b/zerver/migrations/0395_alter_realm_wildcard_mention_policy.py @@ -0,0 +1,32 @@ +# Generated by Django 3.2.13 on 2022-07-05 12:23 + +from django.db import migrations, models +from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor +from django.db.migrations.state import StateApps + + +def fix_wildcard_mention_policy_stream_admins_value( + apps: StateApps, schema_editor: BaseDatabaseSchemaEditor +) -> None: + Realm = apps.get_model("zerver", "Realm") + WILDCARD_MENTION_POLICY_STREAM_ADMINS = 4 + WILDCARD_MENTION_POLICY_ADMINS = 5 + Realm.objects.filter(wildcard_mention_policy=WILDCARD_MENTION_POLICY_STREAM_ADMINS).update( + wildcard_mention_policy=WILDCARD_MENTION_POLICY_ADMINS + ) + + +class Migration(migrations.Migration): + + dependencies = [ + ("zerver", "0394_alter_realm_want_advertise_in_communities_directory"), + ] + + operations = [ + migrations.AlterField( + model_name="realm", + name="wildcard_mention_policy", + field=models.PositiveSmallIntegerField(default=5), + ), + migrations.RunPython(fix_wildcard_mention_policy_stream_admins_value, elidable=True), + ] diff --git a/zerver/models.py b/zerver/models.py index ff1e229e1f..dae0a7bafd 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -414,18 +414,16 @@ class Realm(models.Model): WILDCARD_MENTION_POLICY_EVERYONE = 1 WILDCARD_MENTION_POLICY_MEMBERS = 2 WILDCARD_MENTION_POLICY_FULL_MEMBERS = 3 - 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, + default=WILDCARD_MENTION_POLICY_ADMINS, ) WILDCARD_MENTION_POLICY_TYPES = [ WILDCARD_MENTION_POLICY_EVERYONE, WILDCARD_MENTION_POLICY_MEMBERS, WILDCARD_MENTION_POLICY_FULL_MEMBERS, - WILDCARD_MENTION_POLICY_STREAM_ADMINS, WILDCARD_MENTION_POLICY_ADMINS, WILDCARD_MENTION_POLICY_NOBODY, WILDCARD_MENTION_POLICY_MODERATORS, diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml index e80f6cdaa0..00475b1111 100644 --- a/zerver/openapi/zulip.yaml +++ b/zerver/openapi/zulip.yaml @@ -4051,7 +4051,6 @@ paths: - 1 => Any user can use wildcard mentions in large streams. - 2 => Only members can use wildcard mentions in large streams. - 3 => Only [full members][calc-full-member] can use wildcard mentions in large streams. - - 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 administrators and moderators can use wildcard mentions in large streams. @@ -4060,7 +4059,8 @@ paths: mentions in large streams, even when permitted to do so. **Changes**: New in Zulip 4.0 (feature level 33). Moderators option added in - Zulip 4.0 (feature level 62). + Zulip 4.0 (feature level 62). Stream administrators option removed in + Zulip 6.0 (feature level 133). [permission-level]: /api/roles-and-permissions#permission-levels [calc-full-member]: /api/roles-and-permissions#determining-if-a-user-is-a-full-member @@ -10889,7 +10889,6 @@ paths: - 1 => Any user can use wildcard mentions in large streams. - 2 => Only members can use wildcard mentions in large streams. - 3 => Only [full members][calc-full-member] can use wildcard mentions in large streams. - - 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 administrators and moderators can use wildcard mentions in large streams. @@ -10898,7 +10897,8 @@ paths: mentions in large streams, even when permitted to do so. **Changes**: New in Zulip 4.0 (feature level 33). Moderators option added in - Zulip 4.0 (feature level 62). + Zulip 4.0 (feature level 62). Stream administrators option removed in + Zulip 6.0 (feature level 133). [permission-level]: /api/roles-and-permissions#permission-levels [calc-full-member]: /api/roles-and-permissions#determining-if-a-user-is-a-full-member diff --git a/zerver/tests/test_message_send.py b/zerver/tests/test_message_send.py index 37922302e5..91ccdd1354 100644 --- a/zerver/tests/test_message_send.py +++ b/zerver/tests/test_message_send.py @@ -1843,18 +1843,6 @@ class StreamMessagesTest(ZulipTestCase): cordelia.save() self.send_and_verify_wildcard_mention_message("cordelia") - do_set_realm_property( - realm, - "wildcard_mention_policy", - Realm.WILDCARD_MENTION_POLICY_STREAM_ADMINS, - acting_user=None, - ) - # TODO: Change this when we implement stream administrators - self.send_and_verify_wildcard_mention_message("cordelia", test_fails=True) - # There is no restriction on small streams. - 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",