diff --git a/web/src/page_params.ts b/web/src/page_params.ts index 86f2ccaa2c..8ffb842ef9 100644 --- a/web/src/page_params.ts +++ b/web/src/page_params.ts @@ -4,6 +4,11 @@ const t1 = performance.now(); export const page_params: { apps_page_url: string; avatar_source: string; + bot_types: { + type_id: number; + name: string; + allowed: boolean; + }[]; corporate_enabled: boolean; development_environment: boolean; language_list: { diff --git a/web/src/settings_bots.js b/web/src/settings_bots.js index 0c36eda69c..56ac2d51fb 100644 --- a/web/src/settings_bots.js +++ b/web/src/settings_bots.js @@ -21,6 +21,7 @@ import {$t, $t_html} from "./i18n"; import {page_params} from "./page_params"; import * as people from "./people"; import * as settings_config from "./settings_config"; +import * as settings_data from "./settings_data"; import * as settings_users from "./settings_users"; import * as stream_data from "./stream_data"; import * as ui_report from "./ui_report"; @@ -60,10 +61,6 @@ function is_local_part(value) { return /^[\w!#$%&'*+/=?^`{|}~-]+(\.[\w!#$%&'*+/=?^`{|}~-]+)*$/i.test(value); } -export function type_id_to_string(type_id) { - return page_params.bot_types.find((bot_type) => bot_type.type_id === type_id).name; -} - export function render_bots() { $("#active_bots_list").empty(); $("#inactive_bots_list").empty(); @@ -76,7 +73,7 @@ export function render_bots() { name: elem.full_name, email: elem.email, user_id: elem.user_id, - type: type_id_to_string(elem.bot_type), + type: settings_data.type_id_to_string(elem.bot_type), avatar_url: elem.avatar_url, api_key: elem.api_key, is_active: elem.is_active, diff --git a/web/src/settings_data.ts b/web/src/settings_data.ts index 07c8371625..2334453999 100644 --- a/web/src/settings_data.ts +++ b/web/src/settings_data.ts @@ -253,3 +253,13 @@ export function user_email_not_configured(): boolean { // page_params.demo_organization_scheduled_deletion_date return page_params.is_owner && page_params.delivery_email === ""; } + +export function type_id_to_string(type_id: number): string | undefined { + const bot_type = page_params.bot_types.find((bot_type) => bot_type.type_id === type_id); + + if (bot_type === undefined) { + return undefined; + } + + return bot_type.name; +} diff --git a/web/src/settings_users.js b/web/src/settings_users.js index bec0b1a5dd..93f43c0b85 100644 --- a/web/src/settings_users.js +++ b/web/src/settings_users.js @@ -23,6 +23,7 @@ import * as scroll_util from "./scroll_util"; import * as settings_account from "./settings_account"; import * as settings_bots from "./settings_bots"; import * as settings_config from "./settings_config"; +import * as settings_data from "./settings_data"; import * as settings_panel_menu from "./settings_panel_menu"; import * as timerender from "./timerender"; import * as ui_report from "./ui_report"; @@ -241,7 +242,7 @@ function bot_info(bot_user_id) { info.user_role_text = people.get_user_type(bot_user_id); // Convert bot type id to string for viewing to the users. - info.bot_type = settings_bots.type_id_to_string(bot_user.bot_type); + info.bot_type = settings_data.type_id_to_string(bot_user.bot_type); info.bot_owner_full_name = bot_owner_full_name(owner_id); diff --git a/web/src/user_profile.js b/web/src/user_profile.js index e47127ae67..af6c6f7640 100644 --- a/web/src/user_profile.js +++ b/web/src/user_profile.js @@ -19,6 +19,7 @@ import * as people from "./people"; import * as popovers from "./popovers"; import * as settings_account from "./settings_account"; import * as settings_bots from "./settings_bots"; +import * as settings_data from "./settings_data"; import * as settings_profile_fields from "./settings_profile_fields"; import * as settings_users from "./settings_users"; import * as stream_data from "./stream_data"; @@ -335,7 +336,7 @@ export function show_user_profile(user, default_tab_key = "profile-tab") { const bot_owner = people.get_by_user_id(bot_owner_id); args.bot_owner = bot_owner; } - args.bot_type = settings_bots.type_id_to_string(user.bot_type); + args.bot_type = settings_data.type_id_to_string(user.bot_type); } $("#user-profile-modal-holder").html(render_user_profile_modal(args)); diff --git a/web/tests/settings_data.test.js b/web/tests/settings_data.test.js index fba2a75373..5420a78289 100644 --- a/web/tests/settings_data.test.js +++ b/web/tests/settings_data.test.js @@ -404,3 +404,22 @@ run_test("can_edit_user_group", () => { page_params.realm_waiting_period_threshold = 0; assert.ok(settings_data.can_edit_user_group(students.id)); }); + +run_test("type_id_to_string", () => { + page_params.bot_types = [ + { + type_id: 1, + name: "Generic bot", + allowed: true, + }, + { + type_id: 2, + name: "Incoming webhook", + allowed: true, + }, + ]; + + assert.equal(settings_data.type_id_to_string(1), "Generic bot"); + assert.equal(settings_data.type_id_to_string(2), "Incoming webhook"); + assert.equal(settings_data.type_id_to_string(5), undefined); +});