diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-20 14:18:08 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-20 14:18:08 +0300 |
commit | 5afcbe03ead9ada87621888a31a62652b10a7e4f (patch) | |
tree | 9918b67a0d0f0bafa6542e839a8be37adf73102d /app/graphql/mutations | |
parent | c97c0201564848c1f53226fe19d71fdcc472f7d0 (diff) |
Add latest changes from gitlab-org/gitlab@16-4-stable-eev16.4.0-rc42
Diffstat (limited to 'app/graphql/mutations')
11 files changed, 94 insertions, 57 deletions
diff --git a/app/graphql/mutations/admin/abuse_report_labels/create.rb b/app/graphql/mutations/admin/abuse_report_labels/create.rb new file mode 100644 index 00000000000..6ec96297da4 --- /dev/null +++ b/app/graphql/mutations/admin/abuse_report_labels/create.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Mutations + module Admin + module AbuseReportLabels + class Create < BaseMutation + graphql_name 'AbuseReportLabelCreate' + + field :label, Types::LabelType, null: true, description: 'Label after mutation.' + + argument :title, GraphQL::Types::String, required: true, description: 'Title of the label.' + + argument :color, GraphQL::Types::String, required: false, default_value: Label::DEFAULT_COLOR, + see: { + 'List of color keywords at mozilla.org' => + 'https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#Color_keywords' + }, + description: <<~DESC + The color of the label given in 6-digit hex notation with leading '#' sign + (for example, `#FFAABB`) or one of the CSS color names. + DESC + + def resolve(args) + raise_resource_not_available_error! unless current_user.can?(:admin_all_resources) + + label = ::Admin::AbuseReportLabels::CreateService.new(args).execute + + { + label: label.persisted? ? label : nil, + errors: errors_on_object(label) + } + end + end + end + end +end diff --git a/app/graphql/mutations/ci/project_ci_cd_settings_update.rb b/app/graphql/mutations/ci/project_ci_cd_settings_update.rb index 082c345adf6..7df277641bf 100644 --- a/app/graphql/mutations/ci/project_ci_cd_settings_update.rb +++ b/app/graphql/mutations/ci/project_ci_cd_settings_update.rb @@ -6,6 +6,7 @@ module Mutations graphql_name 'ProjectCiCdSettingsUpdate' include FindsProject + include Gitlab::Utils::StrongMemoize authorize :admin_project @@ -37,13 +38,11 @@ module Mutations description: 'CI/CD settings after mutation.' def resolve(full_path:, **args) - project = authorized_find!(full_path) - if args[:job_token_scope_enabled] raise Gitlab::Graphql::Errors::ArgumentError, 'job_token_scope_enabled can only be set to false' end - settings = project.ci_cd_settings + settings = project(full_path).ci_cd_settings settings.update(args) { @@ -51,6 +50,14 @@ module Mutations errors: errors_on_object(settings) } end + + private + + def project(full_path) + strong_memoize_with(:project, full_path) do + authorized_find!(full_path) + end + end end end end diff --git a/app/graphql/mutations/issues/bulk_update.rb b/app/graphql/mutations/issues/bulk_update.rb index 9c9dd3cf2fc..05e83fc82bb 100644 --- a/app/graphql/mutations/issues/bulk_update.rb +++ b/app/graphql/mutations/issues/bulk_update.rb @@ -15,7 +15,7 @@ module Mutations argument :parent_id, ::Types::GlobalIDType[::IssueParent], required: true, description: 'Global ID of the parent to which the bulk update will be scoped. ' \ - 'The parent can be a project **(FREE)** or a group **(PREMIUM)**. ' \ + 'The parent can be a project **(FREE ALL)** or a group **(PREMIUM ALL)**. ' \ 'Example `IssueParentID` are `"gid://gitlab/Project/1"` and `"gid://gitlab/Group/1"`.' argument :ids, [::Types::GlobalIDType[::Issue]], diff --git a/app/graphql/mutations/issues/update.rb b/app/graphql/mutations/issues/update.rb index 35deb9e0af8..cd02c96e000 100644 --- a/app/graphql/mutations/issues/update.rb +++ b/app/graphql/mutations/issues/update.rb @@ -34,7 +34,8 @@ module Mutations argument :time_estimate, GraphQL::Types::String, required: false, - description: 'Estimated time to complete the issue, or `0` to remove the current estimate.' + description: 'Estimated time to complete the issue. ' \ + 'Use `null` or `0` to remove the current estimate.' def resolve(project_path:, iid:, **args) issue = authorized_find!(project_path: project_path, iid: iid) @@ -67,8 +68,9 @@ module Mutations args[:remove_label_ids] = parse_label_ids(args[:remove_label_ids]) args[:label_ids] = parse_label_ids(args[:label_ids]) - unless args[:time_estimate].nil? - args[:time_estimate] = Gitlab::TimeTrackingFormatter.parse(args[:time_estimate], keep_zero: true) + if args.key?(:time_estimate) + args[:time_estimate] = + args[:time_estimate].nil? ? 0 : Gitlab::TimeTrackingFormatter.parse(args[:time_estimate], keep_zero: true) end args diff --git a/app/graphql/mutations/merge_requests/update.rb b/app/graphql/mutations/merge_requests/update.rb index 470292df86c..427e07e4a70 100644 --- a/app/graphql/mutations/merge_requests/update.rb +++ b/app/graphql/mutations/merge_requests/update.rb @@ -28,7 +28,8 @@ module Mutations argument :time_estimate, GraphQL::Types::String, required: false, - description: 'Estimated time to complete the merge request, or `0` to remove the current estimate.' + description: 'Estimated time to complete the merge request. ' \ + 'Use `null` or `0` to remove the current estimate.' def resolve(project_path:, iid:, **args) merge_request = authorized_find!(project_path: project_path, iid: iid) @@ -55,8 +56,9 @@ module Mutations private def parse_arguments(args) - unless args[:time_estimate].nil? - args[:time_estimate] = Gitlab::TimeTrackingFormatter.parse(args[:time_estimate], keep_zero: true) + if args.key?(:time_estimate) + args[:time_estimate] = + args[:time_estimate].nil? ? 0 : Gitlab::TimeTrackingFormatter.parse(args[:time_estimate], keep_zero: true) end args.compact diff --git a/app/graphql/mutations/metrics/dashboard/annotations/base.rb b/app/graphql/mutations/metrics/dashboard/annotations/base.rb deleted file mode 100644 index ad52f84378d..00000000000 --- a/app/graphql/mutations/metrics/dashboard/annotations/base.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -module Mutations - module Metrics - module Dashboard - module Annotations - class Base < BaseMutation - private - - # This method is defined here in order to be used by `authorized_find!` in the subclasses. - def find_object(id:) - GitlabSchema.object_from_id(id, expected_type: ::Metrics::Dashboard::Annotation) - end - end - end - end - end -end diff --git a/app/graphql/mutations/metrics/dashboard/annotations/create.rb b/app/graphql/mutations/metrics/dashboard/annotations/create.rb index 59ddffe3aad..e544b96f679 100644 --- a/app/graphql/mutations/metrics/dashboard/annotations/create.rb +++ b/app/graphql/mutations/metrics/dashboard/annotations/create.rb @@ -70,28 +70,8 @@ module Mutations private - def ready?(**args) - raise_resource_not_available_error! if Feature.enabled?(:remove_monitor_metrics) - - # Raise error if both cluster_id and environment_id are present or neither is present - unless args[:cluster_id].present? ^ args[:environment_id].present? - raise Gitlab::Graphql::Errors::ArgumentError, ANNOTATION_SOURCE_ARGUMENT_ERROR - end - - super(**args) - end - - def annotation_create_params(args) - annotation_source = AnnotationSource.new(object: annotation_source(args)) - - args[annotation_source.type] = annotation_source.object - - args - end - - def annotation_source(args) - annotation_source_id = args[:cluster_id] || args[:environment_id] - authorized_find!(id: annotation_source_id) + def ready?(**_args) + raise_resource_not_available_error! end end end diff --git a/app/graphql/mutations/metrics/dashboard/annotations/delete.rb b/app/graphql/mutations/metrics/dashboard/annotations/delete.rb index 61fcf8e0b13..d2f2d9a0e32 100644 --- a/app/graphql/mutations/metrics/dashboard/annotations/delete.rb +++ b/app/graphql/mutations/metrics/dashboard/annotations/delete.rb @@ -4,12 +4,12 @@ module Mutations module Metrics module Dashboard module Annotations - class Delete < Base + class Delete < BaseMutation graphql_name 'DeleteAnnotation' authorize :admin_metrics_dashboard_annotation - argument :id, ::Types::GlobalIDType[::Metrics::Dashboard::Annotation], + argument :id, GraphQL::Types::String, required: true, description: 'Global ID of the annotation to delete.' diff --git a/app/graphql/mutations/work_items/linked_items/add.rb b/app/graphql/mutations/work_items/linked_items/add.rb index b346b074e85..e0c17a61205 100644 --- a/app/graphql/mutations/work_items/linked_items/add.rb +++ b/app/graphql/mutations/work_items/linked_items/add.rb @@ -9,6 +9,9 @@ module Mutations argument :link_type, ::Types::WorkItems::RelatedLinkTypeEnum, required: false, description: 'Type of link. Defaults to `RELATED`.' + argument :work_items_ids, [::Types::GlobalIDType[::WorkItem]], + required: true, + description: "Global IDs of the items to link. Maximum number of IDs you can provide: #{MAX_WORK_ITEMS}." private diff --git a/app/graphql/mutations/work_items/linked_items/base.rb b/app/graphql/mutations/work_items/linked_items/base.rb index 1d8d74b02ac..a1d9bced930 100644 --- a/app/graphql/mutations/work_items/linked_items/base.rb +++ b/app/graphql/mutations/work_items/linked_items/base.rb @@ -10,9 +10,6 @@ module Mutations argument :id, ::Types::GlobalIDType[::WorkItem], required: true, description: 'Global ID of the work item.' - argument :work_items_ids, [::Types::GlobalIDType[::WorkItem]], - required: true, - description: "Global IDs of the items to link. Maximum number of IDs you can provide: #{MAX_WORK_ITEMS}." field :work_item, Types::WorkItemType, null: true, description: 'Updated work item.' @@ -26,7 +23,7 @@ module Mutations if args[:work_items_ids].size > MAX_WORK_ITEMS raise Gitlab::Graphql::Errors::ArgumentError, format( - _('No more than %{max_work_items} work items can be linked at the same time.'), + _('No more than %{max_work_items} work items can be modified at the same time.'), max_work_items: MAX_WORK_ITEMS ) end @@ -50,7 +47,7 @@ module Mutations private def update_links(work_item, params) - raise NotImplementedError + raise NotImplementedError, "#{self.class} does not implement #{__method__}" end end end diff --git a/app/graphql/mutations/work_items/linked_items/remove.rb b/app/graphql/mutations/work_items/linked_items/remove.rb new file mode 100644 index 00000000000..078f05d2025 --- /dev/null +++ b/app/graphql/mutations/work_items/linked_items/remove.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +module Mutations + module WorkItems + module LinkedItems + class Remove < Base + graphql_name 'WorkItemRemoveLinkedItems' + description 'Remove items linked to the work item.' + + argument :work_items_ids, [::Types::GlobalIDType[::WorkItem]], + required: true, + description: "Global IDs of the items to unlink. Maximum number of IDs you can provide: #{MAX_WORK_ITEMS}." + + private + + def update_links(work_item, params) + gids = params.delete(:work_items_ids) + raise Gitlab::Graphql::Errors::ArgumentError, "workItemsIds cannot be empty" if gids.empty? + + work_item_ids = gids.filter_map { |gid| gid.model_id.to_i } + ::WorkItems::RelatedWorkItemLinks::DestroyService + .new(work_item, current_user, { item_ids: work_item_ids }) + .execute + end + end + end + end +end |