summaryrefslogtreecommitdiff
path: root/lib/api/group_export.rb
blob: dc14813eefc382262b61db388813c498c3ffe3f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true

module API
  class GroupExport < Grape::API::Instance
    helpers Helpers::RateLimiter

    before do
      not_found! unless Feature.enabled?(:group_import_export, user_group, default_enabled: true)

      authorize! :admin_group, user_group
    end

    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
        check_rate_limit! :group_download_export, [current_user, user_group]

        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
        check_rate_limit! :group_export, [current_user]

        export_service = ::Groups::ImportExport::ExportService.new(group: user_group, user: current_user)

        if export_service.async_execute
          accepted!
        else
          render_api_error!(message: 'Group export could not be started.')
        end
      end
    end
  end
end