From fc06924fd28cb125a6e9bb89ff311819af883a5b Mon Sep 17 00:00:00 2001 From: Jennica Stiehl <25069483+stiehlrod@users.noreply.github.com> Date: Mon, 2 Dec 2024 09:39:26 -0700 Subject: [PATCH 1/3] Api 28113 replace bgs ext poa updater (#19325) * Adds flipper feature. * Moves the find_by_ssn call to PersonWebService from LocalBgs. * Adds VetRecordService to LocalBgs. * Adds ability to switch between bgs-ext & local_bgs for vet_record & person_web_service. * Getting successful responses, but getting 'BGS Error: update_birls_record failed with code BPNQ0100' * Reverts instance variable. Adds definition. Adds PAYEE_NUMBER value. * Refactors poa_updater. Replaces find_by_ssn in local_bgs due to many failing tests. Created a ticket to remove that method from local_bgs since it exists in two places. * WIP: switching branches. * Cleans up poa_updater. Adds definitions. Updates vcr cassette. * Removes find_birls_record * Corrects vet record service. Updates tests with flipper feature, and replaces vcr cassette. * Updates person web service * Removes method definitions. * Renames flippers, separates features into two flippers. Adds two tests. Need to re-record vcr cassette. * Updates test and shared vcr cassette. * Adds flipper test. * Adds tests for flipper. --- config/features.yml | 4 + .../claims_api/bgs_client/definitions.rb | 21 + .../app/sidekiq/claims_api/poa_updater.rb | 62 +- .../lib/bgs_service/person_web_service.rb | 9 - .../lib/bgs_service/vet_record_web_service.rb | 24 + .../spec/sidekiq/poa_updater_spec.rb | 46 +- .../bgs/person_web_service/find_by_ssn.yml | 1154 +++++++++++++---- 7 files changed, 1026 insertions(+), 294 deletions(-) create mode 100644 modules/claims_api/lib/bgs_service/vet_record_web_service.rb diff --git a/config/features.yml b/config/features.yml index 2eac790e6e6..7aedc668a01 100644 --- a/config/features.yml +++ b/config/features.yml @@ -249,6 +249,10 @@ features: actor_type: user description: Uses person web service rather than local bgs enable_in_development: true + claims_api_use_vet_record_service: + actor_type: user + description: Uses local_bgs rather than bgs-ext + enable_in_development: true claims_api_526_v2_uploads_bd_refactor: actor_type: user description: When enabled, sends 526 forms to BD via the refactored logic diff --git a/modules/claims_api/app/clients/claims_api/bgs_client/definitions.rb b/modules/claims_api/app/clients/claims_api/bgs_client/definitions.rb index f9ba0fa3134..4a3e4896d57 100644 --- a/modules/claims_api/app/clients/claims_api/bgs_client/definitions.rb +++ b/modules/claims_api/app/clients/claims_api/bgs_client/definitions.rb @@ -351,6 +351,27 @@ module CreateVeteranRepresentative end ## + # VetRecordService + ## + module VetRecordServiceBean + DEFINITION = + Bean.new( + path: 'VetRecordServiceBean', + namespaces: Namespaces.new( + target: 'http://services.share.benefits.vba.va.gov/', + data: nil + ) + ) + end + + module VetRecordWebService + DEFINITION = + Service.new( + bean: VetRecordServiceBean::DEFINITION, + path: 'VetRecordWebService' + ) + end + # VnpAtchmsWebServiceBean # module VnpAtchmsWebServiceBean diff --git a/modules/claims_api/app/sidekiq/claims_api/poa_updater.rb b/modules/claims_api/app/sidekiq/claims_api/poa_updater.rb index c67ae8dda9c..292fc50c824 100644 --- a/modules/claims_api/app/sidekiq/claims_api/poa_updater.rb +++ b/modules/claims_api/app/sidekiq/claims_api/poa_updater.rb @@ -1,25 +1,20 @@ # frozen_string_literal: true require 'bgs' +require 'bgs_service/person_web_service' +require 'bgs_service/vet_record_web_service' module ClaimsApi class PoaUpdater < ClaimsApi::ServiceBase - def perform(power_of_attorney_id, rep = nil) # rubocop:disable Metrics/MethodLength + def perform(power_of_attorney_id, rep = nil) poa_form = ClaimsApi::PowerOfAttorney.find(power_of_attorney_id) - service = BGS::Services.new( - external_uid: poa_form.external_uid, - external_key: poa_form.external_key - ) ssn = poa_form.auth_headers['va_eauth_pnid'] - file_number = service.people.find_by_ssn(ssn)[:file_nbr] # rubocop:disable Rails/DynamicFindBy + + file_number = find_by_ssn(ssn, poa_form) poa_code = extract_poa_code(poa_form.form_data) - response = service.vet_record.update_birls_record( - file_number:, - ssn:, - poa_code: - ) + response = update_birls_record(file_number, ssn, poa_code, poa_form) if response[:return_code] == 'BMOD0001' poa_form.status = ClaimsApi::PowerOfAttorney::UPDATED @@ -49,5 +44,50 @@ def vanotify?(auth_headers, rep) false end end + + def bgs_ext_service(poa_form) + BGS::Services.new( + external_uid: poa_form.external_uid, + external_key: poa_form.external_key + ) + end + + def person_web_service(poa_form) + ClaimsApi::PersonWebService.new( + external_uid: poa_form.external_uid, + external_key: poa_form.external_key + ) + end + + def vet_record_service(poa_form) + ClaimsApi::VetRecordWebService.new( + external_uid: poa_form.external_uid, + external_key: poa_form.external_key + ) + end + + def find_by_ssn(ssn, poa_form) + if Flipper.enabled? :claims_api_use_person_web_service + person_web_service(poa_form).find_by_ssn(ssn)[:file_nbr] # rubocop:disable Rails/DynamicFindBy + else + bgs_ext_service(poa_form).people.find_by_ssn(ssn)[:file_nbr] # rubocop:disable Rails/DynamicFindBy + end + end + + def update_birls_record(file_number, ssn, poa_code, poa_form) + if Flipper.enabled? :claims_api_use_vet_record_service + vet_record_service(poa_form).update_birls_record( + file_number:, + ssn:, + poa_code: + ) + else + bgs_ext_service(poa_form).vet_record.update_birls_record( + file_number:, + ssn:, + poa_code: + ) + end + end end end diff --git a/modules/claims_api/lib/bgs_service/person_web_service.rb b/modules/claims_api/lib/bgs_service/person_web_service.rb index 600ddb2bbcc..0c3ac728b04 100644 --- a/modules/claims_api/lib/bgs_service/person_web_service.rb +++ b/modules/claims_api/lib/bgs_service/person_web_service.rb @@ -45,13 +45,4 @@ def find_by_ssn(ssn) make_request(endpoint: bean_name, action: 'findPersonBySSN', body:, key: 'PersonDTO') end end - - # finds a PERSON row by SSN - def find_by_ssn(ssn) - body = Nokogiri::XML::DocumentFragment.parse <<~EOXML - #{ssn} - EOXML - - make_request(endpoint: bean_name, action: 'findPersonBySSN', body:, key: 'PersonDTO') - end end diff --git a/modules/claims_api/lib/bgs_service/vet_record_web_service.rb b/modules/claims_api/lib/bgs_service/vet_record_web_service.rb new file mode 100644 index 00000000000..a378029a916 --- /dev/null +++ b/modules/claims_api/lib/bgs_service/vet_record_web_service.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module ClaimsApi + class VetRecordWebService < ClaimsApi::LocalBGS + def bean_name + 'VetRecordServiceBean/VetRecordWebService' + end + + def update_birls_record(**options) + poa_code = options[:poa_code] + body = Nokogiri::XML::DocumentFragment.parse <<~EOML + + #{options[:file_number]} + #{options[:ssn]} + #{poa_code[0]} + #{poa_code[1]}#{poa_code[2]} + 00 + + EOML + + make_request(endpoint: bean_name, body:, action: 'updateBirlsRecord', key: 'return') + end + end +end diff --git a/modules/claims_api/spec/sidekiq/poa_updater_spec.rb b/modules/claims_api/spec/sidekiq/poa_updater_spec.rb index dd2816d7bdd..ae3fdec4c8a 100644 --- a/modules/claims_api/spec/sidekiq/poa_updater_spec.rb +++ b/modules/claims_api/spec/sidekiq/poa_updater_spec.rb @@ -2,11 +2,14 @@ require 'rails_helper' -RSpec.describe ClaimsApi::PoaUpdater, type: :job do +RSpec.describe ClaimsApi::PoaUpdater, type: :job, vcr: 'bgs/person_web_service/find_by_ssn' do subject { described_class } before do Sidekiq::Job.clear_all + allow(Flipper).to receive(:enabled?).with(:claims_api_use_vet_record_service).and_return false + allow(Flipper).to receive(:enabled?).with(:claims_api_use_person_web_service).and_return false + allow(Flipper).to receive(:enabled?).with(:lighthouse_claims_api_v2_poa_va_notify).and_return false end let(:user) { FactoryBot.create(:user, :loa3) } @@ -19,6 +22,7 @@ context "when call to BGS 'update_birls_record' is successful" do context 'and the poaCode is retrieved successfully from the V2 2122a form data' do it "updates the form's status and creates 'ClaimsApi::PoaVBMSUpdater' job" do + allow(Flipper).to receive(:enabled?).with(:claims_api_use_person_web_service).and_return false create_mock_lighthouse_service expect(ClaimsApi::PoaVBMSUpdater).to receive(:perform_async) @@ -114,6 +118,7 @@ context 'deciding to send a VA Notify email' do before do create_mock_lighthouse_service + allow(Flipper).to receive(:enabled?).with(:lighthouse_claims_api_v2_poa_va_notify).and_return true end let(:poa) { create_poa } @@ -134,6 +139,7 @@ context 'when the flipper is on' do it 'does not send the vanotify job' do + allow(Flipper).to receive(:enabled?).with(:lighthouse_claims_api_v2_poa_va_notify).and_return false Flipper.disable(:lighthouse_claims_api_v2_poa_va_notify) poa.auth_headers.merge!({ @@ -186,6 +192,44 @@ end end + describe 'when the claims_api_use_person_web_service flipper is on' do + let(:person_web_service) { instance_double(ClaimsApi::PersonWebService) } + + before do + allow(Flipper).to receive(:enabled?).with(:claims_api_use_person_web_service).and_return true + allow(ClaimsApi::PersonWebService).to receive(:new).with(external_uid: anything, + external_key: anything) + .and_return(person_web_service) + allow(person_web_service).to receive(:find_by_ssn).and_return({ file_nbr: '796111863' }) + end + + it 'calls local bgs person web service instead of bgs-ext' do + poa = create_poa + subject.new.perform(poa.id) + + expect(person_web_service).to have_received(:find_by_ssn) + end + end + + describe 'when the claims_api_use_vet_record_service flipper is on' do + let(:vet_record_web_service) { instance_double(ClaimsApi::VetRecordWebService) } + + before do + allow(Flipper).to receive(:enabled?).with(:claims_api_use_vet_record_service).and_return true + allow(ClaimsApi::VetRecordWebService).to receive(:new).with(external_uid: anything, + external_key: anything) + .and_return(vet_record_web_service) + allow(vet_record_web_service).to receive(:update_birls_record).and_return({ return_code: 'BMOD0001' }) + end + + it 'calls local bgs vet record service instead of bgs-ext' do + poa = create_poa + subject.new.perform(poa.id) + + expect(vet_record_web_service).to have_received(:update_birls_record) + end + end + private def create_poa diff --git a/spec/support/vcr_cassettes/bgs/person_web_service/find_by_ssn.yml b/spec/support/vcr_cassettes/bgs/person_web_service/find_by_ssn.yml index 52cdc548ad4..f8ee36c91bc 100644 --- a/spec/support/vcr_cassettes/bgs/person_web_service/find_by_ssn.yml +++ b/spec/support/vcr_cassettes/bgs/person_web_service/find_by_ssn.yml @@ -21,7 +21,7 @@ http_interactions: message: OK headers: Date: - - Thu, 21 Nov 2024 21:19:08 GMT + - Tue, 26 Nov 2024 21:56:34 GMT Server: - Apache X-Frame-Options: @@ -41,20 +41,74 @@ http_interactions: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - + + - - + + + + + + + + + + + @@ -62,11 +116,11 @@ http_interactions: - - + + - - + + @@ -74,11 +128,11 @@ http_interactions: - - + + - - + + @@ -86,23 +140,11 @@ http_interactions: - - - - - - - - - - - - - - + + - - + + @@ -110,12 +152,30 @@ http_interactions: + + + + + + + + + + + + + + + + + + @@ -128,23 +188,17 @@ http_interactions: - - - - - - - - + + - - + + @@ -158,77 +212,29 @@ http_interactions: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + - - + + - - + + @@ -236,79 +242,123 @@ http_interactions: - - - - - - - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + @@ -319,20 +369,15 @@ http_interactions: - - - - - - - - - + + + + @@ -344,85 +389,220 @@ http_interactions: - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + - - - + + + + + + + + + + - - - + + + + + + + + + + - - - + + + + + + + + + + - - - + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + - - - - + + + + + + + + + + + - - - - + + + + + + + + + + + - - - - + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + @@ -446,7 +626,7 @@ http_interactions: - + @@ -458,7 +638,7 @@ http_interactions: - + @@ -470,7 +650,7 @@ http_interactions: - + @@ -482,7 +662,7 @@ http_interactions: - + @@ -494,7 +674,7 @@ http_interactions: - + @@ -506,7 +686,7 @@ http_interactions: - + @@ -518,7 +698,7 @@ http_interactions: - + @@ -530,7 +710,7 @@ http_interactions: - + @@ -542,7 +722,7 @@ http_interactions: - + @@ -554,7 +734,7 @@ http_interactions: - + @@ -566,7 +746,7 @@ http_interactions: - + @@ -578,7 +758,7 @@ http_interactions: - + @@ -590,7 +770,7 @@ http_interactions: - + @@ -602,7 +782,7 @@ http_interactions: - + @@ -614,7 +794,7 @@ http_interactions: - + @@ -626,7 +806,7 @@ http_interactions: - + @@ -638,7 +818,7 @@ http_interactions: - + @@ -650,7 +830,309 @@ http_interactions: - + + + + + + + + recorded_at: Tue, 26 Nov 2024 21:56:34 GMT +- request: + method: post + uri: "/PersonWebServiceBean/PersonWebService" + body: + encoding: UTF-8 + string: |- + + + VAgovAPI + + + 10.0.0.205 + 281 + VAgovAPI + 123 + 1@2.com + + + 796104437 + headers: + Host: + - ".vba.va.gov" + Soapaction: + - '"findPersonBySSN"' + Content-Type: + - text/xml;charset=UTF-8 + Content-Length: + - '1261' + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Date: + - Tue, 26 Nov 2024 21:56:35 GMT + Server: + - Apache + X-Frame-Options: + - SAMEORIGIN + Transfer-Encoding: + - chunked + Content-Type: + - text/xml; charset=utf-8 + Strict-Transport-Security: + - max-age=16000000; includeSubDomains; preload; + body: + encoding: UTF-8 + string: rO0ABXdTAB13ZWJsb2dpYy5hcHAuQ29ycG9yYXRlRGF0YUVBUgAAANYAAAAjd2VibG9naWMud29ya2FyZWEuU3RyaW5nV29ya0NvbnRleHQABTMuNS4wAAA=TAMPAFL1950-10-04T00:00:00-06:002022-01-01T00:00:00-06:002022-09-16T12:24:00-05:002022-09-16T12:24:00-05:00YCORPuser228@gmail.comN796104437MARK-2M2024-11-26T15:36:00-06:00VAgovAPI1@2.com123281VAGOVAPI - + BUPD218942542UVAGOVAPIPOLARBEAR-2T-1YUnknownNUU13367440Person13367440N7961044374317JR-137Y + recorded_at: Tue, 26 Nov 2024 21:56:35 GMT +- request: + method: get + uri: "/VetRecordServiceBean/VetRecordWebService?WSDL" + body: + encoding: US-ASCII + string: '' + headers: + Host: + - ".vba.va.gov" + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Date: + - Tue, 26 Nov 2024 21:56:35 GMT + Server: + - Apache + X-Frame-Options: + - SAMEORIGIN + Transfer-Encoding: + - chunked + Content-Type: + - text/xml;charset=utf-8 + Strict-Transport-Security: + - max-age=16000000; includeSubDomains; preload; + body: + encoding: UTF-8 + string: |- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -658,11 +1140,11 @@ http_interactions: - - + + - + @@ -670,11 +1152,11 @@ http_interactions: - - + + - + @@ -682,11 +1164,11 @@ http_interactions: - - + + - + @@ -694,11 +1176,11 @@ http_interactions: - - + + - + @@ -706,11 +1188,11 @@ http_interactions: - - + + - + @@ -718,11 +1200,11 @@ http_interactions: - - + + - + @@ -730,11 +1212,11 @@ http_interactions: - - + + - + @@ -742,11 +1224,11 @@ http_interactions: - - + + - + @@ -754,11 +1236,11 @@ http_interactions: - - + + - + @@ -766,11 +1248,11 @@ http_interactions: - - + + - + @@ -778,11 +1260,11 @@ http_interactions: - - + + - + @@ -790,11 +1272,11 @@ http_interactions: - - + + - + @@ -802,11 +1284,11 @@ http_interactions: - - + + - + @@ -814,11 +1296,11 @@ http_interactions: - - + + - + @@ -826,25 +1308,49 @@ http_interactions: - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - recorded_at: Thu, 21 Nov 2024 21:19:08 GMT + recorded_at: Tue, 26 Nov 2024 21:56:35 GMT - request: method: post - uri: "/PersonWebServiceBean/PersonWebService" + uri: "/VetRecordServiceBean/VetRecordWebService" body: encoding: UTF-8 string: |- - + VAgovAPI @@ -852,20 +1358,20 @@ http_interactions: 10.0.0.205 281 VAgovAPI - 796378881 - 796378881 + 123 + 1@2.com - 796378881 + 79610443779610443700074 headers: Host: - ".vba.va.gov" Soapaction: - - '"findPersonBySSN"' + - '"updateBirlsRecord"' Content-Type: - text/xml;charset=UTF-8 Content-Length: - - '1269' + - '1476' Accept-Encoding: - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 Accept: @@ -878,11 +1384,15 @@ http_interactions: message: OK headers: Date: - - Thu, 21 Nov 2024 21:19:08 GMT + - Tue, 26 Nov 2024 21:56:36 GMT Server: - Apache X-Frame-Options: - SAMEORIGIN + X-Oracle-Dms-Ecid: + - fdfca44e-78a2-4e38-9b9e-cb506638b894-0001e406 + X-Oracle-Dms-Rid: + - '0' Transfer-Encoding: - chunked Content-Type: @@ -893,8 +1403,106 @@ http_interactions: encoding: UTF-8 string: rO0ABXdTAB13ZWJsb2dpYy5hcHAuQ29ycG9yYXRlRGF0YUVBUgAAANYAAAAjd2VibG9naWMud29ya2FyZWEuU3RyaW5nV29ya0NvbnRleHQABTMuNS4wAAA=SALINASKS1954-12-15T00:00:00-06:002022-10-03T15:35:53-05:002022-10-03T15:35:53-05:00YCORP0valid@somedomain.comN796378881JESSE-2M2024-11-21T15:18:35-06:00VAgovAPIlighthouse-vets-apilighthouse-vets-api281VAGOVAPI - - BUPD218935360UVAGOVAPIGRAY-1ADSUSEONLY-1YNUU600045026Person600045026NN796378881031781Y - recorded_at: Thu, 21 Nov 2024 21:19:08 GMT + xmlns:work="http://oracle.com/weblogic/soap/workarea/">rO0ABXdTAB13ZWJsb2dpYy5hcHAuQ29ycG9yYXRlRGF0YUVBUgAAANYAAAAjd2VibG9naWMud29ya2FyZWEuU3RyaW5nV29ya0NvbnRleHQABTMuNS4wAAA=BMOD0001BIRLS + Update successful796104437796104437 + ARMY0101196510011972SAT E6 + HON + ARMY1002197201012005SAT E6 + UHC + POLARBEARMARKTJRERRORSCAUSESTUXJRERRORSCAUSESTUXJRWEBBMARKJR1004195010/04/19500101202201/01/20220CLAIM3171123201011/23/2010 + + + EDU 3511119201011/19/2010 + + + + + + + + + + + + + + + + + + + + + + + + + + + 317YMDYNNUNKNOWN074 + + + + + + + + + + + + + + + + + + 000VAGOVAPI2811126202411/26/2024 1 + recorded_at: Tue, 26 Nov 2024 21:56:37 GMT recorded_with: VCR 6.3.1 From 603349d87532b640c531b0f716865557a4897e58 Mon Sep 17 00:00:00 2001 From: Michael Clement Date: Mon, 2 Dec 2024 11:42:30 -0500 Subject: [PATCH 2/3] 97006 Update email map with failure email templates - IVC CHAMPVA forms (#19596) * updated map with new email templates * comma --- config/settings.yml | 3 +++ modules/ivc_champva/app/services/ivc_champva/email.rb | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config/settings.yml b/config/settings.yml index a1def94448d..97865d97869 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -1365,8 +1365,11 @@ vanotify: form_10_7959f_1_email: form_10_7959f_1_email form_10_7959f_1_failure_email: form_10_7959f_1_failure_email form_10_7959f_2_email: form_10_7959f_2_email + form_10_7959f_2_failure_email: form_10_7959f_2_failure_email form_10_7959c_email: form_10_7959c_email + form_10_7959c_failure_email: form_10_7959c_failure_email form_10_7959a_email: form_10_7959a_email + form_10_7959a_failure_email: form_10_7959a_failure_email health_apps_1010: api_key: fake_secret template_id: diff --git a/modules/ivc_champva/app/services/ivc_champva/email.rb b/modules/ivc_champva/app/services/ivc_champva/email.rb index 3ec25ef3e08..abcfb624f01 100644 --- a/modules/ivc_champva/app/services/ivc_champva/email.rb +++ b/modules/ivc_champva/app/services/ivc_champva/email.rb @@ -10,8 +10,11 @@ class Email '10-7959F-1' => Settings.vanotify.services.ivc_champva.template_id.form_10_7959f_1_email, '10-7959F-1-FAILURE' => Settings.vanotify.services.ivc_champva.template_id.form_10_7959f_1_failure_email, '10-7959F-2' => Settings.vanotify.services.ivc_champva.template_id.form_10_7959f_2_email, + '10-7959F-2-FAILURE' => Settings.vanotify.services.ivc_champva.template_id.form_10_7959f_2_failure_email, '10-7959C' => Settings.vanotify.services.ivc_champva.template_id.form_10_7959c_email, - '10-7959A' => Settings.vanotify.services.ivc_champva.template_id.form_10_7959a_email + '10-7959C-FAILURE' => Settings.vanotify.services.ivc_champva.template_id.form_10_7959c_failure_email, + '10-7959A' => Settings.vanotify.services.ivc_champva.template_id.form_10_7959a_email, + '10-7959A-FAILURE' => Settings.vanotify.services.ivc_champva.template_id.form_10_7959a_failure_email }.freeze def initialize(data) From ce5a96b52e1d727eb8a48816a0ab7d1dc30fd50c Mon Sep 17 00:00:00 2001 From: Trevor Bosaw Date: Mon, 2 Dec 2024 09:41:25 -0800 Subject: [PATCH 3/3] [VI-740] Skipping MHV Account creation call during auth if user is authenticating from a 'custom' call (#19651) --- app/controllers/v1/sessions_controller.rb | 10 ++++- app/services/login/after_login_actions.rb | 8 ++-- .../login/after_login_actions_spec.rb | 44 ++++++++++--------- 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/app/controllers/v1/sessions_controller.rb b/app/controllers/v1/sessions_controller.rb index 3e7b6b72764..9a84db5b630 100644 --- a/app/controllers/v1/sessions_controller.rb +++ b/app/controllers/v1/sessions_controller.rb @@ -408,11 +408,17 @@ def set_cookies end def after_login_actions - client_id = url_service.tracker.payload_attr(:application) - Login::AfterLoginActions.new(@current_user, client_id).perform + Login::AfterLoginActions.new(@current_user, skip_mhv_account_creation).perform log_persisted_session_and_warnings end + def skip_mhv_account_creation + skip_mhv_account_creation_client = url_service.tracker.payload_attr(:application) == SAML::User::MHV_ORIGINAL_CSID + skip_mhv_account_creation_type = url_service.tracker.payload_attr(:type) == 'custom' + + skip_mhv_account_creation_client || skip_mhv_account_creation_type + end + def log_persisted_session_and_warnings obscure_token = Session.obscure_token(@session_object.token) Rails.logger.info("Logged in user with id #{@session_object&.uuid}, token #{obscure_token}") diff --git a/app/services/login/after_login_actions.rb b/app/services/login/after_login_actions.rb index e97f4145c32..18464aa4d6d 100644 --- a/app/services/login/after_login_actions.rb +++ b/app/services/login/after_login_actions.rb @@ -6,11 +6,11 @@ module Login class AfterLoginActions include Accountable - attr_reader :current_user, :client_id + attr_reader :current_user, :skip_mhv_account_creation - def initialize(user, client_id) + def initialize(user, skip_mhv_account_creation) @current_user = user - @client_id = client_id + @skip_mhv_account_creation = skip_mhv_account_creation end def perform @@ -32,7 +32,7 @@ def perform private def create_mhv_account - return if client_id.in?(SAML::URLService::SKIP_MHV_ACCOUNT_CREATION_CLIENTS) + return if skip_mhv_account_creation current_user.create_mhv_account_async end diff --git a/spec/services/login/after_login_actions_spec.rb b/spec/services/login/after_login_actions_spec.rb index 88547d7fb5e..c12262c9d94 100644 --- a/spec/services/login/after_login_actions_spec.rb +++ b/spec/services/login/after_login_actions_spec.rb @@ -4,7 +4,7 @@ RSpec.describe Login::AfterLoginActions do describe '#perform' do - let(:client_id) { 'some-client-id' } + let(:skip_mhv_account_creation) { false } context 'creating credential email' do let(:user) { create(:user, email:, idme_uuid:) } @@ -13,7 +13,7 @@ let(:email) { 'some-email' } it 'creates a user credential email with expected attributes' do - expect { described_class.new(user, client_id).perform }.to change(UserCredentialEmail, :count) + expect { described_class.new(user, skip_mhv_account_creation).perform }.to change(UserCredentialEmail, :count) user_credential_email = user.user_verification.user_credential_email expect(user_credential_email.credential_email).to eq(email) end @@ -30,7 +30,9 @@ after { Timecop.return } it 'creates a user acceptable verified credential with expected attributes' do - expect { described_class.new(user, client_id).perform }.to change(UserAcceptableVerifiedCredential, :count) + expect do + described_class.new(user, skip_mhv_account_creation).perform + end.to change(UserAcceptableVerifiedCredential, :count) user_avc = UserAcceptableVerifiedCredential.find_by(user_account: user.user_account) expect(user_avc.idme_verified_credential_at).to eq(expected_avc_at) end @@ -47,7 +49,7 @@ it 'does not call TUD account checkout' do expect_any_instance_of(TestUserDashboard::UpdateUser).not_to receive(:call) - described_class.new(user, client_id).perform + described_class.new(user, skip_mhv_account_creation).perform end end @@ -62,7 +64,7 @@ it 'calls TUD account checkout' do expect_any_instance_of(TestUserDashboard::UpdateUser).to receive(:call) - described_class.new(user, client_id).perform + described_class.new(user, skip_mhv_account_creation).perform end end @@ -75,17 +77,17 @@ context 'with non-existent login stats record' do it 'creates an account_login_stats record' do - expect { described_class.new(user, client_id).perform }.to \ + expect { described_class.new(user, skip_mhv_account_creation).perform }.to \ change(AccountLoginStat, :count).by(1) end it 'updates the correct login stats column' do - described_class.new(user, client_id).perform + described_class.new(user, skip_mhv_account_creation).perform expect(AccountLoginStat.last.send("#{login_type_stat}_at")).not_to be_nil end it 'updates the current_verification column' do - described_class.new(user, client_id).perform + described_class.new(user, skip_mhv_account_creation).perform expect(AccountLoginStat.last.current_verification).to eq('loa1') end @@ -93,7 +95,7 @@ login_type = 'something_invalid' allow_any_instance_of(UserIdentity).to receive(:sign_in).and_return(service_name: login_type) - expect { described_class.new(user, client_id).perform }.not_to \ + expect { described_class.new(user, skip_mhv_account_creation).perform }.not_to \ change(AccountLoginStat, :count) end end @@ -107,7 +109,7 @@ end it 'does not create another record' do - expect { described_class.new(user, client_id).perform }.not_to \ + expect { described_class.new(user, skip_mhv_account_creation).perform }.not_to \ change(AccountLoginStat, :count) end @@ -115,7 +117,7 @@ stat = AccountLoginStat.last expect do - described_class.new(user, client_id).perform + described_class.new(user, skip_mhv_account_creation).perform stat.reload end.to change(stat, :myhealthevet_at) end @@ -126,7 +128,7 @@ stat = AccountLoginStat.last expect do - described_class.new(user, client_id).perform + described_class.new(user, skip_mhv_account_creation).perform stat.reload end.not_to change(stat, :myhealthevet_at) @@ -136,7 +138,7 @@ it 'triggers sentry error if update fails' do allow_any_instance_of(AccountLoginStat).to receive(:update!).and_raise('Failure!') expect_any_instance_of(described_class).to receive(:log_error) - described_class.new(user, client_id).perform + described_class.new(user, skip_mhv_account_creation).perform end end @@ -145,7 +147,7 @@ it 'triggers sentry error message' do expect_any_instance_of(described_class).to receive(:no_account_log_message) - expect { described_class.new(user, client_id).perform }.not_to \ + expect { described_class.new(user, skip_mhv_account_creation).perform }.not_to \ change(AccountLoginStat, :count) end end @@ -168,7 +170,7 @@ shared_examples 'identity-mpi id validation' do it 'logs a warning when Identity & MPI values conflict' do expect(Rails.logger).to receive(:warn).at_least(:once).with(expected_error_message, expected_error_data) - described_class.new(loa3_user, client_id).perform + described_class.new(loa3_user, skip_mhv_account_creation).perform end end @@ -218,18 +220,20 @@ allow(user).to receive(:create_mhv_account_async) end - context 'when the client_id is not in SKIP_MHV_ACCOUNT_CREATION_CLIENTS' do + context 'when skip_mhv_account_creation is set to false' do + let(:skip_mhv_account_creation) { false } + it 'calls create_mhv_account_async' do - described_class.new(user, client_id).perform + described_class.new(user, skip_mhv_account_creation).perform expect(user).to have_received(:create_mhv_account_async) end end - context 'when the client_id is in SKIP_MHV_ACCOUNT_CREATION_CLIENTS' do - let(:client_id) { 'mhv' } + context 'when skip_mhv_account_creation is set to true' do + let(:skip_mhv_account_creation) { true } it 'does not call create_mhv_account_async' do - described_class.new(user, client_id).perform + described_class.new(user, skip_mhv_account_creation).perform expect(user).not_to have_received(:create_mhv_account_async) end end