summaryrefslogtreecommitdiff
path: root/lib/api/applications.rb
blob: 6fc9408a57010a518878051501214a15d6aca5b5 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# frozen_string_literal: true

module API
  # External applications API
  class Applications < ::API::Base
    before { authenticated_as_admin! }

    feature_category :authentication_and_authorization

    resource :applications do
      desc 'Create a new application' do
        detail 'This feature was introduced in GitLab 10.5'
        success code: 200, model: Entities::ApplicationWithSecret
      end
      params do
        requires :name, type: String, desc: 'Name of the application.', documentation: { example: 'MyApplication' }
        requires :redirect_uri, type: String, desc: 'Redirect URI of the application.', documentation: { example: 'https://redirect.uri' }
        requires :scopes, type: String,
                          desc: 'Scopes of the application. You can specify multiple scopes by separating\
                                 each scope using a space',
                          allow_blank: false

        optional :confidential,
                 type: Boolean,
                 default: true,
                 desc: 'The application is used where the client secret can be kept confidential. Native mobile apps \
                        and Single Page Apps are considered non-confidential. Defaults to true if not supplied'
      end
      post do
        application = Doorkeeper::Application.new(declared_params)

        if application.save
          present application, with: Entities::ApplicationWithSecret
        else
          render_validation_error! application
        end
      end

      desc 'Get applications' do
        detail 'List all registered applications'
        success Entities::Application
        is_array true
      end
      get do
        applications = ApplicationsFinder.new.execute
        present applications, with: Entities::Application
      end

      desc 'Delete an application' do
        detail 'Delete a specific application'
        success code: 204
      end
      params do
        requires :id, type: Integer, desc: 'The ID of the application (not the application_id)'
      end
      delete ':id' do
        application = ApplicationsFinder.new(params).execute
        break not_found!('Application') unless application

        application.destroy

        no_content!
      end
    end
  end
end