Deleting a user from admin user page has the option to also block signups from the same email address

This commit is contained in:
Neil Lalonde 2013-07-25 16:51:24 -04:00
parent 8cee3a9fcd
commit 5f3e9131ed
4 changed files with 63 additions and 18 deletions

View file

@ -215,25 +215,49 @@ Discourse.AdminUser = Discourse.User.extend({
destroy: function() {
var user = this;
bootbox.confirm(I18n.t("admin.user.delete_confirm"), I18n.t("no_value"), I18n.t("yes_value"), function(result) {
if(result) {
Discourse.ajax("/admin/users/" + user.get('id') + '.json', { type: 'DELETE' }).then(function(data) {
if (data.deleted) {
bootbox.alert(I18n.t("admin.user.deleted"), function() {
document.location = "/admin/users/list/active";
});
} else {
bootbox.alert(I18n.t("admin.user.delete_failed"));
if (data.user) {
user.mergeAttributes(data.user);
}
}
}, function(jqXHR, status, error) {
Discourse.AdminUser.find( user.get('username') ).then(function(u){ user.mergeAttributes(u); });
var performDestroy = function(block) {
Discourse.ajax("/admin/users/" + user.get('id') + '.json', {
type: 'DELETE',
data: block ? {block_email: true} : {}
}).then(function(data) {
if (data.deleted) {
bootbox.alert(I18n.t("admin.user.deleted"), function() {
document.location = "/admin/users/list/active";
});
} else {
bootbox.alert(I18n.t("admin.user.delete_failed"));
});
if (data.user) {
user.mergeAttributes(data.user);
}
}
}, function(jqXHR, status, error) {
Discourse.AdminUser.find( user.get('username') ).then(function(u){ user.mergeAttributes(u); });
bootbox.alert(I18n.t("admin.user.delete_failed"));
});
};
var message = I18n.t("admin.user.delete_confirm");
var buttons = [{
"label": I18n.t("composer.cancel"),
"class": "cancel",
"link": true
}, {
"label": I18n.t('admin.user.delete_dont_block'),
"class": "btn",
"callback": function(){
performDestroy(false);
}
});
}, {
"label": I18n.t('admin.user.delete_and_block'),
"class": "btn",
"callback": function(){
performDestroy(true);
}
}];
bootbox.dialog(message, buttons, {"classes": "delete-user-modal"});
},
loadDetails: function() {

View file

@ -297,6 +297,25 @@
}
}
.delete-user-modal {
.modal-footer {
.btn {
font-weight: normal;
text-align: left;
font-size: 14px;
line-height: 20px;
margin-bottom: 10px;
display: inline-block;
margin-left: 0;
}
.cancel {
text-decoration: underline;
display: block;
margin-right: 5px;
}
}
}
.permission-list{
list-style:none;
margin: 0 0 30px;

View file

@ -118,7 +118,7 @@ class Admin::UsersController < Admin::AdminController
user = User.where(id: params[:id]).first
guardian.ensure_can_delete_user!(user)
begin
if UserDestroyer.new(current_user).destroy(user, params.slice(:delete_posts))
if UserDestroyer.new(current_user).destroy(user, params.slice(:delete_posts, :block_email))
render json: {deleted: true}
else
render json: {deleted: false, user: AdminDetailedUserSerializer.new(user, root: false).as_json}

View file

@ -1234,6 +1234,8 @@ en:
delete: "Delete User"
delete_forbidden: "This user can't be deleted because there are posts. Delete all this user's posts first."
delete_confirm: "Are you SURE you want to permanently delete this user from the site? This action is permanent!"
delete_and_block: "<strong>Yes</strong>, and <strong>block</strong> signups with the same email address"
delete_dont_block: "<strong>Yes</strong>, and <strong>allow</strong> signups with the same email address"
deleted: "The user was deleted."
delete_failed: "There was an error deleting that user. Make sure all posts are deleted before trying to delete the user."
send_activation_email: "Send Activation Email"