debian-mirror-gitlab/app/services/destroy_group_service.rb

28 lines
836 B
Ruby
Raw Normal View History

2015-09-11 14:41:01 +05:30
class DestroyGroupService
attr_accessor :group, :current_user
def initialize(group, user)
@group, @current_user = group, user
end
2016-09-13 17:45:13 +05:30
def async_execute
group.transaction do
# 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}")
end
end
2015-09-11 14:41:01 +05:30
def execute
2016-06-02 11:05:42 +05:30
group.projects.each do |project|
2016-09-13 17:45:13 +05:30
# Execute the destruction of the models immediately to ensure atomic cleanup.
2015-09-11 14:41:01 +05:30
# Skip repository removal because we remove directory with namespace
2016-09-13 17:45:13 +05:30
# that contain all these repositories
::Projects::DestroyService.new(project, current_user, skip_repo: true).execute
2015-09-11 14:41:01 +05:30
end
2016-09-13 17:45:13 +05:30
group.really_destroy!
2015-09-11 14:41:01 +05:30
end
end