debian-mirror-gitlab/lib/api/group_export.rb

138 lines
4.5 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
module API
2021-01-03 14:25:43 +05:30
class GroupExport < ::API::Base
2019-12-26 22:10:19 +05:30
before do
authorize! :admin_group, user_group
end
2021-01-29 00:20:46 +05:30
feature_category :importers
2022-07-16 23:28:13 +05:30
urgency :low
2021-01-29 00:20:46 +05:30
2019-12-26 22:10:19 +05:30
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.'
2023-01-13 00:05:48 +05:30
tags %w[group_export]
produces %w[application/octet-stream application/json]
success code: 200
failure [
{ code: 400, message: 'Bad request' },
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not found' },
{ code: 503, message: 'Service unavailable' }
]
2019-12-26 22:10:19 +05:30
end
get ':id/export/download' do
2022-01-26 12:08:38 +05:30
check_rate_limit! :group_download_export, scope: [current_user, user_group]
2020-06-23 00:09:42 +05:30
2019-12-26 22:10:19 +05:30
if user_group.export_file_exists?
2021-09-04 01:27:46 +05:30
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-12-26 22:10:19 +05:30
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.'
2023-01-13 00:05:48 +05:30
tags %w[group_export]
success code: 202
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not found' },
{ code: 429, message: 'Too many requests' },
{ code: 503, message: 'Service unavailable' }
]
2019-12-26 22:10:19 +05:30
end
post ':id/export' do
2022-01-26 12:08:38 +05:30
check_rate_limit! :group_export, scope: current_user
2020-06-23 00:09:42 +05:30
2020-04-22 19:07:51 +05:30
export_service = ::Groups::ImportExport::ExportService.new(group: user_group, user: current_user)
2019-12-26 22:10:19 +05:30
2020-04-22 19:07:51 +05:30
if export_service.async_execute
accepted!
else
render_api_error!(message: 'Group export could not be started.')
end
2019-12-26 22:10:19 +05:30
end
2021-06-08 01:23:25 +05:30
2023-03-17 16:20:25 +05:30
resource do
before do
not_found! unless Gitlab::CurrentSettings.bulk_import_enabled?
end
2021-06-08 01:23:25 +05:30
2023-03-17 16:20:25 +05:30
desc 'Start relations export' do
detail 'This feature was introduced in GitLab 13.12'
tags %w[group_export]
success code: 202
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not found' },
{ code: 503, message: 'Service unavailable' }
]
2021-06-08 01:23:25 +05:30
end
2023-03-17 16:20:25 +05:30
post ':id/export_relations' do
response = ::BulkImports::ExportService.new(portable: user_group, user: current_user).execute
2021-06-08 01:23:25 +05:30
2023-03-17 16:20:25 +05:30
if response.success?
accepted!
else
render_api_error!(message: 'Group relations export could not be started.')
end
end
2021-06-08 01:23:25 +05:30
2023-03-17 16:20:25 +05:30
desc 'Download relations export' do
detail 'This feature was introduced in GitLab 13.12'
produces %w[application/octet-stream application/json]
tags %w[group_export]
success code: 200
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not found' },
{ code: 503, message: 'Service unavailable' }
]
2021-06-08 01:23:25 +05:30
end
2023-03-17 16:20:25 +05:30
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
2021-06-08 01:23:25 +05:30
2023-03-17 16:20:25 +05:30
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'
is_array true
tags %w[group_export]
success code: 200, model: Entities::BulkImports::ExportStatus
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 403, message: 'Forbidden' },
{ code: 404, message: 'Not found' },
{ code: 503, message: 'Service unavailable' }
]
end
get ':id/export_relations/status' do
present user_group.bulk_import_exports, with: Entities::BulkImports::ExportStatus
end
2021-06-08 01:23:25 +05:30
end
2019-12-26 22:10:19 +05:30
end
end
end