diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-20 13:43:29 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-20 13:43:29 +0300 |
commit | 3b1af5cc7ed2666ff18b718ce5d30fa5a2756674 (patch) | |
tree | 3bc4a40e0ee51ec27eabf917c537033c0c5b14d4 /app/graphql/mutations | |
parent | 9bba14be3f2c211bf79e15769cd9b77bc73a13bc (diff) |
Add latest changes from gitlab-org/gitlab@16-1-stable-eev16.1.0-rc42
Diffstat (limited to 'app/graphql/mutations')
23 files changed, 257 insertions, 65 deletions
diff --git a/app/graphql/mutations/achievements/delete_user_achievement.rb b/app/graphql/mutations/achievements/delete_user_achievement.rb new file mode 100644 index 00000000000..f1527c2981a --- /dev/null +++ b/app/graphql/mutations/achievements/delete_user_achievement.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +module Mutations + module Achievements + class DeleteUserAchievement < BaseMutation + graphql_name 'UserAchievementsDelete' + + include Gitlab::Graphql::Authorize::AuthorizeResource + + field :user_achievement, + ::Types::Achievements::UserAchievementType, + null: true, + description: 'Deleted user achievement.' + + argument :user_achievement_id, ::Types::GlobalIDType[::Achievements::UserAchievement], + required: true, + description: 'Global ID of the user achievement being deleted.' + + authorize :destroy_user_achievement + + def resolve(args) + user_achievement = authorized_find!(id: args[:user_achievement_id]) + + result = ::Achievements::DestroyUserAchievementService.new(current_user, user_achievement).execute + { user_achievement: result.payload, errors: result.errors } + end + + def find_object(id:) + GitlabSchema.object_from_id(id, expected_type: ::Achievements::UserAchievement) + end + end + end +end diff --git a/app/graphql/mutations/ci/ci_cd_settings_update.rb b/app/graphql/mutations/ci/ci_cd_settings_update.rb deleted file mode 100644 index a7d99d2a496..00000000000 --- a/app/graphql/mutations/ci/ci_cd_settings_update.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -module Mutations - module Ci - # TODO: Remove after 16.0, see https://gitlab.com/gitlab-org/gitlab/-/issues/361801#note_1373963840 - class CiCdSettingsUpdate < ProjectCiCdSettingsUpdate - graphql_name 'CiCdSettingsUpdate' - - def ready?(**args) - raise Gitlab::Graphql::Errors::ResourceNotAvailable, '`remove_cicd_settings_update` feature flag is enabled.' \ - if Feature.enabled?(:remove_cicd_settings_update) - - super - end - end - end -end diff --git a/app/graphql/mutations/ci/job_artifact/bulk_destroy.rb b/app/graphql/mutations/ci/job_artifact/bulk_destroy.rb index 53036496de4..1ef59fbeba4 100644 --- a/app/graphql/mutations/ci/job_artifact/bulk_destroy.rb +++ b/app/graphql/mutations/ci/job_artifact/bulk_destroy.rb @@ -38,11 +38,6 @@ module Mutations project = authorized_find!(id: project_id) - if Feature.disabled?(:ci_job_artifact_bulk_destroy, project) - raise Gitlab::Graphql::Errors::ResourceNotAvailable, - '`ci_job_artifact_bulk_destroy` feature flag is disabled.' - end - raise Gitlab::Graphql::Errors::ArgumentError, 'IDs array of job artifacts can not be empty' if ids.empty? result = ::Ci::JobArtifacts::BulkDeleteByProjectService.new( diff --git a/app/graphql/mutations/ci/pipeline/cancel.rb b/app/graphql/mutations/ci/pipeline/cancel.rb index c52e3b4f4b8..810f458fd75 100644 --- a/app/graphql/mutations/ci/pipeline/cancel.rb +++ b/app/graphql/mutations/ci/pipeline/cancel.rb @@ -11,12 +11,12 @@ module Mutations def resolve(id:) pipeline = authorized_find!(id: id) - if pipeline.cancelable? - pipeline.cancel_running + result = ::Ci::CancelPipelineService.new(pipeline: pipeline, current_user: current_user).execute + if result.success? { success: true, errors: [] } else - { success: false, errors: ['Pipeline is not cancelable'] } + { success: false, errors: [result.message] } end end end diff --git a/app/graphql/mutations/dependency_proxy/group_settings/update.rb b/app/graphql/mutations/dependency_proxy/group_settings/update.rb index 6be07edd883..ee510373f34 100644 --- a/app/graphql/mutations/dependency_proxy/group_settings/update.rb +++ b/app/graphql/mutations/dependency_proxy/group_settings/update.rb @@ -8,10 +8,11 @@ module Mutations include Mutations::ResolvesGroup - description 'These settings can be adjusted by the group Owner or Maintainer. However, in GitLab 16.0, we ' \ - 'will be limiting this to the Owner role. ' \ - '[GitLab-#364441](https://gitlab.com/gitlab-org/gitlab/-/issues/364441) proposes making ' \ - 'this change to match the permissions level in the user interface.' + description <<~DESC + These settings can be adjusted by the group Owner or Maintainer. + [Issue 370471](https://gitlab.com/gitlab-org/gitlab/-/issues/370471) proposes limiting + this to Owners only to match the permissions level in the user interface. + DESC authorize :admin_dependency_proxy 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 79d7a93c4e2..0759b8e1beb 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 @@ -8,6 +8,12 @@ module Mutations include Mutations::ResolvesGroup + description <<~DESC + These settings can be adjusted by the group Owner or Maintainer. + [Issue 370471](https://gitlab.com/gitlab-org/gitlab/-/issues/370471) proposes limiting + this to Owners only to match the permissions level in the user interface. + DESC + authorize :admin_dependency_proxy argument :group_path, diff --git a/app/graphql/mutations/environments/create.rb b/app/graphql/mutations/environments/create.rb new file mode 100644 index 00000000000..271585eb06c --- /dev/null +++ b/app/graphql/mutations/environments/create.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +module Mutations + module Environments + class Create < ::Mutations::BaseMutation + graphql_name 'EnvironmentCreate' + description 'Create an environment.' + + include FindsProject + + authorize :create_environment + + argument :project_path, + GraphQL::Types::ID, + required: true, + description: 'Full path of the project.' + + argument :name, + GraphQL::Types::String, + required: true, + description: 'Name of the environment.' + + argument :external_url, + GraphQL::Types::String, + required: false, + description: 'External URL of the environment.' + + argument :tier, + Types::DeploymentTierEnum, + required: false, + description: 'Tier of the environment.' + + argument :cluster_agent_id, + ::Types::GlobalIDType[::Clusters::Agent], + required: false, + description: 'Cluster agent of the environment.' + + field :environment, + Types::EnvironmentType, + null: true, + description: 'Created environment.' + + def resolve(project_path:, **kwargs) + project = authorized_find!(project_path) + + kwargs[:cluster_agent] = GitlabSchema.find_by_gid(kwargs.delete(:cluster_agent_id))&.sync + + response = ::Environments::CreateService.new(project, current_user, kwargs).execute + + if response.success? + { environment: response.payload[:environment], errors: [] } + else + { environment: response.payload[:environment], errors: response.errors } + end + end + end + end +end diff --git a/app/graphql/mutations/environments/delete.rb b/app/graphql/mutations/environments/delete.rb new file mode 100644 index 00000000000..5e3958b7936 --- /dev/null +++ b/app/graphql/mutations/environments/delete.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module Mutations + module Environments + class Delete < ::Mutations::BaseMutation + graphql_name 'EnvironmentDelete' + description 'Delete an environment.' + + authorize :destroy_environment + + argument :id, + ::Types::GlobalIDType[::Environment], + required: true, + description: 'Global ID of the environment to Delete.' + + def resolve(id:, **kwargs) + environment = authorized_find!(id: id) + + response = ::Environments::DestroyService.new(environment.project, current_user, kwargs).execute(environment) + + if response.success? + { errors: [] } + else + { errors: response.errors } + end + end + end + end +end diff --git a/app/graphql/mutations/environments/update.rb b/app/graphql/mutations/environments/update.rb new file mode 100644 index 00000000000..431a7add00e --- /dev/null +++ b/app/graphql/mutations/environments/update.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +module Mutations + module Environments + class Update < ::Mutations::BaseMutation + graphql_name 'EnvironmentUpdate' + description 'Update an environment.' + + authorize :update_environment + + argument :id, + ::Types::GlobalIDType[::Environment], + required: true, + description: 'Global ID of the environment to update.' + + argument :external_url, + GraphQL::Types::String, + required: false, + description: 'External URL of the environment.' + + argument :tier, + Types::DeploymentTierEnum, + required: false, + description: 'Tier of the environment.' + + argument :cluster_agent_id, + ::Types::GlobalIDType[::Clusters::Agent], + required: false, + description: 'Cluster agent of the environment.' + + field :environment, + Types::EnvironmentType, + null: true, + description: 'Environment after attempt to update.' + + def resolve(id:, **kwargs) + environment = authorized_find!(id: id) + + convert_cluster_agent_id(kwargs) + + response = ::Environments::UpdateService.new(environment.project, current_user, kwargs).execute(environment) + + if response.success? + { environment: response.payload[:environment], errors: [] } + else + { environment: response.payload[:environment], errors: response.errors } + end + end + + private + + def convert_cluster_agent_id(kwargs) + return unless kwargs.key?(:cluster_agent_id) + + kwargs[:cluster_agent] = if kwargs[:cluster_agent_id] + ::Clusters::Agent.find_by_id(kwargs[:cluster_agent_id].model_id) + end + end + end + end +end diff --git a/app/graphql/mutations/issues/create.rb b/app/graphql/mutations/issues/create.rb index 0c1acdf316e..c8a4d0aaa86 100644 --- a/app/graphql/mutations/issues/create.rb +++ b/app/graphql/mutations/issues/create.rb @@ -81,9 +81,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), project) - - spam_params = ::Spam::SpamParams.new_from_request(request: context[:request]) - result = ::Issues::CreateService.new(container: project, current_user: current_user, params: params, spam_params: spam_params).execute + result = ::Issues::CreateService.new(container: project, current_user: current_user, params: params).execute check_spam_action_response!(result[:issue]) if result[:issue] diff --git a/app/graphql/mutations/issues/set_confidential.rb b/app/graphql/mutations/issues/set_confidential.rb index 08578881a13..79216e0f821 100644 --- a/app/graphql/mutations/issues/set_confidential.rb +++ b/app/graphql/mutations/issues/set_confidential.rb @@ -15,11 +15,8 @@ module Mutations def resolve(project_path:, iid:, confidential:) issue = authorized_find!(project_path: project_path, iid: iid) project = issue.project - # Changing confidentiality affects spam checking rules, therefore we need to provide - # spam_params so a check can be performed. - spam_params = ::Spam::SpamParams.new_from_request(request: context[:request]) - - ::Issues::UpdateService.new(container: project, current_user: current_user, params: { confidential: confidential }, spam_params: spam_params) + # Changing confidentiality affects spam checking rules, therefore we need to perform a spam check + ::Issues::UpdateService.new(container: project, current_user: current_user, params: { confidential: confidential }, perform_spam_check: true) .execute(issue) check_spam_action_response!(issue) diff --git a/app/graphql/mutations/issues/update.rb b/app/graphql/mutations/issues/update.rb index b5af048dc07..2a863893cf1 100644 --- a/app/graphql/mutations/issues/update.rb +++ b/app/graphql/mutations/issues/update.rb @@ -41,8 +41,7 @@ module Mutations args = parse_arguments(args) - spam_params = ::Spam::SpamParams.new_from_request(request: context[:request]) - ::Issues::UpdateService.new(container: project, current_user: current_user, params: args, spam_params: spam_params).execute(issue) + ::Issues::UpdateService.new(container: project, current_user: current_user, params: args, perform_spam_check: true).execute(issue) { issue: issue, diff --git a/app/graphql/mutations/namespace/package_settings/update.rb b/app/graphql/mutations/namespace/package_settings/update.rb index ea72b71715c..96bee693a1e 100644 --- a/app/graphql/mutations/namespace/package_settings/update.rb +++ b/app/graphql/mutations/namespace/package_settings/update.rb @@ -8,6 +8,12 @@ module Mutations include Mutations::ResolvesNamespace + description <<~DESC + These settings can be adjusted by the group Owner or Maintainer. + [Issue 370471](https://gitlab.com/gitlab-org/gitlab/-/issues/370471) proposes limiting + this to Owners only to match the permissions level in the user interface. + DESC + authorize :admin_package argument :namespace_path, diff --git a/app/graphql/mutations/notes/update/base.rb b/app/graphql/mutations/notes/update/base.rb index 4c6df2776cc..09b814d903e 100644 --- a/app/graphql/mutations/notes/update/base.rb +++ b/app/graphql/mutations/notes/update/base.rb @@ -24,12 +24,9 @@ module Mutations note_params(note, args) ).execute(note) - # It's possible for updated_note to be `nil`, in the situation - # where the note is deleted within `Notes::UpdateService` due to - # the body of the note only containing Quick Actions. { - note: updated_note&.reset, - errors: updated_note ? errors_on_object(updated_note) : [] + note: updated_note.destroyed? ? nil : updated_note.reset, + errors: updated_note.destroyed? ? [] : errors_on_object(updated_note) } end diff --git a/app/graphql/mutations/projects/sync_fork.rb b/app/graphql/mutations/projects/sync_fork.rb index 4520f6388c5..6a4ec4a26b8 100644 --- a/app/graphql/mutations/projects/sync_fork.rb +++ b/app/graphql/mutations/projects/sync_fork.rb @@ -22,9 +22,6 @@ module Mutations def resolve(project_path:, target_branch:) project = authorized_find!(project_path, target_branch) - return respond(nil, ['Feature flag is disabled']) unless Feature.enabled?(:synchronize_fork, - project.fork_source) - return respond(nil, ['Target branch does not exist']) unless project.repository.branch_exists?(target_branch) details_resolver = Resolvers::Projects::ForkDetailsResolver.new(object: project, context: context, field: nil) diff --git a/app/graphql/mutations/snippets/create.rb b/app/graphql/mutations/snippets/create.rb index 96ac3f8a113..1c7dbfa751d 100644 --- a/app/graphql/mutations/snippets/create.rb +++ b/app/graphql/mutations/snippets/create.rb @@ -48,8 +48,7 @@ module Mutations process_args_for_params!(args) - spam_params = ::Spam::SpamParams.new_from_request(request: context[:request]) - service = ::Snippets::CreateService.new(project: project, current_user: current_user, params: args, spam_params: spam_params) + service = ::Snippets::CreateService.new(project: project, current_user: current_user, params: args) service_response = service.execute # Only when the user is not an api user and the operation was successful diff --git a/app/graphql/mutations/snippets/update.rb b/app/graphql/mutations/snippets/update.rb index 39843a3714a..7faf9cf9019 100644 --- a/app/graphql/mutations/snippets/update.rb +++ b/app/graphql/mutations/snippets/update.rb @@ -33,8 +33,7 @@ module Mutations process_args_for_params!(args) - spam_params = ::Spam::SpamParams.new_from_request(request: context[:request]) - service = ::Snippets::UpdateService.new(project: snippet.project, current_user: current_user, params: args, spam_params: spam_params) + service = ::Snippets::UpdateService.new(project: snippet.project, current_user: current_user, params: args, perform_spam_check: true) service_response = service.execute(snippet) # TODO: DRY this up - From here down, this is all duplicated with Mutations::Snippets::Create#resolve, except for diff --git a/app/graphql/mutations/users/set_namespace_commit_email.rb b/app/graphql/mutations/users/set_namespace_commit_email.rb new file mode 100644 index 00000000000..72ef0635bb3 --- /dev/null +++ b/app/graphql/mutations/users/set_namespace_commit_email.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +module Mutations + module Users + class SetNamespaceCommitEmail < BaseMutation + graphql_name 'UserSetNamespaceCommitEmail' + + argument :namespace_id, + ::Types::GlobalIDType[::Namespace], + required: true, + description: 'ID of the namespace to set the namespace commit email for.' + + argument :email_id, + ::Types::GlobalIDType[::Email], + required: false, + description: 'ID of the email to set.' + + field :namespace_commit_email, + Types::Users::NamespaceCommitEmailType, + null: true, + description: 'User namespace commit email after mutation.' + + authorize :read_namespace + + def resolve(args) + namespace = authorized_find!(args[:namespace_id]) + args[:email_id] = args[:email_id].model_id + + result = ::Users::SetNamespaceCommitEmailService.new(current_user, namespace, args[:email_id], {}).execute + { + namespace_commit_email: result.payload[:namespace_commit_email], + errors: result.errors + } + end + + private + + def find_object(id) + GitlabSchema.object_from_id( + id, expected_type: [::Namespace, ::Namespaces::UserNamespace, ::Namespaces::ProjectNamespace]).sync + end + end + end +end diff --git a/app/graphql/mutations/work_items/convert.rb b/app/graphql/mutations/work_items/convert.rb index 83bca56d900..b1936027fdc 100644 --- a/app/graphql/mutations/work_items/convert.rb +++ b/app/graphql/mutations/work_items/convert.rb @@ -27,13 +27,11 @@ module Mutations work_item_type = find_work_item_type!(attributes[:work_item_type_id]) authorize_work_item_type!(work_item, work_item_type) - spam_params = ::Spam::SpamParams.new_from_request(request: context[:request]) - update_result = ::WorkItems::UpdateService.new( container: work_item.project, current_user: current_user, params: { work_item_type: work_item_type, issue_type: work_item_type.base_type }, - spam_params: spam_params + perform_spam_check: true ).execute(work_item) check_spam_action_response!(work_item) diff --git a/app/graphql/mutations/work_items/create.rb b/app/graphql/mutations/work_items/create.rb index dfd2d5d1f88..9f7b7b5db97 100644 --- a/app/graphql/mutations/work_items/create.rb +++ b/app/graphql/mutations/work_items/create.rb @@ -60,7 +60,6 @@ module Mutations container_path = project_path || namespace_path container = authorized_find!(container_path) - spam_params = ::Spam::SpamParams.new_from_request(request: context[:request]) params = global_id_compatibility_params(attributes).merge(author_id: current_user.id) type = ::WorkItems::Type.find(attributes[:work_item_type_id]) widget_params = extract_widget_params!(type, params) @@ -69,7 +68,6 @@ module Mutations container: container, current_user: current_user, params: params, - spam_params: spam_params, widget_params: widget_params ).execute diff --git a/app/graphql/mutations/work_items/create_from_task.rb b/app/graphql/mutations/work_items/create_from_task.rb index 23ae09b23fd..bf5c999bf75 100644 --- a/app/graphql/mutations/work_items/create_from_task.rb +++ b/app/graphql/mutations/work_items/create_from_task.rb @@ -30,13 +30,10 @@ module Mutations def resolve(id:, work_item_data:) work_item = authorized_find!(id: id) - spam_params = ::Spam::SpamParams.new_from_request(request: context[:request]) - result = ::WorkItems::CreateFromTaskService.new( work_item: work_item, current_user: current_user, - work_item_params: work_item_data, - spam_params: spam_params + work_item_params: work_item_data ).execute check_spam_action_response!(result[:work_item]) if result[:work_item] diff --git a/app/graphql/mutations/work_items/update.rb b/app/graphql/mutations/work_items/update.rb index 3fd0f5aab62..f22e9bcf393 100644 --- a/app/graphql/mutations/work_items/update.rb +++ b/app/graphql/mutations/work_items/update.rb @@ -21,7 +21,6 @@ module Mutations work_item = authorized_find!(id: id) - spam_params = ::Spam::SpamParams.new_from_request(request: context[:request]) widget_params = extract_widget_params!(work_item.work_item_type, attributes) interpret_quick_actions!(work_item, current_user, widget_params, attributes) @@ -31,7 +30,7 @@ module Mutations current_user: current_user, params: attributes, widget_params: widget_params, - spam_params: spam_params + perform_spam_check: true ).execute(work_item) check_spam_action_response!(work_item) diff --git a/app/graphql/mutations/work_items/update_task.rb b/app/graphql/mutations/work_items/update_task.rb index 8dcc4c325ea..d3df235f894 100644 --- a/app/graphql/mutations/work_items/update_task.rb +++ b/app/graphql/mutations/work_items/update_task.rb @@ -29,13 +29,11 @@ module Mutations work_item = authorized_find!(id: id) task = authorized_find_task!(task_data_hash[:id]) - spam_params = ::Spam::SpamParams.new_from_request(request: context[:request]) - ::WorkItems::UpdateService.new( container: task.project, current_user: current_user, params: task_data_hash.except(:id), - spam_params: spam_params + perform_spam_check: true ).execute(task) check_spam_action_response!(task) |