Class: Mutations::WorkItems::Update

Inherits:
BaseMutation
  • Object
show all
Includes:
SpamProtection, UpdateArguments, Widgetable
Defined in:
app/graphql/mutations/work_items/update.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 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, #ready?, #unauthorized_object

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

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

Instance Method Details

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


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

def resolve(id:, **attributes)
  work_item = authorized_find!(id: id)

  unless work_item.project.work_items_feature_flag_enabled?
    return { errors: ['`work_items` feature flag disabled for this project'] }
  end

  spam_params = ::Spam::SpamParams.new_from_request(request: context[:request])
  widget_params = extract_widget_params(work_item.work_item_type, attributes)

  update_result = ::WorkItems::UpdateService.new(
    project: work_item.project,
    current_user: current_user,
    params: attributes,
    widget_params: widget_params,
    spam_params: spam_params
  ).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