mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
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:
@@ -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();
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<div id="admin-bot-list" class="settings-section" data-name="bot-list-admin">
|
||||
<div class="tip bot-settings-tip"></div>
|
||||
<div class="bot-settings-tip" id="admin-bot-settings-tip">
|
||||
</div>
|
||||
<div class="clear-float"></div>
|
||||
<div>
|
||||
<button class="button rounded sea-green add-a-new-bot {{#unless can_create_new_bots}}hide{{/unless}}">{{t "Add a new bot" }}</button>
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
{{#*inline "z-api"}}<a href="/api" target="_blank" rel="noopener noreferrer">{{> @partial-block}}</a>{{/inline}}
|
||||
{{/tr}}
|
||||
</div>
|
||||
<div class="tip bot-settings-tip"></div>
|
||||
<div class="bot-settings-tip" id="personal-bot-settings-tip">
|
||||
</div>
|
||||
<div>
|
||||
<button class="button rounded sea-green add-a-new-bot {{#unless can_create_new_bots}}hide{{/unless}}">{{t "Add a new bot" }}</button>
|
||||
</div>
|
||||
|
||||
7
web/templates/settings/bot_settings_tip.hbs
Normal file
7
web/templates/settings/bot_settings_tip.hbs
Normal file
@@ -0,0 +1,7 @@
|
||||
{{#if (eq realm_bot_creation_policy permission_type.admins_only.code)}}
|
||||
<div class='tip'>{{t "Only organization administrators can add bots to this organization." }}</div>
|
||||
{{else if (eq realm_bot_creation_policy permission_type.restricted.code) }}
|
||||
<div class='tip'>{{t "Only organization administrators can add generic bots." }}</div>
|
||||
{{else}}
|
||||
<div class='tip'>{{t "Anyone in this organization can add bots." }}</div>
|
||||
{{/if}}
|
||||
Reference in New Issue
Block a user