Skip to content

Commit

Permalink
Merge branch 'master' into 98065/replace-json-schema
Browse files Browse the repository at this point in the history
  • Loading branch information
iandonovan committed Dec 17, 2024
2 parents b2fc708 + ef3c028 commit 085c581
Show file tree
Hide file tree
Showing 21 changed files with 402 additions and 29 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ group :development, :test do
gem 'byebug', platforms: :ruby # Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'danger'
gem 'database_cleaner'
gem 'debug'
gem 'factory_bot_rails'
gem 'faker'
# CAUTION: faraday_curl may not provide all headers used in the actual faraday request. Be cautious if using this to
Expand Down
6 changes: 5 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ GEM
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
colored2 (3.1.2)
combine_pdf (1.0.26)
combine_pdf (1.0.29)
matrix
ruby-rc4 (>= 0.1.5)
committee (5.4.0)
Expand Down Expand Up @@ -375,6 +375,9 @@ GEM
libddwaf (~> 1.14.0.0.0)
msgpack
debase-ruby_core_source (3.3.1)
debug (1.9.2)
irb (~> 1.10)
reline (>= 0.3.8)
declarative (0.0.20)
deep_merge (1.2.2)
descendants_tracker (0.0.4)
Expand Down Expand Up @@ -1181,6 +1184,7 @@ DEPENDENCIES
date_validator
ddtrace
debts_api!
debug
decision_reviews!
dhp_connected_devices!
dogstatsd-ruby (= 5.6.3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ def separation_locations
:all_users,
:get_separation_locations
) do
provider = Flipper.enabled?(:disability_compensation_staging_lighthouse_brd) ? :lighthouse_staging : nil
api_provider = ApiProviderFactory.call(
type: ApiProviderFactory::FACTORIES[:brd],
provider: nil,
provider:,
options: {},
current_user: @current_user,
feature_toggle: ApiProviderFactory::FEATURE_TOGGLE_BRD
Expand Down
3 changes: 3 additions & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ features:
caregiver_retry_form_validation:
actor_type: user
description: Enables 1010CG to retry schema validation
disability_compensation_staging_lighthouse_brd:
actor_type: user
description: Switches to Lighthouse Staging BRD Service. NEVER ENABLE IN PRODUCTION.
hca_browser_monitoring_enabled:
actor_type: user
description: Enables browser monitoring for the health care application.
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20241213171608_add_path_to_banners.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPathToBanners < ActiveRecord::Migration[7.2]
def change
add_column :banners, :path, :string
end
end
7 changes: 7 additions & 0 deletions db/migrate/20241213173113_add_index_to_banners_path.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddIndexToBannersPath < ActiveRecord::Migration[7.2]
disable_ddl_transaction!

def change
add_index :banners, :path, algorithm: :concurrently
end
end
4 changes: 3 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
require 'disability_compensation/providers/brd/brd_provider'
require 'disability_compensation/providers/brd/evss_brd_provider'
require 'disability_compensation/providers/brd/lighthouse_brd_provider'
require 'disability_compensation/providers/brd/lighthouse_staging_brd_provider'
require 'disability_compensation/providers/generate_pdf/generate_pdf_provider'
require 'disability_compensation/providers/generate_pdf/evss_generate_pdf_provider'
require 'disability_compensation/providers/generate_pdf/lighthouse_generate_pdf_provider'
Expand All @@ -28,7 +29,8 @@ class UndefinedFactoryTypeError < StandardError; end

API_PROVIDER = {
evss: :evss,
lighthouse: :lighthouse
lighthouse: :lighthouse,
lighthouse_staging: :lighthouse_staging
}.freeze

FACTORIES = {
Expand Down Expand Up @@ -166,6 +168,8 @@ def brd_service_provider
EvssBRDProvider.new(@current_user)
when API_PROVIDER[:lighthouse]
LighthouseBRDProvider.new(@current_user)
when API_PROVIDER[:lighthouse_staging]
LighthouseStagingBRDProvider.new(@current_user)
else
raise NotImplementedError, 'No known BRD Api Provider type provided'
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require 'disability_compensation/providers/brd/lighthouse_brd_provider'
require 'lighthouse/benefits_reference_data_staging/service'

class LighthouseStagingBRDProvider < LighthouseBRDProvider
def initialize(_current_user)
super
@service = BenefitsReferenceData::Staging::Service.new
end
end
68 changes: 68 additions & 0 deletions lib/lighthouse/benefits_reference_data_staging/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# frozen_string_literal: true

require 'common/client/configuration/rest'
require 'faraday/multipart'

module BenefitsReferenceData
##
# HTTP client configuration for the {BenefitsReferenceData::Service},
# sets the base path, the base request headers, and a service name for breakers and metrics.

module Staging
class Configuration < Common::Client::Configuration::REST
self.read_timeout = Settings.lighthouse.benefits_reference_data.timeout || 20

##
# @return [String] Base path for benefits_reference_data URLs.
#
def base_path
settings = Settings.lighthouse.benefits_reference_data
url = settings.staging_url
path = settings.path
version = settings.version
safe_slash_merge(url, path, version)
end

##
# @return [String] Service name to use in breakers and metrics.
#
def service_name
'BenefitsReferenceDataStaging'
end

##
# @return [Hash] The basic headers required for any benefits_reference_data API call.
#
def self.base_request_headers
key = Settings.lighthouse.staging_api_key
message = "No api_key set for LH benefits_reference_data_staging. Please set 'lighthouse.staging_api_key'"
raise message if key.nil?

super.merge('apiKey' => key)
end

##
# Creates the a connection with parsing json and adding breakers functionality.
#
# @return [Faraday::Connection] a Faraday connection instance.
#
def connection
@conn ||= Faraday.new(base_path, headers: base_request_headers, request: request_options) do |faraday|
faraday.use :breakers
faraday.use Faraday::Response::RaiseError

faraday.request :multipart
faraday.request :json
faraday.response :json
faraday.adapter Faraday.default_adapter
end
end

private

def safe_slash_merge(*url_segments)
url_segments.map { |segment| segment.sub(%r{^/}, '').chomp('/') }.join('/')
end
end
end
end
45 changes: 45 additions & 0 deletions lib/lighthouse/benefits_reference_data_staging/service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

require 'common/client/base'
require 'common/client/concerns/monitoring'
require 'common/client/errors'
require 'common/exceptions/forbidden'
require 'common/exceptions/schema_validation_errors'
require 'lighthouse/benefits_reference_data_staging/configuration'
require 'lighthouse/benefits_reference_data/service_exception'

module BenefitsReferenceData
##
# Proxy Service for the Lighthouse Benefits Reference Data API.

module Staging
class Service < Common::Client::Base
include SentryLogging
include Common::Client::Concerns::Monitoring

configuration BenefitsReferenceData::Staging::Configuration

# ap @configuration.base_request_headers; exit

STATSD_KEY_PREFIX = 'api.benefits_reference_data_staging'

##
# Hit a Benefits Reference Data End-point
#
# @path end-point [string|symbol] a string or symbol of the end-point you wish to hit.
# @params params hash [Hash] a hash of key-value pairs of parameters
#
# @return [Faraday::Response]
#
def get_data(path:, params: {})
headers = config.base_request_headers
begin
response = perform :get, path, params, headers
rescue => e
raise BenefitsReferenceData::ServiceException.new(e), 'Lighthouse Error'
end
response
end
end
end
end
11 changes: 9 additions & 2 deletions modules/ivc_champva/app/services/ivc_champva/attachments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module IvcChampva
module Attachments
attr_accessor :form_id, :uuid, :data

def handle_attachments(file_path)
def handle_attachments(file_path) # rubocop:disable Metrics/MethodLength
file_paths = [file_path]
attachments = get_attachments

Expand All @@ -22,7 +22,14 @@ def handle_attachments(file_path)
File.join(File.dirname(attachment), new_file_name)
end

File.rename(attachment, new_file_path)
if Flipper.enabled?(:champva_pdf_decrypt, @current_user)
# Use FileUtils.mv to handle `Errno::EXDEV` error since encrypted PDFs
# get stashed in the clamav_tmp dir which is a different device on staging, apparently
FileUtils.mv(attachment, new_file_path) # Performs a copy automatically if mv fails
else
File.rename(attachment, new_file_path)
end

file_paths << new_file_path
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ def get_first_name_from_user

def get_personalization(first_name)
if @form_number.start_with? 'vba_21_0966'
default_personalization(first_name).merge(form21_0966_personalization)
personalization = default_personalization(first_name).merge(form21_0966_personalization)
personalization.except!('lighthouse_updated_at') unless lighthouse_updated_at
personalization
else
default_personalization(first_name)
end
Expand Down Expand Up @@ -325,7 +327,7 @@ def form20_10207_contact_info
def form21_0845_contact_info
# (vet && signed in)
if @form_data['authorizer_type'] == 'veteran'
[@form_data['authorizer_email'] || @user&.va_profile_email, @form_data.dig('veteran_full_name', 'first')]
[@form_data['veteran_email'] || @user&.va_profile_email, @form_data.dig('veteran_full_name', 'first')]

# (non-vet && signed in) || (non-vet && anon)
elsif @form_data['authorizer_type'] == 'nonVeteran'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,6 @@
'first_name' => 'Veteran',
'date_submitted' => Time.zone.today.strftime('%B %d, %Y'),
'confirmation_number' => confirmation_number,
'lighthouse_updated_at' => nil,
'intent_to_file_benefits' => 'survivors pension benefits',
'intent_to_file_benefits_links' => '[Apply for DIC, Survivors Pension, and/or Accrued Benefits ' \
'(VA Form 21P-534EZ)](https://www.va.gov/find-forms/about-form-21p-534ez/)',
Expand All @@ -942,7 +941,6 @@
'first_name' => 'Veteran',
'date_submitted' => Time.zone.today.strftime('%B %d, %Y'),
'confirmation_number' => confirmation_number,
'lighthouse_updated_at' => nil,
'intent_to_file_benefits' => 'survivors pension benefits',
'intent_to_file_benefits_links' => '[Apply for DIC, Survivors Pension, and/or Accrued Benefits ' \
'(VA Form 21P-534EZ)](https://www.va.gov/find-forms/about-form-21p-534ez/)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,14 +691,14 @@
it 'veteran authorizer' do
allow(VANotify::EmailJob).to receive(:perform_async)
data['authorizer_type'] = 'veteran'
data['authorizer_email'] = 'authorizer_email@example.com'
data['veteran_email'] = 'veteran_email@example.com'

subject = described_class.new(config, user: create(:user))

subject.send

expect(VANotify::EmailJob).to have_received(:perform_async).with(
'authorizer_email@example.com',
'veteran_email@example.com',
'form21_0845_confirmation_email_template_id',
{
'first_name' => 'John',
Expand Down Expand Up @@ -785,6 +785,7 @@
end

describe '21_0966' do
let(:lighthouse_updated_at) { 1.day.ago }
let(:date_submitted) { Time.zone.today.strftime('%B %d, %Y') }
let(:data) do
fixture_path = Rails.root.join(
Expand All @@ -794,7 +795,7 @@
end
let(:config) do
{ form_data: data, form_number: 'vba_21_0966',
confirmation_number: 'confirmation_number', date_submitted: }
confirmation_number: 'confirmation_number', date_submitted:, lighthouse_updated_at: }
end
let(:user) { create(:user, :loa3) }

Expand All @@ -812,7 +813,7 @@
'first_name' => 'Veteran',
'date_submitted' => date_submitted,
'confirmation_number' => 'confirmation_number',
'lighthouse_updated_at' => nil,
'lighthouse_updated_at' => lighthouse_updated_at,
'intent_to_file_benefits' => 'survivors pension benefits',
'intent_to_file_benefits_links' => '[Apply for DIC, Survivors Pension, and/or Accrued Benefits ' \
'(VA Form 21P-534EZ)](https://www.va.gov/find-forms/about-form-21p-534ez/)',
Expand Down Expand Up @@ -841,7 +842,7 @@
'first_name' => 'I',
'date_submitted' => date_submitted,
'confirmation_number' => 'confirmation_number',
'lighthouse_updated_at' => nil,
'lighthouse_updated_at' => lighthouse_updated_at,
'intent_to_file_benefits' => 'survivors pension benefits',
'intent_to_file_benefits_links' => '[Apply for DIC, Survivors Pension, and/or Accrued Benefits ' \
'(VA Form 21P-534EZ)](https://www.va.gov/find-forms/about-form-21p-534ez/)',
Expand Down Expand Up @@ -884,7 +885,6 @@
'first_name' => 'Veteran',
'date_submitted' => date_submitted,
'confirmation_number' => 'confirmation_number',
'lighthouse_updated_at' => nil,
'intent_to_file_benefits' => 'survivors pension benefits',
'intent_to_file_benefits_links' => '[Apply for DIC, Survivors Pension, and/or Accrued Benefits ' \
'(VA Form 21P-534EZ)](https://www.va.gov/find-forms/about-form-21p-534ez/)',
Expand Down Expand Up @@ -913,7 +913,6 @@
'first_name' => 'I',
'date_submitted' => date_submitted,
'confirmation_number' => 'confirmation_number',
'lighthouse_updated_at' => nil,
'intent_to_file_benefits' => 'survivors pension benefits',
'intent_to_file_benefits_links' => '[Apply for DIC, Survivors Pension, and/or Accrued Benefits ' \
'(VA Form 21P-534EZ)](https://www.va.gov/find-forms/about-form-21p-534ez/)',
Expand Down
Loading

0 comments on commit 085c581

Please sign in to comment.