gitlab-org--gitlab-foss/app/services/delete_user_service.rb

27 lines
770 B
Ruby
Raw Normal View History

class DeleteUserService
attr_accessor :current_user
def initialize(current_user)
@current_user = current_user
end
def execute(user, options = {})
2016-03-12 07:11:30 -05:00
if !options[:delete_solo_owned_groups] && user.solo_owned_groups.present?
user.errors[:base] << 'You must transfer ownership or delete groups before you can remove user'
return user
end
user.solo_owned_groups.each do |group|
2016-03-04 03:49:23 -05:00
DestroyGroupService.new(group, current_user).execute
end
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