From a92106e3eaaba9155654bf2319b75848bd1d2ef5 Mon Sep 17 00:00:00 2001 From: roanster007 Date: Thu, 2 May 2024 22:33:36 +0530 Subject: [PATCH] settings: Add synchronization in deactivating users. Previously, when a user is activated or deactivated through the "Organization Settings", the corresponding tables of deactivated or activated users are not updated until the modal is re rendered. This is fixed by updating the table with new entries every time a new event to either activate or deactivate the user is received. Fixes #29891 --- web/src/settings_users.js | 24 ++++++++++++++++++++++++ web/src/user_events.js | 3 +++ web/tests/user_events.test.js | 1 + 3 files changed, 28 insertions(+) diff --git a/web/src/settings_users.js b/web/src/settings_users.js index 534a925cdcd9ac..b08eb5d29584fe 100644 --- a/web/src/settings_users.js +++ b/web/src/settings_users.js @@ -95,6 +95,10 @@ export function update_view_on_deactivate(user_id) { $button.empty().append($("").addClass(["fa", "fa-user-plus"]).attr("aria-hidden", "true")); $row.removeClass("reactivated_user"); $row.addClass("deactivated_user"); + + if (!people.is_valid_bot_user(user_id)) { + redraw_non_active_users_list(); + } } function update_view_on_reactivate($row) { @@ -420,6 +424,26 @@ export function redraw_bots_list() { bot_list_widget.hard_redraw(); } +export function redraw_active_users_list() { + if (!section.active.list_widget) { + return; + } + + const active_user_ids = people.get_active_user_ids(); + section.active.list_widget.replace_list_data(active_user_ids); + section.active.list_widget.hard_redraw(); +} + +function redraw_non_active_users_list() { + if (!section.deactivated.list_widget) { + return; + } + + const non_active_user_ids = people.get_non_active_human_ids(); + section.deactivated.list_widget.replace_list_data(non_active_user_ids); + section.deactivated.list_widget.hard_redraw(); +} + function start_data_load() { loading.make_indicator($("#admin_page_users_loading_indicator"), { text: $t({defaultMessage: "Loading…"}), diff --git a/web/src/user_events.js b/web/src/user_events.js index 77644024b6a5ce..87094251615c5e 100644 --- a/web/src/user_events.js +++ b/web/src/user_events.js @@ -169,6 +169,9 @@ export const update_person = function update(person) { if (Object.hasOwn(person, "is_active")) { if (person.is_active) { people.add_active_user(person_obj); + if (!people.is_valid_bot_user(person.user_id)) { + settings_users.redraw_active_users_list(); + } } else { people.deactivate(person_obj); stream_events.remove_deactivated_user_from_all_streams(person.user_id); diff --git a/web/tests/user_events.test.js b/web/tests/user_events.test.js index 76425d736fc67a..52c6e0c4c701aa 100644 --- a/web/tests/user_events.test.js +++ b/web/tests/user_events.test.js @@ -271,6 +271,7 @@ run_test("updates", ({override}) => { assert.ok(!people.is_person_active(isaac.user_id)); assert.ok(user_removed_from_streams); + override(settings_users, "redraw_active_users_list", noop); user_events.update_person({user_id: isaac.user_id, is_active: true}); assert.ok(people.is_person_active(isaac.user_id));