Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message: Fix moving messages between streams for non-admins.
sahil839bf9c17e8a8a3
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.pyindex c86263daca1..0be05eb49e6 100644--- a/zerver/lib/actions.py+++ b/zerver/lib/actions.py@@ -2802,8 +2802,11 @@ def check_update_message(is_no_topic_msg = message.topic_name() == "(no topic)"- if not can_edit_content_or_topic(message, user_profile, is_no_topic_msg, content, topic_name):- raise JsonableError(_("You don't have permission to edit this message"))+ if content is not None or topic_name is not None:+ if not can_edit_content_or_topic(+ message, user_profile, is_no_topic_msg, content, topic_name+ ):+ raise JsonableError(_("You don't have permission to edit this message"))# If there is a change to the content, check that it hasn't been too long# Allow an extra 20 seconds since we potentially allow editing 15 secondsdiff --git a/zerver/tests/test_message_edit.py b/zerver/tests/test_message_edit.pyindex ac65146a773..33f4247c096 100644--- a/zerver/tests/test_message_edit.py+++ b/zerver/tests/test_message_edit.py@@ -1528,6 +1528,48 @@ class EditMessageTest(EditMessageTestCase):)check_move_message_to_stream(UserProfile.ROLE_MEMBER)+ def test_move_message_to_stream_with_topic_editing_not_allowed(self) -> None:+ (user_profile, old_stream, new_stream, msg_id, msg_id_later) = self.prepare_move_topics(+ "othello", "old_stream_1", "new_stream_1", "test"+ )++ realm = user_profile.realm+ realm.allow_community_topic_editing = False+ realm.save()+ self.login("cordelia")++ do_set_realm_property(+ user_profile.realm,+ "move_messages_between_streams_policy",+ Realm.POLICY_MEMBERS_ONLY,+ acting_user=None,+ )++ result = self.client_patch(+ "/json/messages/" + str(msg_id),+ {+ "message_id": msg_id,+ "stream_id": new_stream.id,+ "propagate_mode": "change_all",+ "topic": "new topic",+ },+ )+ self.assert_json_error(result, "You don't have permission to edit this message")++ result = self.client_patch(+ "/json/messages/" + str(msg_id),+ {+ "message_id": msg_id,+ "stream_id": new_stream.id,+ "propagate_mode": "change_all",+ },+ )+ self.assert_json_success(result)+ messages = get_topic_messages(user_profile, old_stream, "test")+ self.assert_length(messages, 1)+ messages = get_topic_messages(user_profile, new_stream, "test")+ self.assert_length(messages, 4)+def test_move_message_to_stream_and_topic(self) -> None:(user_profile, old_stream, new_stream, msg_id, msg_id_later) = self.prepare_move_topics("iago", "test move stream", "new stream", "test"