Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2015-06-23 01:08:02 +0300
committerStan Hu <stanhu@gmail.com>2015-06-23 17:46:24 +0300
commitd5ed8a42ef1dd79b5801de52e6455c946ae3ded5 (patch)
treef4abc171d0d9b215aa0fd4d4e912183acf612110
parent93ba5b9048aa6cff8e47c69a1cca4f240d6a64db (diff)
Fix error when deleting a user who has projects
Closes #1856 Closes https://github.com/gitlabhq/gitlabhq/issues/9394
-rw-r--r--CHANGELOG1
-rw-r--r--app/controllers/admin/users_controller.rb2
-rw-r--r--app/controllers/registrations_controller.rb2
-rw-r--r--app/services/delete_user_service.rb6
-rw-r--r--lib/api/users.rb2
-rw-r--r--spec/controllers/admin/users_controller_spec.rb24
6 files changed, 34 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 396a14b9d15..a7bb4e9f25c 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
Please view this file on the master branch, on stable branches it's out of date.
v 7.13.0 (unreleased)
+ - Fix error when deleting a user who has projects (Stan Hu)
- Update maintenance documentation to explain no need to recompile asssets for omnibus installations (Stan Hu)
- Support commenting on diffs in side-by-side mode (Stan Hu)
- Fix JavaScript error when clicking on the comment button on a diff line that has a comment already (Stan Hu)
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index 06d6d61e907..2bc236871b0 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -86,7 +86,7 @@ class Admin::UsersController < Admin::ApplicationController
end
def destroy
- DeleteUserService.new.execute(user)
+ DeleteUserService.new(current_user).execute(user)
respond_to do |format|
format.html { redirect_to admin_users_path }
diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb
index 6ccc7934f2f..3b3dc86cb68 100644
--- a/app/controllers/registrations_controller.rb
+++ b/app/controllers/registrations_controller.rb
@@ -6,7 +6,7 @@ class RegistrationsController < Devise::RegistrationsController
end
def destroy
- DeleteUserService.new.execute(current_user)
+ DeleteUserService.new(current_user).execute(current_user)
respond_to do |format|
format.html { redirect_to new_user_session_path, notice: "Account successfully removed." }
diff --git a/app/services/delete_user_service.rb b/app/services/delete_user_service.rb
index 9017a63af3b..e622fd5ea5d 100644
--- a/app/services/delete_user_service.rb
+++ b/app/services/delete_user_service.rb
@@ -1,4 +1,10 @@
class DeleteUserService
+ attr_accessor :current_user
+
+ def initialize(current_user)
+ @current_user = current_user
+ end
+
def execute(user)
if user.solo_owned_groups.present?
user.errors[:base] << 'You must transfer ownership or delete groups before you can remove user'
diff --git a/lib/api/users.rb b/lib/api/users.rb
index 7d4c68c7412..9b268cfe8bc 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -194,7 +194,7 @@ module API
user = User.find_by(id: params[:id])
if user
- DeleteUserService.new.execute(user)
+ DeleteUserService.new(current_user).execute(user)
else
not_found!('User')
end
diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb
new file mode 100644
index 00000000000..f27e861e175
--- /dev/null
+++ b/spec/controllers/admin/users_controller_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe Admin::UsersController do
+ let(:admin) { create(:admin) }
+
+ before do
+ sign_in(admin)
+ end
+
+ describe 'DELETE #user with projects' do
+ let(:user) { create(:user) }
+ let(:project) { create(:project, namespace: user.namespace) }
+
+ before do
+ project.team << [user, :developer]
+ end
+
+ it 'deletes user' do
+ delete :destroy, id: user.username, format: :json
+ expect(response.status).to eq(200)
+ expect { User.find(user.id) }.to raise_exception(ActiveRecord::RecordNotFound)
+ end
+ end
+end