-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into pension-77412-logs
- Loading branch information
Showing
128 changed files
with
3,326 additions
and
525 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'iso_country_codes' | ||
|
||
class FormProfiles::VA21p530v2 < FormProfile | ||
def metadata | ||
{ | ||
version: 0, | ||
prefill: true, | ||
returnUrl: '/claimant-information' | ||
} | ||
end | ||
|
||
def prefill | ||
@identity_information = initialize_identity_information | ||
@contact_information = initialize_contact_information | ||
if @contact_information&.address&.country.present? | ||
@contact_information.address.country = convert_to_iso2(@contact_information.address.country) | ||
end | ||
mappings = self.class.mappings_for_form(form_id) | ||
|
||
form_data = generate_prefill(mappings) if FormProfile.prefill_enabled_forms.include?(form_id) | ||
|
||
{ form_data:, metadata: } | ||
end | ||
|
||
private | ||
|
||
def convert_to_iso2(country_code) | ||
code = IsoCountryCodes.find(country_code) | ||
code.alpha2 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,8 @@ def process_attachments! | |
|
||
CentralMail::SubmitSavedClaimJob.new.perform(id) | ||
end | ||
|
||
def business_line | ||
'EDU' | ||
end | ||
end |
Oops, something went wrong.