debian-mirror-gitlab/app/graphql/mutations/work_items/create.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

77 lines
2.7 KiB
Ruby
Raw Normal View History

2022-03-02 08:16:31 +05:30
# frozen_string_literal: true
module Mutations
module WorkItems
class Create < BaseMutation
2022-04-04 11:22:00 +05:30
graphql_name 'WorkItemCreate'
2022-03-02 08:16:31 +05:30
include Mutations::SpamProtection
include FindsProject
2022-08-13 15:12:31 +05:30
include Mutations::WorkItems::Widgetable
2022-03-02 08:16:31 +05:30
2022-07-23 23:45:48 +05:30
description "Creates a work item. Available only when feature flag `work_items` is enabled."
2022-03-02 08:16:31 +05:30
authorize :create_work_item
2022-08-27 11:52:29 +05:30
argument :confidential, GraphQL::Types::Boolean,
required: false,
description: 'Sets the work item confidentiality.'
2022-03-02 08:16:31 +05:30
argument :description, GraphQL::Types::String,
required: false,
description: copy_field_description(Types::WorkItemType, :description)
2022-08-13 15:12:31 +05:30
argument :hierarchy_widget, ::Types::WorkItems::Widgets::HierarchyCreateInputType,
required: false,
description: 'Input for hierarchy widget.'
2022-03-02 08:16:31 +05:30
argument :project_path, GraphQL::Types::ID,
required: true,
description: 'Full path of the project the work item is associated with.'
argument :title, GraphQL::Types::String,
required: true,
description: copy_field_description(Types::WorkItemType, :title)
argument :work_item_type_id, ::Types::GlobalIDType[::WorkItems::Type],
required: true,
description: 'Global ID of a work item type.'
field :work_item, Types::WorkItemType,
null: true,
description: 'Created work item.'
def resolve(project_path:, **attributes)
project = authorized_find!(project_path)
2022-04-04 11:22:00 +05:30
2022-06-21 17:19:12 +05:30
unless project.work_items_feature_flag_enabled?
2022-04-04 11:22:00 +05:30
return { errors: ['`work_items` feature flag disabled for this project'] }
end
2022-08-13 15:12:31 +05:30
spam_params = ::Spam::SpamParams.new_from_request(request: context[:request])
2022-03-02 08:16:31 +05:30
params = global_id_compatibility_params(attributes).merge(author_id: current_user.id)
2022-08-13 15:12:31 +05:30
type = ::WorkItems::Type.find(attributes[:work_item_type_id])
widget_params = extract_widget_params!(type, params)
2022-03-02 08:16:31 +05:30
2022-08-13 15:12:31 +05:30
create_result = ::WorkItems::CreateService.new(
project: project,
current_user: current_user,
params: params,
spam_params: spam_params,
widget_params: widget_params
).execute
2022-03-02 08:16:31 +05:30
2022-04-04 11:22:00 +05:30
check_spam_action_response!(create_result[:work_item]) if create_result[:work_item]
2022-03-02 08:16:31 +05:30
{
2022-04-04 11:22:00 +05:30
work_item: create_result.success? ? create_result[:work_item] : nil,
errors: create_result.errors
2022-03-02 08:16:31 +05:30
}
end
private
def global_id_compatibility_params(params)
params[:work_item_type_id] = params[:work_item_type_id]&.model_id
params
end
end
end
end