2015-09-11 14:41:01 +05:30
|
|
|
class DeleteUserService
|
|
|
|
attr_accessor :current_user
|
|
|
|
|
|
|
|
def initialize(current_user)
|
|
|
|
@current_user = current_user
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
def execute(user, options = {})
|
|
|
|
if !options[:delete_solo_owned_groups] && user.solo_owned_groups.present?
|
2015-09-11 14:41:01 +05:30
|
|
|
user.errors[:base] << 'You must transfer ownership or delete groups before you can remove user'
|
2016-06-02 11:05:42 +05:30
|
|
|
return user
|
|
|
|
end
|
|
|
|
|
|
|
|
user.solo_owned_groups.each do |group|
|
|
|
|
DestroyGroupService.new(group, current_user).execute
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
user.personal_projects.each do |project|
|
|
|
|
# Skip repository removal because we remove directory with namespace
|
|
|
|
# that contain all this repositories
|
2016-09-13 17:45:13 +05:30
|
|
|
::Projects::DestroyService.new(project, current_user, skip_repo: true).async_execute
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
# Destroy the namespace after destroying the user since certain methods may depend on the namespace existing
|
|
|
|
namespace = user.namespace
|
|
|
|
user_data = user.destroy
|
|
|
|
namespace.really_destroy!
|
|
|
|
|
|
|
|
user_data
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
end
|