2019-11-14 07:06:30 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
2020-10-14 20:08:42 -04:00
|
|
|
class GroupExport < ::API::Base
|
2019-11-14 07:06:30 -05:00
|
|
|
before do
|
|
|
|
authorize! :admin_group, user_group
|
|
|
|
end
|
|
|
|
|
2020-10-29 08:08:50 -04:00
|
|
|
feature_category :importers
|
|
|
|
|
2019-11-14 07:06:30 -05:00
|
|
|
params do
|
|
|
|
requires :id, type: String, desc: 'The ID of a group'
|
|
|
|
end
|
|
|
|
resource :groups, requirements: { id: %r{[^/]+} } do
|
|
|
|
desc 'Download export' do
|
|
|
|
detail 'This feature was introduced in GitLab 12.5.'
|
|
|
|
end
|
|
|
|
get ':id/export/download' do
|
2021-12-10 10:10:24 -05:00
|
|
|
check_rate_limit! :group_download_export, scope: [current_user, user_group]
|
2020-06-03 08:08:21 -04:00
|
|
|
|
2019-11-14 07:06:30 -05:00
|
|
|
if user_group.export_file_exists?
|
2021-06-15 02:10:17 -04:00
|
|
|
if user_group.export_archive_exists?
|
|
|
|
present_carrierwave_file!(user_group.export_file)
|
|
|
|
else
|
|
|
|
render_api_error!('The group export file is not available yet', 404)
|
|
|
|
end
|
2019-11-14 07:06:30 -05:00
|
|
|
else
|
|
|
|
render_api_error!('404 Not found or has expired', 404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Start export' do
|
|
|
|
detail 'This feature was introduced in GitLab 12.5.'
|
|
|
|
end
|
|
|
|
post ':id/export' do
|
2021-12-10 10:10:24 -05:00
|
|
|
check_rate_limit! :group_export, scope: current_user
|
2020-06-03 08:08:21 -04:00
|
|
|
|
2020-04-09 08:09:24 -04:00
|
|
|
export_service = ::Groups::ImportExport::ExportService.new(group: user_group, user: current_user)
|
2019-11-14 07:06:30 -05:00
|
|
|
|
2020-04-09 08:09:24 -04:00
|
|
|
if export_service.async_execute
|
|
|
|
accepted!
|
|
|
|
else
|
|
|
|
render_api_error!(message: 'Group export could not be started.')
|
|
|
|
end
|
2019-11-14 07:06:30 -05:00
|
|
|
end
|
2021-05-04 14:10:03 -04:00
|
|
|
|
|
|
|
desc 'Start relations export' do
|
|
|
|
detail 'This feature was introduced in GitLab 13.12'
|
|
|
|
end
|
|
|
|
post ':id/export_relations' do
|
2021-05-12 05:10:19 -04:00
|
|
|
response = ::BulkImports::ExportService.new(portable: user_group, user: current_user).execute
|
2021-05-04 14:10:03 -04:00
|
|
|
|
|
|
|
if response.success?
|
|
|
|
accepted!
|
|
|
|
else
|
|
|
|
render_api_error!(message: 'Group relations export could not be started.')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Download relations export' do
|
|
|
|
detail 'This feature was introduced in GitLab 13.12'
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :relation, type: String, desc: 'Group relation name'
|
|
|
|
end
|
|
|
|
get ':id/export_relations/download' do
|
|
|
|
export = user_group.bulk_import_exports.find_by_relation(params[:relation])
|
|
|
|
file = export&.upload&.export_file
|
|
|
|
|
|
|
|
if file
|
|
|
|
present_carrierwave_file!(file)
|
|
|
|
else
|
|
|
|
render_api_error!('404 Not found', 404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Relations export status' do
|
|
|
|
detail 'This feature was introduced in GitLab 13.12'
|
|
|
|
end
|
|
|
|
get ':id/export_relations/status' do
|
|
|
|
present user_group.bulk_import_exports, with: Entities::BulkImports::ExportStatus
|
|
|
|
end
|
2019-11-14 07:06:30 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|