Skip to content

Commit

Permalink
Merge branch 'master' into add-extra-date-stamp-for-4142
Browse files Browse the repository at this point in the history
  • Loading branch information
Thrillberg authored Apr 8, 2024
2 parents c85c819 + 57d14ca commit e70944a
Show file tree
Hide file tree
Showing 26 changed files with 713 additions and 59 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ app/models/rate_limited_search.rb @department-of-veterans-affairs/va-api-enginee
app/models/saml_request_tracker.rb @department-of-veterans-affairs/octo-identity
app/models/saved_claim.rb @department-of-veterans-affairs/Benefits-Team-1 @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
app/models/session.rb @department-of-veterans-affairs/octo-identity
app/models/saved_claim/burial.rb @department-of-veterans-affairs/benefits-non-disability @department-of-veterans-affairs/pensions @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
app/models/saved_claim/pension.rb @department-of-veterans-affairs/pensions @department-of-veterans-affairs/backend-review-group
app/models/saved_claim/veteran_readiness_employment_claim.rb @department-of-veterans-affairs/benefits-non-disability @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
app/models/sign_in @department-of-veterans-affairs/octo-identity
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ GEM
rswag-ui (2.13.0)
actionpack (>= 3.1, < 7.2)
railties (>= 3.1, < 7.2)
rubocop (1.62.1)
rubocop (1.63.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand Down
2 changes: 1 addition & 1 deletion app/models/saved_claim/burial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def regional_office
end

def attachment_keys
%i[transportationReceipts deathCertificate].freeze
%i[transportationReceipts deathCertificate militarySeparationDocuments additionalEvidence].freeze
end

def email
Expand Down
8 changes: 6 additions & 2 deletions app/sidekiq/lighthouse/submit_benefits_intake_claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ def generate_metadata
'veteranFirstName' => veteran_full_name['first'],
'veteranLastName' => veteran_full_name['last'],
'fileNumber' => form['vaFileNumber'] || form['veteranSocialSecurityNumber'],
'zipCode' => address['country'] == 'USA' ? address['postalCode'] : FOREIGN_POSTALCODE,
'zipCode' => address['postalCode'],
'source' => "#{@claim.class} va.gov",
'docType' => @claim.form_id,
'businessLine' => @claim.business_line
}

SimpleFormsApiSubmission::MetadataValidator.validate(metadata)
SimpleFormsApiSubmission::MetadataValidator.validate(metadata, zip_code_is_us_based: check_zipcode(address))
end

# rubocop:disable Metrics/MethodLength
Expand Down Expand Up @@ -149,5 +149,9 @@ def cleanup_file_paths
Common::FileHelpers.delete_file_if_exists(@pdf_path) if @pdf_path
@attachment_paths&.each { |p| Common::FileHelpers.delete_file_if_exists(p) }
end

def check_zipcode(address)
address['country'].upcase.in?(%w[USA US])
end
end
end
8 changes: 6 additions & 2 deletions app/swagger/swagger/schemas/contacts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Contacts
key :required, [:data]
property :data, type: :array do
items do
property :id, type: :string, example: 'dbbf9a58-41e5-40c0-bdb5-fc1407aa1f05'
property :id, type: :string
property :type, type: :string
property :attributes do
key :$ref, :Contact
Expand All @@ -21,7 +21,11 @@ class Contacts

swagger_schema :Contact do
key :required, %i[contact_type given_name family_name primary_phone]
property :contact_type, type: :string, enum: VAProfile::Models::AssociatedPerson::CONTACT_TYPES
property(
:contact_type,
type: :string,
enum: VAProfile::Models::AssociatedPerson::PERSONAL_HEALTH_CARE_CONTACT_TYPES
)
property :given_name, type: %i[string null]
property :family_name, type: %i[string null]
property :relationship, type: %i[string null]
Expand Down
8 changes: 8 additions & 0 deletions lib/lighthouse/benefits_claims/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ def get_claim(id, lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, opt
raise BenefitsClaims::ServiceException.new(e.response), 'Lighthouse Error'
end

def get_power_of_attorney(lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, options = {})
config.get("#{@icn}/power-of-attorney", lighthouse_client_id, lighthouse_rsa_key_path, options).body
rescue Faraday::TimeoutError
raise BenefitsClaims::ServiceException.new({ status: 504 }), 'Lighthouse Error'
rescue Faraday::ClientError, Faraday::ServerError => e
raise BenefitsClaims::ServiceException.new(e.response), 'Lighthouse Error'
end

def submit5103(user, id, options = {})
params = {}
is_dependent = SponsorResolver.dependent?(user)
Expand Down
12 changes: 10 additions & 2 deletions lib/va_profile/models/associated_person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,27 @@ class AssociatedPerson < Base
OTHER_EMERGENCY_CONTACT = 'Other emergency contact'
PRIMARY_NEXT_OF_KIN = 'Primary Next of Kin'
OTHER_NEXT_OF_KIN = 'Other Next of Kin'
DESIGNEE = 'Designee'
POWER_OF_ATTORNEY = 'Power of Attorney'

CONTACT_TYPES = [
PERSONAL_HEALTH_CARE_CONTACT_TYPES = [
EMERGENCY_CONTACT,
OTHER_EMERGENCY_CONTACT,
PRIMARY_NEXT_OF_KIN,
OTHER_NEXT_OF_KIN
].freeze

CONTACT_TYPES = [
*PERSONAL_HEALTH_CARE_CONTACT_TYPES,
DESIGNEE,
POWER_OF_ATTORNEY
].freeze

attribute :contact_type, String
attribute :given_name, Common::TitlecaseString
attribute :middle_name, Common::TitlecaseString
attribute :family_name, Common::TitlecaseString
attribute :relationship, Common::TitlecaseString
attribute :relationship, String
attribute :address_line1, String
attribute :address_line2, String
attribute :address_line3, String
Expand Down
30 changes: 18 additions & 12 deletions lib/va_profile/profile/v3/health_benefit_bio_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,39 @@ module VAProfile
module Profile
module V3
class HealthBenefitBioResponse < VAProfile::Response
attr_reader :body

attribute :contacts, Array[VAProfile::Models::AssociatedPerson]
attribute :messages, Array[VAProfile::Models::Message]
attribute :va_profile_tx_audit_id, String

def initialize(response)
@body = response.body
body = response.body
contacts = body.dig('profile', 'health_benefit', 'associated_persons')
&.select { |p| valid_contact_types.include?(p['contact_type']) }
&.sort_by { |p| valid_contact_types.index(p['contact_type']) }
messages = body['messages']
super(response.status, { contacts:, messages: })
va_profile_tx_audit_id = response.response_headers['vaprofiletxauditid']
super(response.status, { contacts:, messages:, va_profile_tx_audit_id: })
end

def metadata
{ status:, messages: }
def debug_data
{
status:,
message:,
va_profile_tx_audit_id:
}
end

private

def valid_contact_types
[
VAProfile::Models::AssociatedPerson::EMERGENCY_CONTACT,
VAProfile::Models::AssociatedPerson::OTHER_EMERGENCY_CONTACT,
VAProfile::Models::AssociatedPerson::PRIMARY_NEXT_OF_KIN,
VAProfile::Models::AssociatedPerson::OTHER_NEXT_OF_KIN
]
VAProfile::Models::AssociatedPerson::PERSONAL_HEALTH_CARE_CONTACT_TYPES
end

def message
m = messages&.first
return '' unless m

"#{m.code} #{m.key} #{m.text}"
end
end
end
Expand Down
6 changes: 4 additions & 2 deletions lib/va_profile/profile/v3/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ def initialize(user)
def get_health_benefit_bio
oid = MPI::Constants::VA_ROOT_OID
path = "#{oid}/#{ERB::Util.url_encode(icn_with_aaid)}"
response = perform(:post, path, { bios: [{ bioPath: 'healthBenefit' }] })
VAProfile::Profile::V3::HealthBenefitBioResponse.new(response)
service_response = perform(:post, path, { bios: [{ bioPath: 'healthBenefit' }] })
response = VAProfile::Profile::V3::HealthBenefitBioResponse.new(service_response)
Sentry.set_extras(response.debug_data) unless response.ok?
response
end

def get_military_info
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# frozen_string_literal: true

require 'lighthouse/benefits_claims/service'

module RepresentationManagement
module V0
class PowerOfAttorneyController < ApplicationController
service_tag 'representation-management'

def index
@active_poa = lighthouse_service.get_power_of_attorney

if @active_poa.blank? || record.blank?
render json: { data: {} }, status: :ok
else
render json: record, serializer:, status: :ok
end
end

private

def lighthouse_service
BenefitsClaims::Service.new(icn)
end

def icn
@current_user&.icn
end

def poa_code
@poa_code ||= @active_poa.dig('data', 'attributes', 'code')
end

def poa_type
@poa_type ||= @active_poa.dig('data', 'type')
end

def record
return @record if defined? @record

@record ||= if poa_type == 'organization'
organization
else
representative
end
end

def serializer
if poa_type == 'organization'
RepresentationManagement::PowerOfAttorney::OrganizationSerializer
else
RepresentationManagement::PowerOfAttorney::RepresentativeSerializer
end
end

def organization
Veteran::Service::Organization.find_by(poa: poa_code)
end

def representative
Veteran::Service::Representative.where('? = ANY(poa_codes)', poa_code).order(created_at: :desc).first
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module RepresentationManagement
module PowerOfAttorney
class BaseSerializer < ActiveModel::Serializer
attribute :address_line1
attribute :address_line2
attribute :address_line3
attribute :address_type
attribute :city
attribute :country_name
attribute :country_code_iso3
attribute :province
attribute :international_postal_code
attribute :state_code
attribute :zip_code
attribute :zip_suffix
attribute :phone
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module RepresentationManagement
module PowerOfAttorney
class OrganizationSerializer < BaseSerializer
attribute :type
attribute :name

def type
'organization'
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module RepresentationManagement
module PowerOfAttorney
class RepresentativeSerializer < BaseSerializer
attribute :type
attribute :name
attribute :email

def type
'representative'
end

def name
object.full_name
end

def phone
object.phone_number
end
end
end
end
1 change: 1 addition & 0 deletions modules/representation_management/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
RepresentationManagement::Engine.routes.draw do
namespace :v0, defaults: { format: 'json' } do
resources :flag_accredited_representatives, only: %i[create]
resources :power_of_attorney, only: %i[index]
end
end
Loading

0 comments on commit e70944a

Please sign in to comment.