2015-06-03 08:07:20 -04:00
|
|
|
class DestroyGroupService
|
|
|
|
attr_accessor :group, :current_user
|
|
|
|
|
|
|
|
def initialize(group, user)
|
|
|
|
@group, @current_user = group, user
|
|
|
|
end
|
|
|
|
|
2016-05-28 22:54:17 -04:00
|
|
|
def async_execute
|
2016-11-17 06:53:41 -05:00
|
|
|
# Soft delete via paranoia gem
|
|
|
|
group.destroy
|
|
|
|
job_id = GroupDestroyWorker.perform_async(group.id, current_user.id)
|
|
|
|
Rails.logger.info("User #{current_user.id} scheduled a deletion of group ID #{group.id} with job ID #{job_id}")
|
2016-05-28 22:54:17 -04:00
|
|
|
end
|
|
|
|
|
2015-06-03 08:07:20 -04:00
|
|
|
def execute
|
2016-02-25 03:20:28 -05:00
|
|
|
group.projects.each do |project|
|
2016-05-28 22:54:17 -04:00
|
|
|
# Execute the destruction of the models immediately to ensure atomic cleanup.
|
2015-06-03 10:16:27 -04:00
|
|
|
# Skip repository removal because we remove directory with namespace
|
2016-05-28 22:54:17 -04:00
|
|
|
# that contain all these repositories
|
|
|
|
::Projects::DestroyService.new(project, current_user, skip_repo: true).execute
|
2015-06-03 08:57:12 -04:00
|
|
|
end
|
|
|
|
|
2016-10-31 07:00:53 -04:00
|
|
|
group.children.each do |group|
|
|
|
|
DestroyGroupService.new(group, current_user).async_execute
|
|
|
|
end
|
|
|
|
|
2016-05-28 22:54:17 -04:00
|
|
|
group.really_destroy!
|
2015-06-03 08:07:20 -04:00
|
|
|
end
|
|
|
|
end
|