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
|
|
|
|
|
2016-02-25 03:20:28 -05:00
|
|
|
def execute(user, options = {})
|
2016-03-12 07:11:30 -05:00
|
|
|
if !options[:delete_solo_owned_groups] && user.solo_owned_groups.present?
|
2015-05-28 06:00:02 -04:00
|
|
|
user.errors[:base] << 'You must transfer ownership or delete groups before you can remove user'
|
2016-02-25 03:20:28 -05:00
|
|
|
return user
|
|
|
|
end
|
|
|
|
|
|
|
|
user.solo_owned_groups.each do |group|
|
2016-03-04 03:49:23 -05:00
|
|
|
DestroyGroupService.new(group, current_user).execute
|
2016-02-25 03:20:28 -05:00
|
|
|
end
|
2015-06-03 08:57:12 -04:00
|
|
|
|
2016-02-25 03:20:28 -05:00
|
|
|
user.personal_projects.each do |project|
|
|
|
|
# Skip repository removal because we remove directory with namespace
|
|
|
|
# that contain all this repositories
|
2016-08-06 10:25:51 -04:00
|
|
|
::Projects::DestroyService.new(project, current_user, skip_repo: true).async_execute
|
2015-05-28 06:00:02 -04:00
|
|
|
end
|
2016-02-25 03:20:28 -05:00
|
|
|
|
2016-05-28 22:54:17 -04:00
|
|
|
# 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-05-28 06:00:02 -04:00
|
|
|
end
|
|
|
|
end
|