diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-20 18:40:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-20 18:40:28 +0300 |
commit | b595cb0c1dec83de5bdee18284abe86614bed33b (patch) | |
tree | 8c3d4540f193c5ff98019352f554e921b3a41a72 /app/graphql/mutations | |
parent | 2f9104a328fc8a4bddeaa4627b595166d24671d0 (diff) |
Add latest changes from gitlab-org/gitlab@15-2-stable-eev15.2.0-rc42
Diffstat (limited to 'app/graphql/mutations')
-rw-r--r-- | app/graphql/mutations/concerns/mutations/work_items/update_arguments.rb | 9 | ||||
-rw-r--r-- | app/graphql/mutations/concerns/mutations/work_items/widgetable.rb | 25 | ||||
-rw-r--r-- | app/graphql/mutations/notes/create/diff_note.rb | 3 | ||||
-rw-r--r-- | app/graphql/mutations/pages/base.rb | 13 | ||||
-rw-r--r-- | app/graphql/mutations/pages/mark_onboarding_complete.rb | 27 | ||||
-rw-r--r-- | app/graphql/mutations/snippets/create.rb | 2 | ||||
-rw-r--r-- | app/graphql/mutations/snippets/update.rb | 2 | ||||
-rw-r--r-- | app/graphql/mutations/user_callouts/create.rb | 2 | ||||
-rw-r--r-- | app/graphql/mutations/work_items/create.rb | 16 | ||||
-rw-r--r-- | app/graphql/mutations/work_items/update.rb | 9 | ||||
-rw-r--r-- | app/graphql/mutations/work_items/update_widgets.rb | 1 |
11 files changed, 100 insertions, 9 deletions
diff --git a/app/graphql/mutations/concerns/mutations/work_items/update_arguments.rb b/app/graphql/mutations/concerns/mutations/work_items/update_arguments.rb index 6a91a097a17..cbe1cfb4099 100644 --- a/app/graphql/mutations/concerns/mutations/work_items/update_arguments.rb +++ b/app/graphql/mutations/concerns/mutations/work_items/update_arguments.rb @@ -15,6 +15,15 @@ module Mutations argument :title, GraphQL::Types::String, required: false, description: copy_field_description(Types::WorkItemType, :title) + argument :description_widget, ::Types::WorkItems::Widgets::DescriptionInputType, + required: false, + description: 'Input for description widget.' + argument :weight_widget, ::Types::WorkItems::Widgets::WeightInputType, + required: false, + description: 'Input for weight widget.' + argument :hierarchy_widget, ::Types::WorkItems::Widgets::HierarchyUpdateInputType, + required: false, + description: 'Input for hierarchy widget.' end end end diff --git a/app/graphql/mutations/concerns/mutations/work_items/widgetable.rb b/app/graphql/mutations/concerns/mutations/work_items/widgetable.rb new file mode 100644 index 00000000000..445b2eb6441 --- /dev/null +++ b/app/graphql/mutations/concerns/mutations/work_items/widgetable.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module Mutations + module WorkItems + module Widgetable + extend ActiveSupport::Concern + + def extract_widget_params!(work_item_type, attributes) + # Get the list of widgets for the work item's type to extract only the supported attributes + widget_keys = ::WorkItems::Type.available_widgets.map(&:api_symbol) + widget_params = attributes.extract!(*widget_keys) + + not_supported_keys = widget_params.keys - work_item_type.widgets.map(&:api_symbol) + if not_supported_keys.present? + raise Gitlab::Graphql::Errors::ArgumentError, + "Following widget keys are not supported by #{work_item_type.name} type: #{not_supported_keys}" + end + + # Cannot use prepare to use `.to_h` on each input due to + # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/87472#note_945199865 + widget_params.transform_values { |values| values.to_h } + end + end + end +end diff --git a/app/graphql/mutations/notes/create/diff_note.rb b/app/graphql/mutations/notes/create/diff_note.rb index 019e7cb8623..7b8c06fd104 100644 --- a/app/graphql/mutations/notes/create/diff_note.rb +++ b/app/graphql/mutations/notes/create/diff_note.rb @@ -32,7 +32,8 @@ module Mutations def create_note_params(noteable, args) super(noteable, args).merge({ type: 'DiffNote', - position: position(noteable, args) + position: position(noteable, args), + merge_request_diff_head_sha: args[:position][:head_sha] }) end diff --git a/app/graphql/mutations/pages/base.rb b/app/graphql/mutations/pages/base.rb new file mode 100644 index 00000000000..5eb8ecdf0ba --- /dev/null +++ b/app/graphql/mutations/pages/base.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Mutations + module Pages + class Base < BaseMutation + include FindsProject + + argument :project_path, GraphQL::Types::ID, + required: true, + description: 'Full path of the project.' + end + end +end diff --git a/app/graphql/mutations/pages/mark_onboarding_complete.rb b/app/graphql/mutations/pages/mark_onboarding_complete.rb new file mode 100644 index 00000000000..2f5ce5db54a --- /dev/null +++ b/app/graphql/mutations/pages/mark_onboarding_complete.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Mutations + module Pages + class MarkOnboardingComplete < Base + graphql_name 'PagesMarkOnboardingComplete' + + field :onboarding_complete, + Boolean, + null: false, + description: "Indicates the new onboarding_complete state of the project's Pages metadata." + + authorize :admin_project + + def resolve(project_path:) + project = authorized_find!(project_path) + + project.mark_pages_onboarding_complete + + { + onboarding_complete: project.pages_metadatum.onboarding_complete, + errors: errors_on_object(project) + } + end + end + end +end diff --git a/app/graphql/mutations/snippets/create.rb b/app/graphql/mutations/snippets/create.rb index 2921a77b86d..96ac3f8a113 100644 --- a/app/graphql/mutations/snippets/create.rb +++ b/app/graphql/mutations/snippets/create.rb @@ -54,7 +54,7 @@ module Mutations # Only when the user is not an api user and the operation was successful if !api_user? && service_response.success? - ::Gitlab::UsageDataCounters::EditorUniqueCounter.track_snippet_editor_edit_action(author: current_user) + ::Gitlab::UsageDataCounters::EditorUniqueCounter.track_snippet_editor_edit_action(author: current_user, project: project) end snippet = service_response.payload[:snippet] diff --git a/app/graphql/mutations/snippets/update.rb b/app/graphql/mutations/snippets/update.rb index 2a2941c5328..39843a3714a 100644 --- a/app/graphql/mutations/snippets/update.rb +++ b/app/graphql/mutations/snippets/update.rb @@ -43,7 +43,7 @@ module Mutations # Only when the user is not an api user and the operation was successful if !api_user? && service_response.success? - ::Gitlab::UsageDataCounters::EditorUniqueCounter.track_snippet_editor_edit_action(author: current_user) + ::Gitlab::UsageDataCounters::EditorUniqueCounter.track_snippet_editor_edit_action(author: current_user, project: snippet.project) end snippet = service_response.payload[:snippet] diff --git a/app/graphql/mutations/user_callouts/create.rb b/app/graphql/mutations/user_callouts/create.rb index 1be99ea0ecd..7f372053e84 100644 --- a/app/graphql/mutations/user_callouts/create.rb +++ b/app/graphql/mutations/user_callouts/create.rb @@ -15,7 +15,7 @@ module Mutations description: 'User callout dismissed.' def resolve(feature_name:) - callout = Users::DismissCalloutService.new( + callout = ::Users::DismissCalloutService.new( container: nil, current_user: current_user, params: { feature_name: feature_name } ).execute errors = errors_on_object(callout) diff --git a/app/graphql/mutations/work_items/create.rb b/app/graphql/mutations/work_items/create.rb index 2ae26ed0e1a..350153eaf19 100644 --- a/app/graphql/mutations/work_items/create.rb +++ b/app/graphql/mutations/work_items/create.rb @@ -7,6 +7,7 @@ module Mutations include Mutations::SpamProtection include FindsProject + include Mutations::WorkItems::Widgetable description "Creates a work item. Available only when feature flag `work_items` is enabled." @@ -15,6 +16,9 @@ module Mutations argument :description, GraphQL::Types::String, required: false, description: copy_field_description(Types::WorkItemType, :description) + argument :hierarchy_widget, ::Types::WorkItems::Widgets::HierarchyCreateInputType, + required: false, + description: 'Input for hierarchy widget.' argument :project_path, GraphQL::Types::ID, required: true, description: 'Full path of the project the work item is associated with.' @@ -36,10 +40,18 @@ module Mutations return { errors: ['`work_items` feature flag disabled for this project'] } end + 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) - spam_params = ::Spam::SpamParams.new_from_request(request: context[:request]) - create_result = ::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, + widget_params: widget_params + ).execute check_spam_action_response!(create_result[:work_item]) if create_result[:work_item] diff --git a/app/graphql/mutations/work_items/update.rb b/app/graphql/mutations/work_items/update.rb index c495da00f41..5d8c574877a 100644 --- a/app/graphql/mutations/work_items/update.rb +++ b/app/graphql/mutations/work_items/update.rb @@ -9,6 +9,7 @@ module Mutations include Mutations::SpamProtection include Mutations::WorkItems::UpdateArguments + include Mutations::WorkItems::Widgetable authorize :update_work_item @@ -24,19 +25,21 @@ module Mutations end spam_params = ::Spam::SpamParams.new_from_request(request: context[:request]) + widget_params = extract_widget_params!(work_item.work_item_type, attributes) - ::WorkItems::UpdateService.new( + update_result = ::WorkItems::UpdateService.new( project: work_item.project, current_user: current_user, params: attributes, + widget_params: widget_params, 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) + work_item: (update_result[:work_item] if update_result[:status] == :success), + errors: Array.wrap(update_result[:message]) } end diff --git a/app/graphql/mutations/work_items/update_widgets.rb b/app/graphql/mutations/work_items/update_widgets.rb index d19da0abaac..7037b7e5a2a 100644 --- a/app/graphql/mutations/work_items/update_widgets.rb +++ b/app/graphql/mutations/work_items/update_widgets.rb @@ -2,6 +2,7 @@ module Mutations module WorkItems + # TODO: Deprecate in favor of using WorkItemUpdate. See https://gitlab.com/gitlab-org/gitlab/-/issues/366300 class UpdateWidgets < BaseMutation graphql_name 'WorkItemUpdateWidgets' description "Updates the attributes of a work item's widgets by global ID." \ |