mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 00:46:03 +00:00
Add the ability to unsubscribe all users from a stream
This resolves Trac #2022 (imported from commit 23d5129a6bec40c33eaf71953cd41ec387646a39)
This commit is contained in:
@@ -2,6 +2,15 @@ var admin = (function () {
|
||||
|
||||
var exports = {};
|
||||
|
||||
function failed_listing_users(xhr, error) {
|
||||
util.destroy_loading_indicator($('#subs_page_loading_indicator'));
|
||||
ui.report_error("Error listing users or bots", xhr, $("#administration-status"));
|
||||
}
|
||||
|
||||
function failed_listing_streams(xhr, error) {
|
||||
ui.report_error("Error listing streams", xhr, $("#administration-status"));
|
||||
}
|
||||
|
||||
function populate_users (realm_people_data) {
|
||||
var users_table = $("#admin_users_table");
|
||||
var deactivated_users_table = $("#admin_deactivated_users_table");
|
||||
@@ -37,22 +46,47 @@ function populate_users (realm_people_data) {
|
||||
_.each(deactivated_users, function (user) {
|
||||
deactivated_users_table.append(templates.render("admin_user_list", {user: user}));
|
||||
});
|
||||
util.destroy_loading_indicator($('#admin_page_users_loading_indicator'));
|
||||
util.destroy_loading_indicator($('#admin_page_bots_loading_indicator'));
|
||||
util.destroy_loading_indicator($('#admin_page_deactivated_users_loading_indicator'));
|
||||
}
|
||||
|
||||
function populate_streams (streams_data) {
|
||||
var streams_table = $("#admin_streams_table");
|
||||
_.each(streams_data.streams, function (stream) {
|
||||
streams_table.append(templates.render("admin_streams_list", {stream: stream}));
|
||||
});
|
||||
util.destroy_loading_indicator($('#admin_page_streams_loading_indicator'));
|
||||
}
|
||||
|
||||
exports.setup_page = function () {
|
||||
function failed_listing(xhr, error) {
|
||||
ui.report_error("Error listing streams or subscriptions", xhr, $("#subscriptions-status"));
|
||||
}
|
||||
// create loading indicators
|
||||
util.make_loading_indicator($('#admin_page_users_loading_indicator'));
|
||||
util.make_loading_indicator($('#admin_page_bots_loading_indicator'));
|
||||
util.make_loading_indicator($('#admin_page_streams_loading_indicator'));
|
||||
util.make_loading_indicator($('#admin_page_deactivated_users_loading_indicator'));
|
||||
|
||||
var req = $.ajax({
|
||||
// Populate users and bots tables
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: '/json/users',
|
||||
dataType: 'json',
|
||||
timeout: 10*1000,
|
||||
success: populate_users,
|
||||
error: failed_listing
|
||||
error: failed_listing_users
|
||||
});
|
||||
|
||||
// Populate streams table
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/json/get_public_streams',
|
||||
dataType: 'json',
|
||||
timeout: 10*1000,
|
||||
success: populate_streams,
|
||||
error: failed_listing_streams
|
||||
});
|
||||
|
||||
// Setup click handlers
|
||||
$(".admin_user_table").on("click", ".deactivate", function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
@@ -65,9 +99,23 @@ exports.setup_page = function () {
|
||||
var user_name = $(".active_user_row").find('.user_name').text();
|
||||
var email = $(".active_user_row").find('.email').text();
|
||||
|
||||
$("#deactivation_modal .email").text(email);
|
||||
$("#deactivation_modal .user_name").text(user_name);
|
||||
$("#deactivation_modal").modal("show");
|
||||
$("#deactivation_user_modal .email").text(email);
|
||||
$("#deactivation_user_modal .user_name").text(user_name);
|
||||
$("#deactivation_user_modal").modal("show");
|
||||
});
|
||||
|
||||
$(".admin_stream_table").on("click", ".deactivate", function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
$(".active_stream_row").removeClass("active_stream_row");
|
||||
|
||||
$(e.target).closest(".stream_row").addClass("active_stream_row");
|
||||
|
||||
var stream_name = $(".active_stream_row").find('.stream_name').text();
|
||||
|
||||
$("#deactivation_stream_modal .stream_name").text(stream_name);
|
||||
$("#deactivation_stream_modal").modal("show");
|
||||
});
|
||||
|
||||
$(".admin_user_table").on("click", ".reactivate", function (e) {
|
||||
@@ -103,13 +151,13 @@ exports.setup_page = function () {
|
||||
});
|
||||
});
|
||||
|
||||
$("#do_deactivate_button").click(function (e) {
|
||||
if ($("#deactivation_modal .email").html() !== $(".active_user_row").find('.email').text()) {
|
||||
$("#do_deactivate_user_button").click(function (e) {
|
||||
if ($("#deactivation_user_modal .email").html() !== $(".active_user_row").find('.email').text()) {
|
||||
blueslip.error("User deactivation canceled due to non-matching fields.");
|
||||
ui.report_message("Deactivation encountered an error. Please reload and try again.",
|
||||
$("#home-error"), 'alert-error');
|
||||
}
|
||||
$("#deactivation_modal").modal("hide");
|
||||
$("#deactivation_user_modal").modal("hide");
|
||||
$(".active_user_row button").prop("disabled", true).text("Working…");
|
||||
$.ajax({
|
||||
type: 'DELETE',
|
||||
@@ -137,6 +185,32 @@ exports.setup_page = function () {
|
||||
});
|
||||
});
|
||||
|
||||
$("#do_deactivate_stream_button").click(function (e) {
|
||||
if ($("#deactivation_stream_modal .stream_name").text() !== $(".active_stream_row").find('.stream_name').text()) {
|
||||
blueslip.error("Stream deactivation canceled due to non-matching fields.");
|
||||
ui.report_message("Deactivation encountered an error. Please reload and try again.",
|
||||
$("#home-error"), 'alert-error');
|
||||
}
|
||||
$("#deactivation_stream_modal").modal("hide");
|
||||
$(".active_stream_row button").prop("disabled", true).text("Working…");
|
||||
$.ajax({
|
||||
type: 'DELETE',
|
||||
url: '/json/streams/' + encodeURIComponent($(".active_stream_row").find('.stream_name').text()),
|
||||
error: function (xhr, error_type) {
|
||||
if (xhr.status.toString().charAt(0) === "4") {
|
||||
$(".active_stream_row button").closest("td").html(
|
||||
$("<p>").addClass("text-error").text($.parseJSON(xhr.responseText).msg)
|
||||
);
|
||||
} else {
|
||||
$(".active_stream_row button").text("Failed!");
|
||||
}
|
||||
},
|
||||
success: function () {
|
||||
var row = $(".active_stream_row");
|
||||
row.remove();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return exports;
|
||||
|
||||
Reference in New Issue
Block a user