Class: Mutations::WorkItems::Convert

Inherits:
BaseMutation
  • Object
show all
Includes:
SpamProtection
Defined in:
app/graphql/mutations/work_items/convert.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, 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(attributes) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/graphql/mutations/work_items/convert.rb', line 24

def resolve(attributes)
  work_item = authorized_find!(id: attributes[:id])

  work_item_type = find_work_item_type!(attributes[:work_item_type_id])
  authorize_work_item_type!(work_item, work_item_type)

  update_result = ::WorkItems::UpdateService.new(
    container: work_item.project,
    current_user: current_user,
    params: { work_item_type: work_item_type, issue_type: work_item_type.base_type },
    perform_spam_check: true
  ).execute(work_item)

  check_spam_action_response!(work_item)

  {
    work_item: (update_result[:work_item] if update_result[:status] == :success),
    errors: Array.wrap(update_result[:message])
  }
end