settings_bots: Move type_id_to_string to settings_data.js.

This commit is contained in:
Sahil Batra 2023-09-25 13:45:19 +05:30 committed by Tim Abbott
parent 71e297efb4
commit 46ab3031a3
6 changed files with 40 additions and 7 deletions

View File

@ -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: {

View File

@ -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,

View File

@ -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;
}

View File

@ -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);

View File

@ -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));

View File

@ -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);
});