message_move: Fix new_topic_name in topic already exists warning.

In the move topic modal, the `new_topic_name` input is disabled if
the user doesn't have permission to move messages between topics.
This commit fixes a bug where `new_topic_name` is undefined since its
input is disabled. This causes `show_topic_already_exists_warning()`
to throw an AssertionError. Hence, the warning is not shown.

Specifically, this bug occurs when a user moves a topic to an
already existing topic in a different channel when he has permission
to move messages between channels but not between topics.

(cherry picked from commit 62745ddccb)
This commit is contained in:
Saubhagya Patel
2025-03-28 16:29:15 +05:30
committed by Tim Abbott
parent 8dcc2bf592
commit d3ff0cb95f

View File

@@ -616,7 +616,12 @@ export async function build_move_topic_to_stream_popover(
if ($("#move_topic_modal select.message_edit_topic_propagate").val() === "change_one") {
return false;
}
const {new_topic_name} = get_params_from_form();
let {new_topic_name} = get_params_from_form();
if (!settings_data.user_can_move_messages_to_another_topic()) {
// new_topic_name is undefined since the new topic input is disabled when
// user does not have permission to edit topic.
new_topic_name = args.topic_name;
}
assert(new_topic_name !== undefined);
// Don't show warning for empty topic as the user is probably
// about to type a new topic name. Note that if topics are