From a7b3560714b4d9cc4ab32dffcd1f74a284b93580 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 18 Feb 2022 09:45:46 +0000 Subject: Add latest changes from gitlab-org/gitlab@14-8-stable-ee --- .../mutations/admin/sidekiq_queues/delete_jobs.rb | 2 +- .../alert_management/http_integration/create.rb | 4 +- .../prometheus_integration/create.rb | 4 +- app/graphql/mutations/boards/create.rb | 3 +- app/graphql/mutations/branches/create.rb | 4 +- app/graphql/mutations/ci/ci_cd_settings_update.rb | 4 +- .../mutations/ci/job_token_scope/add_project.rb | 4 +- .../mutations/ci/job_token_scope/remove_project.rb | 4 +- app/graphql/mutations/ci/runner/delete.rb | 2 +- app/graphql/mutations/ci/runner/update.rb | 7 ++- app/graphql/mutations/clusters/agents/create.rb | 4 +- app/graphql/mutations/commits/create.rb | 4 +- .../concerns/mutations/can_mutate_spammable.rb | 51 ------------------ .../container_expiration_policies/update.rb | 4 +- .../container_repositories/destroy_tags.rb | 5 +- app/graphql/mutations/custom_emoji/create.rb | 4 +- .../customer_relations/contacts/create.rb | 4 +- .../customer_relations/contacts/update.rb | 4 +- .../customer_relations/organizations/create.rb | 4 +- .../customer_relations/organizations/update.rb | 4 +- .../dependency_proxy/group_settings/update.rb | 4 +- .../image_ttl_group_policy/update.rb | 4 +- app/graphql/mutations/design_management/delete.rb | 4 +- app/graphql/mutations/groups/update.rb | 4 +- app/graphql/mutations/issues/create.rb | 19 ++++++- app/graphql/mutations/issues/set_confidential.rb | 4 +- .../mutations/issues/set_escalation_status.rb | 6 +-- app/graphql/mutations/jira_import/import_users.rb | 4 +- app/graphql/mutations/jira_import/start.rb | 4 +- app/graphql/mutations/labels/create.rb | 4 +- app/graphql/mutations/merge_requests/accept.rb | 12 ++--- app/graphql/mutations/merge_requests/create.rb | 4 +- .../mutations/namespace/package_settings/update.rb | 4 +- .../mutations/release_asset_links/create.rb | 7 ++- app/graphql/mutations/snippets/create.rb | 5 +- app/graphql/mutations/snippets/update.rb | 5 +- app/graphql/mutations/user_preferences/update.rb | 28 ++++++++++ app/graphql/mutations/work_items/create.rb | 18 +++++-- app/graphql/mutations/work_items/delete.rb | 47 +++++++++++++++++ app/graphql/mutations/work_items/update.rb | 61 ++++++++++++++++++++++ 40 files changed, 241 insertions(+), 133 deletions(-) delete mode 100644 app/graphql/mutations/concerns/mutations/can_mutate_spammable.rb create mode 100644 app/graphql/mutations/user_preferences/update.rb create mode 100644 app/graphql/mutations/work_items/delete.rb create mode 100644 app/graphql/mutations/work_items/update.rb (limited to 'app/graphql/mutations') diff --git a/app/graphql/mutations/admin/sidekiq_queues/delete_jobs.rb b/app/graphql/mutations/admin/sidekiq_queues/delete_jobs.rb index c4f91d0c15c..b1db355aa40 100644 --- a/app/graphql/mutations/admin/sidekiq_queues/delete_jobs.rb +++ b/app/graphql/mutations/admin/sidekiq_queues/delete_jobs.rb @@ -8,7 +8,7 @@ module Mutations ADMIN_MESSAGE = 'You must be an admin to use this mutation' - ::Gitlab::ApplicationContext::KNOWN_KEYS.each do |key| + ::Gitlab::ApplicationContext.known_keys.each do |key| argument key, GraphQL::Types::String, required: false, diff --git a/app/graphql/mutations/alert_management/http_integration/create.rb b/app/graphql/mutations/alert_management/http_integration/create.rb index 04840ac43bd..f8d1a383706 100644 --- a/app/graphql/mutations/alert_management/http_integration/create.rb +++ b/app/graphql/mutations/alert_management/http_integration/create.rb @@ -4,10 +4,10 @@ module Mutations module AlertManagement module HttpIntegration class Create < HttpIntegrationBase - include FindsProject - graphql_name 'HttpIntegrationCreate' + include FindsProject + argument :project_path, GraphQL::Types::ID, required: true, description: 'Project to create the integration in.' diff --git a/app/graphql/mutations/alert_management/prometheus_integration/create.rb b/app/graphql/mutations/alert_management/prometheus_integration/create.rb index 0153bd0e42a..9c3aefce033 100644 --- a/app/graphql/mutations/alert_management/prometheus_integration/create.rb +++ b/app/graphql/mutations/alert_management/prometheus_integration/create.rb @@ -4,10 +4,10 @@ module Mutations module AlertManagement module PrometheusIntegration class Create < PrometheusIntegrationBase - include FindsProject - graphql_name 'PrometheusIntegrationCreate' + include FindsProject + argument :project_path, GraphQL::Types::ID, required: true, description: 'Project to create the integration in.' diff --git a/app/graphql/mutations/boards/create.rb b/app/graphql/mutations/boards/create.rb index 080bf7c6e79..773ba08a291 100644 --- a/app/graphql/mutations/boards/create.rb +++ b/app/graphql/mutations/boards/create.rb @@ -3,10 +3,9 @@ module Mutations module Boards class Create < ::Mutations::BaseMutation - include Mutations::ResolvesResourceParent - graphql_name 'CreateBoard' + include Mutations::ResolvesResourceParent include Mutations::Boards::CommonMutationArguments field :board, diff --git a/app/graphql/mutations/branches/create.rb b/app/graphql/mutations/branches/create.rb index 078c84bcdc0..b851622bfde 100644 --- a/app/graphql/mutations/branches/create.rb +++ b/app/graphql/mutations/branches/create.rb @@ -3,10 +3,10 @@ module Mutations module Branches class Create < BaseMutation - include FindsProject - graphql_name 'CreateBranch' + include FindsProject + argument :project_path, GraphQL::Types::ID, required: true, description: 'Project full path the branch is associated with.' diff --git a/app/graphql/mutations/ci/ci_cd_settings_update.rb b/app/graphql/mutations/ci/ci_cd_settings_update.rb index 7bd38bc2998..dec90ced962 100644 --- a/app/graphql/mutations/ci/ci_cd_settings_update.rb +++ b/app/graphql/mutations/ci/ci_cd_settings_update.rb @@ -3,10 +3,10 @@ module Mutations module Ci class CiCdSettingsUpdate < BaseMutation - include FindsProject - graphql_name 'CiCdSettingsUpdate' + include FindsProject + authorize :admin_project argument :full_path, GraphQL::Types::ID, diff --git a/app/graphql/mutations/ci/job_token_scope/add_project.rb b/app/graphql/mutations/ci/job_token_scope/add_project.rb index 41adcae2c82..e16c08cb116 100644 --- a/app/graphql/mutations/ci/job_token_scope/add_project.rb +++ b/app/graphql/mutations/ci/job_token_scope/add_project.rb @@ -4,10 +4,10 @@ module Mutations module Ci module JobTokenScope class AddProject < BaseMutation - include FindsProject - graphql_name 'CiJobTokenScopeAddProject' + include FindsProject + authorize :admin_project argument :project_path, GraphQL::Types::ID, diff --git a/app/graphql/mutations/ci/job_token_scope/remove_project.rb b/app/graphql/mutations/ci/job_token_scope/remove_project.rb index dd6b2358dd5..f503b4f2f7a 100644 --- a/app/graphql/mutations/ci/job_token_scope/remove_project.rb +++ b/app/graphql/mutations/ci/job_token_scope/remove_project.rb @@ -4,10 +4,10 @@ module Mutations module Ci module JobTokenScope class RemoveProject < BaseMutation - include FindsProject - graphql_name 'CiJobTokenScopeRemoveProject' + include FindsProject + authorize :admin_project argument :project_path, GraphQL::Types::ID, diff --git a/app/graphql/mutations/ci/runner/delete.rb b/app/graphql/mutations/ci/runner/delete.rb index 88dc426398b..21c3d55881c 100644 --- a/app/graphql/mutations/ci/runner/delete.rb +++ b/app/graphql/mutations/ci/runner/delete.rb @@ -20,7 +20,7 @@ module Mutations error = authenticate_delete_runner!(runner) return { errors: [error] } if error - runner.destroy! + ::Ci::UnregisterRunnerService.new(runner).execute { errors: runner.errors.full_messages } end diff --git a/app/graphql/mutations/ci/runner/update.rb b/app/graphql/mutations/ci/runner/update.rb index e37ab1081f9..e6123b4283a 100644 --- a/app/graphql/mutations/ci/runner/update.rb +++ b/app/graphql/mutations/ci/runner/update.rb @@ -28,7 +28,12 @@ module Mutations argument :active, GraphQL::Types::Boolean, required: false, - description: 'Indicates the runner is allowed to receive jobs.' + description: 'Indicates the runner is allowed to receive jobs.', + deprecated: { reason: :renamed, replacement: 'paused', milestone: '14.8' } + + argument :paused, GraphQL::Types::Boolean, + required: false, + description: 'Indicates the runner is not allowed to receive jobs.' argument :locked, GraphQL::Types::Boolean, required: false, description: 'Indicates the runner is locked.' diff --git a/app/graphql/mutations/clusters/agents/create.rb b/app/graphql/mutations/clusters/agents/create.rb index 0896cc7b203..deaa9c2d656 100644 --- a/app/graphql/mutations/clusters/agents/create.rb +++ b/app/graphql/mutations/clusters/agents/create.rb @@ -4,12 +4,12 @@ module Mutations module Clusters module Agents class Create < BaseMutation + graphql_name 'CreateClusterAgent' + 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.' diff --git a/app/graphql/mutations/commits/create.rb b/app/graphql/mutations/commits/create.rb index 3eb1912dbc4..00ec64becc8 100644 --- a/app/graphql/mutations/commits/create.rb +++ b/app/graphql/mutations/commits/create.rb @@ -3,6 +3,8 @@ module Mutations module Commits class Create < BaseMutation + graphql_name 'CommitCreate' + include FindsProject class UrlHelpers @@ -10,8 +12,6 @@ module Mutations include Gitlab::Routing end - graphql_name 'CommitCreate' - argument :project_path, GraphQL::Types::ID, required: true, description: 'Project full path the branch is associated with.' diff --git a/app/graphql/mutations/concerns/mutations/can_mutate_spammable.rb b/app/graphql/mutations/concerns/mutations/can_mutate_spammable.rb deleted file mode 100644 index f1ae54aa014..00000000000 --- a/app/graphql/mutations/concerns/mutations/can_mutate_spammable.rb +++ /dev/null @@ -1,51 +0,0 @@ -# frozen_string_literal: true - -module Mutations - # This concern is deprecated and will be deleted in 14.6 - # - # Use the SpamProtection concern instead. - module CanMutateSpammable - extend ActiveSupport::Concern - - DEPRECATION_NOTICE = { - reason: 'Use spam protection with HTTP headers instead', - milestone: '13.11' - }.freeze - - included do - argument :captcha_response, GraphQL::Types::String, - required: false, - deprecated: DEPRECATION_NOTICE, - description: 'Valid CAPTCHA response value obtained by using the provided captchaSiteKey with a CAPTCHA API to present a challenge to be solved on the client. Required to resubmit if the previous operation returned "NeedsCaptchaResponse: true".' - - argument :spam_log_id, GraphQL::Types::Int, - required: false, - deprecated: DEPRECATION_NOTICE, - description: 'Spam log ID which must be passed along with a valid CAPTCHA response for the operation to be completed. Required to resubmit if the previous operation returned "NeedsCaptchaResponse: true".' - - field :spam, - GraphQL::Types::Boolean, - null: true, - deprecated: DEPRECATION_NOTICE, - description: 'Indicates whether the operation was detected as definite spam. There is no option to resubmit the request with a CAPTCHA response.' - - field :needs_captcha_response, - GraphQL::Types::Boolean, - null: true, - deprecated: DEPRECATION_NOTICE, - description: 'Indicates whether the operation was detected as possible spam and not completed. If CAPTCHA is enabled, the request must be resubmitted with a valid CAPTCHA response and spam_log_id included for the operation to be completed. Included only when an operation was not completed because "NeedsCaptchaResponse" is true.' - - field :spam_log_id, - GraphQL::Types::Int, - null: true, - deprecated: DEPRECATION_NOTICE, - description: 'Spam log ID which must be passed along with a valid CAPTCHA response for an operation to be completed. Included only when an operation was not completed because "NeedsCaptchaResponse" is true.' - - field :captcha_site_key, - GraphQL::Types::String, - null: true, - deprecated: DEPRECATION_NOTICE, - description: 'CAPTCHA site key which must be used to render a challenge for the user to solve to obtain a valid captchaResponse value. Included only when an operation was not completed because "NeedsCaptchaResponse" is true.' - end - end -end diff --git a/app/graphql/mutations/container_expiration_policies/update.rb b/app/graphql/mutations/container_expiration_policies/update.rb index db4acadfc38..762058acf3d 100644 --- a/app/graphql/mutations/container_expiration_policies/update.rb +++ b/app/graphql/mutations/container_expiration_policies/update.rb @@ -3,10 +3,10 @@ module Mutations module ContainerExpirationPolicies class Update < Mutations::BaseMutation - include FindsProject - graphql_name 'UpdateContainerExpirationPolicy' + include FindsProject + authorize :destroy_container_image argument :project_path, diff --git a/app/graphql/mutations/container_repositories/destroy_tags.rb b/app/graphql/mutations/container_repositories/destroy_tags.rb index c2737820d22..7777f903516 100644 --- a/app/graphql/mutations/container_repositories/destroy_tags.rb +++ b/app/graphql/mutations/container_repositories/destroy_tags.rb @@ -3,12 +3,11 @@ module Mutations module ContainerRepositories class DestroyTags < ::Mutations::ContainerRepositories::DestroyBase - LIMIT = 20 + graphql_name 'DestroyContainerRepositoryTags' + LIMIT = 20 TOO_MANY_TAGS_ERROR_MESSAGE = "Number of tags is greater than #{LIMIT}" - graphql_name 'DestroyContainerRepositoryTags' - authorize :destroy_container_image argument :id, diff --git a/app/graphql/mutations/custom_emoji/create.rb b/app/graphql/mutations/custom_emoji/create.rb index ad392d6c814..269ea6c9999 100644 --- a/app/graphql/mutations/custom_emoji/create.rb +++ b/app/graphql/mutations/custom_emoji/create.rb @@ -3,10 +3,10 @@ module Mutations module CustomEmoji class Create < BaseMutation - include Mutations::ResolvesGroup - graphql_name 'CreateCustomEmoji' + include Mutations::ResolvesGroup + authorize :create_custom_emoji field :custom_emoji, diff --git a/app/graphql/mutations/customer_relations/contacts/create.rb b/app/graphql/mutations/customer_relations/contacts/create.rb index 3495f30f227..96dc047c3db 100644 --- a/app/graphql/mutations/customer_relations/contacts/create.rb +++ b/app/graphql/mutations/customer_relations/contacts/create.rb @@ -4,11 +4,11 @@ module Mutations module CustomerRelations module Contacts class Create < BaseMutation + graphql_name 'CustomerRelationsContactCreate' + include ResolvesIds include Gitlab::Graphql::Authorize::AuthorizeResource - graphql_name 'CustomerRelationsContactCreate' - field :contact, Types::CustomerRelations::ContactType, null: true, diff --git a/app/graphql/mutations/customer_relations/contacts/update.rb b/app/graphql/mutations/customer_relations/contacts/update.rb index e2f671058f0..a3abf37f21f 100644 --- a/app/graphql/mutations/customer_relations/contacts/update.rb +++ b/app/graphql/mutations/customer_relations/contacts/update.rb @@ -4,10 +4,10 @@ module Mutations module CustomerRelations module Contacts class Update < Mutations::BaseMutation - include ResolvesIds - graphql_name 'CustomerRelationsContactUpdate' + include ResolvesIds + authorize :admin_crm_contact field :contact, diff --git a/app/graphql/mutations/customer_relations/organizations/create.rb b/app/graphql/mutations/customer_relations/organizations/create.rb index 17e0e9ad459..43c50a9fb30 100644 --- a/app/graphql/mutations/customer_relations/organizations/create.rb +++ b/app/graphql/mutations/customer_relations/organizations/create.rb @@ -4,11 +4,11 @@ module Mutations module CustomerRelations module Organizations class Create < BaseMutation + graphql_name 'CustomerRelationsOrganizationCreate' + include ResolvesIds include Gitlab::Graphql::Authorize::AuthorizeResource - graphql_name 'CustomerRelationsOrganizationCreate' - field :organization, Types::CustomerRelations::OrganizationType, null: true, diff --git a/app/graphql/mutations/customer_relations/organizations/update.rb b/app/graphql/mutations/customer_relations/organizations/update.rb index 21fcf565239..0c05541dbd7 100644 --- a/app/graphql/mutations/customer_relations/organizations/update.rb +++ b/app/graphql/mutations/customer_relations/organizations/update.rb @@ -4,10 +4,10 @@ module Mutations module CustomerRelations module Organizations class Update < Mutations::BaseMutation - include ResolvesIds - graphql_name 'CustomerRelationsOrganizationUpdate' + include ResolvesIds + authorize :admin_crm_organization field :organization, diff --git a/app/graphql/mutations/dependency_proxy/group_settings/update.rb b/app/graphql/mutations/dependency_proxy/group_settings/update.rb index d10e43cde29..65c919db3c3 100644 --- a/app/graphql/mutations/dependency_proxy/group_settings/update.rb +++ b/app/graphql/mutations/dependency_proxy/group_settings/update.rb @@ -4,10 +4,10 @@ module Mutations module DependencyProxy module GroupSettings class Update < Mutations::BaseMutation - include Mutations::ResolvesGroup - graphql_name 'UpdateDependencyProxySettings' + include Mutations::ResolvesGroup + authorize :admin_dependency_proxy argument :group_path, diff --git a/app/graphql/mutations/dependency_proxy/image_ttl_group_policy/update.rb b/app/graphql/mutations/dependency_proxy/image_ttl_group_policy/update.rb index a5eb114b2da..79d7a93c4e2 100644 --- a/app/graphql/mutations/dependency_proxy/image_ttl_group_policy/update.rb +++ b/app/graphql/mutations/dependency_proxy/image_ttl_group_policy/update.rb @@ -4,10 +4,10 @@ module Mutations module DependencyProxy module ImageTtlGroupPolicy class Update < Mutations::BaseMutation - include Mutations::ResolvesGroup - graphql_name 'UpdateDependencyProxyImageTtlGroupPolicy' + include Mutations::ResolvesGroup + authorize :admin_dependency_proxy argument :group_path, diff --git a/app/graphql/mutations/design_management/delete.rb b/app/graphql/mutations/design_management/delete.rb index 4e9f0aad934..9e643110628 100644 --- a/app/graphql/mutations/design_management/delete.rb +++ b/app/graphql/mutations/design_management/delete.rb @@ -3,10 +3,10 @@ module Mutations module DesignManagement class Delete < Base - Errors = ::Gitlab::Graphql::Errors - graphql_name "DesignManagementDelete" + Errors = ::Gitlab::Graphql::Errors + argument :filenames, [GraphQL::Types::String], required: true, description: "Filenames of the designs to delete.", diff --git a/app/graphql/mutations/groups/update.rb b/app/graphql/mutations/groups/update.rb index 9c5628a57cd..be7a14d0b43 100644 --- a/app/graphql/mutations/groups/update.rb +++ b/app/graphql/mutations/groups/update.rb @@ -3,10 +3,10 @@ module Mutations module Groups class Update < Mutations::BaseMutation - include Mutations::ResolvesGroup - graphql_name 'GroupUpdate' + include Mutations::ResolvesGroup + authorize :admin_group field :group, Types::GroupType, diff --git a/app/graphql/mutations/issues/create.rb b/app/graphql/mutations/issues/create.rb index 72b03cc27c2..6bf8caf82d7 100644 --- a/app/graphql/mutations/issues/create.rb +++ b/app/graphql/mutations/issues/create.rb @@ -3,12 +3,12 @@ module Mutations module Issues class Create < BaseMutation + graphql_name 'CreateIssue' + include Mutations::SpamProtection include FindsProject include CommonMutationArguments - graphql_name 'CreateIssue' - authorize :create_issue argument :project_path, GraphQL::Types::ID, @@ -51,6 +51,14 @@ module Mutations required: false, description: 'Array of user IDs to assign to the issue.' + argument :move_before_id, ::Types::GlobalIDType[::Issue], + required: false, + description: 'Global ID of issue that should be placed before the current issue.' + + argument :move_after_id, ::Types::GlobalIDType[::Issue], + required: false, + description: 'Global ID of issue that should be placed after the current issue.' + field :issue, Types::IssueType, null: true, @@ -93,6 +101,13 @@ module Mutations 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 } + if params[:move_before_id].present? || params[:move_after_id].present? + params[:move_between_ids] = [ + params.delete(:move_before_id)&.model_id, + params.delete(:move_after_id)&.model_id + ] + end + params end diff --git a/app/graphql/mutations/issues/set_confidential.rb b/app/graphql/mutations/issues/set_confidential.rb index 35e629ddc90..abfd6fec0bd 100644 --- a/app/graphql/mutations/issues/set_confidential.rb +++ b/app/graphql/mutations/issues/set_confidential.rb @@ -3,10 +3,10 @@ module Mutations module Issues class SetConfidential < Base - include Mutations::SpamProtection - graphql_name 'IssueSetConfidential' + include Mutations::SpamProtection + argument :confidential, GraphQL::Types::Boolean, required: true, diff --git a/app/graphql/mutations/issues/set_escalation_status.rb b/app/graphql/mutations/issues/set_escalation_status.rb index 6073b73277b..4f3fcb4886d 100644 --- a/app/graphql/mutations/issues/set_escalation_status.rb +++ b/app/graphql/mutations/issues/set_escalation_status.rb @@ -14,7 +14,7 @@ module Mutations project = issue.project authorize_escalation_status!(project) - check_feature_availability!(project, issue) + check_feature_availability!(issue) ::Issues::UpdateService.new( project: project, @@ -36,8 +36,8 @@ module Mutations raise_resource_not_available_error! end - def check_feature_availability!(project, issue) - return if Feature.enabled?(:incident_escalations, project) && issue.supports_escalation? + def check_feature_availability!(issue) + return if issue.supports_escalation? raise Gitlab::Graphql::Errors::ResourceNotAvailable, 'Feature unavailable for provided issue' end diff --git a/app/graphql/mutations/jira_import/import_users.rb b/app/graphql/mutations/jira_import/import_users.rb index 8d82a058dd0..b3874caee61 100644 --- a/app/graphql/mutations/jira_import/import_users.rb +++ b/app/graphql/mutations/jira_import/import_users.rb @@ -3,10 +3,10 @@ module Mutations module JiraImport class ImportUsers < BaseMutation - include FindsProject - graphql_name 'JiraImportUsers' + include FindsProject + authorize :admin_project field :jira_users, diff --git a/app/graphql/mutations/jira_import/start.rb b/app/graphql/mutations/jira_import/start.rb index 4929d6f394a..ea071c45bcf 100644 --- a/app/graphql/mutations/jira_import/start.rb +++ b/app/graphql/mutations/jira_import/start.rb @@ -3,10 +3,10 @@ module Mutations module JiraImport class Start < BaseMutation - include FindsProject - graphql_name 'JiraImportStart' + include FindsProject + authorize :admin_project field :jira_import, diff --git a/app/graphql/mutations/labels/create.rb b/app/graphql/mutations/labels/create.rb index cb3ba7939ae..3cd41dc01de 100644 --- a/app/graphql/mutations/labels/create.rb +++ b/app/graphql/mutations/labels/create.rb @@ -3,10 +3,10 @@ module Mutations module Labels class Create < BaseMutation - include Mutations::ResolvesResourceParent - graphql_name 'LabelCreate' + include Mutations::ResolvesResourceParent + field :label, Types::LabelType, null: true, diff --git a/app/graphql/mutations/merge_requests/accept.rb b/app/graphql/mutations/merge_requests/accept.rb index 7ce850901af..ebd9e2b8fdd 100644 --- a/app/graphql/mutations/merge_requests/accept.rb +++ b/app/graphql/mutations/merge_requests/accept.rb @@ -3,12 +3,6 @@ module Mutations module MergeRequests class Accept < Base - NOT_MERGEABLE = 'This branch cannot be merged' - HOOKS_VALIDATION_ERROR = 'Pre-merge hooks failed' - SHA_MISMATCH = 'The merge-head is not at the anticipated SHA' - MERGE_FAILED = 'The merge failed' - ALREADY_SCHEDULED = 'The merge request is already scheduled to be merged' - graphql_name 'MergeRequestAccept' authorize :accept_merge_request description <<~DESC @@ -17,6 +11,12 @@ module Mutations immediately if possible, or using one of the automatic merge strategies. DESC + NOT_MERGEABLE = 'This branch cannot be merged' + HOOKS_VALIDATION_ERROR = 'Pre-merge hooks failed' + SHA_MISMATCH = 'The merge-head is not at the anticipated SHA' + MERGE_FAILED = 'The merge failed' + ALREADY_SCHEDULED = 'The merge request is already scheduled to be merged' + argument :strategy, ::Types::MergeStrategyEnum, required: false, diff --git a/app/graphql/mutations/merge_requests/create.rb b/app/graphql/mutations/merge_requests/create.rb index dc1d5a22bc9..2883c02a671 100644 --- a/app/graphql/mutations/merge_requests/create.rb +++ b/app/graphql/mutations/merge_requests/create.rb @@ -3,10 +3,10 @@ module Mutations module MergeRequests class Create < BaseMutation - include FindsProject - graphql_name 'MergeRequestCreate' + include FindsProject + argument :project_path, GraphQL::Types::ID, required: true, description: 'Project full path the merge request is associated with.' diff --git a/app/graphql/mutations/namespace/package_settings/update.rb b/app/graphql/mutations/namespace/package_settings/update.rb index 400169d6b64..934b75193d7 100644 --- a/app/graphql/mutations/namespace/package_settings/update.rb +++ b/app/graphql/mutations/namespace/package_settings/update.rb @@ -4,10 +4,10 @@ module Mutations module Namespace module PackageSettings class Update < Mutations::BaseMutation - include Mutations::ResolvesNamespace - graphql_name 'UpdateNamespacePackageSettings' + include Mutations::ResolvesNamespace + authorize :create_package_settings argument :namespace_path, diff --git a/app/graphql/mutations/release_asset_links/create.rb b/app/graphql/mutations/release_asset_links/create.rb index db486640507..f6445514ce9 100644 --- a/app/graphql/mutations/release_asset_links/create.rb +++ b/app/graphql/mutations/release_asset_links/create.rb @@ -3,14 +3,13 @@ module Mutations module ReleaseAssetLinks class Create < BaseMutation - include FindsProject - graphql_name 'ReleaseAssetLinkCreate' - authorize :create_release - + include FindsProject include Types::ReleaseAssetLinkSharedInputArguments + authorize :create_release + argument :project_path, GraphQL::Types::ID, required: true, description: 'Full path of the project the asset link is associated with.' diff --git a/app/graphql/mutations/snippets/create.rb b/app/graphql/mutations/snippets/create.rb index c01b0e4a01b..2921a77b86d 100644 --- a/app/graphql/mutations/snippets/create.rb +++ b/app/graphql/mutations/snippets/create.rb @@ -3,14 +3,13 @@ module Mutations module Snippets class Create < BaseMutation + graphql_name 'CreateSnippet' + include ServiceCompatibility - include CanMutateSpammable include Mutations::SpamProtection authorize :create_snippet - graphql_name 'CreateSnippet' - field :snippet, Types::SnippetType, null: true, diff --git a/app/graphql/mutations/snippets/update.rb b/app/graphql/mutations/snippets/update.rb index 9ecaa8d4bf2..2a2941c5328 100644 --- a/app/graphql/mutations/snippets/update.rb +++ b/app/graphql/mutations/snippets/update.rb @@ -3,12 +3,11 @@ module Mutations module Snippets class Update < Base + graphql_name 'UpdateSnippet' + include ServiceCompatibility - include CanMutateSpammable include Mutations::SpamProtection - graphql_name 'UpdateSnippet' - argument :id, ::Types::GlobalIDType[::Snippet], required: true, description: 'Global ID of the snippet to update.' diff --git a/app/graphql/mutations/user_preferences/update.rb b/app/graphql/mutations/user_preferences/update.rb new file mode 100644 index 00000000000..c92c6d725b7 --- /dev/null +++ b/app/graphql/mutations/user_preferences/update.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +module Mutations + module UserPreferences + class Update < BaseMutation + graphql_name 'UserPreferencesUpdate' + + argument :issues_sort, Types::IssueSortEnum, + required: false, + description: 'Sort order for issue lists.' + + field :user_preferences, + Types::UserPreferencesType, + null: true, + description: 'User preferences after mutation.' + + def resolve(**attributes) + user_preferences = current_user.user_preference + user_preferences.update(attributes) + + { + user_preferences: user_preferences.valid? ? user_preferences : nil, + errors: errors_on_object(user_preferences) + } + end + end + end +end diff --git a/app/graphql/mutations/work_items/create.rb b/app/graphql/mutations/work_items/create.rb index 88b8cefd8d2..81454db62b1 100644 --- a/app/graphql/mutations/work_items/create.rb +++ b/app/graphql/mutations/work_items/create.rb @@ -3,10 +3,13 @@ module Mutations module WorkItems class Create < BaseMutation + graphql_name 'WorkItemCreate' + include Mutations::SpamProtection include FindsProject - graphql_name 'WorkItemCreate' + description "Creates a work item." \ + " Available only when feature flag `work_items` is enabled. The feature is experimental and is subject to change without notice." authorize :create_work_item @@ -29,16 +32,21 @@ module Mutations def resolve(project_path:, **attributes) project = authorized_find!(project_path) + + unless Feature.enabled?(:work_items, project) + return { errors: ['`work_items` feature flag disabled for this project'] } + end + params = global_id_compatibility_params(attributes).merge(author_id: current_user.id) spam_params = ::Spam::SpamParams.new_from_request(request: context[:request]) - work_item = ::WorkItems::CreateService.new(project: project, current_user: current_user, params: params, spam_params: spam_params).execute + create_result = ::WorkItems::CreateService.new(project: project, current_user: current_user, params: params, spam_params: spam_params).execute - check_spam_action_response!(work_item) + check_spam_action_response!(create_result[:work_item]) if create_result[:work_item] { - work_item: work_item.valid? ? work_item : nil, - errors: errors_on_object(work_item) + work_item: create_result.success? ? create_result[:work_item] : nil, + errors: create_result.errors } end diff --git a/app/graphql/mutations/work_items/delete.rb b/app/graphql/mutations/work_items/delete.rb new file mode 100644 index 00000000000..71792a802c0 --- /dev/null +++ b/app/graphql/mutations/work_items/delete.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +module Mutations + module WorkItems + class Delete < BaseMutation + graphql_name 'WorkItemDelete' + description "Deletes a work item." \ + " Available only when feature flag `work_items` is enabled. The feature is experimental and is subject to change without notice." + + authorize :delete_work_item + + argument :id, ::Types::GlobalIDType[::WorkItem], + required: true, + description: 'Global ID of the work item.' + + field :project, Types::ProjectType, + null: true, + description: 'Project the deleted work item belonged to.' + + def resolve(id:) + work_item = authorized_find!(id: id) + + unless Feature.enabled?(:work_items, work_item.project) + return { errors: ['`work_items` feature flag disabled for this project'] } + end + + result = ::WorkItems::DeleteService.new( + project: work_item.project, + current_user: current_user + ).execute(work_item) + + { + project: result.success? ? work_item.project : nil, + errors: result.errors + } + end + + private + + def find_object(id:) + # TODO: Remove coercion when working on https://gitlab.com/gitlab-org/gitlab/-/issues/257883 + id = ::Types::GlobalIDType[::WorkItem].coerce_isolated_input(id) + GitlabSchema.find_by_gid(id) + end + end + end +end diff --git a/app/graphql/mutations/work_items/update.rb b/app/graphql/mutations/work_items/update.rb new file mode 100644 index 00000000000..3ab9ba2d502 --- /dev/null +++ b/app/graphql/mutations/work_items/update.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +module Mutations + module WorkItems + class Update < BaseMutation + graphql_name 'WorkItemUpdate' + description "Updates a work item by Global ID." \ + " Available only when feature flag `work_items` is enabled. The feature is experimental and is subject to change without notice." + + include Mutations::SpamProtection + + authorize :update_work_item + + argument :id, ::Types::GlobalIDType[::WorkItem], + required: true, + description: 'Global ID of the work item.' + argument :state_event, Types::WorkItems::StateEventEnum, + description: 'Close or reopen a work item.', + required: false + argument :title, GraphQL::Types::String, + required: false, + description: copy_field_description(Types::WorkItemType, :title) + + field :work_item, Types::WorkItemType, + null: true, + description: 'Updated work item.' + + def resolve(id:, **attributes) + work_item = authorized_find!(id: id) + + unless Feature.enabled?(:work_items, work_item.project) + return { errors: ['`work_items` feature flag disabled for this project'] } + end + + spam_params = ::Spam::SpamParams.new_from_request(request: context[:request]) + + ::WorkItems::UpdateService.new( + project: work_item.project, + current_user: current_user, + params: attributes, + spam_params: spam_params + ).execute(work_item) + + check_spam_action_response!(work_item) + + { + work_item: work_item.valid? ? work_item : nil, + errors: errors_on_object(work_item) + } + end + + private + + def find_object(id:) + # TODO: Remove coercion when working on https://gitlab.com/gitlab-org/gitlab/-/issues/257883 + id = ::Types::GlobalIDType[::WorkItem].coerce_isolated_input(id) + GitlabSchema.find_by_gid(id) + end + end + end +end -- cgit v1.2.3