From 0cd51f2feadf0937d6d814ef4616a004f29728a0 Mon Sep 17 00:00:00 2001 From: Vector73 Date: Wed, 11 Sep 2024 22:56:04 +0530 Subject: [PATCH] settings: Remove `delete_own_message_policy` realm property. Removed `delete_own_message_policy` realm property as the permission to delete own messages is controlled by `can_delete_own_message_group` setting. --- api_docs/changelog.md | 3 ++ web/src/server_events_dispatch.js | 1 - web/tests/popover_menus_data.test.js | 1 - web/tests/settings_org.test.js | 2 - zerver/lib/events.py | 6 --- ..._remove_realm_delete_own_message_policy.py | 16 +++++++ zerver/models/realms.py | 6 --- zerver/openapi/zulip.yaml | 20 -------- zerver/tests/test_events.py | 1 - zerver/tests/test_home.py | 1 - zerver/tests/test_realm.py | 48 ------------------- zerver/views/realm.py | 2 - 12 files changed, 19 insertions(+), 88 deletions(-) create mode 100644 zerver/migrations/0582_remove_realm_delete_own_message_policy.py diff --git a/api_docs/changelog.md b/api_docs/changelog.md index 5cf265a5b4..3f2c21e96d 100644 --- a/api_docs/changelog.md +++ b/api_docs/changelog.md @@ -27,6 +27,9 @@ format used by the Zulip server that they are interacting with. Added `can_delete_own_message_group` realm setting which is a [group-setting value](/api/group-setting-values) describing the set of users with permission to delete the messages that they have sent in the organization. +* `PATCH /realm`, [`GET /events`](/api/get-events): Removed + `delete_own_message_policy` property, as the permission to delete own messages + is now controlled by `can_delete_own_message_group` setting. **Feature level 290** diff --git a/web/src/server_events_dispatch.js b/web/src/server_events_dispatch.js index 96ffd12bf5..7830f57459 100644 --- a/web/src/server_events_dispatch.js +++ b/web/src/server_events_dispatch.js @@ -215,7 +215,6 @@ export function dispatch_normal_event(event) { invite_to_stream_policy: noop, default_code_block_language: noop, default_language: noop, - delete_own_message_policy: noop, description: noop, digest_emails_enabled: noop, digest_weekday: noop, diff --git a/web/tests/popover_menus_data.test.js b/web/tests/popover_menus_data.test.js index ae3f3da4be..ca107a6980 100644 --- a/web/tests/popover_menus_data.test.js +++ b/web/tests/popover_menus_data.test.js @@ -123,7 +123,6 @@ function set_page_params_no_edit_restrictions() { realm.realm_message_content_edit_limit_seconds = null; realm.realm_allow_edit_history = true; realm.realm_message_content_delete_limit_seconds = null; - realm.realm_delete_own_message_policy = 1; realm.realm_enable_read_receipts = true; realm.realm_edit_topic_policy = 5; realm.realm_move_messages_within_stream_limit_seconds = null; diff --git a/web/tests/settings_org.test.js b/web/tests/settings_org.test.js index 967069524e..d2d0708cb9 100644 --- a/web/tests/settings_org.test.js +++ b/web/tests/settings_org.test.js @@ -443,8 +443,6 @@ function test_discard_changes_button(discard_changes) { realm.realm_edit_topic_policy = settings_config.common_message_policy_values.by_everyone.code; realm.realm_allow_message_editing = true; realm.realm_message_content_edit_limit_seconds = 3600; - realm.realm_delete_own_message_policy = - settings_config.common_message_policy_values.by_everyone.code; realm.realm_message_content_delete_limit_seconds = 120; const $allow_edit_history = $("#id_realm_allow_edit_history").prop("checked", false); diff --git a/zerver/lib/events.py b/zerver/lib/events.py index fc4cebd27b..04a7e58bc6 100644 --- a/zerver/lib/events.py +++ b/zerver/lib/events.py @@ -94,7 +94,6 @@ from zerver.models.linkifiers import linkifiers_for_realm from zerver.models.realm_emoji import get_all_custom_emoji_for_realm from zerver.models.realm_playgrounds import get_realm_playgrounds from zerver.models.realms import ( - CommonMessagePolicyEnum, EditTopicPolicyEnum, get_corresponding_policy_value_for_group_setting, get_realm_domains, @@ -333,11 +332,6 @@ def fetch_initial_state_data( state["realm_edit_topic_policy"] = ( EditTopicPolicyEnum.ADMINS_ONLY if user_profile is None else realm.edit_topic_policy ) - state["realm_delete_own_message_policy"] = ( - CommonMessagePolicyEnum.ADMINS_ONLY - if user_profile is None - else realm.delete_own_message_policy - ) # This setting determines whether to send presence and also # whether to display of users list in the right sidebar; we diff --git a/zerver/migrations/0582_remove_realm_delete_own_message_policy.py b/zerver/migrations/0582_remove_realm_delete_own_message_policy.py new file mode 100644 index 0000000000..4a11fa7225 --- /dev/null +++ b/zerver/migrations/0582_remove_realm_delete_own_message_policy.py @@ -0,0 +1,16 @@ +# Generated by Django 5.0.7 on 2024-09-09 12:53 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("zerver", "0581_alter_realm_can_delete_own_message_group"), + ] + + operations = [ + migrations.RemoveField( + model_name="realm", + name="delete_own_message_policy", + ), + ] diff --git a/zerver/models/realms.py b/zerver/models/realms.py index 35f91caa84..dfd530f089 100644 --- a/zerver/models/realms.py +++ b/zerver/models/realms.py @@ -318,11 +318,6 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub "UserGroup", on_delete=models.RESTRICT, related_name="+" ) - # Who in the organization is allowed to delete messages they themselves sent. - delete_own_message_policy = models.PositiveSmallIntegerField( - default=CommonMessagePolicyEnum.EVERYONE - ) - # Who in the organization is allowed to edit topics of any message. edit_topic_policy = models.PositiveSmallIntegerField(default=EditTopicPolicyEnum.EVERYONE) @@ -657,7 +652,6 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub bot_creation_policy=int, default_code_block_language=str, default_language=str, - delete_own_message_policy=int, description=str, digest_emails_enabled=bool, digest_weekday=int, diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml index 45614b6566..00263b44d1 100644 --- a/zerver/openapi/zulip.yaml +++ b/zerver/openapi/zulip.yaml @@ -15698,26 +15698,6 @@ paths: setting controlled this permission; `true` corresponded to `Everyone`, and `false` to `Admins`. - $ref: "#/components/schemas/GroupSettingValue" - realm_delete_own_message_policy: - type: integer - description: | - Present if `realm` is present in `fetch_event_types`. - - The [policy][permission-level] defining which users can delete - messages that they had sent. - - - 1 = Members only - - 2 = Admins only - - 3 = [Full members][calc-full-member] only - - 4 = Admins and moderators only - - 5 = Everyone - - **Changes**: New in Zulip 5.0 (feature level 101), replacing the - previous `allow_message_deleting` boolean; - `true` corresponded to `everyone`, and `false` to `admins only`. - - [permission-level]: /api/roles-and-permissions#permission-levels - [calc-full-member]: /api/roles-and-permissions#determining-if-a-user-is-a-full-member realm_bot_creation_policy: type: integer description: | diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py index 07cc5488ea..ca4d9e0ed7 100644 --- a/zerver/tests/test_events.py +++ b/zerver/tests/test_events.py @@ -3497,7 +3497,6 @@ class RealmPropertyActionTest(BaseAction): invite_to_realm_policy=Realm.INVITE_TO_REALM_POLICY_TYPES, move_messages_between_streams_policy=Realm.MOVE_MESSAGES_BETWEEN_STREAMS_POLICY_TYPES, add_custom_emoji_policy=Realm.COMMON_POLICY_TYPES, - delete_own_message_policy=Realm.COMMON_MESSAGE_POLICY_TYPES, edit_topic_policy=Realm.COMMON_MESSAGE_POLICY_TYPES, message_content_edit_limit_seconds=[1000, 1100, 1200, None], move_messages_within_stream_limit_seconds=[1000, 1100, 1200], diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py index 1102fc4c95..1448db27a7 100644 --- a/zerver/tests/test_home.py +++ b/zerver/tests/test_home.py @@ -145,7 +145,6 @@ class HomeTest(ZulipTestCase): "realm_default_language", "realm_default_stream_groups", "realm_default_streams", - "realm_delete_own_message_policy", "realm_description", "realm_digest_emails_enabled", "realm_digest_weekday", diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.py index d0d371ea38..7865771a4a 100644 --- a/zerver/tests/test_realm.py +++ b/zerver/tests/test_realm.py @@ -63,7 +63,6 @@ from zerver.models import ( from zerver.models.groups import SystemGroups from zerver.models.realm_audit_logs import AuditLogEventType from zerver.models.realms import ( - CommonMessagePolicyEnum, CommonPolicyEnum, InviteToRealmPolicyEnum, MoveMessagesBetweenStreamsPolicyEnum, @@ -857,7 +856,6 @@ class RealmTest(ZulipTestCase): invite_to_realm_policy=10, move_messages_between_streams_policy=10, add_custom_emoji_policy=10, - delete_own_message_policy=10, edit_topic_policy=10, message_content_edit_limit_seconds=0, move_messages_within_stream_limit_seconds=0, @@ -1709,7 +1707,6 @@ class RealmAPITest(ZulipTestCase): invite_to_realm_policy=Realm.INVITE_TO_REALM_POLICY_TYPES, move_messages_between_streams_policy=Realm.MOVE_MESSAGES_BETWEEN_STREAMS_POLICY_TYPES, add_custom_emoji_policy=Realm.COMMON_POLICY_TYPES, - delete_own_message_policy=Realm.COMMON_MESSAGE_POLICY_TYPES, edit_topic_policy=Realm.EDIT_TOPIC_POLICY_TYPES, message_content_edit_limit_seconds=[1000, 1100, 1200], move_messages_within_stream_limit_seconds=[1000, 1100, 1200], @@ -2351,51 +2348,6 @@ class RealmAPITest(ZulipTestCase): ) self.assertEqual(realm.move_messages_between_streams_limit_seconds, None) - def test_update_realm_delete_own_message_policy(self) -> None: - """Tests updating the realm property 'delete_own_message_policy'.""" - realm = get_realm("zulip") - self.assertEqual(realm.delete_own_message_policy, CommonMessagePolicyEnum.EVERYONE) - realm = self.update_with_api( - "delete_own_message_policy", CommonMessagePolicyEnum.ADMINS_ONLY - ) - self.assertEqual(realm.delete_own_message_policy, CommonMessagePolicyEnum.ADMINS_ONLY) - self.assertEqual(realm.message_content_delete_limit_seconds, 600) - realm = self.update_with_api("delete_own_message_policy", CommonMessagePolicyEnum.EVERYONE) - realm = self.update_with_api("message_content_delete_limit_seconds", 100) - self.assertEqual(realm.delete_own_message_policy, CommonMessagePolicyEnum.EVERYONE) - self.assertEqual(realm.message_content_delete_limit_seconds, 100) - realm = self.update_with_api( - "message_content_delete_limit_seconds", orjson.dumps("unlimited").decode() - ) - self.assertEqual(realm.message_content_delete_limit_seconds, None) - realm = self.update_with_api("message_content_delete_limit_seconds", 600) - self.assertEqual(realm.delete_own_message_policy, CommonMessagePolicyEnum.EVERYONE) - self.assertEqual(realm.message_content_delete_limit_seconds, 600) - realm = self.update_with_api( - "delete_own_message_policy", CommonMessagePolicyEnum.MODERATORS_ONLY - ) - self.assertEqual(realm.delete_own_message_policy, CommonMessagePolicyEnum.MODERATORS_ONLY) - realm = self.update_with_api( - "delete_own_message_policy", CommonMessagePolicyEnum.FULL_MEMBERS_ONLY - ) - self.assertEqual(realm.delete_own_message_policy, CommonMessagePolicyEnum.FULL_MEMBERS_ONLY) - realm = self.update_with_api( - "delete_own_message_policy", CommonMessagePolicyEnum.MEMBERS_ONLY - ) - self.assertEqual(realm.delete_own_message_policy, CommonMessagePolicyEnum.MEMBERS_ONLY) - - # Test that 0 is invalid value. - req = dict(message_content_delete_limit_seconds=orjson.dumps(0).decode()) - result = self.client_patch("/json/realm", req) - self.assert_json_error(result, "Bad value for 'message_content_delete_limit_seconds': 0") - - # Test that only "unlimited" string is valid and others are invalid. - req = dict(message_content_delete_limit_seconds=orjson.dumps("invalid").decode()) - result = self.client_patch("/json/realm", req) - self.assert_json_error( - result, "Bad value for 'message_content_delete_limit_seconds': invalid" - ) - def do_test_changing_settings_by_owners_only(self, setting_name: str) -> None: bool_tests: list[bool] = [False, True] test_values: dict[str, Any] = dict( diff --git a/zerver/views/realm.py b/zerver/views/realm.py index 7b8a77bcd1..831b91b9cb 100644 --- a/zerver/views/realm.py +++ b/zerver/views/realm.py @@ -50,7 +50,6 @@ from zerver.lib.validator import check_capped_url, check_string from zerver.models import Realm, RealmReactivationStatus, RealmUserDefault, UserProfile from zerver.models.realms import ( BotCreationPolicyEnum, - CommonMessagePolicyEnum, CommonPolicyEnum, DigestWeekdayEnum, EditTopicPolicyEnum, @@ -115,7 +114,6 @@ def update_realm( add_custom_emoji_policy: Json[CommonPolicyEnum] | None = None, can_delete_any_message_group: Json[GroupSettingChangeRequest] | None = None, can_delete_own_message_group: Json[GroupSettingChangeRequest] | None = None, - delete_own_message_policy: Json[CommonMessagePolicyEnum] | None = None, message_content_delete_limit_seconds_raw: Annotated[ Json[int | str] | None, ApiParamConfig("message_content_delete_limit_seconds"),