File: organizations.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (47 lines) | stat: -rw-r--r-- 1,681 bytes parent folder | download
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
# frozen_string_literal: true

module API
  class Organizations < ::API::Base
    feature_category :cell

    before { authenticate! }

    helpers do
      def authorize_organization_creation!
        authorize! :create_organization
      end
    end

    resource :organizations do
      desc 'Create an organization' do
        detail 'This feature was introduced in GitLab 17.5. \
                    This feature is currently in an experimental state. \
                    This feature is behind the `allow_organization_creation` feature flag.'
        success Entities::Organizations::Organization
        tags %w[organizations]
      end
      params do
        requires :name, type: String, desc: 'The name of the organization'
        requires :path, type: String, desc: 'The path of the organization'
        optional :description, type: String, desc: 'The description of the organization'
        optional :avatar, type: ::API::Validations::Types::WorkhorseFile, desc: 'The avatar image for the organization',
          documentation: { type: 'file' }
      end
      post do
        forbidden! unless Feature.enabled?(:allow_organization_creation, current_user)
        check_rate_limit!(:create_organization_api, scope: current_user)
        authorize_organization_creation!

        response = ::Organizations::CreateService
          .new(current_user: current_user, params: declared_params(include_missing: false))
          .execute

        if response.success?
          present response[:organization], with: Entities::Organizations::Organization
        else
          render_api_error!(response.message, :bad_request)
        end
      end
    end
  end
end