Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

bots: Improve bots permission banner.

Ujjawal Modi0eca9cb3193f
diff --git a/web/src/admin.js b/web/src/admin.js
index 51ddad13180..f1eb4849e9b 100644
--- a/web/src/admin.js
+++ b/web/src/admin.js
@@ -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();
diff --git a/web/src/settings.js b/web/src/settings.js
index 5198b4ec7ef..c19b7c0d48f 100644
--- a/web/src/settings.js
+++ b/web/src/settings.js
@@ -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);
}
diff --git a/web/src/settings_bots.js b/web/src/settings_bots.js
index b264f2fe352..e181f3fe4e4 100644
--- a/web/src/settings_bots.js
+++ b/web/src/settings_bots.js
@@ -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;
+ }
+
+ if (page_params.is_admin && !for_org_settings) {
+ $tip_container.hide();
+ return;
}
- $(".bot-settings-tip").text(tip_text);
+
+ 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);
}
diff --git a/web/templates/settings/bot_list_admin.hbs b/web/templates/settings/bot_list_admin.hbs
index 14c4dc58376..9f912a9fadb 100644
--- a/web/templates/settings/bot_list_admin.hbs
+++ b/web/templates/settings/bot_list_admin.hbs
@@ -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>
diff --git a/web/templates/settings/bot_settings.hbs b/web/templates/settings/bot_settings.hbs
index beafdb1c44d..85ec703a8fb 100644
--- a/web/templates/settings/bot_settings.hbs
+++ b/web/templates/settings/bot_settings.hbs
@@ -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>
diff --git a/web/templates/settings/bot_settings_tip.hbs b/web/templates/settings/bot_settings_tip.hbs
new file mode 100644
index 00000000000..711bc9b8888
--- /dev/null
+++ b/web/templates/settings/bot_settings_tip.hbs
@@ -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}}