Class: Mutations::Snippets::Create

Inherits:
BaseMutation
  • Object
show all
Includes:
ServiceCompatibility, Mutations::SpamProtection
Defined in:
app/graphql/mutations/snippets/create.rb

Constant Summary

Constants included from Mutations::SpamProtection

Mutations::SpamProtection::NEEDS_CAPTCHA_RESPONSE_MESSAGE, Mutations::SpamProtection::NeedsCaptchaResponseError, Mutations::SpamProtection::SPAM_DISALLOWED_MESSAGE, Mutations::SpamProtection::SpamActionError, Mutations::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 included from ServiceCompatibility

#convert_blob_actions_to_snippet_actions!

Methods inherited from BaseMutation

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

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

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

Instance Method Details

#resolve(project_path: nil, **args) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/graphql/mutations/snippets/create.rb', line 42

def resolve(project_path: nil, **args)
  if project_path.present?
    project = authorized_find!(project_path)
  else
    authorize!(:global)
  end

  process_args_for_params!(args)

  service = ::Snippets::CreateService.new(project: project, current_user: current_user, params: args)
  service_response = service.execute

  # 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, project: project)
  end

  snippet = service_response.payload[:snippet]
  check_spam_action_response!(snippet)

  {
    snippet: service_response.success? ? snippet : nil,
    errors: errors_on_object(snippet)
  }
end