Skip to content

Commit

Permalink
users_list: Fix updating of users list on reactivate/deactivate.
Browse files Browse the repository at this point in the history
User is added to deactivated users list when user is deactivated from
active users list and it remains in the active users for re-toggle
(in case of mistake) and same happens for reactivating users from
deactivated users list.

Whenever user enters any of the list from somehwhere else, list is
up-to-date.

Fixes #14165
  • Loading branch information
sahil839 committed Mar 26, 2020
1 parent eb29423 commit 02eff01
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
4 changes: 4 additions & 0 deletions static/js/settings_sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ exports.load_settings_section = function (section) {
loaded_groups.add(group);
};

exports.reset_users_section = function () {
loaded_groups.delete('org_users');
};

exports.reset_sections = function () {
loaded_groups.clear();
settings_emoji.reset();
Expand Down
53 changes: 30 additions & 23 deletions static/js/settings_users.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ const render_user_info_form_modal = require('../templates/user_info_form_modal.h

const meta = {
loaded: false,
click_handlers_registered: false,
};

exports.reset = function () {
meta.loaded = false;
meta.click_handlers_registered = false;
};

function compare_a_b(a, b) {
Expand All @@ -24,6 +26,20 @@ function get_user_info_row(user_id) {
return $("tr.user_row[data-user-id='" + user_id + "']");
}

const LAST_ACTIVE_NEVER = -1;
const LAST_ACTIVE_UNKNOWN = -2;

function get_last_active(user) {
const presence_info = presence.presence_info.get(user.user_id);
if (!presence_info) {
return LAST_ACTIVE_UNKNOWN;
}
if (!isNaN(presence_info.last_active)) {
return presence_info.last_active;
}
return LAST_ACTIVE_NEVER;
}

function update_view_on_deactivate(row) {
const button = row.find("button.deactivate");
const user_role = row.find(".user_role");
Expand Down Expand Up @@ -111,20 +127,6 @@ function failed_listing_users(xhr) {
ui_report.error(i18n.t("Error listing users or bots"), xhr, status);
}

const LAST_ACTIVE_NEVER = -1;
const LAST_ACTIVE_UNKNOWN = -2;

function get_last_active(user) {
const presence_info = presence.presence_info.get(user.user_id);
if (!presence_info) {
return LAST_ACTIVE_UNKNOWN;
}
if (!isNaN(presence_info.last_active)) {
return presence_info.last_active;
}
return LAST_ACTIVE_NEVER;
}

function populate_users(realm_people_data) {
let active_users = [];
let deactivated_users = [];
Expand Down Expand Up @@ -317,13 +319,8 @@ function open_user_info_form_modal(person) {
return user_info_form_modal;
}

exports.on_load_success = function (realm_people_data) {
meta.loaded = true;

populate_users(realm_people_data);

exports.register_click_handlers = function () {
const modal_elem = $("#deactivation_user_modal").expectOne();

$(".admin_user_table").on("click", ".deactivate", function (e) {
// 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`.
Expand All @@ -342,7 +339,6 @@ exports.on_load_success = function (realm_people_data) {
modal_elem.find('.do_deactivate_button').click(function () {
const user_id = modal_elem.data('user-id');
const row = get_user_info_row(user_id);

modal_elem.modal("hide");
const row_deactivate_button = row.find("button.deactivate");
row_deactivate_button.prop("disabled", true).text(i18n.t("Working…"));
Expand All @@ -357,13 +353,13 @@ exports.on_load_success = function (realm_people_data) {
const status = get_status_field();
const url = '/json/users/' + encodeURIComponent(user_id);
settings_ui.do_settings_change(channel.del, url, {}, status, opts);
settings_sections.reset_users_section();

});

$(".admin_bot_table").on("click", ".deactivate", function (e) {
e.preventDefault();
e.stopPropagation();

const button_elem = $(e.target);
const row = button_elem.closest(".user_row");
const bot_id = parseInt(row.attr("data-user-id"), 10);
Expand Down Expand Up @@ -392,7 +388,6 @@ exports.on_load_success = function (realm_people_data) {
const url = '/json/users/' + encodeURIComponent(user_id) + "/reactivate";
const data = {};
const status = get_status_field();

const opts = {
success_continuation: function () {
update_view_on_reactivate(row);
Expand All @@ -403,6 +398,7 @@ exports.on_load_success = function (realm_people_data) {
};

settings_ui.do_settings_change(channel.post, url, data, status, opts);
settings_sections.reset_users_section();
});

$('.admin_bot_table').on('click', '.user_row .view_user_profile', function (e) {
Expand Down Expand Up @@ -485,6 +481,17 @@ exports.on_load_success = function (realm_people_data) {
overlays.close_modal('user-info-form-modal');
});
});
};

exports.on_load_success = function (realm_people_data) {
meta.loaded = true;

populate_users(realm_people_data);

if (!meta.click_handlers_registered) {
exports.register_click_handlers();
meta.click_handlers_registered = true;
}

};

Expand Down

0 comments on commit 02eff01

Please sign in to comment.