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.
This commit is contained in:
Sahil Batra 2022-04-19 16:23:29 +05:30 committed by Tim Abbott
parent ad9a7d2e06
commit 815bf609fa
4 changed files with 19 additions and 15 deletions

View File

@ -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), * [`POST /register`](/api/register-queue), [`GET /events`](/api/get-events),
`PATCH /realm`: Nobody added as an option for the realm setting `PATCH /realm`: Nobody added as an option for the realm setting
`move_messages_between_streams_policy`. `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 Feature levels 157-158 are reserved for future use in 6.x maintenance
releases. releases.

View File

@ -918,7 +918,7 @@ def check_update_message(
""" """
message, ignored_user_message = access_message(user_profile, message_id) 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")) raise JsonableError(_("Your organization has turned off message editing"))
# The zerver/views/message_edit.py call point already strips this # The zerver/views/message_edit.py call point already strips this

View File

@ -6460,6 +6460,11 @@ paths:
**Note**: See [configuring message editing][config-message-editing] **Note**: See [configuring message editing][config-message-editing]
for detailed documentation on when users are allowed to edit topics. 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 [config-message-editing]: /help/configure-message-editing-and-deletion
x-curl-examples-parameters: x-curl-examples-parameters:
oneOf: oneOf:

View File

@ -1043,19 +1043,18 @@ class EditMessageTest(EditMessageTestCase):
set_message_editing_params(True, "unlimited", Realm.POLICY_ADMINS_ONLY) set_message_editing_params(True, "unlimited", Realm.POLICY_ADMINS_ONLY)
do_edit_message_assert_success(id_, "D") 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) set_message_editing_params(False, 240, Realm.POLICY_ADMINS_ONLY)
do_edit_message_assert_error( do_edit_message_assert_success(id_, "B", True)
id_, "E", "Your organization has turned off message editing", 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) set_message_editing_params(False, 120, Realm.POLICY_ADMINS_ONLY)
do_edit_message_assert_error( do_edit_message_assert_success(id_, "F", True)
id_, "F", "Your organization has turned off message editing", True
)
set_message_editing_params(False, "unlimited", Realm.POLICY_ADMINS_ONLY) set_message_editing_params(False, "unlimited", Realm.POLICY_ADMINS_ONLY)
do_edit_message_assert_error( do_edit_message_assert_success(id_, "G", True)
id_, "G", "Your organization has turned off message editing", True
)
def test_edit_topic_policy(self) -> None: def test_edit_topic_policy(self) -> None:
def set_message_editing_params( def set_message_editing_params(
@ -1162,11 +1161,9 @@ class EditMessageTest(EditMessageTestCase):
id_, "H", "You don't have permission to edit this message", "iago" 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) set_message_editing_params(False, "unlimited", Realm.POLICY_EVERYONE)
do_edit_message_assert_error( do_edit_message_assert_success(id_, "D", "cordelia")
id_, "D", "Your organization has turned off message editing", "cordelia"
)
# non-admin users cannot edit topics sent > 72 hrs ago # non-admin users cannot edit topics sent > 72 hrs ago
message.date_sent = message.date_sent - datetime.timedelta(seconds=290000) message.date_sent = message.date_sent - datetime.timedelta(seconds=290000)