summaryrefslogtreecommitdiff
path: root/app/graphql/mutations/customer_relations/contacts/create.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-10-20 08:43:02 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-10-20 08:43:02 +0000
commitd9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch)
tree2341ef426af70ad1e289c38036737e04b0aa5007 /app/graphql/mutations/customer_relations/contacts/create.rb
parentd6e514dd13db8947884cd58fe2a9c2a063400a9b (diff)
downloadgitlab-ce-d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb.tar.gz
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'app/graphql/mutations/customer_relations/contacts/create.rb')
-rw-r--r--app/graphql/mutations/customer_relations/contacts/create.rb69
1 files changed, 69 insertions, 0 deletions
diff --git a/app/graphql/mutations/customer_relations/contacts/create.rb b/app/graphql/mutations/customer_relations/contacts/create.rb
new file mode 100644
index 00000000000..77b4864468b
--- /dev/null
+++ b/app/graphql/mutations/customer_relations/contacts/create.rb
@@ -0,0 +1,69 @@
+# frozen_string_literal: true
+
+module Mutations
+ module CustomerRelations
+ module Contacts
+ class Create < BaseMutation
+ include ResolvesIds
+ include Gitlab::Graphql::Authorize::AuthorizeResource
+
+ graphql_name 'CustomerRelationsContactCreate'
+
+ field :contact,
+ Types::CustomerRelations::ContactType,
+ null: true,
+ description: 'Contact after the mutation.'
+
+ argument :group_id, ::Types::GlobalIDType[::Group],
+ required: true,
+ description: 'Group for the contact.'
+
+ argument :organization_id, ::Types::GlobalIDType[::CustomerRelations::Organization],
+ required: false,
+ description: 'Organization for the contact.'
+
+ argument :first_name, GraphQL::Types::String,
+ required: true,
+ description: 'First name of the contact.'
+
+ argument :last_name, GraphQL::Types::String,
+ required: true,
+ description: 'Last name of the contact.'
+
+ argument :phone, GraphQL::Types::String,
+ required: false,
+ description: 'Phone number of the contact.'
+
+ argument :email, GraphQL::Types::String,
+ required: false,
+ description: 'Email address of the contact.'
+
+ argument :description, GraphQL::Types::String,
+ required: false,
+ description: 'Description of or notes for the contact.'
+
+ authorize :admin_contact
+
+ 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)
+
+ set_organization!(args)
+ result = ::CustomerRelations::Contacts::CreateService.new(group: group, current_user: current_user, params: args).execute
+ { contact: result.payload, errors: result.errors }
+ end
+
+ def find_object(id:)
+ GitlabSchema.object_from_id(id, expected_type: ::Group)
+ end
+
+ def set_organization!(args)
+ return unless args[:organization_id]
+
+ args[:organization_id] = resolve_ids(args[:organization_id], ::Types::GlobalIDType[::CustomerRelations::Organization])[0]
+ end
+ end
+ end
+ end
+end