settings_users: Show all bots in organization settings.

We intended to show all the bots in the bots organization settings for
non-admin users as well. This switches from bot_data.all_user_ids() to
people.get_bot_ids() to get a full set of ids for all the bots in the
organization.

Because the source of data changes, "realm_user" instead of "realm_bot"
triggers the update of the bots list.

The code example (example4) is updated since we incorporate a side
effect into "realm_user"'s "add" op.

Note that while "realm_user" does not have a "delete" op, we still stop
redrawing bots on "relam_bot"'s "delete" op, because "delete" was only
triggered when the bot owner changes, the bot does not disappear from
the list of all bots.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
Zixuan James Li
2023-01-28 21:00:46 -05:00
committed by Tim Abbott
parent 5ecd0cecf4
commit b21f533af3
4 changed files with 30 additions and 32 deletions

View File

@@ -177,19 +177,19 @@ function bot_owner_full_name(owner_id) {
}
function bot_info(bot_user_id) {
const bot_user = bot_data.get(bot_user_id);
const bot_user = people.get_by_user_id(bot_user_id);
if (!bot_user) {
return undefined;
}
const owner_id = bot_user.owner_id;
const owner_id = bot_user.bot_owner_id;
const info = {};
info.is_bot = true;
info.role = people.get_by_user_id(bot_user_id).role;
info.is_active = bot_user.is_active;
info.role = bot_user.role;
info.is_active = people.is_person_active(bot_user.user_id);
info.user_id = bot_user.user_id;
info.full_name = bot_user.full_name;
info.bot_owner_id = owner_id;
@@ -254,7 +254,7 @@ section.bots.create_table = () => {
loading.make_indicator($("#admin_page_bots_loading_indicator"), {text: "Loading..."});
const $bots_table = $("#admin_bots_table");
$bots_table.hide();
const bot_user_ids = bot_data.all_user_ids();
const bot_user_ids = people.get_bot_ids();
bot_list_widget = ListWidget.create($bots_table, bot_user_ids, {
name: "admin_bot_list",
@@ -378,7 +378,7 @@ export function redraw_bots_list() {
// 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.
const bot_user_ids = bot_data.all_user_ids();
const bot_user_ids = people.get_bot_ids();
bot_list_widget.replace_list_data(bot_user_ids);
bot_list_widget.hard_redraw();
}