debian-mirror-gitlab/app/services/groups/destroy_service.rb

37 lines
1.2 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Groups
class DestroyService < Groups::BaseService
2018-11-20 20:47:30 +05:30
DestroyError = Class.new(StandardError)
2017-08-17 22:00:37 +05:30
def async_execute
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
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2017-08-17 22:00:37 +05:30
def execute
group.prepare_for_destroy
2018-11-20 20:47:30 +05:30
group.projects.includes(:project_feature).each do |project|
2017-08-17 22:00:37 +05:30
# Execute the destruction of the models immediately to ensure atomic cleanup.
2018-11-20 20:47:30 +05:30
success = ::Projects::DestroyService.new(project, current_user).execute
raise DestroyError, "Project #{project.id} can't be deleted" unless success
2017-08-17 22:00:37 +05:30
end
2018-11-20 20:47:30 +05:30
# reload the relation to prevent triggering destroy hooks on the projects again
group.projects.reload
2017-08-17 22:00:37 +05:30
group.children.each do |group|
# This needs to be synchronous since the namespace gets destroyed below
DestroyService.new(group, current_user).execute
end
2017-09-10 17:25:29 +05:30
group.chat_team&.remove_mattermost_team(current_user)
2018-03-17 18:26:18 +05:30
group.destroy
2017-08-17 22:00:37 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2017-08-17 22:00:37 +05:30
end
end