message edit: Handle topic edit tries for private messages.

Fixes #18604.
This commit is contained in:
Abhijeet Prasad Bodas
2021-05-26 15:34:30 +05:30
committed by Tim Abbott
parent 4b30fc01e4
commit 15f78abd68
2 changed files with 18 additions and 0 deletions

View File

@@ -2719,6 +2719,8 @@ def validate_message_edit_payload(
if not message.is_stream_message():
if stream_id is not None:
raise JsonableError(_("Private messages cannot be moved to streams."))
if topic_name is not None:
raise JsonableError(_("Private messages cannot have topics."))
if propagate_mode != "change_one" and topic_name is None and stream_id is None:
raise JsonableError(_("Invalid propagate_mode without topic edit"))

View File

@@ -127,6 +127,22 @@ class EditMessagePayloadTest(EditMessageTestCase):
self.assert_json_error(result, "Private messages cannot be moved to streams.")
def test_private_message_edit_topic(self) -> None:
hamlet = self.example_user("hamlet")
self.login("hamlet")
cordelia = self.example_user("cordelia")
msg_id = self.send_personal_message(hamlet, cordelia)
result = self.client_patch(
"/json/messages/" + str(msg_id),
{
"message_id": msg_id,
"topic": "Should not exist",
},
)
self.assert_json_error(result, "Private messages cannot have topics.")
def test_propagate_invalid(self) -> None:
self.login("hamlet")
id1 = self.send_stream_message(self.example_user("hamlet"), "Scotland", topic_name="topic1")