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-move: Improve time limit error for "change_all" moves.

Sahil Batra89b5a9a9092c
diff --git a/api_docs/unmerged.d/ZF-a6120e.md b/api_docs/unmerged.d/ZF-a6120e.md
new file mode 100644
index 00000000000..547df21b064
--- /dev/null
+++ b/api_docs/unmerged.d/ZF-a6120e.md
@@ -0,0 +1,6 @@
+* [`PATCH /messages/{message_id}`](/api/update-message): For requests with
+ `"propagate_mode": "change_all"` from users who are not administrators
+ or moderators, the `"code": "MOVE_MESSAGES_TIME_LIMIT_EXCEEDED"` error
+ response is now also returned when the target message itself is past
+ the time limit, as long as at least one message in the topic is within
+ the limit.
diff --git a/zerver/actions/message_edit.py b/zerver/actions/message_edit.py
index 94818038b09..4887fc2dae9 100644
--- a/zerver/actions/message_edit.py
+++ b/zerver/actions/message_edit.py
@@ -1512,6 +1512,9 @@ def check_time_limit_for_change_all_propagate_mode(
# We return if all messages are allowed to move.
return
+ if len(messages_allowed_to_move) == 0:
+ raise JsonableError(_("The time limit for moving this topic has passed."))
+
raise MessageMoveError(
first_message_id_allowed_to_move=messages_allowed_to_move[0],
total_messages_in_topic=total_messages_requested_to_move,
@@ -1639,6 +1642,7 @@ def check_stream_topic_edit_permissions(
if (
user_profile.realm.move_messages_within_stream_limit_seconds is not None
and not user_profile.is_moderator
+ and message_edit_request.propagate_mode != "change_all"
):
deadline_seconds = (
user_profile.realm.move_messages_within_stream_limit_seconds + edit_limit_buffer
@@ -1767,6 +1771,7 @@ def check_update_message(
if (
user_profile.realm.move_messages_between_streams_limit_seconds is not None
and not user_profile.is_moderator
+ and propagate_mode != "change_all"
):
deadline_seconds = (
user_profile.realm.move_messages_between_streams_limit_seconds
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index b4ce6617c16..76e27781900 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -10743,10 +10743,9 @@ paths:
}
description: |
A special failed JSON response (`"code": "MOVE_MESSAGES_TIME_LIMIT_EXCEEDED"`)
- for when the user has permission to move
- the target message, but asked to move all messages in a topic
- (`"propagate_mode": "change_all"`) and the user does not have permission
- to move the entire topic.
+ for when the user asked to move all messages in a topic
+ (`"propagate_mode": "change_all"`) and the user can move at least one message
+ but does not have permission to move the entire topic.
This happens when the topic contains some messages that are older than an
applicable time limit for the requested topic move (see
@@ -10788,7 +10787,13 @@ paths:
of a topic that they have access to, without this error or any confirmation
dialog.
- **Changes**: New in Zulip 7.0 (feature level 172).
+ **Changes**: Before Zulip 13.0 (feature level ZF-a6120e), this error
+ response was only returned when the request's target message was
+ itself within the time limit. As of this feature level, it is also
+ returned when the target message is past the limit but at least one
+ message in the topic is within it.
+
+ New in Zulip 7.0 (feature level 172).
[private-channels]: /help/channel-permissions#private-channels
- allOf:
diff --git a/zerver/tests/test_message_move_stream.py b/zerver/tests/test_message_move_stream.py
index 41fe91b6b3c..032f14ca080 100644
--- a/zerver/tests/test_message_move_stream.py
+++ b/zerver/tests/test_message_move_stream.py
@@ -230,6 +230,26 @@ class MessageMoveStreamTest(ZulipTestCase):
messages = get_topic_messages(user_profile, new_stream, new_topic_name)
self.assert_length(messages, 0)
+ # Using an older message (id2) for the request still reports
+ # how many recent messages can be moved, rather than rejecting
+ # outright.
+ result = self.client_patch(
+ f"/json/messages/{id2}",
+ params_dict,
+ )
+ self.assert_json_error(
+ result,
+ "You only have permission to move the 3/5 most recent messages in this topic.",
+ )
+
+ # Check message count in old topic and/or stream.
+ messages = get_topic_messages(user_profile, old_stream, old_topic_name)
+ self.assert_length(messages, 5)
+
+ # Check message count in new topic and/or stream.
+ messages = get_topic_messages(user_profile, new_stream, new_topic_name)
+ self.assert_length(messages, 0)
+
json = orjson.loads(result.content)
first_message_id_allowed_to_move = json["first_message_id_allowed_to_move"]
@@ -1021,6 +1041,7 @@ class MessageMoveStreamTest(ZulipTestCase):
user: UserProfile,
old_stream: Stream,
new_stream: Stream,
+ propagate_mode: str = "change_all",
*,
expect_error_message: str | None = None,
) -> None:
@@ -1029,7 +1050,7 @@ class MessageMoveStreamTest(ZulipTestCase):
"/json/messages/" + str(msg_id),
{
"stream_id": new_stream.id,
- "propagate_mode": "change_all",
+ "propagate_mode": propagate_mode,
"send_notification_to_new_thread": orjson.dumps(False).decode(),
},
)
@@ -1056,6 +1077,14 @@ class MessageMoveStreamTest(ZulipTestCase):
cordelia,
test_stream_1,
test_stream_2,
+ expect_error_message="You only have permission to move the 2/3 most recent messages in this topic.",
+ )
+
+ check_move_message_to_stream(
+ cordelia,
+ test_stream_1,
+ test_stream_2,
+ propagate_mode="change_one",
expect_error_message="The time limit for editing this message's channel has passed",
)
diff --git a/zerver/tests/test_message_move_topic.py b/zerver/tests/test_message_move_topic.py
index c0a6d9752df..32159a0f15c 100644
--- a/zerver/tests/test_message_move_topic.py
+++ b/zerver/tests/test_message_move_topic.py
@@ -1494,6 +1494,22 @@ class MessageMoveTopicTest(ZulipTestCase):
"You only have permission to move the 2/5 most recent messages in this topic.",
)
+ # Using an older message (id3) for the request still reports
+ # how many recent messages can be moved, rather than rejecting
+ # outright.
+ result = self.client_patch(
+ f"/json/messages/{id3}",
+ {
+ "topic": "edited",
+ "propagate_mode": "change_all",
+ "send_notification_to_new_thread": "false",
+ },
+ )
+ self.assert_json_error(
+ result,
+ "You only have permission to move the 2/5 most recent messages in this topic.",
+ )
+
def test_notify_new_topic(self) -> None:
user_profile = self.example_user("iago")
self.login("iago")
@@ -2664,9 +2680,7 @@ class MessageMoveTopicTest(ZulipTestCase):
"propagate_mode": "change_all",
},
)
- self.assert_json_error(
- result, "The time limit for editing this message's topic has passed."
- )
+ self.assert_json_error(result, "The time limit for moving this topic has passed.")
result = self.resolve_topic_containing_message(
cordelia,
@@ -2879,9 +2893,7 @@ class MessageMoveTopicTest(ZulipTestCase):
"propagate_mode": "change_all",
},
)
- self.assert_json_error(
- result, "The time limit for editing this message's topic has passed."
- )
+ self.assert_json_error(result, "The time limit for moving this topic has passed.")
result = self.resolve_topic_containing_message(
hamlet,