bots: Improve bots permission banner.

Added a separate template file for banner
messages in bots panel under personal and organisation
settings.

Banners for bots panel under personal
settings are shown only when user cannot add bots.
Banners for bots panel under organisation settings are shown
only when user cannot add bots or user is administrator.

Fixes #24155
This commit is contained in:
Ujjawal Modi
2023-03-03 18:44:01 +05:30
committed by Tim Abbott
parent 560ce87063
commit 0eca9cb319
6 changed files with 35 additions and 17 deletions

View File

@@ -218,7 +218,7 @@ export function build_page() {
$("#settings_content .organization-box").html(rendered_admin_tab);
$("#settings_content .alert").removeClass("show");
settings_bots.update_bot_settings_tip();
settings_bots.update_bot_settings_tip($("#admin-bot-settings-tip"), true);
settings_invites.update_invite_users_setting_tip();
insert_tip_box();

View File

@@ -114,6 +114,7 @@ export function build_page() {
owner_is_only_user_in_organization: people.get_active_human_count() === 1,
});
settings_bots.update_bot_settings_tip($("#personal-bot-settings-tip"), false);
$(".settings-box").html(rendered_settings_tab);
}

View File

@@ -4,6 +4,7 @@ import $ from "jquery";
import render_settings_deactivation_bot_modal from "../templates/confirm_dialog/confirm_deactivate_bot.hbs";
import render_add_new_bot_form from "../templates/settings/add_new_bot_form.hbs";
import render_bot_avatar_row from "../templates/settings/bot_avatar_row.hbs";
import render_bot_settings_tip from "../templates/settings/bot_settings_tip.hbs";
import render_edit_bot_form from "../templates/settings/edit_bot_form.hbs";
import render_settings_edit_embedded_bot_service from "../templates/settings/edit_embedded_bot_service.hbs";
import render_settings_edit_outgoing_webhook_service from "../templates/settings/edit_outgoing_webhook_service.hbs";
@@ -156,20 +157,26 @@ export function can_create_new_bots() {
return page_params.realm_bot_creation_policy !== bot_creation_policy_values.admins_only.code;
}
export function update_bot_settings_tip() {
const permission_type = bot_creation_policy_values;
const current_permission = page_params.realm_bot_creation_policy;
let tip_text;
if (current_permission === permission_type.admins_only.code) {
tip_text = $t({
defaultMessage: "Only organization administrators can add bots to this organization.",
});
} else if (current_permission === permission_type.restricted.code) {
tip_text = $t({defaultMessage: "Only organization administrators can add generic bots."});
} else {
tip_text = $t({defaultMessage: "Anyone in this organization can add bots."});
export function update_bot_settings_tip($tip_container, for_org_settings) {
if (
!page_params.is_admin &&
page_params.realm_bot_creation_policy === bot_creation_policy_values.everyone.code
) {
$tip_container.hide();
return;
}
$(".bot-settings-tip").text(tip_text);
if (page_params.is_admin && !for_org_settings) {
$tip_container.hide();
return;
}
const rendered_tip = render_bot_settings_tip({
realm_bot_creation_policy: page_params.realm_bot_creation_policy,
permission_type: bot_creation_policy_values,
});
$tip_container.show();
$tip_container.html(rendered_tip);
}
function update_add_bot_button() {
@@ -183,7 +190,8 @@ function update_add_bot_button() {
}
export function update_bot_permissions_ui() {
update_bot_settings_tip();
update_bot_settings_tip($("#admin-bot-settings-tip"), true);
update_bot_settings_tip($("#personal-bot-settings-tip"), false);
update_add_bot_button();
$("#id_realm_bot_creation_policy").val(page_params.realm_bot_creation_policy);
}