From 815bf609facd49e4fd60622a2b2a66f3d9cbe850 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Tue, 19 Apr 2022 16:23:29 +0530 Subject: [PATCH] message_edit: Topic and stream editing do not depend on allow_message_editing. We change the topic and stream edit permssions to not depend on allow_message_editing setting in the API and are allowed even if allow_message_editing is set to False based on other settings like edit_topic_policy and can_move_message_between_streams. Fixes a part of #21739. --- templates/zerver/api/changelog.md | 2 ++ zerver/actions/message_edit.py | 2 +- zerver/openapi/zulip.yaml | 5 +++++ zerver/tests/test_message_edit.py | 25 +++++++++++-------------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/templates/zerver/api/changelog.md b/templates/zerver/api/changelog.md index 2290b0ce12..30086bb534 100644 --- a/templates/zerver/api/changelog.md +++ b/templates/zerver/api/changelog.md @@ -28,6 +28,8 @@ format used by the Zulip server that they are interacting with. * [`POST /register`](/api/register-queue), [`GET /events`](/api/get-events), `PATCH /realm`: Nobody added as an option for the realm setting `move_messages_between_streams_policy`. +* [`PATCH /messages/{message_id}`](/api/update-message): Permission to edit stream + and topic of messages do not depend on `allow_message_editing` setting now. Feature levels 157-158 are reserved for future use in 6.x maintenance releases. diff --git a/zerver/actions/message_edit.py b/zerver/actions/message_edit.py index 03592da5ca..e8851a9e16 100644 --- a/zerver/actions/message_edit.py +++ b/zerver/actions/message_edit.py @@ -918,7 +918,7 @@ def check_update_message( """ message, ignored_user_message = access_message(user_profile, message_id) - if not user_profile.realm.allow_message_editing: + if content is not None and not user_profile.realm.allow_message_editing: raise JsonableError(_("Your organization has turned off message editing")) # The zerver/views/message_edit.py call point already strips this diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml index fe33668a3b..aa65839a16 100644 --- a/zerver/openapi/zulip.yaml +++ b/zerver/openapi/zulip.yaml @@ -6460,6 +6460,11 @@ paths: **Note**: See [configuring message editing][config-message-editing] for detailed documentation on when users are allowed to edit topics. + **Changes**: Before Zulip 7.0 (feature level 159), editing + streams and topics of messages was forbidden if + `allow_message_editing` was `false`, regardless of the + `edit_topic_policy` or `move_messages_between_streams_policy`. + [config-message-editing]: /help/configure-message-editing-and-deletion x-curl-examples-parameters: oneOf: diff --git a/zerver/tests/test_message_edit.py b/zerver/tests/test_message_edit.py index 937b922a98..b57ae24307 100644 --- a/zerver/tests/test_message_edit.py +++ b/zerver/tests/test_message_edit.py @@ -1043,19 +1043,18 @@ class EditMessageTest(EditMessageTestCase): set_message_editing_params(True, "unlimited", Realm.POLICY_ADMINS_ONLY) do_edit_message_assert_success(id_, "D") - # without allow_message_editing, nothing is allowed + # without allow_message_editing, editing content is not allowed but + # editing topic is allowed if topic-edit time limit has not passed + # irrespective of content-edit time limit. set_message_editing_params(False, 240, Realm.POLICY_ADMINS_ONLY) - do_edit_message_assert_error( - id_, "E", "Your organization has turned off message editing", True - ) + do_edit_message_assert_success(id_, "B", True) + + set_message_editing_params(False, 240, Realm.POLICY_ADMINS_ONLY) + do_edit_message_assert_success(id_, "E", True) set_message_editing_params(False, 120, Realm.POLICY_ADMINS_ONLY) - do_edit_message_assert_error( - id_, "F", "Your organization has turned off message editing", True - ) + do_edit_message_assert_success(id_, "F", True) set_message_editing_params(False, "unlimited", Realm.POLICY_ADMINS_ONLY) - do_edit_message_assert_error( - id_, "G", "Your organization has turned off message editing", True - ) + do_edit_message_assert_success(id_, "G", True) def test_edit_topic_policy(self) -> None: def set_message_editing_params( @@ -1162,11 +1161,9 @@ class EditMessageTest(EditMessageTestCase): id_, "H", "You don't have permission to edit this message", "iago" ) - # users cannot edit topics if allow_message_editing is False + # users can edit topics even if allow_message_editing is False set_message_editing_params(False, "unlimited", Realm.POLICY_EVERYONE) - do_edit_message_assert_error( - id_, "D", "Your organization has turned off message editing", "cordelia" - ) + do_edit_message_assert_success(id_, "D", "cordelia") # non-admin users cannot edit topics sent > 72 hrs ago message.date_sent = message.date_sent - datetime.timedelta(seconds=290000)