Skip to content

Commit

Permalink
Use New Status Field to Maintain InProgressForm Data for Dependents …
Browse files Browse the repository at this point in the history
…Application (#16097)

* Plucked db changes

* Add rakelib task

* App changes

* Modify Codeowners

---------

Co-authored-by: Rachal Cassity <[email protected]>
  • Loading branch information
tfink419 and RachalCassity authored May 9, 2024
1 parent 41a2edc commit 8e6112a
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 29 deletions.
6 changes: 3 additions & 3 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ app/controllers/v0/higher_level_reviews_controller.rb @department-of-veterans-af
app/controllers/v0/higher_level_reviews @department-of-veterans-affairs/benefits-decision-reviews-be @department-of-veterans-affairs/backend-review-group
app/controllers/v0/id_card_announcement_subscription_controller.rb @department-of-veterans-affairs/backend-review-group
app/controllers/v0/id_card_attributes_controller.rb @department-of-veterans-affairs/backend-review-group
app/controllers/v0/in_progress_forms_controller.rb @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
app/controllers/v0/in_progress_forms_controller.rb @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group @department-of-veterans-affairs/benefits-dependents-management
app/controllers/v0/intent_to_files_controller.rb @department-of-veterans-affairs/Disability-Experience @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
app/controllers/v0/letters_controller.rb @department-of-veterans-affairs/benefits-management-tools-be @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
app/controllers/v0/letters_generator_controller.rb @department-of-veterans-affairs/benefits-management-tools-be @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
Expand Down Expand Up @@ -271,7 +271,7 @@ app/models/id_card_attributes.rb @department-of-veterans-affairs/backend-review-
app/models/identifier_index.rb @department-of-veterans-affairs/vsa-debt-resolution @department-of-veterans-affairs/backend-review-group
app/models/inherited_proofing @department-of-veterans-affairs/octo-identity
app/models/inherited_proof_verified_user_account.rb @department-of-veterans-affairs/octo-identity
app/models/in_progress_form.rb @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
app/models/in_progress_form.rb @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group @department-of-veterans-affairs/benefits-dependents-management
app/models/ivc_champva_form.rb @department-of-veterans-affairs/champva-engineering @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
app/models/lighthouse_document.rb @department-of-veterans-affairs/backend-review-group
app/models/maintenance_window.rb @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
Expand Down Expand Up @@ -1482,7 +1482,7 @@ spec/models/health_care_application_spec.rb @department-of-veterans-affairs/vfs-
spec/models/iam_user_identity_spec.rb @department-of-veterans-affairs/octo-identity
spec/models/inherited_proofing @department-of-veterans-affairs/octo-identity
spec/models/inherited_proof_verified_user_account_spec.rb @department-of-veterans-affairs/octo-identity
spec/models/in_progress_form_spec.rb @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/models/in_progress_form_spec.rb @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group @department-of-veterans-affairs/benefits-dependents-management
spec/models/ivc_champva_forms_spec.rb @department-of-veterans-affairs/champva-engineering @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/models/message_spec.rb @department-of-veterans-affairs/vfs-mhv-secure-messaging @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/models/mhv_opt_in_flag_spec.rb @department-of-veterans-affairs/vfs-mhv-secure-messaging @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/v0/dependents_applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create
dependent_service.submit_686c_form(claim)

Rails.logger.info "ClaimID=#{claim.confirmation_number} Form=#{claim.class::FORM}"
clear_saved_form(claim.form_id)
# clear_saved_form(claim.form_id) # We do not want to destroy the InProgressForm for this submission

render(json: claim)
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/v0/in_progress_forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class InProgressFormsController < ApplicationController
def index
# :unaltered prevents the keys from being deeply transformed, which might corrupt some keys
# see https://github.com/department-of-veterans-affairs/va.gov-team/issues/17595 for more details
render json: InProgressForm.for_user(@current_user), key_transform: :unaltered
render json: InProgressForm.submission_pending.for_user(@current_user), key_transform: :unaltered
end

def show
Expand Down Expand Up @@ -37,7 +37,7 @@ def destroy
private

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

def form_id
Expand Down
2 changes: 2 additions & 0 deletions app/models/in_progress_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def cast(value)
scope :for_form, ->(form_id) { where(form_id:) }
scope :not_submitted, -> { where.not("metadata -> 'submission' ->> 'status' = ?", 'applicationSubmitted') }
scope :unsubmitted_fsr, -> { for_form('5655').not_submitted }
enum :status, %w[pending processing], prefix: :submission, default: :pending
scope :submission_pending, -> { where(status: [nil, 'pending']) } # override to include nil
attribute :user_uuid, CleanUUID.new
serialize :form_data, coder: JsonMarshal::Marshaller
has_kms_key
Expand Down
2 changes: 2 additions & 0 deletions app/services/bgs/dependent_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def get_dependents
def submit_686c_form(claim)
Rails.logger.info('BGS::DependentService running!', { user_uuid: uuid, saved_claim_id: claim.id, icn: })

InProgressForm.find_by(form_id: BGS::SubmitForm686cJob::FORM_ID, user_uuid: uuid)&.submission_processing!

encrypted_vet_info = KmsEncrypted::Box.new.encrypt(get_form_hash_686c.to_json)
submit_pdf_job(claim:, encrypted_vet_info:)

Expand Down
2 changes: 1 addition & 1 deletion app/services/users/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def veteran_status
end

def in_progress_forms
InProgressForm.for_user(user).map do |form|
InProgressForm.submission_pending.for_user(user).map do |form|
{
form: form.form_id,
metadata: form.metadata,
Expand Down
22 changes: 11 additions & 11 deletions app/sidekiq/bgs/submit_form674_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Invalid674Claim < StandardError; end
include Sidekiq::Job
include SentryLogging

attr_reader :claim, :user, :in_progress_copy, :user_uuid, :saved_claim_id, :vet_info, :icn
attr_reader :claim, :user, :user_uuid, :saved_claim_id, :vet_info, :icn

sidekiq_options retry: 14

Expand All @@ -19,23 +19,19 @@ class Invalid674Claim < StandardError; end
Rails.logger.error('BGS::SubmitForm674Job failed, retries exhausted...',
{ user_uuid:, saved_claim_id:, icn:, error: })

BGS::SubmitForm674Job.send_backup_submission(encrypted_user_struct_hash, vet_info, saved_claim_id)
BGS::SubmitForm674Job.send_backup_submission(encrypted_user_struct_hash, vet_info, saved_claim_id, user_uuid)
end

def perform(user_uuid, icn, saved_claim_id, encrypted_vet_info, encrypted_user_struct_hash = nil)
Rails.logger.info('BGS::SubmitForm674Job running!', { user_uuid:, saved_claim_id:, icn: })
instance_params(encrypted_vet_info, icn, encrypted_user_struct_hash, user_uuid, saved_claim_id)

in_progress_form = InProgressForm.find_by(form_id: FORM_ID, user_uuid:)
@in_progress_copy = in_progress_form_copy(in_progress_form)

submit_form

send_confirmation_email
in_progress_form&.destroy
Rails.logger.info('BGS::SubmitForm674Job succeeded!', { user_uuid:, saved_claim_id:, icn: })
InProgressForm.destroy_by(form_id: FORM_ID, user_uuid:)
rescue => e
salvage_save_in_progress_form(FORM_ID, user_uuid, @in_progress_copy) if @in_progress_copy.present?
handle_filtered_errors!(e:, encrypted_user_struct_hash:, encrypted_vet_info:)

Rails.logger.warn('BGS::SubmitForm674Job received error, retrying...',
Expand All @@ -52,7 +48,7 @@ def handle_filtered_errors!(e:, encrypted_user_struct_hash:, encrypted_vet_info:
{ user_uuid:, saved_claim_id:, icn:, error: e.message, nested_error: e.cause&.message })

vet_info = JSON.parse(KmsEncrypted::Box.new.decrypt(encrypted_vet_info))
self.class.send_backup_submission(encrypted_user_struct_hash, vet_info, saved_claim_id)
self.class.send_backup_submission(encrypted_user_struct_hash, vet_info, saved_claim_id, user_uuid)
raise Sidekiq::JobRetry::Skip
end

Expand All @@ -62,6 +58,7 @@ def instance_params(encrypted_vet_info, icn, encrypted_user_struct_hash, user_uu
@icn = icn
@user_uuid = user_uuid
@saved_claim_id = saved_claim_id
@claim = SavedClaim::DependencyClaim.find(saved_claim_id)
end

def self.generate_user_struct(encrypted_user_struct, vet_info)
Expand All @@ -85,7 +82,7 @@ def self.generate_user_struct(encrypted_user_struct, vet_info)
)
end

def self.send_backup_submission(encrypted_user_struct_hash, vet_info, saved_claim_id)
def self.send_backup_submission(encrypted_user_struct_hash, vet_info, saved_claim_id, user_uuid)
if Flipper.enabled?(:dependents_central_submission)
user = generate_user_struct(encrypted_user_struct_hash, vet_info)
CentralMail::SubmitCentralForm686cJob.perform_async(saved_claim_id,
Expand All @@ -94,13 +91,16 @@ def self.send_backup_submission(encrypted_user_struct_hash, vet_info, saved_clai
else
DependentsApplicationFailureMailer.build(user).deliver_now if user&.email.present? # rubocop:disable Style/IfInsideElse # Temporary for flipper
end
InProgressForm.destroy_by(form_id: FORM_ID, user_uuid:)
rescue => e
Rails.logger.warn('BGS::SubmitForm674Job backup submission failed...',
{ user_uuid:, saved_claim_id:, error: e.message, nested_error: e.cause&.message })
InProgressForm.find_by(form_id: FORM_ID, user_uuid:)&.submission_pending!
end

private

def submit_form
@claim = SavedClaim::DependencyClaim.find(saved_claim_id)

claim.add_veteran_info(vet_info)

raise Invalid674Claim unless claim.valid?(:run_686_form_jobs)
Expand Down
22 changes: 11 additions & 11 deletions app/sidekiq/bgs/submit_form686c_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Invalid686cClaim < StandardError; end
include Sidekiq::Job
include SentryLogging

attr_reader :claim, :user, :in_progress_copy, :user_uuid, :saved_claim_id, :vet_info, :icn
attr_reader :claim, :user, :user_uuid, :saved_claim_id, :vet_info, :icn

sidekiq_options retry: 14

Expand All @@ -19,23 +19,19 @@ class Invalid686cClaim < StandardError; end
Rails.logger.error('BGS::SubmitForm686cJob failed, retries exhausted!',
{ user_uuid:, saved_claim_id:, icn:, error: })

BGS::SubmitForm686cJob.send_backup_submission(vet_info, saved_claim_id)
BGS::SubmitForm686cJob.send_backup_submission(vet_info, saved_claim_id, user_uuid)
end

def perform(user_uuid, icn, saved_claim_id, encrypted_vet_info)
Rails.logger.info('BGS::SubmitForm686cJob running!', { user_uuid:, saved_claim_id:, icn: })
instance_params(encrypted_vet_info, icn, user_uuid, saved_claim_id)

in_progress_form = InProgressForm.find_by(form_id: FORM_ID, user_uuid:)
@in_progress_copy = in_progress_form_copy(in_progress_form)

submit_forms(encrypted_vet_info)

send_confirmation_email
in_progress_form&.destroy
Rails.logger.info('BGS::SubmitForm686cJob succeeded!', { user_uuid:, saved_claim_id:, icn: })
InProgressForm.destroy_by(form_id: FORM_ID, user_uuid:) unless claim.submittable_674?
rescue => e
salvage_save_in_progress_form(FORM_ID, user_uuid, @in_progress_copy) if @in_progress_copy.present?
handle_filtered_errors!(e:, encrypted_vet_info:)

Rails.logger.warn('BGS::SubmitForm686cJob received error, retrying...',
Expand All @@ -52,7 +48,7 @@ def handle_filtered_errors!(e:, encrypted_vet_info:)
{ user_uuid:, saved_claim_id:, icn:, error: e.message, nested_error: e.cause&.message })

vet_info = JSON.parse(KmsEncrypted::Box.new.decrypt(encrypted_vet_info))
self.class.send_backup_submission(vet_info, saved_claim_id)
self.class.send_backup_submission(vet_info, saved_claim_id, user_uuid)
raise Sidekiq::JobRetry::Skip
end

Expand All @@ -62,6 +58,7 @@ def instance_params(encrypted_vet_info, icn, user_uuid, saved_claim_id)
@icn = icn
@user_uuid = user_uuid
@saved_claim_id = saved_claim_id
@claim = SavedClaim::DependencyClaim.find(saved_claim_id)
end

def self.generate_user_struct(vet_info)
Expand All @@ -81,7 +78,7 @@ def self.generate_user_struct(vet_info)
)
end

def self.send_backup_submission(vet_info, saved_claim_id)
def self.send_backup_submission(vet_info, saved_claim_id, user_uuid)
if Flipper.enabled?(:dependents_central_submission)
user = generate_user_struct(vet_info)
CentralMail::SubmitCentralForm686cJob.perform_async(saved_claim_id,
Expand All @@ -90,13 +87,16 @@ def self.send_backup_submission(vet_info, saved_claim_id)
else
DependentsApplicationFailureMailer.build(user).deliver_now if user&.email.present? # rubocop:disable Style/IfInsideElse
end
InProgressForm.destroy_by(form_id: FORM_ID, user_uuid:)
rescue => e
Rails.logger.warn('BGS::SubmitForm686cJob backup submission failed...',
{ user_uuid:, saved_claim_id:, error: e.message, nested_error: e.cause&.message })
InProgressForm.find_by(form_id: FORM_ID, user_uuid:)&.submission_pending!
end

private

def submit_forms(encrypted_vet_info)
@claim = SavedClaim::DependencyClaim.find(saved_claim_id)

claim.add_veteran_info(vet_info)

raise Invalid686cClaim unless claim.valid?(:run_686_form_jobs)
Expand Down

0 comments on commit 8e6112a

Please sign in to comment.