Class: V0::InProgressFormsController

Inherits:
ApplicationController show all
Includes:
IgnoreNotFound
Defined in:
app/controllers/v0/in_progress_forms_controller.rb

Constant Summary

Constants inherited from ApplicationController

ApplicationController::VERSION_STATUS

Constants included from SignIn::Authentication

SignIn::Authentication::BEARER_PATTERN

Constants included from ExceptionHandling

ExceptionHandling::SKIP_SENTRY_EXCEPTION_TYPES

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_user

Instance Method Summary collapse

Methods included from IgnoreNotFound

#skip_sentry_exception_types

Methods inherited from ApplicationController

#clear_saved_form, #cors_preflight, #pagination_params, #render_job_id, #routing_error, #set_csrf_header

Methods included from Traceable

#set_trace_tags

Methods included from SentryControllerLogging

#set_tags_and_extra_context, #tags_context, #user_context

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata

Methods included from Instrumentation

#append_info_to_payload

Methods included from SignIn::Authentication

#access_token, #access_token_authenticate, #authenticate, #authenticate_access_token, #bearer_token, #cookie_access_token, #handle_authenticate_error, #load_user, #load_user_object, #scrub_bearer_token, #validate_request_ip

Methods included from Headers

#set_app_info_headers

Methods included from ExceptionHandling

#render_errors, #report_mapped_exception, #report_original_exception, #skip_sentry_exception?, #skip_sentry_exception_types

Methods included from AuthenticationAndSSOConcerns

#authenticate, #clear_session, #extend_session!, #load_user, #log_sso_info, #render_unauthorized, #reset_session, #set_api_cookie!, #set_current_user, #set_session_expiration_header, #set_session_object, #sign_in_service_exp_time, #sign_in_service_session, #sso_cookie_content, #sso_logging_info, #validate_inbound_login_params, #validate_session

Methods included from SignIn::AudienceValidator

#authenticate, #validate_audience!

Instance Method Details

#camelize_with_olivebranch(form_json) ⇒ Object (private)



61
62
63
64
65
66
67
68
# File 'app/controllers/v0/in_progress_forms_controller.rb', line 61

def camelize_with_olivebranch(form_json)
  # camelize exactly as OliveBranch would
  # inspired by vets-api/blob/327b26c76ea7904744014ea35463022e8b50f3fb/lib/tasks/support/schema_camelizer.rb#L27
  OliveBranch::Transformations.transform(
    form_json,
    OliveBranch::Transformations.method(:camelize)
  )
end

#camelized_prefill_for_userObject (private)

the front end is always expecting camelCase –this ensures that, even if the OliveBranch inflection header isn’t used, camelCase keys are sent



57
58
59
# File 'app/controllers/v0/in_progress_forms_controller.rb', line 57

def camelized_prefill_for_user
  camelize_with_olivebranch(FormProfile.for(form_id: params[:id], user: @current_user).prefill.as_json)
end

#destroyObject



38
39
40
41
42
43
# File 'app/controllers/v0/in_progress_forms_controller.rb', line 38

def destroy
  raise Common::Exceptions::RecordNotFound, form_id if form_for_user.blank?

  form_for_user.destroy
  render json: InProgressFormSerializer.new(form_for_user)
end

#form_for_userObject (private)



47
48
49
# File 'app/controllers/v0/in_progress_forms_controller.rb', line 47

def form_for_user
  @form_for_user ||= InProgressForm.submission_pending.form_for_user(form_id, @current_user)
end

#form_idObject (private)



51
52
53
# File 'app/controllers/v0/in_progress_forms_controller.rb', line 51

def form_id
  params[:id]
end

#indexObject



8
9
10
11
12
13
# File 'app/controllers/v0/in_progress_forms_controller.rb', line 8

def index
  # the keys of metadata shouldn't be deeply transformed, which might corrupt some keys
  # see https://github.com/department-of-veterans-affairs/va.gov-team/issues/17595 for more details
  pending_submissions = InProgressForm.submission_pending.for_user(@current_user)
  render json: InProgressFormSerializer.new(pending_submissions)
end

#showObject



15
16
17
# File 'app/controllers/v0/in_progress_forms_controller.rb', line 15

def show
  render json: form_for_user&. || camelized_prefill_for_user
end

#updateObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/v0/in_progress_forms_controller.rb', line 19

def update
  form = InProgressForm.form_for_user(form_id, @current_user) ||
         InProgressForm.new(form_id:, user_uuid: @current_user.uuid)
  form. = @current_user.
  form.real_user_uuid = @current_user.uuid

  ClaimFastTracking::MaxCfiMetrics.log_form_update(form, params)

  form.update!(form_data: params[:form_data] || params[:formData], metadata: params[:metadata])

  if Flipper.enabled?(:intent_to_file_lighthouse_enabled, @current_user) && form.id_previously_changed? &&
     Lighthouse::CreateIntentToFileJob::ITF_FORMS.include?(form.form_id)
    Lighthouse::CreateIntentToFileJob.perform_async(form.id, @current_user.icn,
                                                    @current_user.participant_id)
  end

  render json: InProgressFormSerializer.new(form)
end