summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <zegerjan@gitlab.com>2016-02-17 14:41:33 +0100
committerZeger-Jan van de Weg <zegerjan@gitlab.com>2016-03-15 21:09:25 +0100
commit4bcc0977500af7af070296e2faf817eed10aafb9 (patch)
tree25dde6dca1a2da1ff9132489101575ce6b90f17a
parentbc590ce63bd2f1af5545b648e6d028a557e7c792 (diff)
downloadgitlab-ce-4bcc0977500af7af070296e2faf817eed10aafb9.tar.gz
A worker deletes a user, so the request doesn't time out
Fixes #13261
-rw-r--r--CHANGELOG1
-rw-r--r--app/controllers/admin/users_controller.rb2
-rw-r--r--app/workers/delete_user_worker.rb10
-rw-r--r--spec/workers/delete_user_worker_spec.rb22
4 files changed, 34 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 7f076f70c7c..6de17a4a098 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -178,6 +178,7 @@ 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 87f4fb455b8..3fe33018d73 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -122,7 +122,7 @@ class Admin::UsersController < Admin::ApplicationController
DeleteUserService.new(current_user).execute(user)
respond_to do |format|
- format.html { redirect_to admin_users_path }
+ format.html { redirect_to admin_users_path, notice: "The user is being deleted." }
format.json { head :ok }
end
end
diff --git a/app/workers/delete_user_worker.rb b/app/workers/delete_user_worker.rb
new file mode 100644
index 00000000000..bcbb6d58b4f
--- /dev/null
+++ b/app/workers/delete_user_worker.rb
@@ -0,0 +1,10 @@
+class DeleteUserWorker
+ include Sidekiq::Worker
+
+ def perform(current_user_id, delete_user_id)
+ delete_user = User.find(delete_user_id)
+ current_user = User.find(current_user_id)
+
+ DeleteUserService.new(current_user).execute(delete_user)
+ end
+end
diff --git a/spec/workers/delete_user_worker_spec.rb b/spec/workers/delete_user_worker_spec.rb
new file mode 100644
index 00000000000..73005c507c6
--- /dev/null
+++ b/spec/workers/delete_user_worker_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+describe DeleteUserWorker do
+ describe "Deletes a user and all their personal projects" do
+ let!(:user) { create(:user) }
+ let!(:current_user) { create(:user) }
+ let!(:namespace) { create(:namespace, owner: user) }
+ let!(:project) { create(:project, namespace: namespace) }
+
+ before do
+ DeleteUserWorker.new.perform(current_user.id, user.id)
+ end
+
+ it 'deletes all personal projects' do
+ expect { Project.find(project.id) }.to raise_error(ActiveRecord::RecordNotFound)
+ end
+
+ it 'deletes the user' do
+ expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+end