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.

settings: Hide actions column when user has no permissions.

Rakshit Chauhana0b20e1b3780
diff --git a/web/src/settings_bots.ts b/web/src/settings_bots.ts
index 213cb29d9a9..6ec5e600452 100644
--- a/web/src/settings_bots.ts
+++ b/web/src/settings_bots.ts
@@ -70,6 +70,7 @@ type BotInfo = {
can_modify: boolean;
cannot_deactivate: boolean;
cannot_edit: boolean;
+ show_manage_buttons: boolean;
display_email: string;
show_download_zuliprc_button: boolean;
show_generate_integration_url_button: boolean;
@@ -426,6 +427,11 @@ function bot_info(bot_user_id: number): BotInfo {
const is_bot_owner = owner_id === current_user.user_id;
const can_modify_bot = current_user.is_admin || is_bot_owner;
+ const is_system_bot = bot_user.is_system_bot ?? false;
+
+ // can_modify_bot is already true for admins, so the extra
+ // is_system_bot check added nothing — collapsed into one flag.
+ const show_manage_buttons = can_modify_bot;
return {
is_bot: true,
@@ -442,8 +448,8 @@ function bot_info(bot_user_id: number): BotInfo {
no_owner: !owner_full_name,
is_current_user: false,
can_modify: can_modify_bot,
- cannot_deactivate: (bot_user.is_system_bot ?? false) || !can_modify_bot,
- cannot_edit: (bot_user.is_system_bot ?? false) || !can_modify_bot,
+ cannot_deactivate: is_system_bot || !can_modify_bot,
+ cannot_edit: is_system_bot || !can_modify_bot,
// It's always safe to show the real email addresses for bot users
display_email: bot_user.email,
...(owner_id
@@ -458,9 +464,19 @@ function bot_info(bot_user_id: number): BotInfo {
show_download_zuliprc_button: is_bot_owner && bot_user.bot_type === GENERIC_BOT_TYPE_INT,
show_generate_integration_url_button:
can_modify_bot && bot_user.bot_type === INCOMING_WEBHOOK_BOT_TYPE_INT,
+ show_manage_buttons,
};
}
+function should_show_actions_column(bot_list: BotInfo[]): boolean {
+ return bot_list.some(
+ (info) =>
+ info.show_download_zuliprc_button ||
+ info.show_generate_integration_url_button ||
+ info.show_manage_buttons,
+ );
+}
+
function handle_bot_deactivation($tbody: JQuery): void {
$tbody.on("click", ".deactivate", (e) => {
e.preventDefault();
@@ -624,6 +640,12 @@ function reset_scrollbar($sel: JQuery): () => void {
};
}
+function update_actions_column_visibility(section: BotSettingsSection, $container: JQuery): void {
+ const current_list = section.list_widget?.get_current_list() ?? [];
+ const show_actions = should_show_actions_column(current_list);
+ $container.find(".bot-list-table").toggleClass("hide-actions-column", !show_actions);
+}
+
function create_all_bots_table(
section: BotSettingsSection,
$container: JQuery,
@@ -649,7 +671,10 @@ function create_all_bots_table(
const $search_input = $container.find(".search");
return are_filters_active(section.filters, $search_input);
},
- onupdate: reset_scrollbar($all_bots_table),
+ onupdate() {
+ update_actions_column_visibility(section, $container);
+ reset_scrollbar($all_bots_table)();
+ },
},
$parent_container: $container.expectOne(),
init_sort: "full_name_alphabetic",
@@ -663,6 +688,8 @@ function create_all_bots_table(
});
settings_users.set_text_search_value($all_bots_table, section.filters.text_search);
+ update_actions_column_visibility(section, $container);
+
loading.destroy_indicator($container.find(".loading-indicator"));
$all_bots_table.show();
}
@@ -691,7 +718,10 @@ function create_your_bots_table(
const $search_input = $container.find(".search");
return are_filters_active(section.filters, $search_input);
},
- onupdate: reset_scrollbar($your_bots_table),
+ onupdate() {
+ update_actions_column_visibility(section, $container);
+ reset_scrollbar($your_bots_table)();
+ },
},
$parent_container: $container.expectOne(),
init_sort: "full_name_alphabetic",
@@ -705,6 +735,8 @@ function create_your_bots_table(
});
settings_users.set_text_search_value($your_bots_table, section.filters.text_search);
+ update_actions_column_visibility(section, $container);
+
loading.destroy_indicator($container.find(".loading-indicator"));
$your_bots_table.show();
}
diff --git a/web/styles/settings.css b/web/styles/settings.css
index dcf74fd5425..7b202a2ea47 100644
--- a/web/styles/settings.css
+++ b/web/styles/settings.css
@@ -415,6 +415,18 @@ select.settings_select {
#personal-bot-list .user-status-settings {
display: flex;
justify-content: flex-end;
+ /* Matches the height of one row of action icon-buttons, so rows keep a consistent height even when no buttons are shown. */
+ min-height: 2.1875em;
+}
+
+.bot-list-table td {
+ /* Keeps row height consistent whether or not the actions column is shown for this table. */
+ height: 2.1875em;
+}
+
+.bot-list-table.hide-actions-column th.actions,
+.bot-list-table.hide-actions-column td.actions {
+ display: none;
}
.config-download-text {
diff --git a/web/templates/settings/bot_list.hbs b/web/templates/settings/bot_list.hbs
index 644c5b8476a..2a7d02977ff 100644
--- a/web/templates/settings/bot_list.hbs
+++ b/web/templates/settings/bot_list.hbs
@@ -8,7 +8,7 @@
</div>
<div class="progressive-table-wrapper" data-simplebar data-simplebar-tab-index="-1">
- <table class="table table-striped wrapped-table">
+ <table class="table table-striped wrapped-table bot-list-table">
<thead class="table-sticky-headers">
<tr>
<th class="active" data-sort="alphabetic" data-sort-prop="full_name">{{t "Name" }}
diff --git a/web/templates/settings/settings_bot_list_row.hbs b/web/templates/settings/settings_bot_list_row.hbs
index f1ff6b7d006..f654f0a0718 100644
--- a/web/templates/settings/settings_bot_list_row.hbs
+++ b/web/templates/settings/settings_bot_list_row.hbs
@@ -41,6 +41,7 @@
}}
</span>
{{/if}}
+ {{#if show_manage_buttons}}
<span class="{{#if cannot_edit}}tippy-zulip-tooltip{{else}}tippy-zulip-delayed-tooltip{{/if}}"
{{#if cannot_edit}}
data-tippy-content="{{t 'This bot cannot be managed.'}}"
@@ -73,6 +74,7 @@
}}
</span>
{{/if}}
+ {{/if}}
</span>
</td>
</tr>