diff options
author | Zeger-Jan van de Weg <zegerjan@gitlab.com> | 2016-02-25 09:20:28 +0100 |
---|---|---|
committer | Zeger-Jan van de Weg <zegerjan@gitlab.com> | 2016-03-15 21:09:25 +0100 |
commit | b221d11a25218d3c2ad5304be91c849e1872be6c (patch) | |
tree | 41e52e9bf8367dd79f078ce22245ef98554d3829 | |
parent | 4bcc0977500af7af070296e2faf817eed10aafb9 (diff) | |
download | gitlab-ce-b221d11a25218d3c2ad5304be91c849e1872be6c.tar.gz |
Add ability to delete a user with force
-rw-r--r-- | CHANGELOG | 2 | ||||
-rw-r--r-- | app/controllers/admin/users_controller.rb | 2 | ||||
-rw-r--r-- | app/models/abuse_report.rb | 4 | ||||
-rw-r--r-- | app/services/delete_user_service.rb | 24 | ||||
-rw-r--r-- | app/services/destroy_group_service.rb | 4 | ||||
-rw-r--r-- | app/workers/delete_user_worker.rb | 4 |
6 files changed, 22 insertions, 18 deletions
diff --git a/CHANGELOG b/CHANGELOG index 6de17a4a098..bdeb9b68bde 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -59,6 +59,7 @@ v 8.5.3 - Show commit message in JIRA mention comment - Makes issue page and merge request page usable on mobile browsers. - Improved UI for profile settings + - User deletion is now done in the background so the request can not time out v 8.5.2 - Fix sidebar overlapping content when screen width was below 1200px @@ -178,7 +179,6 @@ v 8.5.0 v 8.4.5 - No CE-specific changes - - User deletion is now done in the background so the request can not time out v 8.4.4 - Update omniauth-saml gem to 1.4.2 diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 3fe33018d73..3063d299b1a 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -119,7 +119,7 @@ class Admin::UsersController < Admin::ApplicationController end def destroy - DeleteUserService.new(current_user).execute(user) + DeleteUserWorker.perform_async(current_user.id, user.id) respond_to do |format| format.html { redirect_to admin_users_path, notice: "The user is being deleted." } diff --git a/app/models/abuse_report.rb b/app/models/abuse_report.rb index cc59aa4e911..155b5f327cb 100644 --- a/app/models/abuse_report.rb +++ b/app/models/abuse_report.rb @@ -19,9 +19,9 @@ class AbuseReport < ActiveRecord::Base validates :message, presence: true validates :user_id, uniqueness: { message: 'has already been reported' } - def remove_user + def remove_user(current_user) user.block - user.destroy + DeleteUserWorker.perform_async(current_user.id, user.id, force: true) end def notify diff --git a/app/services/delete_user_service.rb b/app/services/delete_user_service.rb index 173e50c9206..390960257c0 100644 --- a/app/services/delete_user_service.rb +++ b/app/services/delete_user_service.rb @@ -5,18 +5,22 @@ class DeleteUserService @current_user = current_user end - def execute(user) - if user.solo_owned_groups.present? + def execute(user, options = {}) + if !options[:force] && user.solo_owned_groups.present? user.errors[:base] << 'You must transfer ownership or delete groups before you can remove user' - user - else - user.personal_projects.each do |project| - # Skip repository removal because we remove directory with namespace - # that contain all this repositories - ::Projects::DestroyService.new(project, current_user, skip_repo: true).pending_delete! - end + return user + end + + user.solo_owned_groups.each do |group| + DeleteGroupService.new(group, current_user).execute + end - user.destroy + user.personal_projects.each do |project| + # Skip repository removal because we remove directory with namespace + # that contain all this repositories + ::Projects::DestroyService.new(project, current_user, skip_repo: true).pending_delete! end + + user.destroy end end diff --git a/app/services/destroy_group_service.rb b/app/services/destroy_group_service.rb index 9189de390a2..3c42ac61be4 100644 --- a/app/services/destroy_group_service.rb +++ b/app/services/destroy_group_service.rb @@ -6,12 +6,12 @@ class DestroyGroupService end def execute - @group.projects.each do |project| + group.projects.each do |project| # Skip repository removal because we remove directory with namespace # that contain all this repositories ::Projects::DestroyService.new(project, current_user, skip_repo: true).pending_delete! end - @group.destroy + group.destroy end end diff --git a/app/workers/delete_user_worker.rb b/app/workers/delete_user_worker.rb index bcbb6d58b4f..6ff361e4d80 100644 --- a/app/workers/delete_user_worker.rb +++ b/app/workers/delete_user_worker.rb @@ -1,10 +1,10 @@ class DeleteUserWorker include Sidekiq::Worker - def perform(current_user_id, delete_user_id) + def perform(current_user_id, delete_user_id, options = {}) delete_user = User.find(delete_user_id) current_user = User.find(current_user_id) - DeleteUserService.new(current_user).execute(delete_user) + DeleteUserService.new(current_user).execute(delete_user, options.symbolize_keys) end end |