From d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 20 Oct 2021 08:43:02 +0000 Subject: Add latest changes from gitlab-org/gitlab@14-4-stable-ee --- app/graphql/mutations/ci/runner/delete.rb | 2 +- .../mutations/clusters/agent_tokens/create.rb | 69 ++++++++++++++++++++++ .../mutations/clusters/agent_tokens/delete.rb | 35 +++++++++++ app/graphql/mutations/clusters/agents/create.rb | 38 ++++++++++++ app/graphql/mutations/clusters/agents/delete.rb | 39 ++++++++++++ .../customer_relations/contacts/create.rb | 69 ++++++++++++++++++++++ .../customer_relations/contacts/update.rb | 61 +++++++++++++++++++ .../customer_relations/organizations/create.rb | 2 +- .../customer_relations/organizations/update.rb | 2 +- .../dependency_proxy/group_settings/update.rb | 49 +++++++++++++++ app/graphql/mutations/issues/create.rb | 5 +- 11 files changed, 366 insertions(+), 5 deletions(-) create mode 100644 app/graphql/mutations/clusters/agent_tokens/create.rb create mode 100644 app/graphql/mutations/clusters/agent_tokens/delete.rb create mode 100644 app/graphql/mutations/clusters/agents/create.rb create mode 100644 app/graphql/mutations/clusters/agents/delete.rb create mode 100644 app/graphql/mutations/customer_relations/contacts/create.rb create mode 100644 app/graphql/mutations/customer_relations/contacts/update.rb create mode 100644 app/graphql/mutations/dependency_proxy/group_settings/update.rb (limited to 'app/graphql/mutations') diff --git a/app/graphql/mutations/ci/runner/delete.rb b/app/graphql/mutations/ci/runner/delete.rb index 8d9a5f15505..88dc426398b 100644 --- a/app/graphql/mutations/ci/runner/delete.rb +++ b/app/graphql/mutations/ci/runner/delete.rb @@ -28,7 +28,7 @@ module Mutations def authenticate_delete_runner!(runner) return if current_user.can_admin_all_resources? - "Runner #{runner.to_global_id} associated with more than one project" if runner.projects.count > 1 + "Runner #{runner.to_global_id} associated with more than one project" if runner.runner_projects.count > 1 end def find_object(id) diff --git a/app/graphql/mutations/clusters/agent_tokens/create.rb b/app/graphql/mutations/clusters/agent_tokens/create.rb new file mode 100644 index 00000000000..07bf2536065 --- /dev/null +++ b/app/graphql/mutations/clusters/agent_tokens/create.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +module Mutations + module Clusters + module AgentTokens + class Create < BaseMutation + graphql_name 'ClusterAgentTokenCreate' + + authorize :create_cluster + + ClusterAgentID = ::Types::GlobalIDType[::Clusters::Agent] + + argument :cluster_agent_id, + ClusterAgentID, + required: true, + description: 'Global ID of the cluster agent that will be associated with the new token.' + + argument :description, + GraphQL::Types::String, + required: false, + description: 'Description of the token.' + + argument :name, + GraphQL::Types::String, + required: true, + description: 'Name of the token.' + + field :secret, + GraphQL::Types::String, + null: true, + description: "Token secret value. Make sure you save it - you won't be able to access it again." + + field :token, + Types::Clusters::AgentTokenType, + null: true, + description: 'Token created after mutation.' + + def resolve(args) + cluster_agent = authorized_find!(id: args[:cluster_agent_id]) + + result = ::Clusters::AgentTokens::CreateService + .new( + container: cluster_agent.project, + current_user: current_user, + params: args.merge(agent_id: cluster_agent.id) + ) + .execute + + payload = result.payload + + { + secret: payload[:secret], + token: payload[:token], + errors: Array.wrap(result.message) + } + end + + private + + def find_object(id:) + # TODO: remove this line when the compatibility layer is removed + # See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883 + id = ClusterAgentID.coerce_isolated_input(id) + GitlabSchema.find_by_gid(id) + end + end + end + end +end diff --git a/app/graphql/mutations/clusters/agent_tokens/delete.rb b/app/graphql/mutations/clusters/agent_tokens/delete.rb new file mode 100644 index 00000000000..603b6b30910 --- /dev/null +++ b/app/graphql/mutations/clusters/agent_tokens/delete.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module Mutations + module Clusters + module AgentTokens + class Delete < BaseMutation + graphql_name 'ClusterAgentTokenDelete' + + authorize :admin_cluster + + TokenID = ::Types::GlobalIDType[::Clusters::AgentToken] + + argument :id, TokenID, + required: true, + description: 'Global ID of the cluster agent token that will be deleted.' + + def resolve(id:) + token = authorized_find!(id: id) + token.destroy + + { errors: errors_on_object(token) } + end + + private + + def find_object(id:) + # TODO: remove this line when the compatibility layer is removed + # See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883 + id = TokenID.coerce_isolated_input(id) + GitlabSchema.find_by_gid(id) + end + end + end + end +end diff --git a/app/graphql/mutations/clusters/agents/create.rb b/app/graphql/mutations/clusters/agents/create.rb new file mode 100644 index 00000000000..0896cc7b203 --- /dev/null +++ b/app/graphql/mutations/clusters/agents/create.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +module Mutations + module Clusters + module Agents + class Create < BaseMutation + include FindsProject + + authorize :create_cluster + + graphql_name 'CreateClusterAgent' + + argument :project_path, GraphQL::Types::ID, + required: true, + description: 'Full path of the associated project for this cluster agent.' + + argument :name, GraphQL::Types::String, + required: true, + description: 'Name of the cluster agent.' + + field :cluster_agent, + Types::Clusters::AgentType, + null: true, + description: 'Cluster agent created after mutation.' + + def resolve(project_path:, name:) + project = authorized_find!(project_path) + result = ::Clusters::Agents::CreateService.new(project, current_user).execute(name: name) + + { + cluster_agent: result[:cluster_agent], + errors: Array.wrap(result[:message]) + } + end + end + end + end +end diff --git a/app/graphql/mutations/clusters/agents/delete.rb b/app/graphql/mutations/clusters/agents/delete.rb new file mode 100644 index 00000000000..9ada1f31f60 --- /dev/null +++ b/app/graphql/mutations/clusters/agents/delete.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +module Mutations + module Clusters + module Agents + class Delete < BaseMutation + graphql_name 'ClusterAgentDelete' + + authorize :admin_cluster + + AgentID = ::Types::GlobalIDType[::Clusters::Agent] + + argument :id, AgentID, + required: true, + description: 'Global ID of the cluster agent that will be deleted.' + + def resolve(id:) + cluster_agent = authorized_find!(id: id) + result = ::Clusters::Agents::DeleteService + .new(container: cluster_agent.project, current_user: current_user) + .execute(cluster_agent) + + { + errors: Array.wrap(result.message) + } + end + + private + + def find_object(id:) + # TODO: remove this line when the compatibility layer is removed + # See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883 + id = AgentID.coerce_isolated_input(id) + GitlabSchema.find_by_gid(id) + end + end + end + end +end 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 diff --git a/app/graphql/mutations/customer_relations/contacts/update.rb b/app/graphql/mutations/customer_relations/contacts/update.rb new file mode 100644 index 00000000000..e9e7c9b6abd --- /dev/null +++ b/app/graphql/mutations/customer_relations/contacts/update.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +module Mutations + module CustomerRelations + module Contacts + class Update < Mutations::BaseMutation + include ResolvesIds + + graphql_name 'CustomerRelationsContactUpdate' + + authorize :admin_contact + + field :contact, + Types::CustomerRelations::ContactType, + null: true, + description: 'Contact after the mutation.' + + argument :id, ::Types::GlobalIDType[::CustomerRelations::Contact], + required: true, + description: 'Global ID of the contact.' + + argument :organization_id, ::Types::GlobalIDType[::CustomerRelations::Organization], + required: false, + description: 'Organization of the contact.' + + argument :first_name, GraphQL::Types::String, + required: false, + description: 'First name of the contact.' + + argument :last_name, GraphQL::Types::String, + required: false, + 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.' + + def resolve(args) + contact = ::Gitlab::Graphql::Lazy.force(GitlabSchema.object_from_id(args.delete(:id), expected_type: ::CustomerRelations::Contact)) + raise_resource_not_available_error! unless contact + + group = contact.group + raise Gitlab::Graphql::Errors::ResourceNotAvailable, 'Feature disabled' unless Feature.enabled?(:customer_relations, group, default_enabled: :yaml) + + authorize!(group) + + result = ::CustomerRelations::Contacts::UpdateService.new(group: group, current_user: current_user, params: args).execute(contact) + { contact: result.payload, errors: result.errors } + end + end + end + end +end diff --git a/app/graphql/mutations/customer_relations/organizations/create.rb b/app/graphql/mutations/customer_relations/organizations/create.rb index 3fa7b0327ca..bb02e1f7346 100644 --- a/app/graphql/mutations/customer_relations/organizations/create.rb +++ b/app/graphql/mutations/customer_relations/organizations/create.rb @@ -31,7 +31,7 @@ module Mutations argument :description, GraphQL::Types::String, required: false, - description: 'Description or notes for the organization.' + description: 'Description of or notes for the organization.' authorize :admin_organization diff --git a/app/graphql/mutations/customer_relations/organizations/update.rb b/app/graphql/mutations/customer_relations/organizations/update.rb index c6ae62193f9..d8eb55d77e9 100644 --- a/app/graphql/mutations/customer_relations/organizations/update.rb +++ b/app/graphql/mutations/customer_relations/organizations/update.rb @@ -32,7 +32,7 @@ module Mutations argument :description, GraphQL::Types::String, required: false, - description: 'Description or notes for the organization.' + description: 'Description of or notes for the organization.' def resolve(args) organization = ::Gitlab::Graphql::Lazy.force(GitlabSchema.object_from_id(args.delete(:id), expected_type: ::CustomerRelations::Organization)) diff --git a/app/graphql/mutations/dependency_proxy/group_settings/update.rb b/app/graphql/mutations/dependency_proxy/group_settings/update.rb new file mode 100644 index 00000000000..d10e43cde29 --- /dev/null +++ b/app/graphql/mutations/dependency_proxy/group_settings/update.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +module Mutations + module DependencyProxy + module GroupSettings + class Update < Mutations::BaseMutation + include Mutations::ResolvesGroup + + graphql_name 'UpdateDependencyProxySettings' + + authorize :admin_dependency_proxy + + argument :group_path, + GraphQL::Types::ID, + required: true, + description: 'Group path for the group dependency proxy.' + + argument :enabled, + GraphQL::Types::Boolean, + required: false, + description: copy_field_description(Types::DependencyProxy::ImageTtlGroupPolicyType, :enabled) + + field :dependency_proxy_setting, + Types::DependencyProxy::GroupSettingType, + null: true, + description: 'Group dependency proxy settings after mutation.' + + def resolve(group_path:, **args) + group = authorized_find!(group_path: group_path) + + result = ::DependencyProxy::GroupSettings::UpdateService + .new(container: group, current_user: current_user, params: args) + .execute + + { + dependency_proxy_setting: result.payload[:dependency_proxy_setting], + errors: result.errors + } + end + + private + + def find_object(group_path:) + resolve_group(full_path: group_path) + end + end + end + end +end diff --git a/app/graphql/mutations/issues/create.rb b/app/graphql/mutations/issues/create.rb index 32f96f1bfe6..70a8f539ccf 100644 --- a/app/graphql/mutations/issues/create.rb +++ b/app/graphql/mutations/issues/create.rb @@ -71,7 +71,7 @@ module Mutations def resolve(project_path:, **attributes) project = authorized_find!(project_path) - params = build_create_issue_params(attributes.merge(author_id: current_user.id)) + params = build_create_issue_params(attributes.merge(author_id: current_user.id), project) spam_params = ::Spam::SpamParams.new_from_request(request: context[:request]) issue = ::Issues::CreateService.new(project: project, current_user: current_user, params: params, spam_params: spam_params).execute @@ -88,7 +88,8 @@ module Mutations private - def build_create_issue_params(params) + # _project argument is unused here, but it is necessary on the EE version of the method + def build_create_issue_params(params, _project) params[:milestone_id] &&= params[:milestone_id]&.model_id params[:assignee_ids] &&= params[:assignee_ids].map { |assignee_id| assignee_id&.model_id } params[:label_ids] &&= params[:label_ids].map { |label_id| label_id&.model_id } -- cgit v1.2.3