mirror of https://github.com/zulip/zulip.git
message_edit: Reject buggy noop topic edit requests.
A buggy client might send a message_edit request to change the topic field, sending the current topic as the new value. Previously, we would treat that as a normal request to edit the topic; now we act as though the API request had not requested a topic change. In the common case that only the topic was in the edit request, this now results in an error that should help client implementations identify their bug. This fixes a bad interaction with the "unresolve topic" logic, which assumed that upstream logic had verified that the topic was actually changing.
This commit is contained in:
parent
5a47e1f289
commit
b2dd15fd86
|
@ -2852,6 +2852,9 @@ def check_update_message(
|
||||||
# use REQ_topic as well (or otherwise are guaranteed to strip input).
|
# use REQ_topic as well (or otherwise are guaranteed to strip input).
|
||||||
if topic_name is not None:
|
if topic_name is not None:
|
||||||
topic_name = topic_name.strip()
|
topic_name = topic_name.strip()
|
||||||
|
if topic_name == message.topic_name():
|
||||||
|
topic_name = None
|
||||||
|
|
||||||
validate_message_edit_payload(message, stream_id, topic_name, propagate_mode, content)
|
validate_message_edit_payload(message, stream_id, topic_name, propagate_mode, content)
|
||||||
|
|
||||||
is_no_topic_msg = message.topic_name() == "(no topic)"
|
is_no_topic_msg = message.topic_name() == "(no topic)"
|
||||||
|
|
|
@ -1968,6 +1968,18 @@ class EditMessageTest(EditMessageTestCase):
|
||||||
)
|
)
|
||||||
id2 = self.send_stream_message(admin_user, "new", topic_name=original_topic)
|
id2 = self.send_stream_message(admin_user, "new", topic_name=original_topic)
|
||||||
|
|
||||||
|
# Check that we don't incorrectly send "unresolve topic"
|
||||||
|
# notifications when asking the preserve the current topic.
|
||||||
|
result = self.client_patch(
|
||||||
|
"/json/messages/" + str(id1),
|
||||||
|
{
|
||||||
|
"message_id": id1,
|
||||||
|
"topic": original_topic,
|
||||||
|
"propagate_mode": "change_all",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
self.assert_json_error(result, "Nothing to change")
|
||||||
|
|
||||||
resolved_topic = RESOLVED_TOPIC_PREFIX + original_topic
|
resolved_topic = RESOLVED_TOPIC_PREFIX + original_topic
|
||||||
result = self.client_patch(
|
result = self.client_patch(
|
||||||
"/json/messages/" + str(id1),
|
"/json/messages/" + str(id1),
|
||||||
|
|
Loading…
Reference in New Issue