summaryrefslogtreecommitdiff
path: root/app/graphql/mutations/customer_relations/organizations/create.rb
blob: bb02e1f73466ac1b929017df3f0d5226e586718a (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
# frozen_string_literal: true

module Mutations
  module CustomerRelations
    module Organizations
      class Create < BaseMutation
        include ResolvesIds
        include Gitlab::Graphql::Authorize::AuthorizeResource

        graphql_name 'CustomerRelationsOrganizationCreate'

        field :organization,
              Types::CustomerRelations::OrganizationType,
              null: true,
              description: 'Organization after the mutation.'

        argument :group_id, ::Types::GlobalIDType[::Group],
                 required: true,
                 description: 'Group for the organization.'

        argument :name,
                 GraphQL::Types::String,
                 required: true,
                 description: 'Name of the organization.'

        argument :default_rate,
                 GraphQL::Types::Float,
                 required: false,
                 description: 'Standard billing rate for the organization.'

        argument :description,
                 GraphQL::Types::String,
                 required: false,
                 description: 'Description of or notes for the organization.'

        authorize :admin_organization

        def resolve(args)
          group = authorized_find!(id: args[:group_id])

          raise Gitlab::Graphql::Errors::ResourceNotAvailable, 'Feature disabled' unless Feature.enabled?(:customer_relations, group, default_enabled: :yaml)

          result = ::CustomerRelations::Organizations::CreateService.new(group: group, current_user: current_user, params: args).execute
          { organization: result.payload, errors: result.errors }
        end

        def find_object(id:)
          GitlabSchema.object_from_id(id, expected_type: ::Group)
        end
      end
    end
  end
end