mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
org_settings: Add main feature to change bot role.
This commit attempts to refactor the `handle_bot_form` by adding new field for `Role` in the `Manage bot` modal. It uses the `/json/users/` url for passing the role of a bot and allow changing it as in case of a normal user. Fixes: #21105
This commit is contained in:
@@ -645,16 +645,20 @@ function handle_bot_form($tbody) {
|
||||
user_id,
|
||||
email: bot.email,
|
||||
full_name: bot.full_name,
|
||||
user_role_values: settings_config.user_role_values,
|
||||
disable_role_dropdown: bot.is_owner && !page_params.is_owner,
|
||||
});
|
||||
|
||||
let owner_widget;
|
||||
|
||||
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']");
|
||||
|
||||
const url = "/json/bots/" + encodeURIComponent(user_id);
|
||||
const data = {
|
||||
full_name: $full_name.val(),
|
||||
role: JSON.stringify(role),
|
||||
};
|
||||
|
||||
if (owner_widget === undefined) {
|
||||
@@ -668,7 +672,7 @@ function handle_bot_form($tbody) {
|
||||
dialog_widget.submit_api_request(channel.patch, url, data);
|
||||
}
|
||||
|
||||
function get_bot_owner_widget() {
|
||||
function get_bot_owner_widget_and_set_role_values() {
|
||||
const owner_id = bot_data.get(user_id).owner_id;
|
||||
|
||||
const user_ids = people.get_active_human_ids();
|
||||
@@ -687,6 +691,17 @@ function handle_bot_form($tbody) {
|
||||
// organizations with 10Ks of users.
|
||||
owner_widget = new DropdownListWidget(opts);
|
||||
owner_widget.setup();
|
||||
|
||||
$("#bot-role-select").val(bot.role);
|
||||
if (!page_params.is_owner) {
|
||||
$("#bot-role-select")
|
||||
.find(
|
||||
`option[value="${CSS.escape(
|
||||
settings_config.user_role_values.owner.code,
|
||||
)}"]`,
|
||||
)
|
||||
.hide();
|
||||
}
|
||||
}
|
||||
|
||||
dialog_widget.launch({
|
||||
@@ -694,7 +709,7 @@ function handle_bot_form($tbody) {
|
||||
html_body,
|
||||
id: "edit_bot_modal",
|
||||
on_click: submit_bot_details,
|
||||
post_render: get_bot_owner_widget,
|
||||
post_render: get_bot_owner_widget_and_set_role_values,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user