Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

message_edit: Use move_messages_within_stream_limit_seconds setting.

Sahil Batra2c4e076fef46
diff --git a/api_docs/changelog.md b/api_docs/changelog.md
index 5bde16a55e1..227af505920 100644
--- a/api_docs/changelog.md
+++ b/api_docs/changelog.md
@@ -26,6 +26,9 @@ format used by the Zulip server that they are interacting with.
`PATCH /realm`: Added new `move_messages_within_stream_limit_seconds` setting.
* [`POST /register`](/api/register-queue), [`GET /events`](/api/get-events),
`PATCH /realm`: Added new `move_messages_between_streams_limit_seconds` setting.
+* [`PATCH /messages/{message_id}`](/api/update-message): Time limit to edit
+ topics, for users other than administrators and moderators, can now be
+ configured using `move_messages_within_stream_limit_seconds` setting.
**Feature level 161**
diff --git a/zerver/actions/message_edit.py b/zerver/actions/message_edit.py
index dcc588f00da..a086e74e265 100644
--- a/zerver/actions/message_edit.py
+++ b/zerver/actions/message_edit.py
@@ -57,7 +57,6 @@ from zerver.models import (
Attachment,
Message,
Reaction,
- Realm,
Stream,
UserMessage,
UserProfile,
@@ -955,11 +954,14 @@ def check_update_message(
# and the time limit for editing topics is passed, raise an error.
if (
topic_name is not None
+ and user_profile.realm.move_messages_within_stream_limit_seconds is not None
and not user_profile.is_realm_admin
and not user_profile.is_moderator
and not is_no_topic_msg
):
- deadline_seconds = Realm.DEFAULT_COMMUNITY_TOPIC_EDITING_LIMIT_SECONDS + edit_limit_buffer
+ deadline_seconds = (
+ user_profile.realm.move_messages_within_stream_limit_seconds + edit_limit_buffer
+ )
if (timezone_now() - message.date_sent) > datetime.timedelta(seconds=deadline_seconds):
raise JsonableError(_("The time limit for editing this message's topic has passed"))
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index 0e9ff9b20f2..8eb27a1ddb3 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -6489,6 +6489,12 @@ 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 162), users who
+ were not administrators or moderators could only edit topics
+ if the target message was sent within the last 3 days. That
+ time limit is now controlled by the
+ `move_messages_within_stream_limit_seconds` setting.
+
**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
diff --git a/zerver/tests/test_message_edit.py b/zerver/tests/test_message_edit.py
index 041ec64d0b3..7b80b3b1d48 100644
--- a/zerver/tests/test_message_edit.py
+++ b/zerver/tests/test_message_edit.py
@@ -1180,9 +1180,9 @@ class EditMessageTest(EditMessageTestCase):
set_message_editing_params(False, "unlimited", Realm.POLICY_EVERYONE)
do_edit_message_assert_success(id_, "D", "cordelia")
- # non-admin users cannot edit topics sent > 72 hrs ago including
+ # non-admin users cannot edit topics sent > 1 week ago including
# sender of the message.
- message.date_sent = message.date_sent - datetime.timedelta(seconds=290000)
+ message.date_sent = message.date_sent - datetime.timedelta(seconds=604900)
message.save()
set_message_editing_params(True, "unlimited", Realm.POLICY_EVERYONE)
do_edit_message_assert_success(id_, "E", "iago")
@@ -1194,6 +1194,16 @@ class EditMessageTest(EditMessageTestCase):
id_, "G", "The time limit for editing this message's topic has passed", "hamlet"
)
+ # set the topic edit limit to two weeks
+ do_set_realm_property(
+ hamlet.realm,
+ "move_messages_within_stream_limit_seconds",
+ 604800 * 2,
+ acting_user=None,
+ )
+ do_edit_message_assert_success(id_, "G", "cordelia")
+ do_edit_message_assert_success(id_, "H", "hamlet")
+
# anyone should be able to edit "no topic" indefinitely
message.set_topic_name("(no topic)")
message.save()