Skip to content

Commit

Permalink
Merge branch 'master' into 9415-vaos-policy
Browse files Browse the repository at this point in the history
  • Loading branch information
aherzberg authored Sep 23, 2024
2 parents a288b79 + 9a4fb45 commit 5490e4f
Show file tree
Hide file tree
Showing 23 changed files with 696 additions and 103 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ app/swagger/swagger/requests/mdot @department-of-veterans-affairs/va-cto-health-
app/swagger/swagger/requests/medical_copays.rb @department-of-veterans-affairs/vsa-debt-resolution @department-of-veterans-affairs/backend-review-group
app/swagger/swagger/requests/messages @department-of-veterans-affairs/vfs-mhv-secure-messaging @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
app/swagger/swagger/requests/mvi_users.rb @department-of-veterans-affairs/octo-identity
app/swagger/swagger/requests/my_va/submission_statuses.rb @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
app/swagger/swagger/requests/onsite_notifications.rb @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
app/swagger/swagger/v1/requests/post911_gi_bill_statuses.rb @department-of-veterans-affairs/backend-review-group @department-of-veterans-affairs/va-iir
app/swagger/swagger/requests/ppiu.rb @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ GEM
llhttp-ffi (0.5.0)
ffi-compiler (~> 1.0)
rake (~> 13.0)
lockbox (1.4.0)
lockbox (1.4.1)
logger (1.6.1)
loofah (2.22.0)
crass (~> 1.0.2)
Expand Down Expand Up @@ -935,7 +935,7 @@ GEM
rubocop-factory_bot (2.26.1)
rubocop (~> 1.61)
rubocop-junit-formatter (0.1.4)
rubocop-rails (2.26.1)
rubocop-rails (2.26.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.52.0, < 2.0)
Expand Down
1 change: 1 addition & 0 deletions app/controllers/v0/apidocs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class ApidocsController < ApplicationController
Swagger::Requests::Messages::TriageTeams,
Swagger::Requests::MviUsers,
Swagger::Requests::OnsiteNotifications,
Swagger::Requests::MyVA::SubmissionStatuses,
Swagger::Requests::IncomeAndAssetsClaims,
Swagger::Requests::PPIU,
Swagger::Requests::PreneedsClaims,
Expand Down
15 changes: 13 additions & 2 deletions app/sidekiq/lighthouse/submit_benefits_intake_claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BenefitsIntakeClaimError < StandardError; end
StatsD.increment("#{STATSD_KEY_PREFIX}.exhausted")
end

def perform(saved_claim_id)
def perform(saved_claim_id) # rubocop:disable Metrics/MethodLength
init(saved_claim_id)

@pdf_path = if @claim.form_id == '21P-530V2'
Expand All @@ -46,7 +46,10 @@ def perform(saved_claim_id)

Rails.logger.info('Lighthouse::SubmitBenefitsIntakeClaim succeeded', generate_log_details)
StatsD.increment("#{STATSD_KEY_PREFIX}.success")
@claim.send_confirmation_email if @claim.respond_to?(:send_confirmation_email)

send_confirmation_email

@lighthouse_service.uuid
rescue => e
Rails.logger.warn('Lighthouse::SubmitBenefitsIntakeClaim failed, retrying...', generate_log_details(e))
StatsD.increment("#{STATSD_KEY_PREFIX}.failure")
Expand Down Expand Up @@ -165,5 +168,13 @@ def cleanup_file_paths
def check_zipcode(address)
address['country'].upcase.in?(%w[USA US])
end

def send_confirmation_email
@claim.respond_to?(:send_confirmation_email) && @claim.send_confirmation_email
rescue => e
Rails.logger.warn('Lighthouse::SubmitBenefitsIntakeClaim send_confirmation_email failed',
generate_log_details(e))
StatsD.increment("#{STATSD_KEY_PREFIX}.send_confirmation_email.failure")
end
end
end
122 changes: 122 additions & 0 deletions app/swagger/swagger/requests/my_va/submission_statuses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# app/controllers/v0/my_va/submission_statuses_controller.rb

# frozen_string_literal: true

module Swagger
module Requests
module MyVA
class SubmissionStatuses
include Swagger::Blocks

swagger_path '/v0/my_va/submission_statuses' do
operation :get do
key :description, 'Get list of submitted forms for the current session'
key :operationId, 'getSubmissionStatuses'
key :tags, %w[
my_va
]

parameter :authorization

key :produces, ['application/json']

response 200 do
key :description, 'submitted forms and statuses'

schema do
key :type, :object

property :data do
key :type, :array
items do
key :required, %i[
id
type
attributes
]
property :id, type: :string, example: '3b03b5a0-3ad9-4207-b61e-3a13ed1c8b80',
description: 'Form submission UID'
property :type, type: :string, example: 'submission_status', description: 'type of request'
property :attributes do
key :$ref, :SubmissionStatusAttrs
end
end
end
end
end

response 296 do
key :description, 'submitted forms but errors occured looking up statuses from lighthouse'

schema do
key :type, :object
key :required, %i[data errors]
property :data do
key :type, :array
items do
key :required, %i[
id
type
attributes
]
property :id, type: :string, example: '3b03b5a0-3ad9-4207-b61e-3a13ed1c8b80',
description: 'Form submission UID'
property :type, type: :string, example: 'submission_status', description: 'type of request'
property :attributes do
key :$ref, :SubmissionStatusAttrs
end
end
end

property :errors do
key :type, :array
items do
key :required, %i[
status
source
title
detail
]
property :status, type: :integer, example: 429, description: 'Error code'
property :source, type: :string, example: 'Lighthouse - Benefits Intake API',
description: 'Error source'
property :title, type: :string, example: 'Form Submission Status: Too Many Requests',
description: 'Error description'
property :detail, type: :string, example: 'API rate limit exceeded', description: 'Error details'
end
end
end
end
end
end

swagger_schema :SubmissionStatusAttrs do
key :type, :object
key :description, 'submitted form attributes'

property :id, type: :string, example: '3b03b5a0-3ad9-4207-b61e-3a13ed1c8b80',
description: 'Submitted form UID from lighthouse'
property :detail, type: [:string, 'null'], example: '',
description: 'Error details (only when errors are present)'
property :form_type, type: :string, example: '21-0845', description: 'The type of form'
property :message, type: [:string, 'null']
property :status, type: [:string, 'null'], enum: [
nil,
'pending',
'uploaded',
'received',
'processing',
'success',
'vbms',
'error',
'expired'
], example: 'received', description: 'The current status of the submission'
property :created_at, type: :string, example: '2023-12-15T20:40:47.583Z',
description: 'The submission record created in VA.gov'
property :updated_at, type: [:string, 'null'], example: '2023-12-15T20:40:54.474Z',
description: 'The last time the submission status was updated'
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,13 @@ def validate
validate_poa_code!(poa_code)
validate_poa_code_for_current_user!(poa_code) if header_request? && !token.client_credentials_token?
if Flipper.enabled?(:lighthouse_claims_api_poa_dependent_claimants) && form_attributes['claimant'].present?
service = ClaimsApi::DependentClaimantVerificationService.new(target_veteran.participant_id,
form_attributes.dig('claimant', 'firstName'),
form_attributes.dig('claimant', 'lastName'),
poa_code)
veteran_participant_id = target_veteran.participant_id
claimant_first_name = form_attributes.dig('claimant', 'firstName')
claimant_last_name = form_attributes.dig('claimant', 'lastName')
service = ClaimsApi::DependentClaimantVerificationService.new(veteran_participant_id:,
claimant_first_name:,
claimant_last_name:,
poa_code:)
service.validate_poa_code_exists!
service.validate_dependent_by_participant_id!
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ def status
private

def shared_form_validation(form_number)
target_veteran
base = form_number == '2122' ? 'serviceOrganization' : 'representative'
poa_code = form_attributes.dig(base, 'poaCode')

# Custom validations for POA submission, we must check this first
@claims_api_forms_validation_errors = validate_form_2122_and_2122a_submission_values(user_profile)
@claims_api_forms_validation_errors = validate_form_2122_and_2122a_submission_values(
target_veteran.participant_id, user_profile, poa_code
)
# JSON validations for POA submission, will combine with previously captured errors and raise
validate_json_schema(form_number.upcase)
@rep_id = validate_registration_number!(form_number)
@rep_id = validate_registration_number!(base, poa_code)

add_claimant_data_to_form if user_profile
# if we get here there were only validations file errors
Expand All @@ -57,10 +61,8 @@ def shared_form_validation(form_number)
end
end

def validate_registration_number!(form_number)
base = form_number == '2122' ? 'serviceOrganization' : 'representative'
def validate_registration_number!(base, poa_code)
rn = form_attributes.dig(base, 'registrationNumber')
poa_code = form_attributes.dig(base, 'poaCode')
rep = ::Veteran::Service::Representative.where('? = ANY(poa_codes) AND representative_id = ?',
poa_code,
rn).order(created_at: :desc).first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ class PowerOfAttorney::RequestController < ClaimsApi::V2::Veterans::PowerOfAttor
FORM_NUMBER = 'POA_REQUEST'

def request_representative
target_veteran
@claims_api_forms_validation_errors = validate_form_2122_and_2122a_submission_values(user_profile)
poa_code = form_attributes.dig('poa', 'poaCode')
@claims_api_forms_validation_errors = validate_form_2122_and_2122a_submission_values(
target_veteran.participant_id, user_profile, poa_code
)

validate_json_schema(FORM_NUMBER)
validate_accredited_representative(form_attributes.dig('poa', 'registrationNumber'),
form_attributes.dig('poa', 'poaCode'))
validate_accredited_organization(form_attributes.dig('poa', 'poaCode'))
poa_code)
validate_accredited_organization(poa_code)

# if we get here, the only errors not raised are form value validation errors
if @claims_api_forms_validation_errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
module ClaimsApi
module V2
module PowerOfAttorneyValidation
def validate_form_2122_and_2122a_submission_values(user_profile)
validate_claimant(user_profile)
def validate_form_2122_and_2122a_submission_values(veteran_participant_id, user_profile, poa_code)
validate_claimant(veteran_participant_id, user_profile, poa_code)
# collect errors and pass back to the controller
raise_error_collection if @errors
end

private

def validate_claimant(user_profile)
def validate_claimant(veteran_participant_id, user_profile, poa_code)
return if form_attributes['claimant'].blank?

validate_claimant_id_included(user_profile)
validate_address
validate_relationship
validate_dependent_claimant(veteran_participant_id, user_profile, poa_code)
end

def validate_address
Expand Down Expand Up @@ -95,6 +96,38 @@ def validate_relationship
end
end

# rubocop:disable Metrics/MethodLength
def validate_dependent_claimant(veteran_participant_id, user_profile, poa_code)
unless Flipper.enabled?(:lighthouse_claims_api_poa_dependent_claimants) && form_attributes['claimant'].present?
return
end

claimant = user_profile.profile
service = ClaimsApi::DependentClaimantVerificationService.new(veteran_participant_id:,
claimant_first_name: claimant.given_names.first,
claimant_last_name: claimant.family_name,
claimant_participant_id: claimant.participant_id,
poa_code:)
begin
service.validate_poa_code_exists!
rescue ::Common::Exceptions::UnprocessableEntity
collect_error_messages(
source: '/poaCode',
detail: ClaimsApi::DependentClaimantVerificationService::POA_CODE_NOT_FOUND_ERROR_MESSAGE
)
end

begin
service.validate_dependent_by_participant_id!
rescue ::Common::Exceptions::UnprocessableEntity
collect_error_messages(
source: '/claimant/claimantId',
detail: ClaimsApi::DependentClaimantVerificationService::CLAIMANT_NOT_A_DEPENDENT_ERROR_MESSAGE
)
end
end
# rubocop:enable Metrics/MethodLength

def validate_claimant_id_included(user_profile)
claimant_icn = form_attributes.dig('claimant', 'claimantId')
if (user_profile.blank? || user_profile&.status == :not_found) && claimant_icn
Expand Down
Loading

0 comments on commit 5490e4f

Please sign in to comment.