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: Require access to messages to move between streams.

Tim Abbott41d499d44c48
diff --git a/zerver/lib/topic.py b/zerver/lib/topic.py
index 9ea27a5ab1f..b0962f82b98 100644
--- a/zerver/lib/topic.py
+++ b/zerver/lib/topic.py
@@ -159,8 +159,18 @@ def update_messages_for_topic_edit(
update_fields = ["edit_history", "last_edit_time"]
- # Evaluate the query before running the update
- messages_list = list(messages)
+ if new_stream is not None:
+ # If we're moving the messages between streams, only move
+ # messages that the acting user can access, so that one cannot
+ # gain access to messages through moving them.
+ from zerver.lib.message import bulk_access_messages
+
+ messages_list = bulk_access_messages(acting_user, messages, stream=old_stream)
+ else:
+ # For single-message edits or topic moves within a stream, we
+ # allow moving history the user may not have access in order
+ # to keep topics together.
+ messages_list = list(messages)
# The cached ORM objects are not changed by the upcoming
# messages.update(), and the remote cache update (done by the
diff --git a/zerver/tests/test_message_edit.py b/zerver/tests/test_message_edit.py
index 96fb20c0dac..f79a66e97fc 100644
--- a/zerver/tests/test_message_edit.py
+++ b/zerver/tests/test_message_edit.py
@@ -1326,7 +1326,7 @@ class EditMessageTest(ZulipTestCase):
"topic": "new topic",
},
)
- self.assertEqual(len(queries), 50)
+ self.assertEqual(len(queries), 52)
self.assertEqual(len(cache_tries), 13)
messages = get_topic_messages(user_profile, old_stream, "test")