diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 13:18:24 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 13:18:24 +0000 |
commit | 0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch) | |
tree | 4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /app/graphql/mutations/customer_relations/organizations | |
parent | 744144d28e3e7fddc117924fef88de5d9674fe4c (diff) | |
download | gitlab-ce-0653e08efd039a5905f3fa4f6e9cef9f5d2f799c.tar.gz |
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'app/graphql/mutations/customer_relations/organizations')
-rw-r--r-- | app/graphql/mutations/customer_relations/organizations/create.rb | 53 | ||||
-rw-r--r-- | app/graphql/mutations/customer_relations/organizations/update.rb | 52 |
2 files changed, 105 insertions, 0 deletions
diff --git a/app/graphql/mutations/customer_relations/organizations/create.rb b/app/graphql/mutations/customer_relations/organizations/create.rb new file mode 100644 index 00000000000..3fa7b0327ca --- /dev/null +++ b/app/graphql/mutations/customer_relations/organizations/create.rb @@ -0,0 +1,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 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 diff --git a/app/graphql/mutations/customer_relations/organizations/update.rb b/app/graphql/mutations/customer_relations/organizations/update.rb new file mode 100644 index 00000000000..c6ae62193f9 --- /dev/null +++ b/app/graphql/mutations/customer_relations/organizations/update.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +module Mutations + module CustomerRelations + module Organizations + class Update < Mutations::BaseMutation + include ResolvesIds + + graphql_name 'CustomerRelationsOrganizationUpdate' + + authorize :admin_organization + + field :organization, + Types::CustomerRelations::OrganizationType, + null: false, + description: 'Organization after the mutation.' + + argument :id, ::Types::GlobalIDType[::CustomerRelations::Organization], + required: true, + description: 'Global ID of the organization.' + + argument :name, + GraphQL::Types::String, + required: false, + 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 or notes for the organization.' + + def resolve(args) + organization = ::Gitlab::Graphql::Lazy.force(GitlabSchema.object_from_id(args.delete(:id), expected_type: ::CustomerRelations::Organization)) + raise_resource_not_available_error! unless organization + + group = organization.group + raise Gitlab::Graphql::Errors::ResourceNotAvailable, 'Feature disabled' unless Feature.enabled?(:customer_relations, group, default_enabled: :yaml) + + authorize!(group) + + result = ::CustomerRelations::Organizations::UpdateService.new(group: group, current_user: current_user, params: args).execute(organization) + { organization: result.payload, errors: result.errors } + end + end + end + end +end |