Skip to content

Commit

Permalink
Merge branch 'ndbex-70721-map-form-fields' into ndbex-71275-pdf-stamping
Browse files Browse the repository at this point in the history
  • Loading branch information
evansmith committed Mar 26, 2024
2 parents f155507 + 0e89d34 commit 382a56a
Show file tree
Hide file tree
Showing 70 changed files with 1,186 additions and 420 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ end

group :test do
gem 'apivore', git: 'https://github.com/department-of-veterans-affairs/apivore', tag: 'v2.0.0.vsp'
gem 'fakeredis'
gem 'mock_redis'
gem 'pdf-inspector'
gem 'rspec_junit_formatter'
gem 'rspec-retry'
Expand Down Expand Up @@ -215,7 +215,7 @@ group :development, :test do
gem 'rubocop-rails'
gem 'rubocop-rspec'
gem 'rubocop-thread_safety'
gem 'sidekiq', '>= 6.4.0'
gem 'sidekiq', '~> 7.2.0'
gem 'timecop'
gem 'webmock'
gem 'yard'
Expand Down
38 changes: 21 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@ PATH
GEM
remote: https://enterprise.contribsys.com/
specs:
sidekiq-ent (2.5.3)
einhorn (>= 0.7.4)
sidekiq (>= 6.5.0, < 7)
sidekiq-pro (>= 5.5.0, < 6)
sidekiq-pro (5.5.8)
sidekiq (~> 6.0, >= 6.5.6)
sidekiq-ent (7.2.2)
einhorn (~> 1.0)
gserver
sidekiq (>= 7.2.0, < 8)
sidekiq-pro (>= 7.2.0, < 8)
sidekiq-pro (7.2.0)
sidekiq (>= 7.2.0, < 8)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -282,7 +283,7 @@ GEM
bundler (>= 1.2.0, < 3)
thor (~> 1.0)
byebug (11.1.3)
carrierwave (3.0.6)
carrierwave (3.0.7)
activemodel (>= 6.0.0)
activesupport (>= 6.0.0)
addressable (~> 2.6)
Expand Down Expand Up @@ -417,8 +418,6 @@ GEM
railties (>= 5.0.0)
faker (3.2.3)
i18n (>= 1.8.11, < 2)
fakeredis (0.9.2)
redis (~> 4.8)
faraday (2.9.0)
faraday-net_http (>= 2.0, < 3.2)
faraday-follow_redirects (0.3.0)
Expand Down Expand Up @@ -634,6 +633,7 @@ GEM
mini_mime (1.1.5)
mini_portile2 (2.8.5)
minitest (5.22.3)
mock_redis (0.44.0)
msgpack (1.7.2)
msgpack (1.7.2-java)
multi_json (1.15.0)
Expand Down Expand Up @@ -812,7 +812,10 @@ GEM
rchardet (1.8.0)
rdoc (6.6.2)
psych (>= 4.0.0)
redis (4.8.1)
redis (5.1.0)
redis-client (>= 0.17.0)
redis-client (0.20.0)
connection_pool
redis-namespace (1.11.0)
redis (>= 4)
regexp_parser (2.9.0)
Expand Down Expand Up @@ -904,7 +907,7 @@ GEM
rubocop-factory_bot (2.25.1)
rubocop (~> 1.41)
rubocop-junit-formatter (0.1.4)
rubocop-rails (2.24.0)
rubocop-rails (2.24.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
Expand Down Expand Up @@ -954,10 +957,11 @@ GEM
shrine (3.5.0)
content_disposition (~> 1.0)
down (~> 5.1)
sidekiq (6.5.12)
connection_pool (>= 2.2.5, < 3)
rack (~> 2.0)
redis (>= 4.5.0, < 5)
sidekiq (7.2.2)
concurrent-ruby (< 2)
connection_pool (>= 2.3.0)
rack (>= 2.2.4)
redis-client (>= 0.19.0)
sidekiq_alive (2.4.0)
gserver (~> 0.0.1)
sidekiq (>= 5, < 8)
Expand Down Expand Up @@ -1122,7 +1126,6 @@ DEPENDENCIES
facilities_api!
factory_bot_rails
faker
fakeredis
faraday (~> 2.9)
faraday-follow_redirects
faraday-httpclient
Expand Down Expand Up @@ -1170,6 +1173,7 @@ DEPENDENCIES
mimemagic
mini_magick
mobile!
mock_redis
mocked_authentication!
my_health!
net-sftp
Expand Down Expand Up @@ -1234,7 +1238,7 @@ DEPENDENCIES
sentry-ruby
shoulda-matchers
shrine
sidekiq (>= 6.4.0)
sidekiq (~> 7.2.0)
sidekiq-ent!
sidekiq-pro!
sidekiq_alive
Expand Down
16 changes: 9 additions & 7 deletions app/controllers/v0/burial_claims_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ class BurialClaimsController < ClaimsBaseController
service_tag 'burial-application'

def create
PensionBurial::TagSentry.tag_sentry

if Flipper.enabled?(:va_burial_v2)
claim = claim_class.new(form: filtered_params[:form], formV2: JSON.parse(filtered_params["form"])["formV2"])
else
claim = claim_class.new(form: filtered_params[:form])
end
PensionBurial::TagSentry.tag_sentry

claim = if Flipper.enabled?(:va_burial_v2)
# cannot parse a nil form, to pass unit tests do a check for form presence
form = filtered_params[:form]
claim_class.new(form:, formV2: form.present? ? JSON.parse(form)['formV2'] : nil)
else
claim_class.new(form: filtered_params[:form])
end

unless claim.save
StatsD.increment("#{stats_key}.failure")
Expand Down
73 changes: 73 additions & 0 deletions app/controllers/v1/pension_ipf_callbacks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# frozen_string_literal: true

require 'decision_review_v1/utilities/logging_utils'

module V1
class PensionIpfCallbacksController < ApplicationController
include ActionController::HttpAuthentication::Token::ControllerMethods
include DecisionReviewV1::Appeals::LoggingUtils

service_tag 'pension-ipf-callbacks'

skip_before_action :verify_authenticity_token, only: [:create]
skip_before_action :authenticate, only: [:create]
skip_after_action :set_csrf_header, only: [:create]
before_action :authenticate_header, only: [:create]

STATUSES_TO_IGNORE = %w[sent delivered temporary-failure].freeze

def create
return render json: nil, status: :not_found unless Flipper.enabled? :pension_ipf_callbacks_endpoint

payload = JSON.parse(request.body.string)

# save encrypted request body in database table for non-successful notifications
payload_status = payload['status']&.downcase
if STATUSES_TO_IGNORE.exclude? payload_status
begin
PensionIpfNotification.create!(payload:)
rescue ActiveRecord::RecordInvalid => e
log_formatted(**log_params(payload).merge(is_success: false), params: { exception_message: e.message })
return render json: { message: 'failed' }
end
end

log_formatted(**log_params(payload).merge(is_success: true))
render json: { message: 'success' }
end

private

def authenticate_header
authenticate_user_with_token || authenticity_error
end

def authenticate_user_with_token
Rails.logger.info('pension-ipf-callbacks-69766 - Received request, authenticating')
authenticate_with_http_token do |token|
return false if bearer_token_secret.nil?

token == bearer_token_secret
end
end

def authenticity_error
Rails.logger.info('pension-ipf-callbacks-69766 - Failed to authenticate request')
render json: { message: 'Invalid credentials' }, status: :unauthorized
end

def bearer_token_secret
Settings.dig(:pension_ipf_vanotify_status_callback, :bearer_token)
end

def log_params(payload)
{
key: :callbacks,
form_id: '21P-527EZ',
user_uuid: nil,
upstream_system: 'VANotify',
body: payload.merge('to' => '<FILTERED>') # scrub PII from logs
}
end
end
end
20 changes: 20 additions & 0 deletions app/models/pension_ipf_notification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require 'json_marshal/marshaller'

class PensionIpfNotification < ApplicationRecord
serialize :payload, JsonMarshal::Marshaller

has_kms_key
has_encrypted :payload, key: :kms_key, **lockbox_options

validates(:payload, presence: true)

before_save :serialize_payload

private

def serialize_payload
self.payload = payload.to_json unless payload.is_a?(String)
end
end
4 changes: 2 additions & 2 deletions app/models/saved_claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SavedClaim < ApplicationRecord
# create a uuid for this second (used in the confirmation number) and store
# the form type based on the constant found in the subclass.
after_initialize do
self.form_id = self.class::FORM.upcase unless (Flipper.enabled?(:va_burial_v2) && self.class == SavedClaim::Burial)
self.form_id = self.class::FORM.upcase unless instance_of?(SavedClaim::Burial)
end

def self.add_form_and_validation(form_id)
Expand All @@ -51,7 +51,7 @@ def process_attachments!

def submit_to_structured_data_services!
# Only 21P-530 burial forms are supported at this time
if !['21P-530', '21P-530V2'].include?(form_id)
unless %w[21P-530 21P-530V2].include?(form_id)
err_message = "Unsupported form id: #{form_id}"
raise Common::Exceptions::UnprocessableEntity.new(detail: err_message), err_message
end
Expand Down
16 changes: 8 additions & 8 deletions app/models/saved_claim/burial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
require 'pension_burial/processing_office'

class SavedClaim::Burial < CentralMailClaim

FORM = '21P-530'

attr_accessor :formV2
# attribute name is passed from the FE as a flag, maintaining camel case
attr_accessor :formV2 # rubocop:disable Naming/MethodName

after_initialize do
if Flipper.enabled?(:va_burial_v2)
self.form_id = (self.formV2 || self.form_id == '21P-530V2') ? '21P-530V2' : self.class::FORM.upcase
else
self.form_id = self.class::FORM.upcase
end
self.form_id = if Flipper.enabled?(:va_burial_v2)
formV2 || form_id == '21P-530V2' ? '21P-530V2' : self.class::FORM.upcase
else
self.class::FORM.upcase
end
end

def process_attachments!
Expand All @@ -39,7 +39,7 @@ def email
def form_matches_schema
return unless form_is_string

JSON::Validator.fully_validate(VetsJsonSchema::SCHEMAS[self.form_id], parsed_form).each do |v|
JSON::Validator.fully_validate(VetsJsonSchema::SCHEMAS[form_id], parsed_form).each do |v|
errors.add(:form, v.to_s)
end
end
Expand Down
4 changes: 4 additions & 0 deletions app/policies/mhv_messaging_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

MHVMessagingPolicy = Struct.new(:user, :mhv_messaging) do
def access?
return false unless user.mhv_correlation_id

client = SM::Client.new(session: { user_id: user.mhv_correlation_id })
validate_client(client)
end

def mobile_access?
return false unless user.mhv_correlation_id

client = Mobile::V0::Messaging::Client.new(session: { user_id: user.mhv_correlation_id })
validate_client(client)
end
Expand Down
2 changes: 1 addition & 1 deletion app/sidekiq/structured_data/process_data_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def perform(saved_claim_id)
ensure
@claim.process_attachments! # upload claim and attachments to Central Mail

send_confirmation_email if ['21P-530', '21P-530V2'].include?(@claim.form_id)
send_confirmation_email if %w[21P-530 21P-530V2].include?(@claim.form_id)
# veteran lookup for hit/miss metrics in support of Automation work
StatsD.increment("#{stats_key}.success",
tags: %W[relationship:#{relationship_type} veteranInMVI:#{veteran&.participant_id}])
Expand Down
8 changes: 8 additions & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,10 @@ features:
actor_type: user
enable_in_development: true
description: Allows appointment cancellations to be routed to Oracle Health sites.
va_online_scheduling_enable_OH_slots_search:
actor_type: user
enable_in_development: true
description: Toggle for routing slots search requests to the VetsAPI Gateway Service(VPG) instead of vaos-service
va_online_scheduling_datadog_RUM:
actor_type: user
description: Enables datadog Real User Monitoring.
Expand Down Expand Up @@ -1284,6 +1288,10 @@ features:
actor_type: user
description: NOD VANotify notification callbacks endpoint
enable_in_development: true
pension_ipf_callbacks_endpoint:
actor_type: user
description: Pension IPF VANotify notification callbacks endpoint
enable_in_development: true
hlr_browser_monitoring_enabled:
actor_type: user
description: HLR Datadog RUM monitoring
Expand Down
10 changes: 7 additions & 3 deletions config/initializers/01_redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
REDIS_CONFIG = Rails.application.config_for(:redis).freeze
# set the current global instance of Redis based on environment specific config

$redis = Redis.new(REDIS_CONFIG[:redis].to_hash)

Redis.exists_returns_integer = true
$redis =
if Rails.env.test?
require 'mock_redis'
MockRedis.new(url: REDIS_CONFIG[:redis][:url])
else
Redis.new(REDIS_CONFIG[:redis].to_h)
end
4 changes: 3 additions & 1 deletion config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
end

# Remove the default error handler
config.error_handlers.delete_if { |handler| handler.is_a?(Sidekiq::ExceptionHandler::Logger) }
config.error_handlers.delete(Sidekiq::Config::ERROR_HANDLER)
end

Sidekiq.strict_args!(false)
end
3 changes: 3 additions & 0 deletions config/redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ test:
<<: *defaults
redis:
inherit_socket: true
url: <%= Settings.redis.app_data.url %>
sidekiq:
url: <%= Settings.redis.sidekiq.url %>

production:
<<: *defaults
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@

scope format: false do
resources :nod_callbacks, only: [:create]
resources :pension_ipf_callbacks, only: [:create]
end
end

Expand Down
Loading

0 comments on commit 382a56a

Please sign in to comment.