diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /app/graphql/mutations | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'app/graphql/mutations')
11 files changed, 168 insertions, 15 deletions
diff --git a/app/graphql/mutations/boards/issues/issue_move_list.rb b/app/graphql/mutations/boards/issues/issue_move_list.rb index 14fe9714f99..e9cae80e5f9 100644 --- a/app/graphql/mutations/boards/issues/issue_move_list.rb +++ b/app/graphql/mutations/boards/issues/issue_move_list.rb @@ -38,10 +38,16 @@ module Mutations required: false, description: 'ID of issue that should be placed after the current issue.' + argument :position_in_list, GraphQL::Types::Int, + required: false, + description: "Position of issue within the board list. Positions start at 0. "\ + "Use #{::Boards::Issues::MoveService::LIST_END_POSITION} to move to the end of the list." + def ready?(**args) if move_arguments(args).blank? raise Gitlab::Graphql::Errors::ArgumentError, - 'At least one of the arguments fromListId, toListId, afterId or beforeId is required' + 'At least one of the arguments ' \ + 'fromListId, toListId, positionInList, moveAfterId, or moveBeforeId is required' end if move_list_arguments(args).one? @@ -49,6 +55,24 @@ module Mutations 'Both fromListId and toListId must be present' end + if args[:position_in_list].present? + if move_list_arguments(args).empty? + raise Gitlab::Graphql::Errors::ArgumentError, + 'Both fromListId and toListId are required when positionInList is given' + end + + if args[:move_before_id].present? || args[:move_after_id].present? + raise Gitlab::Graphql::Errors::ArgumentError, + 'positionInList is mutually exclusive with any of moveBeforeId or moveAfterId' + end + + if args[:position_in_list] != ::Boards::Issues::MoveService::LIST_END_POSITION && + args[:position_in_list] < 0 + raise Gitlab::Graphql::Errors::ArgumentError, + "positionInList must be >= 0 or #{::Boards::Issues::MoveService::LIST_END_POSITION}" + end + end + super end @@ -77,7 +101,7 @@ module Mutations end def move_arguments(args) - args.slice(:from_list_id, :to_list_id, :move_after_id, :move_before_id) + args.slice(:from_list_id, :to_list_id, :position_in_list, :move_after_id, :move_before_id) end def error_for(result) diff --git a/app/graphql/mutations/ci/job/artifacts_destroy.rb b/app/graphql/mutations/ci/job/artifacts_destroy.rb new file mode 100644 index 00000000000..c27ab9c4d89 --- /dev/null +++ b/app/graphql/mutations/ci/job/artifacts_destroy.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +module Mutations + module Ci + module Job + class ArtifactsDestroy < Base + graphql_name 'JobArtifactsDestroy' + + authorize :destroy_artifacts + + field :job, + Types::Ci::JobType, + null: true, + description: 'Job with artifacts to be deleted.' + + field :destroyed_artifacts_count, + GraphQL::Types::Int, + null: false, + description: 'Number of artifacts deleted.' + + def find_object(id: ) + GlobalID::Locator.locate(id) + end + + def resolve(id:) + job = authorized_find!(id: id) + + result = ::Ci::JobArtifacts::DestroyBatchService.new(job.job_artifacts, pick_up_at: Time.current).execute + { + job: job, + destroyed_artifacts_count: result[:destroyed_artifacts_count], + errors: Array(result[:errors]) + } + end + end + end + end +end diff --git a/app/graphql/mutations/ci/job_artifact/destroy.rb b/app/graphql/mutations/ci/job_artifact/destroy.rb new file mode 100644 index 00000000000..47b3535d631 --- /dev/null +++ b/app/graphql/mutations/ci/job_artifact/destroy.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +module Mutations + module Ci + module JobArtifact + class Destroy < BaseMutation + graphql_name 'ArtifactDestroy' + + authorize :destroy_artifacts + + ArtifactID = ::Types::GlobalIDType[::Ci::JobArtifact] + + argument :id, + ArtifactID, + required: true, + description: 'ID of the artifact to delete.' + + field :artifact, + Types::Ci::JobArtifactType, + null: true, + description: 'Deleted artifact.' + + def find_object(id: ) + GlobalID::Locator.locate(id) + end + + def resolve(id:) + artifact = authorized_find!(id: id) + + if artifact.destroy + { errors: [] } + else + { errors: artifact.errors.full_messages } + end + end + end + end + end +end diff --git a/app/graphql/mutations/ci/runner/bulk_delete.rb b/app/graphql/mutations/ci/runner/bulk_delete.rb index 4c1c2967799..4265099d28e 100644 --- a/app/graphql/mutations/ci/runner/bulk_delete.rb +++ b/app/graphql/mutations/ci/runner/bulk_delete.rb @@ -40,9 +40,7 @@ module Mutations private def model_ids_of(ids) - ids.map do |gid| - gid.model_id.to_i - end.compact + ids.filter_map { |gid| gid.model_id.to_i } end def find_all_runners_by_ids(ids) diff --git a/app/graphql/mutations/ci/runner/update.rb b/app/graphql/mutations/ci/runner/update.rb index 1c6cf6989bf..f98138646be 100644 --- a/app/graphql/mutations/ci/runner/update.rb +++ b/app/graphql/mutations/ci/runner/update.rb @@ -48,8 +48,13 @@ module Mutations description: 'Indicates the runner is able to run untagged jobs.' argument :tag_list, [GraphQL::Types::String], - required: false, - description: 'Tags associated with the runner.' + required: false, + description: 'Tags associated with the runner.' + + argument :associated_projects, [::Types::GlobalIDType[::Project]], + required: false, + description: 'Projects associated with the runner. Available only for project runners.', + prepare: -> (global_ids, ctx) { global_ids&.filter_map { |gid| gid.model_id.to_i } } field :runner, Types::Ci::RunnerType, @@ -59,16 +64,47 @@ module Mutations def resolve(id:, **runner_attrs) runner = authorized_find!(id) - unless ::Ci::Runners::UpdateRunnerService.new(runner).update(runner_attrs) - return { runner: nil, errors: runner.errors.full_messages } + associated_projects_ids = runner_attrs.delete(:associated_projects) + + response = { runner: runner, errors: [] } + ::Ci::Runner.transaction do + associate_runner_projects(response, runner, associated_projects_ids) if associated_projects_ids.present? + update_runner(response, runner, runner_attrs) end - { runner: runner, errors: [] } + response end def find_object(id) GitlabSchema.find_by_gid(id) end + + private + + def associate_runner_projects(response, runner, associated_project_ids) + unless runner.project_type? + raise Gitlab::Graphql::Errors::ArgumentError, + "associatedProjects must not be specified for '#{runner.runner_type}' scope" + end + + result = ::Ci::Runners::SetRunnerAssociatedProjectsService.new( + runner: runner, + current_user: current_user, + project_ids: associated_project_ids + ).execute + return if result.success? + + response[:errors] = result.errors + raise ActiveRecord::Rollback + end + + def update_runner(response, runner, attrs) + result = ::Ci::Runners::UpdateRunnerService.new(runner).execute(attrs) + return if result.success? + + response[:errors] = result.errors + raise ActiveRecord::Rollback + end end end end diff --git a/app/graphql/mutations/custom_emoji/create.rb b/app/graphql/mutations/custom_emoji/create.rb index 269ea6c9999..535ff44a7fd 100644 --- a/app/graphql/mutations/custom_emoji/create.rb +++ b/app/graphql/mutations/custom_emoji/create.rb @@ -28,6 +28,10 @@ module Mutations description: 'Location of the emoji file.' def resolve(group_path:, **args) + if Feature.disabled?(:custom_emoji) + raise Gitlab::Graphql::Errors::ResourceNotAvailable, 'Custom emoji feature is disabled' + end + group = authorized_find!(group_path: group_path) # See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/37911#note_444682238 args[:external] = true diff --git a/app/graphql/mutations/custom_emoji/destroy.rb b/app/graphql/mutations/custom_emoji/destroy.rb index 863b8152cc7..64e3f2ed7d3 100644 --- a/app/graphql/mutations/custom_emoji/destroy.rb +++ b/app/graphql/mutations/custom_emoji/destroy.rb @@ -17,6 +17,10 @@ module Mutations description: 'Global ID of the custom emoji to destroy.' def resolve(id:) + if Feature.disabled?(:custom_emoji) + raise Gitlab::Graphql::Errors::ResourceNotAvailable, 'Custom emoji feature is disabled' + end + custom_emoji = authorized_find!(id: id) custom_emoji.destroy! diff --git a/app/graphql/mutations/dependency_proxy/group_settings/update.rb b/app/graphql/mutations/dependency_proxy/group_settings/update.rb index 65c919db3c3..6be07edd883 100644 --- a/app/graphql/mutations/dependency_proxy/group_settings/update.rb +++ b/app/graphql/mutations/dependency_proxy/group_settings/update.rb @@ -8,6 +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.' + authorize :admin_dependency_proxy argument :group_path, diff --git a/app/graphql/mutations/incident_management/timeline_event/promote_from_note.rb b/app/graphql/mutations/incident_management/timeline_event/promote_from_note.rb index 31ae29d896b..bb1da9278ff 100644 --- a/app/graphql/mutations/incident_management/timeline_event/promote_from_note.rb +++ b/app/graphql/mutations/incident_management/timeline_event/promote_from_note.rb @@ -6,6 +6,8 @@ module Mutations class PromoteFromNote < Base graphql_name 'TimelineEventPromoteFromNote' + include NotesHelper + argument :note_id, Types::GlobalIDType[::Note], required: true, description: 'Note ID from which the timeline event promoted.' @@ -20,7 +22,7 @@ module Mutations incident, current_user, promoted_from_note: note, - note: note.note, + note: build_note_string(note), occurred_at: note.created_at, editable: true ).execute @@ -38,6 +40,11 @@ module Mutations super end + def build_note_string(note) + commented = _('commented') + "@#{note.author.username} [#{commented}](#{noteable_note_url(note)}): '#{note.note}'" + end + def raise_noteable_not_incident! raise_resource_not_available_error! 'Note does not belong to an incident' end diff --git a/app/graphql/mutations/releases/create.rb b/app/graphql/mutations/releases/create.rb index 70a0e71c869..ba1fa8d446c 100644 --- a/app/graphql/mutations/releases/create.rb +++ b/app/graphql/mutations/releases/create.rb @@ -32,7 +32,7 @@ module Mutations argument :released_at, Types::TimeType, required: false, - description: 'Date and time for the release. Defaults to the current date and time.' + description: 'Date and time for the release. Defaults to the current time. Expected in ISO 8601 format (`2019-03-15T08:00:00Z`). Only provide this field if creating an upcoming or historical release.' argument :milestones, [GraphQL::Types::String], required: false, diff --git a/app/graphql/mutations/todos/restore_many.rb b/app/graphql/mutations/todos/restore_many.rb index fe0ad6df65b..20913a9e7da 100644 --- a/app/graphql/mutations/todos/restore_many.rb +++ b/app/graphql/mutations/todos/restore_many.rb @@ -32,9 +32,7 @@ module Mutations private def model_ids_of(ids) - ids.map do |gid| - gid.model_id.to_i - end.compact + ids.filter_map { |gid| gid.model_id.to_i } end def raise_too_many_todos_requested_error |