Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
aherzberg committed Sep 23, 2024
2 parents 538c15c + 5c10857 commit 7432bff
Show file tree
Hide file tree
Showing 38 changed files with 812 additions and 157 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
16 changes: 0 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,6 @@ PATH
veteran_confirmation (0.0.1)
vye (0.1.0)

GEM
remote: https://enterprise.contribsys.com/
specs:
sidekiq-ent (7.2.4)
einhorn (~> 1.0)
gserver
sidekiq (>= 7.2.0, < 8)
sidekiq-pro (>= 7.2.0, < 8)
sidekiq-pro (7.2.1)
base64
sidekiq (>= 7.2.0, < 8)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -405,7 +393,6 @@ GEM
dry-initializer (~> 3.0)
dry-schema (>= 1.12, < 2)
zeitwerk (~> 2.6)
einhorn (1.0.0)
erubi (1.13.0)
et-orbi (1.2.11)
tzinfo
Expand Down Expand Up @@ -527,7 +514,6 @@ GEM
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
gserver (0.0.1)
guard (2.18.1)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
Expand Down Expand Up @@ -1274,8 +1260,6 @@ DEPENDENCIES
shoulda-matchers
shrine
sidekiq (~> 7.2.0)
sidekiq-ent!
sidekiq-pro!
sign_in_service
simple_forms_api!
simplecov
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
51 changes: 29 additions & 22 deletions app/controllers/v0/backend_statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,48 @@ module V0
class BackendStatusesController < ApplicationController
service_tag 'maintenance-windows'
skip_before_action :authenticate
before_action :validate_service, only: [:show]

# NOTE: this endpoint is somewhat misleading. Index gets data from PagerDuty and
# show only looks at GI bill scheduled downtime (and gets no data from PagerDuty)
def index
statuses = ExternalServicesRedis::Status.new.fetch_or_cache
maintenance_windows = MaintenanceWindow.end_after(Time.zone.now)

options = { params: { maintenance_windows: } }
render json: BackendStatusesSerializer.new(statuses, options)
render json: BackendStatusesSerializer.new(backend_statuses, options)
end

# GET /v0/backend_statuses/:service
def show
@backend_service = params[:service]
raise Common::Exceptions::RecordNotFound, @backend_service unless recognized_service?
render json: BackendStatusSerializer.new(backend_status)
end

# get status
be_status = BackendStatus.new(name: @backend_service)
case @backend_service
when BackendServices::GI_BILL_STATUS
be_status.is_available = BenefitsEducation::Service.within_scheduled_uptime?
be_status.uptime_remaining = BenefitsEducation::Service.seconds_until_downtime
else
# default service is up!
be_status.is_available = true
be_status.uptime_remaining = 0
end
private

render json: BackendStatusSerializer.new(be_status)
# NOTE: Data is from PagerDuty
def backend_statuses
@backend_statuses ||= ExternalServicesRedis::Status.new.fetch_or_cache
end

private
def maintenance_windows
@maintenance_windows ||= MaintenanceWindow.end_after(Time.zone.now)
end

# NOTE: Data is GI bill scheduled downtime
def backend_status
@backend_status ||= BackendStatus.new(name: backend_service)
end

def backend_service
params[:service]
end

def validate_service
raise Common::Exceptions::RecordNotFound, backend_service unless recognized_service?
end

def recognized_service?
BackendServices.all.include?(@backend_service)
BackendServices.all.include?(backend_service)
end

def backend_status_is_available
backend_service == BackendServices::GI_BILL_STATUS
end
end
end
25 changes: 20 additions & 5 deletions app/models/backend_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,29 @@
class BackendStatus
include ActiveModel::Serialization
include ActiveModel::Validations
include Virtus.model(nullify_blank: true)

attribute :name, String
attribute :service_id, String
attribute :is_available, Boolean
attribute :uptime_remaining, Integer
attr_reader :name, :service_id

validates :name, presence: true
validates :is_available, presence: true
validates :uptime_remaining, presence: true

def initialize(name:, service_id: nil)
@name = name
@service_id = service_id
end

def available?
gibs_service? ? BenefitsEducation::Service.within_scheduled_uptime? : true
end

def uptime_remaining
gibs_service? ? BenefitsEducation::Service.seconds_until_downtime.to_i : 0
end

private

def gibs_service?
@name == BackendServices::GI_BILL_STATUS
end
end
2 changes: 1 addition & 1 deletion app/serializers/backend_status_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class BackendStatusSerializer

attribute :name
attribute :service_id
attribute :is_available
attribute :is_available, &:available?
attribute :uptime_remaining
end
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
Loading

0 comments on commit 7432bff

Please sign in to comment.