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

49 lines
1.3 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
2020-06-23 00:09:42 +05:30
helpers Helpers::RateLimiter
2019-12-26 22:10:19 +05:30
before do
2020-03-13 15:44:24 +05:30
not_found! unless Feature.enabled?(:group_import_export, user_group, default_enabled: true)
2019-12-26 22:10:19 +05:30
authorize! :admin_group, user_group
end
2021-01-29 00:20:46 +05:30
feature_category :importers
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.'
end
get ':id/export/download' do
2020-06-23 00:09:42 +05:30
check_rate_limit! :group_download_export, [current_user, user_group]
2019-12-26 22:10:19 +05:30
if user_group.export_file_exists?
present_carrierwave_file!(user_group.export_file)
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
2020-06-23 00:09:42 +05:30
check_rate_limit! :group_export, [current_user]
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
end
end
end