Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
settings: Fix lock icon for "Bots" panel in left sidebar.
Sahil Batra46fcd7628121
diff --git a/web/src/server_events_dispatch.js b/web/src/server_events_dispatch.jsindex 818776f2dca..b35d78d0cff 100644--- a/web/src/server_events_dispatch.js+++ b/web/src/server_events_dispatch.js@@ -498,6 +498,7 @@ export function dispatch_normal_event(event) {if (user.bot_owner_id === current_user.user_id) {settings_bots.redraw_your_bots_list();settings_bots.toggle_bot_config_download_container();+ settings_bots.update_lock_icon_in_sidebar();}break;}@@ -505,6 +506,7 @@ export function dispatch_normal_event(event) {bot_data.del(event.bot.user_id);settings_bots.redraw_your_bots_list();settings_bots.toggle_bot_config_download_container();+ settings_bots.update_lock_icon_in_sidebar();break;case "update":bot_data.update(event.bot.user_id, event.bot);diff --git a/web/src/settings.ts b/web/src/settings.tsindex f34cd73af13..6447da17fda 100644--- a/web/src/settings.ts+++ b/web/src/settings.ts@@ -5,6 +5,7 @@ import timezones from "../generated/timezones.json";import render_settings_overlay from "../templates/settings_overlay.hbs";import render_settings_tab from "../templates/settings_tab.hbs";+import * as bot_data from "./bot_data.ts";import * as browser_history from "./browser_history.ts";import * as common from "./common.ts";import * as flatpickr from "./flatpickr.ts";@@ -52,7 +53,10 @@ export function update_lock_icon_in_sidebar(): void {$(".org-settings-list .locked").show();- if (settings_bots.can_create_incoming_webhooks()) {+ if (+ settings_bots.can_create_incoming_webhooks() ||+ bot_data.get_all_bots_ids_for_current_user().length > 0+ ) {$(".org-settings-list li[data-section='bots'] .locked").hide();}@@ -201,6 +205,8 @@ export function initialize(): void {show_uploaded_files_section: realm.max_file_upload_size_mib > 0,show_emoji_settings_lock: !settings_data.user_can_add_custom_emoji(),can_create_new_bots: settings_bots.can_create_incoming_webhooks(),+ can_manage_bot:+ current_user.is_admin || bot_data.get_all_bots_ids_for_current_user().length > 0,can_edit_user_panel:current_user.is_admin ||settings_data.user_can_create_multiuse_invite() ||diff --git a/web/src/settings_bots.ts b/web/src/settings_bots.tsindex e5ccc62055b..8dc3dde5064 100644--- a/web/src/settings_bots.ts+++ b/web/src/settings_bots.ts@@ -195,9 +195,19 @@ export function update_bot_settings_tip($tip_container: JQuery): void {function update_add_bot_button(): void {if (can_create_incoming_webhooks()) {$("#admin-bot-list .add-a-new-bot").show();- $(".org-settings-list li[data-section='bots'] .locked").hide();} else {$("#admin-bot-list .add-a-new-bot").hide();+ }+}++export function update_lock_icon_in_sidebar(): void {+ if (+ can_create_incoming_webhooks() ||+ current_user.is_admin ||+ bot_data.get_all_bots_ids_for_current_user().length > 0+ ) {+ $(".org-settings-list li[data-section='bots'] .locked").hide();+ } else {$(".org-settings-list li[data-section='bots'] .locked").show();}}@@ -205,6 +215,7 @@ function update_add_bot_button(): void {export function update_bot_permissions_ui(): void {update_bot_settings_tip($("#admin-bot-settings-tip"));update_add_bot_button();+ update_lock_icon_in_sidebar();}export function get_allowed_bot_types(): BotType[] {diff --git a/web/src/ui_init.js b/web/src/ui_init.jsindex 42afacefcbb..9da0359e683 100644--- a/web/src/ui_init.js+++ b/web/src/ui_init.js@@ -506,6 +506,11 @@ export async function initialize_everything(state_data) {await people.initialize(current_user.user_id, state_data.people, state_data.user_groups);starred_messages.initialize(state_data.starred_messages);+ // Must happen after people.initialize(). And also before+ // settings.initialize(), as we check if the user owns any+ // bot to show the lock icon for "Bots" panel+ bot_data.initialize(state_data.bot);+// The emoji module must be initialized before the right sidebar// module, so that we can display custom emoji in statuses.emoji.initialize({@@ -644,7 +649,6 @@ export async function initialize_everything(state_data) {drafts.initialize(); // Must happen before reload_setup.initialize()reload_setup.initialize();unread.initialize(state_data.unread);- bot_data.initialize(state_data.bot); // Must happen after people.initialize()message_fetch.initialize(() => {recent_view_ui.set_initial_message_fetch_status(false);recent_view_ui.revive_current_focus();diff --git a/web/templates/settings_overlay.hbs b/web/templates/settings_overlay.hbsindex 6faaab61622..0b268655061 100644--- a/web/templates/settings_overlay.hbs+++ b/web/templates/settings_overlay.hbs@@ -97,7 +97,7 @@<li class="sidebar-item" tabindex="0" data-section="bots"><i class="sidebar-item-icon zulip-icon zulip-icon-bot" aria-hidden="true"></i><div class="text">{{t "Bots" }}</div>- <i class="locked fa fa-lock tippy-zulip-tooltip" {{#if can_create_new_bots}}style="display: none;"{{/if}} data-tippy-content="{{t 'Only organization administrators can edit these settings.' }}"></i>+ <i class="locked fa fa-lock tippy-zulip-tooltip" {{#if (or can_create_new_bots can_manage_bot)}}style="display: none;"{{/if}} data-tippy-content="{{t 'You do not have permission to create or manage bots.' }}"></i></li>{{/unless}}{{#if is_admin}}diff --git a/web/tests/dispatch.test.cjs b/web/tests/dispatch.test.cjsindex 5e9cc7dfdfc..739697ee3d3 100644--- a/web/tests/dispatch.test.cjs+++ b/web/tests/dispatch.test.cjs@@ -849,6 +849,7 @@ run_test("realm_bot add", ({override}) => {override(bot_data, "add", bot_stub.f);override(settings_bots, "redraw_your_bots_list", noop);override(settings_bots, "toggle_bot_config_download_container", noop);+ override(settings_bots, "update_lock_icon_in_sidebar", noop);dispatch(event);@@ -863,6 +864,7 @@ run_test("realm_bot delete", ({override}) => {override(bot_data, "del", bot_stub.f);override(settings_bots, "redraw_your_bots_list", noop);override(settings_bots, "toggle_bot_config_download_container", noop);+ override(settings_bots, "update_lock_icon_in_sidebar", noop);dispatch(event);assert.equal(bot_stub.num_calls, 1);