Class: Mutations::Issues::Create

Inherits:
BaseMutation
  • Object
show all
Includes:
FindsProject, CommonMutationArguments, SpamProtection
Defined in:
app/graphql/mutations/issues/create.rb

Constant Summary

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

Instance Method Summary collapse

Methods included from Spam::Concerns::HasSpamActionResponseFields

#spam_action_response_fields

Methods inherited from BaseMutation

#api_user?, authorization, authorization_scopes, 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!

Instance Method Details

#ready?(**args) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
72
73
74
75
76
# File 'app/graphql/mutations/issues/create.rb', line 69

def ready?(**args)
  if args[:discussion_to_resolve].present? && args[:merge_request_to_resolve_discussions_of].blank?
    raise Gitlab::Graphql::Errors::ArgumentError,
      'to resolve a discussion please also provide `merge_request_to_resolve_discussions_of` parameter'
  end

  super
end

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



78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/graphql/mutations/issues/create.rb', line 78

def resolve(project_path:, **attributes)
  project = authorized_find!(project_path)
  params = build_create_issue_params(attributes.merge(author_id: current_user.id), project)
  result = ::Issues::CreateService.new(container: project, current_user: current_user, params: params).execute

  check_spam_action_response!(result[:issue]) if result[:issue]

  {
    issue: result.success? ? result[:issue] : nil,
    errors: result.errors
  }
end