Class: Mutations::WorkItems::Create

Inherits:
BaseMutation
  • Object
show all
Includes:
FindsNamespace, SpamProtection, SharedArguments, Widgetable
Defined in:
app/graphql/mutations/work_items/create.rb

Constant Summary collapse

MUTUALLY_EXCLUSIVE_ARGUMENTS_ERROR =
'Please provide either projectPath or namespacePath argument, but not both.'

Constants included from SpamProtection

SpamProtection::NEEDS_CAPTCHA_RESPONSE_MESSAGE, SpamProtection::NeedsCaptchaResponseError, SpamProtection::SPAM_DISALLOWED_MESSAGE, SpamProtection::SpamActionError, SpamProtection::SpamDisallowedError

Constants inherited from BaseMutation

BaseMutation::ERROR_MESSAGE

Constants included from Gitlab::Graphql::Authorize::AuthorizeResource

Gitlab::Graphql::Authorize::AuthorizeResource::ConfigurationError, Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Widgetable

#extract_widget_params!

Methods included from Spam::Concerns::HasSpamActionResponseFields

#spam_action_response_fields

Methods inherited from BaseMutation

#api_user?, authorization, authorized?, authorizes_object?, #current_user, #errors_on_object, #load_application_object, #read_only?, #unauthorized_object

Methods included from Gitlab::Graphql::Authorize::AuthorizeResource

#authorize!, #authorized_find!, #authorized_resource?, #find_object, #raise_resource_not_available_error!

Class Method Details

.authorization_scopesObject



19
20
21
# File 'app/graphql/mutations/work_items/create.rb', line 19

def self.authorization_scopes
  super + [:ai_workflows]
end

Instance Method Details

#ready?(**args) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
94
95
96
97
# File 'app/graphql/mutations/work_items/create.rb', line 91

def ready?(**args)
  if args.slice(:project_path, :namespace_path)&.length != 1
    raise Gitlab::Graphql::Errors::ArgumentError, MUTUALLY_EXCLUSIVE_ARGUMENTS_ERROR
  end

  super
end

#resolve(project_path: nil, namespace_path: nil, **attributes) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'app/graphql/mutations/work_items/create.rb', line 99

def resolve(project_path: nil, namespace_path: nil, **attributes)
  Gitlab::QueryLimiting.disable!('https://gitlab.com/gitlab-org/gitlab/-/issues/578961')

  container_path = project_path || namespace_path
  container = authorized_find!(container_path)
  params = params_with_work_item_type(attributes).merge(author_id: current_user.id,
    scope_validator: context[:scope_validator])
  params = params_with_resolve_discussion_params(params)
  type = params[:work_item_type]
  raise_resource_not_available_error! unless type

  check_feature_available!(container, type, params)
  widget_params = extract_widget_params!(type, params, container)

  create_result = ::WorkItems::CreateService.new(
    container: container,
    current_user: current_user,
    params: params,
    widget_params: widget_params
  ).execute

  check_spam_action_response!(create_result[:work_item]) if create_result[:work_item]

  {
    work_item: create_result.success? ? create_result[:work_item] : nil,
    errors: create_result.errors
  }
end