From d4189fa6ca0b03bd2ea945eee045c3d23300749e Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Fri, 8 Jul 2022 22:15:17 +0530 Subject: [PATCH] settings: Allow editing config data of bots from admin edit modal. We now allow admins to edit configuration of outgoing webhook and embedded bots from the edit form in "Organization" settings section. In next commit we would deduplicate the code to use same modal in both "Organization" and "Personal" settings sections. --- static/js/settings_bots.js | 32 +++++++++++++++++++++ static/templates/settings/edit_bot_form.hbs | 2 ++ 2 files changed, 34 insertions(+) diff --git a/static/js/settings_bots.js b/static/js/settings_bots.js index f17b8e58f7..a0c03b1768 100644 --- a/static/js/settings_bots.js +++ b/static/js/settings_bots.js @@ -257,6 +257,9 @@ export function show_edit_bot_info_modal(user_id, from_user_info_popover) { let owner_widget; let avatar_widget; + const bot_type = bot.bot_type.toString(); + const service = bot_data.get_services(bot.user_id)[0]; + function submit_bot_details() { const role = Number.parseInt($("#bot-role-select").val().trim(), 10); const $full_name = $("#dialog_widget_modal").find("input[name='full_name']"); @@ -275,6 +278,19 @@ export function show_edit_bot_info_modal(user_id, from_user_info_popover) { formData.append("bot_owner_id", human_user_id); } + if (bot_type === OUTGOING_WEBHOOK_BOT_TYPE) { + const service_payload_url = $("#edit_service_base_url").val(); + const service_interface = $("#edit_service_interface :selected").val(); + formData.append("service_payload_url", JSON.stringify(service_payload_url)); + formData.append("service_interface", service_interface); + } else if (bot_type === EMBEDDED_BOT_TYPE && service !== undefined) { + const config_data = {}; + $("#config_edit_inputbox input").each(function () { + config_data[$(this).attr("name")] = $(this).val(); + }); + formData.append("config_data", JSON.stringify(config_data)); + } + const $file_input = $("#bot-edit-form").find(".edit_bot_avatar_file_input"); for (const [i, file] of Array.prototype.entries.call($file_input[0].files)) { formData.append("file-" + i, file); @@ -325,6 +341,22 @@ export function show_edit_bot_info_modal(user_id, from_user_info_popover) { avatar_widget = avatar.build_bot_edit_widget($("#bot-edit-form")); + if (bot_type === OUTGOING_WEBHOOK_BOT_TYPE) { + $("#service_data").append( + render_settings_edit_outgoing_webhook_service({ + service, + }), + ); + $("#edit_service_interface").val(service.interface); + } + if (bot_type === EMBEDDED_BOT_TYPE) { + $("#service_data").append( + render_settings_edit_embedded_bot_service({ + service, + }), + ); + } + $("#bot-edit-form").on("click", ".deactivate_bot_button", (e) => { e.preventDefault(); e.stopPropagation(); diff --git a/static/templates/settings/edit_bot_form.hbs b/static/templates/settings/edit_bot_form.hbs index 17c59033f4..b781deff6d 100644 --- a/static/templates/settings/edit_bot_form.hbs +++ b/static/templates/settings/edit_bot_form.hbs @@ -27,6 +27,8 @@ widget_name="edit_bot_owner" list_placeholder=(t 'Filter users')}} +
+