2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-06-21 11:04:15 +02:00
|
|
|
import render_settings_deactivation_user_modal from "../templates/confirm_dialog/confirm_deactivate_user.hbs";
|
2022-10-25 22:24:26 +02:00
|
|
|
import render_settings_reactivation_bot_modal from "../templates/confirm_dialog/confirm_reactivate_bot.hbs";
|
2022-03-18 13:03:26 +01:00
|
|
|
import render_settings_reactivation_user_modal from "../templates/confirm_dialog/confirm_reactivate_user.hbs";
|
2021-04-22 16:41:45 +02:00
|
|
|
import render_admin_human_form from "../templates/settings/admin_human_form.hbs";
|
2021-04-24 21:18:23 +02:00
|
|
|
import render_admin_user_list from "../templates/settings/admin_user_list.hbs";
|
2021-02-28 01:21:11 +01:00
|
|
|
|
2021-03-16 23:38:59 +01:00
|
|
|
import * as blueslip from "./blueslip";
|
2021-02-28 01:24:30 +01:00
|
|
|
import * as bot_data from "./bot_data";
|
2021-02-28 01:21:11 +01:00
|
|
|
import * as channel from "./channel";
|
2021-05-26 13:30:27 +02:00
|
|
|
import * as confirm_dialog from "./confirm_dialog";
|
2021-07-05 20:37:19 +02:00
|
|
|
import * as dialog_widget from "./dialog_widget";
|
2021-06-09 19:43:01 +02:00
|
|
|
import {$t, $t_html} from "./i18n";
|
2021-02-28 01:21:11 +01:00
|
|
|
import * as ListWidget from "./list_widget";
|
|
|
|
import * as loading from "./loading";
|
2021-03-25 22:35:45 +01:00
|
|
|
import {page_params} from "./page_params";
|
2021-02-28 01:21:11 +01:00
|
|
|
import * as people from "./people";
|
|
|
|
import * as presence from "./presence";
|
|
|
|
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";
|
2021-02-28 21:33:10 +01:00
|
|
|
import * as ui from "./ui";
|
2021-02-28 01:21:11 +01:00
|
|
|
import * as user_pill from "./user_pill";
|
2019-07-09 21:24:00 +02:00
|
|
|
|
2020-05-07 15:43:20 +02:00
|
|
|
const section = {
|
|
|
|
active: {},
|
|
|
|
deactivated: {},
|
|
|
|
bots: {},
|
|
|
|
};
|
|
|
|
|
2019-08-16 06:02:53 +02:00
|
|
|
function compare_a_b(a, b) {
|
|
|
|
if (a > b) {
|
|
|
|
return 1;
|
|
|
|
} else if (a === b) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-04-15 15:09:23 +02:00
|
|
|
function sort_email(a, b) {
|
2020-07-15 01:29:15 +02:00
|
|
|
const email_a = settings_data.email_for_user_settings(a) || "";
|
|
|
|
const email_b = settings_data.email_for_user_settings(b) || "";
|
2020-07-15 00:34:28 +02:00
|
|
|
return compare_a_b(email_a.toLowerCase(), email_b.toLowerCase());
|
2020-04-15 15:09:23 +02:00
|
|
|
}
|
|
|
|
|
2020-05-10 12:52:27 +02:00
|
|
|
function sort_bot_email(a, b) {
|
|
|
|
function email(bot) {
|
2020-07-15 01:29:15 +02:00
|
|
|
return (bot.display_email || "").toLowerCase();
|
2020-05-10 12:52:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return compare_a_b(email(a), email(b));
|
|
|
|
}
|
|
|
|
|
2020-04-12 12:13:47 +02:00
|
|
|
function sort_role(a, b) {
|
2021-05-24 13:31:02 +02:00
|
|
|
return compare_a_b(a.role, b.role);
|
2020-04-12 12:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function sort_bot_owner(a, b) {
|
2020-05-10 12:52:27 +02:00
|
|
|
function owner_name(bot) {
|
2020-07-15 01:29:15 +02:00
|
|
|
return (bot.bot_owner_full_name || "").toLowerCase();
|
2020-04-15 15:35:14 +02:00
|
|
|
}
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
return compare_a_b(owner_name(a), owner_name(b));
|
2020-04-12 12:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function sort_last_active(a, b) {
|
2020-03-25 22:17:45 +01:00
|
|
|
return compare_a_b(
|
2020-06-02 21:07:09 +02:00
|
|
|
presence.last_active_date(a.user_id) || 0,
|
2020-07-02 02:16:03 +02:00
|
|
|
presence.last_active_date(b.user_id) || 0,
|
2020-03-25 22:17:45 +01:00
|
|
|
);
|
2020-04-12 12:13:47 +02:00
|
|
|
}
|
|
|
|
|
2021-11-02 15:53:47 +01:00
|
|
|
function sort_user_id(a, b) {
|
|
|
|
return compare_a_b(a.user_id, b.user_id);
|
|
|
|
}
|
|
|
|
|
2018-07-14 12:43:04 +02:00
|
|
|
function get_user_info_row(user_id) {
|
2021-02-03 23:23:32 +01:00
|
|
|
return $(`tr.user_row[data-user-id='${CSS.escape(user_id)}']`);
|
2017-04-08 20:08:35 +02:00
|
|
|
}
|
|
|
|
|
2022-02-25 12:06:40 +01:00
|
|
|
export function update_view_on_deactivate(user_id) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $row = get_user_info_row(user_id);
|
|
|
|
if ($row.length === 0) {
|
2022-02-25 12:06:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $button = $row.find("button.deactivate");
|
|
|
|
const $user_role = $row.find(".user_role");
|
|
|
|
$button.prop("disabled", false);
|
|
|
|
$row.find("button.open-user-form").hide();
|
|
|
|
$row.find("i.deactivated-user-icon").show();
|
|
|
|
$button.addClass("btn-warning reactivate");
|
|
|
|
$button.removeClass("deactivate btn-danger");
|
2022-08-16 06:50:20 +02:00
|
|
|
$button.empty().append($("<i>").addClass(["fa", "fa-user-plus"]).attr("aria-hidden", "true"));
|
2022-01-25 11:36:19 +01:00
|
|
|
$button.attr("title", "Reactivate");
|
|
|
|
$row.addClass("deactivated_user");
|
|
|
|
|
|
|
|
if ($user_role) {
|
|
|
|
const user_id = $row.data("user-id");
|
|
|
|
$user_role.text(
|
|
|
|
`${$t({defaultMessage: "Deactivated"})} (${people.get_user_type(user_id)})`,
|
|
|
|
);
|
2019-05-16 10:36:20 +02:00
|
|
|
}
|
2017-04-08 20:08:35 +02:00
|
|
|
}
|
2019-03-18 11:04:03 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
function update_view_on_reactivate($row) {
|
|
|
|
const $button = $row.find("button.reactivate");
|
|
|
|
const $user_role = $row.find(".user_role");
|
|
|
|
$row.find("button.open-user-form").show();
|
|
|
|
$row.find("i.deactivated-user-icon").hide();
|
|
|
|
$button.addClass("btn-danger deactivate");
|
|
|
|
$button.removeClass("btn-warning reactivate");
|
|
|
|
$button.attr("title", "Deactivate");
|
2022-08-16 06:50:20 +02:00
|
|
|
$button.empty().append($("<i>").addClass(["fa", "fa-user-times"]).attr("aria-hidden", "true"));
|
2022-01-25 11:36:19 +01:00
|
|
|
$row.removeClass("deactivated_user");
|
|
|
|
|
|
|
|
if ($user_role) {
|
|
|
|
const user_id = $row.data("user-id");
|
|
|
|
$user_role.text(people.get_user_type(user_id));
|
2019-05-16 10:36:20 +02:00
|
|
|
}
|
2019-03-18 11:04:03 +01:00
|
|
|
}
|
|
|
|
|
2019-01-14 14:04:27 +01:00
|
|
|
function get_status_field() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const current_tab = settings_panel_menu.org_settings.current_tab();
|
2019-01-14 14:04:27 +01:00
|
|
|
switch (current_tab) {
|
2020-07-15 02:14:03 +02:00
|
|
|
case "deactivated-users-admin":
|
|
|
|
return $("#deactivated-user-field-status").expectOne();
|
|
|
|
case "user-list-admin":
|
|
|
|
return $("#user-field-status").expectOne();
|
|
|
|
case "bot-list-admin":
|
|
|
|
return $("#bot-field-status").expectOne();
|
|
|
|
default:
|
2020-09-24 07:56:29 +02:00
|
|
|
throw new Error("Invalid admin settings page");
|
2019-01-14 14:04:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-09 04:14:32 +02:00
|
|
|
function failed_listing_users() {
|
2020-07-15 01:29:15 +02:00
|
|
|
loading.destroy_indicator($("#subs_page_loading_indicator"));
|
2019-11-02 00:06:25 +01:00
|
|
|
const status = get_status_field();
|
2020-06-09 04:14:32 +02:00
|
|
|
const user_id = people.my_current_user_id();
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("Error while listing users for user_id " + user_id, status);
|
2017-04-08 20:08:35 +02:00
|
|
|
}
|
|
|
|
|
2020-06-09 04:14:32 +02:00
|
|
|
function populate_users() {
|
|
|
|
const active_user_ids = people.get_active_human_ids();
|
|
|
|
const deactivated_user_ids = people.get_non_active_human_ids();
|
2020-05-09 20:06:14 +02:00
|
|
|
|
2020-06-09 04:14:32 +02:00
|
|
|
if (active_user_ids.length === 0 && deactivated_user_ids.length === 0) {
|
|
|
|
failed_listing_users();
|
2020-01-16 20:12:06 +01:00
|
|
|
}
|
2017-04-08 20:08:35 +02:00
|
|
|
|
2020-06-10 03:02:34 +02:00
|
|
|
section.active.create_table(active_user_ids);
|
|
|
|
section.deactivated.create_table(deactivated_user_ids);
|
2020-05-07 15:43:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function reset_scrollbar($sel) {
|
|
|
|
return function () {
|
|
|
|
ui.reset_scrollbar($sel);
|
2017-09-26 22:16:52 +02:00
|
|
|
};
|
2020-05-07 15:43:20 +02:00
|
|
|
}
|
2017-09-26 22:16:52 +02:00
|
|
|
|
2020-05-11 00:54:00 +02:00
|
|
|
function bot_owner_full_name(owner_id) {
|
|
|
|
if (!owner_id) {
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2020-05-11 00:54:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const bot_owner = people.get_by_user_id(owner_id);
|
|
|
|
if (!bot_owner) {
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2020-05-11 00:54:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return bot_owner.full_name;
|
|
|
|
}
|
|
|
|
|
2020-05-10 12:52:27 +02:00
|
|
|
function bot_info(bot_user_id) {
|
2023-01-29 03:00:46 +01:00
|
|
|
const bot_user = people.get_by_user_id(bot_user_id);
|
2020-05-10 12:52:27 +02:00
|
|
|
|
|
|
|
if (!bot_user) {
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2020-05-10 12:52:27 +02:00
|
|
|
}
|
|
|
|
|
2023-01-29 03:00:46 +01:00
|
|
|
const owner_id = bot_user.bot_owner_id;
|
2020-05-11 00:54:00 +02:00
|
|
|
|
2020-05-08 13:46:28 +02:00
|
|
|
const info = {};
|
|
|
|
|
2020-05-08 15:21:12 +02:00
|
|
|
info.is_bot = true;
|
2023-01-29 03:00:46 +01:00
|
|
|
info.role = bot_user.role;
|
|
|
|
info.is_active = people.is_person_active(bot_user.user_id);
|
2020-05-08 15:21:12 +02:00
|
|
|
info.user_id = bot_user.user_id;
|
|
|
|
info.full_name = bot_user.full_name;
|
2020-05-11 00:54:00 +02:00
|
|
|
info.bot_owner_id = owner_id;
|
2022-03-31 08:31:45 +02:00
|
|
|
info.user_role_text = people.get_user_type(bot_user_id);
|
2020-05-08 13:46:28 +02:00
|
|
|
|
|
|
|
// Convert bot type id to string for viewing to the users.
|
2020-05-08 15:21:12 +02:00
|
|
|
info.bot_type = settings_bots.type_id_to_string(bot_user.bot_type);
|
2020-05-08 13:46:28 +02:00
|
|
|
|
2020-05-11 00:54:00 +02:00
|
|
|
info.bot_owner_full_name = bot_owner_full_name(owner_id);
|
2020-05-08 13:46:28 +02:00
|
|
|
|
2020-05-11 00:54:00 +02:00
|
|
|
if (!info.bot_owner_full_name) {
|
2020-05-08 15:21:12 +02:00
|
|
|
info.no_owner = true;
|
2021-04-13 06:51:54 +02:00
|
|
|
info.bot_owner_full_name = $t({defaultMessage: "No owner"});
|
2020-05-08 13:46:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
info.is_current_user = false;
|
|
|
|
info.can_modify = page_params.is_admin;
|
|
|
|
|
2021-11-09 19:12:33 +01:00
|
|
|
// It's always safe to show the real email addresses for bot users
|
2020-05-08 13:46:28 +02:00
|
|
|
info.display_email = bot_user.email;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2020-05-08 15:09:21 +02:00
|
|
|
function get_last_active(user) {
|
|
|
|
const last_active_date = presence.last_active_date(user.user_id);
|
|
|
|
|
|
|
|
if (!last_active_date) {
|
2021-04-13 06:51:54 +02:00
|
|
|
return $t({defaultMessage: "Unknown"});
|
2020-05-08 15:09:21 +02:00
|
|
|
}
|
|
|
|
return timerender.render_now(last_active_date).time_str;
|
|
|
|
}
|
|
|
|
|
|
|
|
function human_info(person) {
|
|
|
|
const info = {};
|
|
|
|
|
2020-05-08 15:21:12 +02:00
|
|
|
info.is_bot = false;
|
2021-04-29 15:49:01 +02:00
|
|
|
info.user_role_text = people.get_user_type(person.user_id);
|
2020-06-09 03:07:35 +02:00
|
|
|
info.is_active = people.is_person_active(person.user_id);
|
2020-05-08 15:21:12 +02:00
|
|
|
info.user_id = person.user_id;
|
|
|
|
info.full_name = person.full_name;
|
|
|
|
info.bot_owner_id = person.bot_owner_id;
|
2020-05-08 15:09:21 +02:00
|
|
|
|
|
|
|
info.can_modify = page_params.is_admin;
|
|
|
|
info.is_current_user = people.is_my_user_id(person.user_id);
|
2020-07-15 00:34:28 +02:00
|
|
|
info.cannot_deactivate = info.is_current_user || (person.is_owner && !page_params.is_owner);
|
2020-05-08 15:09:21 +02:00
|
|
|
info.display_email = settings_data.email_for_user_settings(person);
|
|
|
|
|
2020-06-09 03:07:35 +02:00
|
|
|
if (info.is_active) {
|
2020-05-08 15:09:21 +02:00
|
|
|
// TODO: We might just want to show this
|
|
|
|
// for deactivated users, too, even though
|
|
|
|
// it might usually just be undefined.
|
|
|
|
info.last_active_date = get_last_active(person);
|
|
|
|
}
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2020-05-20 00:32:34 +02:00
|
|
|
let bot_list_widget;
|
|
|
|
|
2020-05-09 20:06:14 +02:00
|
|
|
section.bots.create_table = () => {
|
2020-07-15 01:29:15 +02:00
|
|
|
loading.make_indicator($("#admin_page_bots_loading_indicator"), {text: "Loading..."});
|
2019-11-02 00:06:25 +01:00
|
|
|
const $bots_table = $("#admin_bots_table");
|
2020-05-18 22:36:37 +02:00
|
|
|
$bots_table.hide();
|
2023-01-29 03:00:46 +01:00
|
|
|
const bot_user_ids = people.get_bot_ids();
|
2020-05-09 20:06:14 +02:00
|
|
|
|
2021-01-29 10:27:56 +01:00
|
|
|
bot_list_widget = ListWidget.create($bots_table, bot_user_ids, {
|
2017-04-20 21:58:12 +02:00
|
|
|
name: "admin_bot_list",
|
2020-05-10 12:52:27 +02:00
|
|
|
get_item: bot_info,
|
|
|
|
modifier: render_admin_user_list,
|
2021-02-03 23:23:32 +01:00
|
|
|
html_selector: (item) => `tr[data-user-id='${CSS.escape(item)}']`,
|
2017-04-20 21:58:12 +02:00
|
|
|
filter: {
|
2022-01-25 11:36:19 +01:00
|
|
|
$element: $bots_table.closest(".settings-section").find(".search"),
|
2020-07-20 22:18:43 +02:00
|
|
|
predicate(item, value) {
|
2020-05-10 12:52:27 +02:00
|
|
|
if (!item) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-07-15 00:34:28 +02:00
|
|
|
return (
|
|
|
|
item.full_name.toLowerCase().includes(value) ||
|
|
|
|
item.display_email.toLowerCase().includes(value)
|
|
|
|
);
|
2017-04-20 21:58:12 +02:00
|
|
|
},
|
2019-01-09 14:30:35 +01:00
|
|
|
onupdate: reset_scrollbar($bots_table),
|
2017-04-20 21:58:12 +02:00
|
|
|
},
|
2022-01-25 11:36:19 +01:00
|
|
|
$parent_container: $("#admin-bot-list").expectOne(),
|
2020-07-15 01:29:15 +02:00
|
|
|
init_sort: ["alphabetic", "full_name"],
|
2020-04-11 16:23:29 +02:00
|
|
|
sort_fields: {
|
2020-05-10 12:52:27 +02:00
|
|
|
email: sort_bot_email,
|
2020-04-11 16:23:29 +02:00
|
|
|
bot_owner: sort_bot_owner,
|
2022-03-31 08:31:45 +02:00
|
|
|
role: sort_role,
|
2020-04-11 16:23:29 +02:00
|
|
|
},
|
2022-01-25 11:36:19 +01:00
|
|
|
$simplebar_container: $("#admin-bot-list .progressive-table-wrapper"),
|
2020-04-11 16:23:29 +02:00
|
|
|
});
|
2019-08-15 07:33:31 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
loading.destroy_indicator($("#admin_page_bots_loading_indicator"));
|
2020-05-18 22:36:37 +02:00
|
|
|
$bots_table.show();
|
2020-05-07 15:43:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
section.active.create_table = (active_users) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const $users_table = $("#admin_users_table");
|
2021-01-29 10:27:56 +01:00
|
|
|
ListWidget.create($users_table, active_users, {
|
2017-04-20 21:58:46 +02:00
|
|
|
name: "users_table_list",
|
2020-06-10 19:36:53 +02:00
|
|
|
get_item: people.get_by_user_id,
|
2020-07-20 22:18:43 +02:00
|
|
|
modifier(item) {
|
2020-05-08 15:09:21 +02:00
|
|
|
const info = human_info(item);
|
|
|
|
return render_admin_user_list(info);
|
2017-04-20 21:58:46 +02:00
|
|
|
},
|
|
|
|
filter: {
|
2022-01-25 11:36:19 +01:00
|
|
|
$element: $users_table.closest(".settings-section").find(".search"),
|
2020-01-13 17:45:53 +01:00
|
|
|
filterer: people.filter_for_user_settings_search,
|
2019-01-09 14:30:35 +01:00
|
|
|
onupdate: reset_scrollbar($users_table),
|
2017-04-20 21:58:46 +02:00
|
|
|
},
|
2022-01-25 11:36:19 +01:00
|
|
|
$parent_container: $("#admin-user-list").expectOne(),
|
2020-07-15 01:29:15 +02:00
|
|
|
init_sort: ["alphabetic", "full_name"],
|
2020-04-11 16:23:29 +02:00
|
|
|
sort_fields: {
|
2020-04-15 15:09:23 +02:00
|
|
|
email: sort_email,
|
2020-04-11 16:23:29 +02:00
|
|
|
last_active: sort_last_active,
|
2020-04-15 15:09:23 +02:00
|
|
|
role: sort_role,
|
2021-11-02 15:53:47 +01:00
|
|
|
id: sort_user_id,
|
2020-04-11 16:23:29 +02:00
|
|
|
},
|
2022-01-25 11:36:19 +01:00
|
|
|
$simplebar_container: $("#admin-user-list .progressive-table-wrapper"),
|
2020-04-11 16:23:29 +02:00
|
|
|
});
|
2019-08-16 06:02:53 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
loading.destroy_indicator($("#admin_page_users_loading_indicator"));
|
2020-05-07 15:43:20 +02:00
|
|
|
$("#admin_users_table").show();
|
|
|
|
};
|
|
|
|
|
|
|
|
section.deactivated.create_table = (deactivated_users) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const $deactivated_users_table = $("#admin_deactivated_users_table");
|
2021-01-29 10:27:56 +01:00
|
|
|
ListWidget.create($deactivated_users_table, deactivated_users, {
|
2017-04-20 21:47:14 +02:00
|
|
|
name: "deactivated_users_table_list",
|
2020-06-10 19:36:53 +02:00
|
|
|
get_item: people.get_by_user_id,
|
2020-07-20 22:18:43 +02:00
|
|
|
modifier(item) {
|
2020-05-08 15:09:21 +02:00
|
|
|
const info = human_info(item);
|
|
|
|
return render_admin_user_list(info);
|
2017-04-20 21:47:14 +02:00
|
|
|
},
|
|
|
|
filter: {
|
2022-01-25 11:36:19 +01:00
|
|
|
$element: $deactivated_users_table.closest(".settings-section").find(".search"),
|
2020-01-13 17:45:53 +01:00
|
|
|
filterer: people.filter_for_user_settings_search,
|
2019-01-09 14:30:35 +01:00
|
|
|
onupdate: reset_scrollbar($deactivated_users_table),
|
2017-04-20 21:47:14 +02:00
|
|
|
},
|
2022-01-25 11:36:19 +01:00
|
|
|
$parent_container: $("#admin-deactivated-users-list").expectOne(),
|
2020-07-15 01:29:15 +02:00
|
|
|
init_sort: ["alphabetic", "full_name"],
|
2020-04-11 16:23:29 +02:00
|
|
|
sort_fields: {
|
2020-04-15 15:09:23 +02:00
|
|
|
email: sort_email,
|
2020-04-11 16:23:29 +02:00
|
|
|
role: sort_role,
|
2021-11-02 15:53:47 +01:00
|
|
|
id: sort_user_id,
|
2020-04-11 16:23:29 +02:00
|
|
|
},
|
2022-01-25 11:36:19 +01:00
|
|
|
$simplebar_container: $("#admin-deactivated-users-list .progressive-table-wrapper"),
|
2020-04-11 16:23:29 +02:00
|
|
|
});
|
2019-08-16 06:18:41 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
loading.destroy_indicator($("#admin_page_deactivated_users_loading_indicator"));
|
2018-03-03 08:33:30 +01:00
|
|
|
$("#admin_deactivated_users_table").show();
|
2020-05-07 15:43:20 +02:00
|
|
|
};
|
2017-04-08 20:08:35 +02:00
|
|
|
|
2021-02-28 01:21:11 +01:00
|
|
|
export function update_bot_data(bot_user_id) {
|
2020-05-29 20:47:16 +02:00
|
|
|
if (!bot_list_widget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-20 00:32:34 +02:00
|
|
|
bot_list_widget.render_item(bot_user_id);
|
2021-02-28 01:21:11 +01:00
|
|
|
}
|
2020-05-20 00:32:34 +02:00
|
|
|
|
2021-02-28 01:21:11 +01:00
|
|
|
export function update_user_data(user_id, new_data) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $user_row = get_user_info_row(user_id);
|
2020-05-09 20:20:26 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
if ($user_row.length === 0) {
|
2020-05-11 12:42:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_data.full_name !== undefined) {
|
|
|
|
// Update the full name in the table
|
2022-01-25 11:36:19 +01:00
|
|
|
$user_row.find(".user_name").text(new_data.full_name);
|
2020-05-11 12:42:36 +02:00
|
|
|
}
|
|
|
|
|
2020-05-30 21:43:19 +02:00
|
|
|
if (new_data.role !== undefined) {
|
2022-01-25 11:36:19 +01:00
|
|
|
$user_row.find(".user_role").text(people.get_user_type(user_id));
|
2020-05-11 12:42:36 +02:00
|
|
|
}
|
2021-02-28 01:21:11 +01:00
|
|
|
}
|
2020-05-11 12:42:36 +02:00
|
|
|
|
2022-03-19 09:34:42 +01:00
|
|
|
export function redraw_bots_list() {
|
|
|
|
if (!bot_list_widget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-22 21:25:45 +02:00
|
|
|
// In order to properly redraw after a user may have been added,
|
|
|
|
// we need to update the bot_list_widget with the new set of bot
|
|
|
|
// user IDs to display.
|
2023-01-29 03:00:46 +01:00
|
|
|
const bot_user_ids = people.get_bot_ids();
|
2022-09-22 21:25:45 +02:00
|
|
|
bot_list_widget.replace_list_data(bot_user_ids);
|
2022-03-19 09:34:42 +01:00
|
|
|
bot_list_widget.hard_redraw();
|
|
|
|
}
|
|
|
|
|
2020-05-07 20:19:00 +02:00
|
|
|
function start_data_load() {
|
2020-07-15 01:29:15 +02:00
|
|
|
loading.make_indicator($("#admin_page_users_loading_indicator"), {text: "Loading..."});
|
2020-07-15 00:34:28 +02:00
|
|
|
loading.make_indicator($("#admin_page_deactivated_users_loading_indicator"), {
|
|
|
|
text: "Loading...",
|
|
|
|
});
|
2018-03-03 08:33:30 +01:00
|
|
|
$("#admin_deactivated_users_table").hide();
|
|
|
|
$("#admin_users_table").hide();
|
2017-04-08 20:08:35 +02:00
|
|
|
|
2020-06-09 04:14:32 +02:00
|
|
|
populate_users();
|
2020-05-07 20:19:00 +02:00
|
|
|
}
|
2017-04-08 20:08:35 +02:00
|
|
|
|
2020-05-09 14:40:22 +02:00
|
|
|
function get_human_profile_data(fields_user_pills) {
|
|
|
|
/*
|
|
|
|
This formats custom profile field data to send to the server.
|
|
|
|
See render_admin_human_form and open_human_form
|
|
|
|
to see how the form is built.
|
|
|
|
|
|
|
|
TODO: Ideally, this logic would be cleaned up or deduplicated with
|
|
|
|
the settings_account.js logic.
|
|
|
|
*/
|
|
|
|
const new_profile_data = [];
|
2021-06-28 13:48:38 +02:00
|
|
|
$("#edit-user-form .custom_user_field_value").each(function () {
|
2022-02-08 00:13:33 +01:00
|
|
|
// Remove duplicate datepicker input element generated flatpickr library
|
2020-05-09 14:40:22 +02:00
|
|
|
if (!$(this).hasClass("form-control")) {
|
|
|
|
new_profile_data.push({
|
2020-10-07 09:17:30 +02:00
|
|
|
id: Number.parseInt(
|
|
|
|
$(this).closest(".custom_user_field").attr("data-field-id"),
|
|
|
|
10,
|
|
|
|
),
|
2020-05-09 14:40:22 +02:00
|
|
|
value: $(this).val(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// Append user type field values also
|
2020-07-16 23:29:01 +02:00
|
|
|
for (const [field_id, field_pills] of fields_user_pills) {
|
2020-05-09 14:40:22 +02:00
|
|
|
if (field_pills) {
|
|
|
|
const user_ids = user_pill.get_user_ids(field_pills);
|
|
|
|
new_profile_data.push({
|
|
|
|
id: field_id,
|
|
|
|
value: user_ids,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_profile_data;
|
|
|
|
}
|
|
|
|
|
2021-11-29 14:20:23 +01:00
|
|
|
export function confirm_deactivation(user_id, handle_confirm, loading_spinner) {
|
2022-04-14 09:15:06 +02:00
|
|
|
// Knowing the number of invites requires making this request. If the request fails,
|
|
|
|
// we won't have the accurate number of invites. So, we don't show the modal if the
|
|
|
|
// request fails.
|
|
|
|
channel.get({
|
|
|
|
url: "/json/invites",
|
|
|
|
timeout: 10 * 1000,
|
|
|
|
success(data) {
|
|
|
|
let number_of_invites_by_user = 0;
|
|
|
|
for (const invite of data.invites) {
|
|
|
|
if (invite.invited_by_user_id === user_id) {
|
|
|
|
number_of_invites_by_user = number_of_invites_by_user + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const bots_owned_by_user = bot_data.get_all_bots_owned_by_user(user_id);
|
|
|
|
const user = people.get_by_user_id(user_id);
|
2021-11-27 15:26:09 +01:00
|
|
|
const realm_uri = page_params.realm_uri;
|
|
|
|
const realm_name = page_params.realm_name;
|
2022-04-14 09:15:06 +02:00
|
|
|
const opts = {
|
|
|
|
username: user.full_name,
|
|
|
|
email: settings_data.email_for_user_settings(user),
|
|
|
|
bots_owned_by_user,
|
|
|
|
number_of_invites_by_user,
|
2021-11-27 15:26:09 +01:00
|
|
|
admin_email: people.my_current_email(),
|
|
|
|
realm_uri,
|
|
|
|
realm_name,
|
2022-04-14 09:15:06 +02:00
|
|
|
};
|
|
|
|
const html_body = render_settings_deactivation_user_modal(opts);
|
|
|
|
|
2022-07-26 21:16:08 +02:00
|
|
|
dialog_widget.launch({
|
2022-04-14 09:15:06 +02:00
|
|
|
html_heading: $t_html(
|
2022-07-26 20:52:40 +02:00
|
|
|
{defaultMessage: "Deactivate {name}?"},
|
2022-04-14 09:15:06 +02:00
|
|
|
{name: user.full_name},
|
|
|
|
),
|
2022-09-01 23:31:35 +02:00
|
|
|
help_link: "/help/deactivate-or-reactivate-a-user#deactivating-a-user",
|
2022-04-14 09:15:06 +02:00
|
|
|
html_body,
|
2022-07-26 21:16:08 +02:00
|
|
|
html_submit_button: $t_html({defaultMessage: "Deactivate"}),
|
2022-04-14 09:15:06 +02:00
|
|
|
id: "deactivate-user-modal",
|
|
|
|
on_click: handle_confirm,
|
|
|
|
loading_spinner,
|
|
|
|
});
|
|
|
|
},
|
2021-05-26 13:30:27 +02:00
|
|
|
});
|
2020-05-08 21:10:43 +02:00
|
|
|
}
|
|
|
|
|
2022-03-22 16:03:22 +01:00
|
|
|
function handle_deactivation($tbody) {
|
2022-01-25 11:36:19 +01:00
|
|
|
$tbody.on("click", ".deactivate", (e) => {
|
2020-05-08 21:10:43 +02:00
|
|
|
// This click event must not get propagated to parent container otherwise the modal
|
|
|
|
// will not show up because of a call to `close_active_modal` in `settings.js`.
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $row = $(e.target).closest(".user_row");
|
|
|
|
const user_id = $row.data("user-id");
|
2021-11-29 13:11:56 +01:00
|
|
|
|
|
|
|
function handle_confirm() {
|
|
|
|
const url = "/json/users/" + encodeURIComponent(user_id);
|
2021-11-27 15:26:09 +01:00
|
|
|
let data = {};
|
|
|
|
if ($(".send_email").is(":checked")) {
|
|
|
|
data = {
|
|
|
|
deactivation_notification_comment: $(".email_field_textarea").val(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-09-01 23:29:09 +02:00
|
|
|
dialog_widget.submit_api_request(channel.del, url, data);
|
2021-11-29 13:11:56 +01:00
|
|
|
}
|
|
|
|
|
2022-03-22 16:03:22 +01:00
|
|
|
confirm_deactivation(user_id, handle_confirm, true);
|
2017-04-08 20:08:35 +02:00
|
|
|
});
|
2020-05-07 16:34:49 +02:00
|
|
|
}
|
2017-04-08 20:08:35 +02:00
|
|
|
|
2022-04-20 15:12:47 +02:00
|
|
|
function handle_bot_deactivation($tbody) {
|
2022-01-25 11:36:19 +01:00
|
|
|
$tbody.on("click", ".deactivate", (e) => {
|
2017-04-08 20:08:35 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $button_elem = $(e.target);
|
|
|
|
const $row = $button_elem.closest(".user_row");
|
|
|
|
const bot_id = Number.parseInt($row.attr("data-user-id"), 10);
|
2019-03-18 12:05:52 +01:00
|
|
|
|
2022-04-20 15:12:47 +02:00
|
|
|
function handle_confirm() {
|
|
|
|
const url = "/json/bots/" + encodeURIComponent(bot_id);
|
|
|
|
dialog_widget.submit_api_request(channel.del, url);
|
|
|
|
}
|
|
|
|
|
2022-07-24 11:41:58 +02:00
|
|
|
settings_bots.confirm_bot_deactivation(bot_id, handle_confirm, true);
|
2017-04-08 20:08:35 +02:00
|
|
|
});
|
2020-05-07 16:34:49 +02:00
|
|
|
}
|
2017-04-08 20:08:35 +02:00
|
|
|
|
2022-03-18 13:03:26 +01:00
|
|
|
export function confirm_reactivation(user_id, handle_confirm, loading_spinner) {
|
|
|
|
const user = people.get_by_user_id(user_id);
|
|
|
|
const opts = {
|
|
|
|
username: user.full_name,
|
|
|
|
};
|
2022-10-25 22:24:26 +02:00
|
|
|
|
|
|
|
let html_body;
|
|
|
|
// check if bot or human
|
|
|
|
if (user.is_bot) {
|
|
|
|
html_body = render_settings_reactivation_bot_modal(opts);
|
|
|
|
} else {
|
|
|
|
html_body = render_settings_reactivation_user_modal(opts);
|
|
|
|
}
|
2022-03-18 13:03:26 +01:00
|
|
|
|
|
|
|
confirm_dialog.launch({
|
|
|
|
html_heading: $t_html({defaultMessage: "Reactivate {name}"}, {name: user.full_name}),
|
2022-09-01 23:31:35 +02:00
|
|
|
help_link: "/help/deactivate-or-reactivate-a-user#reactivating-a-user",
|
2022-03-18 13:03:26 +01:00
|
|
|
html_body,
|
|
|
|
on_click: handle_confirm,
|
|
|
|
loading_spinner,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-20 12:45:39 +01:00
|
|
|
function handle_reactivation($tbody) {
|
2022-01-25 11:36:19 +01:00
|
|
|
$tbody.on("click", ".reactivate", (e) => {
|
2017-04-08 20:08:35 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
// Go up the tree until we find the user row, then grab the email element
|
2022-01-25 11:36:19 +01:00
|
|
|
const $button_elem = $(e.target);
|
|
|
|
const $row = $button_elem.closest(".user_row");
|
|
|
|
const user_id = Number.parseInt($row.attr("data-user-id"), 10);
|
2019-11-02 00:06:25 +01:00
|
|
|
|
2022-03-20 12:45:39 +01:00
|
|
|
function handle_confirm() {
|
|
|
|
const $row = get_user_info_row(user_id);
|
|
|
|
const url = "/json/users/" + encodeURIComponent(user_id) + "/reactivate";
|
2022-04-28 17:52:03 +02:00
|
|
|
const opts = {
|
|
|
|
success_continuation() {
|
2022-03-20 12:45:39 +01:00
|
|
|
update_view_on_reactivate($row);
|
|
|
|
},
|
2022-04-28 17:52:03 +02:00
|
|
|
};
|
|
|
|
dialog_widget.submit_api_request(channel.post, url, {}, opts);
|
2022-03-20 12:45:39 +01:00
|
|
|
}
|
2019-03-18 12:05:52 +01:00
|
|
|
|
2022-03-20 12:45:39 +01:00
|
|
|
confirm_reactivation(user_id, handle_confirm, true);
|
2017-04-08 20:08:35 +02:00
|
|
|
});
|
2020-05-07 16:34:49 +02:00
|
|
|
}
|
2017-04-08 20:08:35 +02:00
|
|
|
|
2022-04-28 17:52:03 +02:00
|
|
|
export function show_edit_user_info_modal(user_id, from_user_info_popover) {
|
2021-11-26 12:45:14 +01:00
|
|
|
const person = people.get_by_user_id(user_id);
|
2018-07-30 09:22:57 +02:00
|
|
|
|
2021-11-26 12:45:14 +01:00
|
|
|
if (!person) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-30 09:22:57 +02:00
|
|
|
|
2022-03-01 09:00:14 +01:00
|
|
|
const user_email = settings_data.email_for_user_settings(person);
|
2021-11-26 12:45:14 +01:00
|
|
|
|
|
|
|
const html_body = render_admin_human_form({
|
|
|
|
user_id,
|
|
|
|
email: user_email,
|
|
|
|
full_name: person.full_name,
|
|
|
|
user_role_values: settings_config.user_role_values,
|
|
|
|
disable_role_dropdown: person.is_owner && !page_params.is_owner,
|
|
|
|
});
|
|
|
|
|
|
|
|
let fields_user_pills;
|
|
|
|
|
|
|
|
function set_role_dropdown_and_fields_user_pills() {
|
|
|
|
$("#user-role-select").val(person.role);
|
|
|
|
if (!page_params.is_owner) {
|
|
|
|
$("#user-role-select")
|
|
|
|
.find(`option[value="${CSS.escape(settings_config.user_role_values.owner.code)}"]`)
|
|
|
|
.hide();
|
2021-07-12 11:37:22 +02:00
|
|
|
}
|
|
|
|
|
2021-11-26 12:45:14 +01:00
|
|
|
const element = "#edit-user-form .custom-profile-field-form";
|
2022-08-18 00:30:47 +02:00
|
|
|
$(element).empty();
|
2021-11-26 12:45:14 +01:00
|
|
|
settings_account.append_custom_profile_fields(element, user_id);
|
|
|
|
settings_account.initialize_custom_date_type_fields(element);
|
|
|
|
fields_user_pills = settings_account.initialize_custom_user_type_fields(
|
|
|
|
element,
|
2021-06-09 19:43:01 +02:00
|
|
|
user_id,
|
2021-11-26 12:45:14 +01:00
|
|
|
true,
|
|
|
|
false,
|
|
|
|
);
|
2022-10-03 20:05:09 +02:00
|
|
|
settings_account.initialize_custom_pronouns_type_fields(element);
|
2021-11-29 14:20:23 +01:00
|
|
|
|
|
|
|
$("#edit-user-form").on("click", ".deactivate_user_button", (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
const user_id = $("#edit-user-form").data("user-id");
|
|
|
|
function handle_confirm() {
|
|
|
|
const url = "/json/users/" + encodeURIComponent(user_id);
|
2022-04-28 17:52:03 +02:00
|
|
|
dialog_widget.submit_api_request(channel.del, url);
|
2021-11-29 14:20:23 +01:00
|
|
|
}
|
|
|
|
const open_deactivate_modal_callback = () =>
|
|
|
|
confirm_deactivation(user_id, handle_confirm, true);
|
|
|
|
dialog_widget.close_modal(open_deactivate_modal_callback);
|
|
|
|
});
|
2021-11-26 12:45:14 +01:00
|
|
|
}
|
2017-04-08 20:08:35 +02:00
|
|
|
|
2021-11-26 12:45:14 +01:00
|
|
|
function submit_user_details() {
|
|
|
|
const role = Number.parseInt($("#user-role-select").val().trim(), 10);
|
2022-01-25 11:36:19 +01:00
|
|
|
const $full_name = $("#edit-user-form").find("input[name='full_name']");
|
2021-11-26 12:45:14 +01:00
|
|
|
const profile_data = get_human_profile_data(fields_user_pills);
|
user settings: Separate code for bot form.
When editing a bot, there are only two fields
that are similar to humans--full name and
email--which are trivial.
Before this commit we used a single codepath
to build the human form and the bot form.
Now we have two simple codepaths.
The tricky nature of the code had already led
to ugly things for the bot codepath that
fortunately weren't user facing, but which
were distracting:
- For bots we would needlessly set things
like is_admin, is_guest in the template
data.
- For bots we would needlessly try to update
custom profile fields.
The code that differs between bots and humans
is nontrivial, and the code was both hard to read
and hard to improve:
- Humans don't have bot owners.
- Bots don't have custom profile fields.
The bot-owner code is nontrivial for performance
reasons. In a big realm there are tens of thousands
of potential bot owners. We avoid the most egregious
performance problems (i.e we don't have multiple
copies of the dropdown), but we may still want
to refine that (at least adding a spinner).
The custom-profile-fields code is nontrivial due
to the dynamic nature of custom profile fields,
which can bring in specialized widgets like
pill fields.
Now each form corresponds to a single endpoint:
* human -> /json/users
* bot -> /json/bots
Before we had a lot of conditional logic in
the template, the code to build to views, and
the code to submit the data. Now everything is
much flatter.
The human code is still a bit messy (more work
coming on that), but the bot code is fairly
pristine. All three components of the bot code
fit on a page, and there are no conditionals:
- admin_bot_form.hbs
- open_bot_form
- handle_bot_form
We may want to grow out the bot code a bit
to allow admins to do more things, such as
adding services, and this will be easier now.
It would also be easier for us now to share
widgets with the per-user bot settings.
Note that the form for editing human data will
continue to be invoked from two panels:
- Users
- Deactivated users
There are some minor differences between
users and deactivated users, but the shape of
the data is the same for both, so that's still
all one codepath.
We eliminate `reset_edit_user` here, since
it was never used.
One nice thing about these forms was that they
had very little custom CSS attached to them
(at form-level specificity), and it turned out
all the custom CSS was for the human-specific
form.
2020-05-09 12:13:03 +02:00
|
|
|
|
2021-11-26 12:45:14 +01:00
|
|
|
const url = "/json/users/" + encodeURIComponent(user_id);
|
|
|
|
const data = {
|
2022-01-25 11:36:19 +01:00
|
|
|
full_name: $full_name.val(),
|
2021-11-26 12:45:14 +01:00
|
|
|
role: JSON.stringify(role),
|
|
|
|
profile_data: JSON.stringify(profile_data),
|
|
|
|
};
|
2022-04-20 19:48:14 +02:00
|
|
|
const opts = {
|
|
|
|
error_continuation() {
|
|
|
|
// Scrolling modal to top, to make error visible to user.
|
|
|
|
$("#edit-user-form")
|
|
|
|
.closest(".simplebar-content-wrapper")
|
|
|
|
.animate({scrollTop: 0}, "fast");
|
|
|
|
},
|
|
|
|
};
|
|
|
|
dialog_widget.submit_api_request(channel.patch, url, data, opts);
|
2021-11-26 12:45:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
dialog_widget.launch({
|
|
|
|
html_heading: $t_html({defaultMessage: "Manage user"}),
|
|
|
|
html_body,
|
|
|
|
on_click: submit_user_details,
|
|
|
|
post_render: set_role_dropdown_and_fields_user_pills,
|
2021-11-26 13:46:11 +01:00
|
|
|
loading_spinner: from_user_info_popover,
|
2021-11-26 12:45:14 +01:00
|
|
|
});
|
|
|
|
}
|
2021-06-09 19:43:01 +02:00
|
|
|
|
2022-04-28 17:52:03 +02:00
|
|
|
function handle_human_form($tbody) {
|
2022-01-25 11:36:19 +01:00
|
|
|
$tbody.on("click", ".open-user-form", (e) => {
|
2021-11-26 12:45:14 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
const user_id = Number.parseInt($(e.currentTarget).attr("data-user-id"), 10);
|
2022-04-28 17:52:03 +02:00
|
|
|
show_edit_user_info_modal(user_id, false);
|
user settings: Separate code for bot form.
When editing a bot, there are only two fields
that are similar to humans--full name and
email--which are trivial.
Before this commit we used a single codepath
to build the human form and the bot form.
Now we have two simple codepaths.
The tricky nature of the code had already led
to ugly things for the bot codepath that
fortunately weren't user facing, but which
were distracting:
- For bots we would needlessly set things
like is_admin, is_guest in the template
data.
- For bots we would needlessly try to update
custom profile fields.
The code that differs between bots and humans
is nontrivial, and the code was both hard to read
and hard to improve:
- Humans don't have bot owners.
- Bots don't have custom profile fields.
The bot-owner code is nontrivial for performance
reasons. In a big realm there are tens of thousands
of potential bot owners. We avoid the most egregious
performance problems (i.e we don't have multiple
copies of the dropdown), but we may still want
to refine that (at least adding a spinner).
The custom-profile-fields code is nontrivial due
to the dynamic nature of custom profile fields,
which can bring in specialized widgets like
pill fields.
Now each form corresponds to a single endpoint:
* human -> /json/users
* bot -> /json/bots
Before we had a lot of conditional logic in
the template, the code to build to views, and
the code to submit the data. Now everything is
much flatter.
The human code is still a bit messy (more work
coming on that), but the bot code is fairly
pristine. All three components of the bot code
fit on a page, and there are no conditionals:
- admin_bot_form.hbs
- open_bot_form
- handle_bot_form
We may want to grow out the bot code a bit
to allow admins to do more things, such as
adding services, and this will be easier now.
It would also be easier for us now to share
widgets with the per-user bot settings.
Note that the form for editing human data will
continue to be invoked from two panels:
- Users
- Deactivated users
There are some minor differences between
users and deactivated users, but the shape of
the data is the same for both, so that's still
all one codepath.
We eliminate `reset_edit_user` here, since
it was never used.
One nice thing about these forms was that they
had very little custom CSS attached to them
(at form-level specificity), and it turned out
all the custom CSS was for the human-specific
form.
2020-05-09 12:13:03 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-07-22 20:42:08 +02:00
|
|
|
function handle_bot_form($tbody) {
|
|
|
|
$tbody.on("click", ".open-user-form", (e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
const user_id = Number.parseInt($(e.currentTarget).attr("data-user-id"), 10);
|
2022-07-08 19:10:15 +02:00
|
|
|
settings_bots.show_edit_bot_info_modal(user_id, false);
|
2017-04-08 20:08:35 +02:00
|
|
|
});
|
2020-05-07 16:34:49 +02:00
|
|
|
}
|
|
|
|
|
2020-05-07 20:19:00 +02:00
|
|
|
section.active.handle_events = () => {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $tbody = $("#admin_users_table").expectOne();
|
2020-05-07 23:07:34 +02:00
|
|
|
|
2022-03-22 16:03:22 +01:00
|
|
|
handle_deactivation($tbody);
|
2022-03-20 12:45:39 +01:00
|
|
|
handle_reactivation($tbody);
|
2022-04-28 17:52:03 +02:00
|
|
|
handle_human_form($tbody);
|
2020-05-07 20:19:00 +02:00
|
|
|
};
|
2017-04-08 20:08:35 +02:00
|
|
|
|
2020-05-07 20:19:00 +02:00
|
|
|
section.deactivated.handle_events = () => {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $tbody = $("#admin_deactivated_users_table").expectOne();
|
2020-05-07 23:07:34 +02:00
|
|
|
|
2022-03-22 16:03:22 +01:00
|
|
|
handle_deactivation($tbody);
|
2022-03-20 12:45:39 +01:00
|
|
|
handle_reactivation($tbody);
|
2022-04-28 17:52:03 +02:00
|
|
|
handle_human_form($tbody);
|
2020-05-07 20:19:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
section.bots.handle_events = () => {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $tbody = $("#admin_bots_table").expectOne();
|
2020-05-07 23:07:34 +02:00
|
|
|
|
2022-04-20 15:12:47 +02:00
|
|
|
handle_bot_deactivation($tbody);
|
2022-03-20 12:45:39 +01:00
|
|
|
handle_reactivation($tbody);
|
2022-04-20 19:48:14 +02:00
|
|
|
handle_bot_form($tbody);
|
2020-05-07 20:19:00 +02:00
|
|
|
};
|
|
|
|
|
2021-02-28 01:21:11 +01:00
|
|
|
export function set_up_humans() {
|
2020-05-07 20:19:00 +02:00
|
|
|
start_data_load();
|
|
|
|
section.active.handle_events();
|
|
|
|
section.deactivated.handle_events();
|
2021-02-28 01:21:11 +01:00
|
|
|
}
|
2020-05-09 20:06:14 +02:00
|
|
|
|
2021-02-28 01:21:11 +01:00
|
|
|
export function set_up_bots() {
|
2020-05-07 20:19:00 +02:00
|
|
|
section.bots.handle_events();
|
2020-05-09 20:06:14 +02:00
|
|
|
section.bots.create_table();
|
2022-09-16 12:40:13 +02:00
|
|
|
|
|
|
|
$("#admin-bot-list .add-a-new-bot").on("click", (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
settings_bots.add_a_new_bot();
|
|
|
|
});
|
2021-02-28 01:21:11 +01:00
|
|
|
}
|