2015-05-28 06:00:02 -04:00
|
|
|
class DeleteUserService
|
2015-06-22 18:08:02 -04:00
|
|
|
attr_accessor :current_user
|
|
|
|
|
|
|
|
def initialize(current_user)
|
|
|
|
@current_user = current_user
|
|
|
|
end
|
|
|
|
|
2015-05-28 06:00:02 -04:00
|
|
|
def execute(user)
|
|
|
|
if user.solo_owned_groups.present?
|
|
|
|
user.errors[:base] << 'You must transfer ownership or delete groups before you can remove user'
|
|
|
|
user
|
|
|
|
else
|
2015-06-03 08:57:12 -04:00
|
|
|
user.personal_projects.each do |project|
|
2015-06-03 10:16:27 -04:00
|
|
|
# Skip repository removal because we remove directory with namespace
|
|
|
|
# that contain all this repositories
|
|
|
|
::Projects::DestroyService.new(project, current_user, skip_repo: true).execute
|
2015-06-03 08:57:12 -04:00
|
|
|
end
|
|
|
|
|
2015-05-28 06:00:02 -04:00
|
|
|
user.destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|