2015-05-28 10:00:02 +00:00
|
|
|
class DeleteUserService
|
2015-06-22 22:08:02 +00:00
|
|
|
attr_accessor :current_user
|
|
|
|
|
|
|
|
def initialize(current_user)
|
|
|
|
@current_user = current_user
|
|
|
|
end
|
|
|
|
|
2016-02-25 08:20:28 +00:00
|
|
|
def execute(user, options = {})
|
|
|
|
if !options[:force] && user.solo_owned_groups.present?
|
2015-05-28 10:00:02 +00:00
|
|
|
user.errors[:base] << 'You must transfer ownership or delete groups before you can remove user'
|
2016-02-25 08:20:28 +00:00
|
|
|
return user
|
|
|
|
end
|
|
|
|
|
|
|
|
user.solo_owned_groups.each do |group|
|
2016-03-04 08:49:23 +00:00
|
|
|
DestroyGroupService.new(group, current_user).execute
|
2016-02-25 08:20:28 +00:00
|
|
|
end
|
2015-06-03 12:57:12 +00:00
|
|
|
|
2016-02-25 08:20:28 +00:00
|
|
|
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!
|
2015-05-28 10:00:02 +00:00
|
|
|
end
|
2016-02-25 08:20:28 +00:00
|
|
|
|
|
|
|
user.destroy
|
2015-05-28 10:00:02 +00:00
|
|
|
end
|
|
|
|
end
|