debian-mirror-gitlab/app/services/bulk_imports/export_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

41 lines
1.1 KiB
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
module BulkImports
class ExportService
2023-07-09 08:55:56 +05:30
# @param portable [Project|Group] A project or a group to export.
# @param user [User] A user performing the export.
# @param batched [Boolean] Whether to export the data in batches.
def initialize(portable:, user:, batched: false)
2021-06-08 01:23:25 +05:30
@portable = portable
@current_user = user
2023-07-09 08:55:56 +05:30
@batched = batched
2021-06-08 01:23:25 +05:30
end
def execute
2023-07-09 08:55:56 +05:30
validate_user_permissions!
2021-06-08 01:23:25 +05:30
FileTransfer.config_for(portable).portable_relations.each do |relation|
2023-07-09 08:55:56 +05:30
RelationExportWorker.perform_async(current_user.id, portable.id, portable.class.name, relation, batched)
2021-06-08 01:23:25 +05:30
end
ServiceResponse.success
rescue StandardError => e
ServiceResponse.error(
message: e.class,
http_status: :unprocessable_entity
)
end
private
2023-07-09 08:55:56 +05:30
attr_reader :portable, :current_user, :batched
def validate_user_permissions!
ability = "admin_#{portable.to_ability_name}"
current_user.can?(ability, portable) ||
raise(::Gitlab::ImportExport::Error.permission_error(current_user, portable))
end
2021-06-08 01:23:25 +05:30
end
end