mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 17:33:37 +08:00
UX: when deleting a user, show a modal indicating that the delete is happening. User hijack so requests don't time out.
This commit is contained in:
parent
3a145b7551
commit
a0447b47e0
|
@ -412,6 +412,7 @@ const AdminUser = Discourse.User.extend({
|
|||
location = document.location.pathname;
|
||||
|
||||
const performDestroy = function(block) {
|
||||
bootbox.dialog(I18n.t('admin.user.deleting_user'));
|
||||
let formData = { context: location };
|
||||
if (block) {
|
||||
formData["block_email"] = true;
|
||||
|
|
|
@ -46,10 +46,12 @@ class Admin::UsersController < Admin::AdminController
|
|||
end
|
||||
|
||||
def delete_all_posts
|
||||
@user = User.find_by(id: params[:user_id])
|
||||
@user.delete_all_posts!(guardian)
|
||||
# staff action logs will have an entry for each post
|
||||
render body: nil
|
||||
hijack do
|
||||
user = User.find_by(id: params[:user_id])
|
||||
user.delete_all_posts!(guardian)
|
||||
# staff action logs will have an entry for each post
|
||||
render body: nil
|
||||
end
|
||||
end
|
||||
|
||||
def suspend
|
||||
|
@ -362,20 +364,23 @@ class Admin::UsersController < Admin::AdminController
|
|||
def destroy
|
||||
user = User.find_by(id: params[:id].to_i)
|
||||
guardian.ensure_can_delete_user!(user)
|
||||
begin
|
||||
options = params.slice(:block_email, :block_urls, :block_ip, :context, :delete_as_spammer)
|
||||
options[:delete_posts] = ActiveModel::Type::Boolean.new.cast(params[:delete_posts])
|
||||
|
||||
if UserDestroyer.new(current_user).destroy(user, options)
|
||||
render json: { deleted: true }
|
||||
else
|
||||
render json: {
|
||||
deleted: false,
|
||||
user: AdminDetailedUserSerializer.new(user, root: false).as_json
|
||||
}
|
||||
options = params.slice(:block_email, :block_urls, :block_ip, :context, :delete_as_spammer)
|
||||
options[:delete_posts] = ActiveModel::Type::Boolean.new.cast(params[:delete_posts])
|
||||
|
||||
hijack do
|
||||
begin
|
||||
if UserDestroyer.new(current_user).destroy(user, options)
|
||||
render json: { deleted: true }
|
||||
else
|
||||
render json: {
|
||||
deleted: false,
|
||||
user: AdminDetailedUserSerializer.new(user, root: false).as_json
|
||||
}
|
||||
end
|
||||
rescue UserDestroyer::PostsExistError
|
||||
raise Discourse::InvalidAccess.new("User #{user.username} has #{user.post_count} posts, so can't be deleted.")
|
||||
end
|
||||
rescue UserDestroyer::PostsExistError
|
||||
raise Discourse::InvalidAccess.new("User #{user.username} has #{user.post_count} posts, so can't be deleted.")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -3608,6 +3608,7 @@ en:
|
|||
delete_confirm: "Are you SURE you want to delete this user? This is permanent!"
|
||||
delete_and_block: "Delete and <b>block</b> this email and IP address"
|
||||
delete_dont_block: "Delete only"
|
||||
deleting_user: "Deleting user..."
|
||||
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"
|
||||
|
|
Loading…
Reference in New Issue
Block a user