Skip to content

Commit

Permalink
settings: Add synchronization in deactivating users.
Browse files Browse the repository at this point in the history
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 zulip#29891
  • Loading branch information
roanster007 committed May 2, 2024
1 parent da675cb commit a92106e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions web/src/settings_users.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export function update_view_on_deactivate(user_id) {
$button.empty().append($("<i>").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) {
Expand Down Expand Up @@ -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…"}),
Expand Down
3 changes: 3 additions & 0 deletions web/src/user_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions web/tests/user_events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

0 comments on commit a92106e

Please sign in to comment.