mirror of https://github.com/zulip/zulip.git
message_edit: Verify the message is in a stream in move message API.
This wasn't being validated before. There wasn't any possibility to actually succeed in moving a private message, because the codepath would fail at assert message.is_stream_message() in do_update_message - but we should have proper error handling for that case instead of internal server errors.
This commit is contained in:
parent
0c0e83eaff
commit
b4542cc059
|
@ -1154,6 +1154,29 @@ class EditMessageTest(ZulipTestCase):
|
|||
"You don't have permission to move this message due to missing access to its stream",
|
||||
)
|
||||
|
||||
def test_move_message_cant_move_private_message(
|
||||
self,
|
||||
) -> None:
|
||||
user_profile = self.example_user("iago")
|
||||
self.assertEqual(user_profile.role, UserProfile.ROLE_REALM_ADMINISTRATOR)
|
||||
self.login("iago")
|
||||
|
||||
hamlet = self.example_user("hamlet")
|
||||
msg_id = self.send_personal_message(user_profile, hamlet)
|
||||
|
||||
verona = get_stream("Verona", user_profile.realm)
|
||||
|
||||
result = self.client_patch(
|
||||
"/json/messages/" + str(msg_id),
|
||||
{
|
||||
"message_id": msg_id,
|
||||
"stream_id": verona.id,
|
||||
"propagate_mode": "change_all",
|
||||
},
|
||||
)
|
||||
|
||||
self.assert_json_error(result, "Message must be a stream message")
|
||||
|
||||
def test_move_message_to_stream_change_later(self) -> None:
|
||||
(user_profile, old_stream, new_stream, msg_id, msg_id_later) = self.prepare_move_topics(
|
||||
"iago", "test move stream", "new stream", "test"
|
||||
|
|
|
@ -206,6 +206,8 @@ def update_message_backend(
|
|||
number_changed = 0
|
||||
|
||||
if stream_id is not None:
|
||||
if not message.is_stream_message():
|
||||
raise JsonableError(_("Message must be a stream message"))
|
||||
if not user_profile.is_realm_admin:
|
||||
raise JsonableError(_("You don't have permission to move this message"))
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue