Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
settings: Duplicate bots panel in "Personal" tab.
Sahil Batra48c7411d7393
diff --git a/web/e2e-tests/settings.test.ts b/web/e2e-tests/settings.test.tsindex 6c1dc1a718c..cf2187da335 100644--- a/web/e2e-tests/settings.test.ts+++ b/web/e2e-tests/settings.test.ts@@ -17,7 +17,7 @@ async function get_decoded_url_in_selector(page: Page, selector: string): Promis}async function open_manage_bot_tab(page: Page, user_id: number): Promise<void> {- const manage_button_selector = `#admin_your_bots_table .user_row[data-user-id="${user_id}"] .manage-user-button`;+ const manage_button_selector = `#personal_your_bots_table .user_row[data-user-id="${user_id}"] .manage-user-button`;await page.waitForSelector(manage_button_selector, {visible: true});await page.click(manage_button_selector);@@ -115,7 +115,7 @@ async function test_get_api_key(page: Page): Promise<void> {}async function test_webhook_bot_creation(page: Page): Promise<void> {- await page.click("#admin-bot-list .add-a-new-bot");+ await page.click("#personal-bot-list .add-a-new-bot");await common.wait_for_micromodal_to_open(page);assert.strictEqual(await common.get_text_from_selector(page, ".dialog_heading"),@@ -165,7 +165,7 @@ async function test_webhook_bot_creation(page: Page): Promise<void> {}async function test_normal_bot_creation(page: Page): Promise<void> {- await page.click("#admin-bot-list .add-a-new-bot");+ await page.click("#personal-bot-list .add-a-new-bot");await common.wait_for_micromodal_to_open(page);assert.strictEqual(await common.get_text_from_selector(page, ".dialog_heading"),@@ -207,13 +207,13 @@ async function test_normal_bot_creation(page: Page): Promise<void> {}async function test_botserverrc(page: Page): Promise<void> {- await page.click("#admin-bot-list .download-botserverrc-file");+ await page.click("#personal-bot-list .download-botserverrc-file");await page.waitForSelector(- '#admin-bot-list .hidden-botserverrc-download[href^="data:application"]',+ '#personal-bot-list .hidden-botserverrc-download[href^="data:application"]',);const botserverrc_decoded_url = await get_decoded_url_in_selector(page,- "#admin-bot-list .hidden-botserverrc-download",+ "#personal-bot-list .hidden-botserverrc-download",);const botserverrc_regex =/^data:application\/octet-stream;charset=utf-8,\[]\nemail=.+\nkey=.+\nsite=.+\ntoken=.+\n$/;@@ -303,7 +303,7 @@ async function test_invalid_edit_bot_form(page: Page): Promise<void> {}async function test_your_bots_section(page: Page): Promise<void> {- await page.click(".your-bots-link");+ await page.click('.normal-settings-list [data-section="bots"]');await test_webhook_bot_creation(page);await test_normal_bot_creation(page);await test_botserverrc(page);diff --git a/web/e2e-tests/user-deactivation.test.ts b/web/e2e-tests/user-deactivation.test.tsindex 895a5669b85..33186753529 100644--- a/web/e2e-tests/user-deactivation.test.ts+++ b/web/e2e-tests/user-deactivation.test.ts@@ -105,7 +105,7 @@ async function test_deactivated_users_section(page: Page): Promise<void> {}async function test_bot_deactivation_and_reactivation(page: Page): Promise<void> {- await page.click("li[data-section='bots']");+ await page.click(".org-settings-list li[data-section='bots']");const default_bot_user_row = await user_row(page, "Zulip Default Bot");diff --git a/web/src/hashchange.ts b/web/src/hashchange.tsindex 0b0ad8bf655..83c8e264ba4 100644--- a/web/src/hashchange.ts+++ b/web/src/hashchange.ts@@ -382,7 +382,10 @@ function do_hashchange_overlay(old_hash: string | undefined): void {// hand-typed a hash.blueslip.warn("missing section for settings");}- settings_panel_menu.normal_settings.activate_section_or_default(section);+ settings_panel_menu.normal_settings.activate_section_or_default(+ section,+ get_settings_tab(section),+ );return;}@@ -414,6 +417,12 @@ function do_hashchange_overlay(old_hash: string | undefined): void {if (is_hashchange_internal) {if (base === "settings") {settings_panel_menu.normal_settings.set_current_tab(section);+ if (section === "bots") {+ settings_panel_menu.normal_settings.set_bot_settings_tab(+ get_settings_tab(section)!,+ "personal",+ );+ }} else {settings_panel_menu.org_settings.set_current_tab(section);if (section === "users") {@@ -490,7 +499,7 @@ function do_hashchange_overlay(old_hash: string | undefined): void {if (base === "settings") {settings.build_page();admin.build_page();- settings.launch(section);+ settings.launch(section, get_settings_tab(section));return;}diff --git a/web/src/settings.ts b/web/src/settings.tsindex 6447da17fda..15d365e8a52 100644--- a/web/src/settings.ts+++ b/web/src/settings.ts@@ -1,5 +1,6 @@import {parseISO} from "date-fns";import $ from "jquery";+import assert from "minimalistic-assert";import timezones from "../generated/timezones.json";import render_settings_overlay from "../templates/settings_overlay.hbs";@@ -168,10 +169,16 @@ export function build_page(): void {user_settings.allow_private_data_export || is_export_without_consent_enabled,private_data_export_is_disabled: is_export_without_consent_enabled,private_data_export_tooltip_text,+ all_bots_list_dropdown_widget_name:+ settings_bots.personal_all_bots_list_dropdown_widget_name,+ your_bots_list_dropdown_widget_name:+ settings_bots.personal_your_bots_list_dropdown_widget_name,});$(".settings-box").html(rendered_settings_tab);common.adjust_mac_kbd_tags("#user_enter_sends_label kbd");++ settings_bots.update_bot_settings_tip($("#personal-bot-settings-tip"));}export function open_settings_overlay(): void {@@ -187,13 +194,17 @@ export function open_settings_overlay(): void {});}-export function launch(section: string): void {+export function launch(section: string, settings_tab: string | undefined): void {settings_sections.reset_sections();open_settings_overlay();if (section !== "") {settings_panel_menu.normal_settings.set_current_tab(section);}+ if (section === "bots") {+ assert(settings_tab !== undefined);+ settings_panel_menu.normal_settings.set_bot_settings_tab(settings_tab, "personal");+ }settings_toggle.goto("settings");}diff --git a/web/src/settings_bots.ts b/web/src/settings_bots.tsindex 410d147e4fb..95022c7dd89 100644--- a/web/src/settings_bots.ts+++ b/web/src/settings_bots.ts@@ -42,6 +42,10 @@ const EMBEDDED_BOT_TYPE = "4";export const org_all_bots_list_dropdown_widget_name = "org_all_bots_list_select_bot_status";export const org_your_bots_list_dropdown_widget_name = "org_your_bots_list_select_bot_status";+export const personal_all_bots_list_dropdown_widget_name =+ "personal_all_bots_list_select_bot_status";+export const personal_your_bots_list_dropdown_widget_name =+ "personal_your_bots_list_select_bot_status";type BotType = {type_id: number;@@ -106,6 +110,24 @@ const org_your_bots_section: BotSettingsSection = {list_widget: undefined,};+const personal_all_bots_section: BotSettingsSection = {+ dropdown_widget_name: personal_all_bots_list_dropdown_widget_name,+ filters: {+ text_search: "",+ status_code: 0,+ },+ list_widget: undefined,+};++const personal_your_bots_section: BotSettingsSection = {+ dropdown_widget_name: personal_your_bots_list_dropdown_widget_name,+ filters: {+ text_search: "",+ status_code: 0,+ },+ list_widget: undefined,+};+function sort_bot_email(a: BotInfo, b: BotInfo): number {function email(bot: BotInfo): string {return (bot.display_email ?? "").toLowerCase();@@ -189,8 +211,10 @@ 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();+ $("#personal-bot-list .add-a-new-bot").show();} else {$("#admin-bot-list .add-a-new-bot").hide();+ $("#personal-bot-list .add-a-new-bot").hide();}}@@ -201,13 +225,16 @@ export function update_lock_icon_in_sidebar(): void {bot_data.get_all_bots_ids_for_current_user().length > 0) {$(".org-settings-list li[data-section='bots'] .locked").hide();+ $(".normal-settings-list li[data-section='bots'] .locked").hide();} else {$(".org-settings-list li[data-section='bots'] .locked").show();+ $(".normal-settings-list li[data-section='bots'] .locked").show();}}export function update_bot_permissions_ui(): void {update_bot_settings_tip($("#admin-bot-settings-tip"));+ update_bot_settings_tip($("#personal-bot-settings-tip"));update_add_bot_button();update_lock_icon_in_sidebar();}@@ -466,30 +493,42 @@ export function toggle_bot_config_download_container(): void {return elem.bot_type === OUTGOING_WEBHOOK_BOT_TYPE_INT && is_active;});$("#admin-bot-list .config-download-text").toggle(bots.length > 0);+ $("#personal-bot-list .config-download-text").toggle(bots.length > 0);}export function redraw_all_bots_list(): void {// In order to properly redraw after a user may have been added,// we need to update the all_bots_section.list_widget with the new// set of bot user IDs to display.- if (!org_all_bots_section.list_widget) {+ if (!org_all_bots_section.list_widget && !personal_all_bots_section.list_widget) {return;}const bot_user_ids = people.get_bot_ids();- org_all_bots_section.list_widget.replace_list_data(bot_user_ids);+ if (org_all_bots_section.list_widget) {+ org_all_bots_section.list_widget.replace_list_data(bot_user_ids);+ }++ if (personal_all_bots_section.list_widget) {+ personal_all_bots_section.list_widget.replace_list_data(bot_user_ids);+ }}export function redraw_your_bots_list(): void {// In order to properly redraw after a user may have been added,// we need to update the your_bots_list_widget with the new set of bot// user IDs to display.- if (!org_your_bots_section.list_widget) {+ if (!org_your_bots_section.list_widget && !personal_your_bots_section.list_widget) {return;}const bot_user_ids_for_current_owner = bot_data.get_all_bots_ids_for_current_user();- org_your_bots_section.list_widget.replace_list_data(bot_user_ids_for_current_owner);+ if (org_your_bots_section.list_widget) {+ org_your_bots_section.list_widget.replace_list_data(bot_user_ids_for_current_owner);+ }+ if (personal_your_bots_section.list_widget) {+ personal_your_bots_section.list_widget.replace_list_data(bot_user_ids_for_current_owner);+ }}function add_value_to_filters(@@ -673,6 +712,14 @@ export function update_bot_data(bot_user_id: number): void {if (org_your_bots_section.list_widget) {org_your_bots_section.list_widget.render_item(bot_info(bot_user_id));}++ if (personal_all_bots_section.list_widget) {+ personal_all_bots_section.list_widget.render_item(bot_info(bot_user_id));+ }++ if (personal_your_bots_section.list_widget) {+ personal_your_bots_section.list_widget.render_item(bot_info(bot_user_id));+ }}function handle_events($tbody: JQuery, section: BotSettingsSection): void {@@ -780,3 +827,25 @@ export function set_up_bots(): void {toggle_bot_config_download_container();}++export function set_up_bots_for_personal_tab(): void {+ handle_events($("#personal_all_bots_table"), personal_all_bots_section);+ handle_events($("#personal_your_bots_table"), personal_your_bots_section);+ create_all_bots_table(+ personal_all_bots_section,+ $("#personal-all-bots-list"),+ "personal_all_bot_list",+ );+ create_your_bots_table(+ personal_your_bots_section,+ $("#personal-your-bots-list"),+ "personal_your_bot_list",+ );++ set_up_bot_handlers($("#personal-bot-list"));++ create_status_filter_dropdown($("#personal-all-bots-list"), personal_all_bots_section);+ create_status_filter_dropdown($("#personal-your-bots-list"), personal_your_bots_section);++ toggle_bot_config_download_container();+}diff --git a/web/src/settings_panel_menu.ts b/web/src/settings_panel_menu.tsindex d384278b39b..bc6c7fd17f2 100644--- a/web/src/settings_panel_menu.ts+++ b/web/src/settings_panel_menu.ts@@ -70,6 +70,7 @@ export class SettingsPanelMenu {current_bot_settings_tab: Record<string, string>;org_user_settings_toggler: Toggle;org_bot_settings_toggler: Toggle;+ personal_bot_settings_toggler: Toggle;constructor(opts: {$main_elem: JQuery; hash_prefix: string}) {this.$main_elem = opts.$main_elem;@@ -80,6 +81,7 @@ export class SettingsPanelMenu {this.current_user_settings_tab = "active";this.current_bot_settings_tab = {org: "all-bots",+ personal: "your-bots",};this.org_user_settings_toggler = components.toggle({html_class: "org-user-settings-switcher",@@ -115,6 +117,7 @@ export class SettingsPanelMenu {});this.org_bot_settings_toggler = this.set_up_bot_settings_toggler("org");+ this.personal_bot_settings_toggler = this.set_up_bot_settings_toggler("personal");this.$main_elem.on("click", "li[data-section]", (e) => {const section = $(e.currentTarget).attr("data-section")!;@@ -257,7 +260,10 @@ export class SettingsPanelMenu {}if (section === "bots") {- return this.current_bot_settings_tab["org"];+ if (this.base === "organization") {+ return this.current_bot_settings_tab["org"];+ }+ return this.current_bot_settings_tab["personal"];}return undefined;@@ -308,15 +314,26 @@ export class SettingsPanelMenu {this.org_user_settings_toggler.goto(settings_tab);}- if (section === "bots" && this.org_bot_settings_toggler !== undefined) {- assert(settings_tab !== undefined);- this.show_bot_settings_toggler(this.org_bot_settings_toggler, $("#admin-bot-list"));- this.org_bot_settings_toggler.goto(settings_tab);+ if (section === "bots") {+ if (this.org_bot_settings_toggler !== undefined && this.base === "organization") {+ assert(settings_tab !== undefined);+ this.show_bot_settings_toggler(this.org_bot_settings_toggler, $("#admin-bot-list"));+ this.org_bot_settings_toggler.goto(settings_tab);+ }++ if (this.personal_bot_settings_toggler !== undefined && this.base === "settings") {+ assert(settings_tab !== undefined);+ this.show_bot_settings_toggler(+ this.personal_bot_settings_toggler,+ $("#personal-bot-list"),+ );+ this.personal_bot_settings_toggler.goto(settings_tab);+ }}$(".settings-section").removeClass("show");- settings_sections.load_settings_section(section);+ settings_sections.load_settings_section(section, this.base);this.get_panel().addClass("show");diff --git a/web/src/settings_sections.ts b/web/src/settings_sections.tsindex 43480a47db8..a8b873b78e1 100644--- a/web/src/settings_sections.ts+++ b/web/src/settings_sections.ts@@ -24,7 +24,7 @@ import * as settings_users from "./settings_users.ts";const load_func_dict = new Map<string, () => void>(); // key is a groupconst loaded_groups = new Set();-export function get_group(section: string): string {+export function get_group(section: string, base: string): string {// Sometimes several sections all share the same code.switch (section) {@@ -34,8 +34,12 @@ export function get_group(section: string): string {case "auth-methods":return "org_misc";- case "bots":- return "org_bots";+ case "bots": {+ if (base === "organization") {+ return "org_bots";+ }+ return "personal_bots";+ }case "users":return "org_users";@@ -67,6 +71,7 @@ export function initialize(): void {// orgload_func_dict.set("org_misc", settings_org.set_up);load_func_dict.set("org_bots", settings_bots.set_up_bots);+ load_func_dict.set("personal_bots", settings_bots.set_up_bots_for_personal_tab);load_func_dict.set("org_users", settings_users.set_up_humans);load_func_dict.set("emoji-settings", settings_emoji.set_up);load_func_dict.set("default-channels-list", settings_streams.set_up);@@ -81,8 +86,8 @@ export function initialize(): void {load_func_dict.set("channel-folders", settings_folders.set_up);}-export function load_settings_section(section: string): void {- const group = get_group(section);+export function load_settings_section(section: string, base: string): void {+ const group = get_group(section, base);if (!load_func_dict.has(group)) {blueslip.error("Unknown section " + section);diff --git a/web/styles/settings.css b/web/styles/settings.cssindex 4ed870a2a0d..93f5975d107 100644--- a/web/styles/settings.css+++ b/web/styles/settings.css@@ -385,7 +385,8 @@ select.settings_select {}#admin-active-users-list,-#admin-bot-list {+#admin-bot-list,+#personal-bot-list {.table tr:first-of-type td {border-top: none;}@@ -396,7 +397,8 @@ select.settings_select {}}-#admin-bot-list .user-status-settings {+#admin-bot-list .user-status-settings,+#personal-bot-list .user-status-settings {display: flex;justify-content: flex-end;}@@ -2085,7 +2087,8 @@ label.preferences-radio-choice-label {}#admin-user-list,- #admin-bot-list {+ #admin-bot-list,+ #personal-bot-list {.user_row {.user_name,.email {@@ -2104,7 +2107,8 @@ label.preferences-radio-choice-label {@media (width < $sm_min) {#admin-user-list,- #admin-bot-list {+ #admin-bot-list,+ #personal-bot-list {.user_row,.table-sticky-headers {.bot_type,diff --git a/web/templates/settings_overlay.hbs b/web/templates/settings_overlay.hbsindex 0b268655061..405a7717640 100644--- a/web/templates/settings_overlay.hbs+++ b/web/templates/settings_overlay.hbs@@ -28,11 +28,10 @@<div class="text">{{t "Notifications" }}</div></li>{{#unless is_guest}}- <li class="redirected-sidebar-item" tabindex="0">- <a href="#organization/bots/your-bots" class="your-bots-link sidebar-item">- <i class="sidebar-item-icon zulip-icon zulip-icon-bot" aria-hidden="true"></i>- <div class="text">{{t 'Bots'}}</div>- </a>+ <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 (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}}<li class="sidebar-item" tabindex="0" data-section="alert-words">diff --git a/web/templates/settings_tab.hbs b/web/templates/settings_tab.hbsindex bc85249695c..c2a51928548 100644--- a/web/templates/settings_tab.hbs+++ b/web/templates/settings_tab.hbs@@ -7,6 +7,8 @@{{> settings/user_notification_settings . }}+ {{> settings/bot_list_admin . prefix="personal" }}+{{> settings/alert_word_settings }}{{> settings/attachments_settings }}