Skip to content

Commit 62e3a47

Browse files
james-taggart-kindsethdarragile6Copilot
authored
Bmt3/128748 mobile link letter ready (#27036)
* Universal Link - One implementation of universal link - Think there might be a better alternative going to explore tomorrow * Controller Move Move the logic for selecting email template to the controller. * Consolidate functions One call for setting the template before send notification and send email. * Test Coverage Adding test coverage for the template change logic. * Lint - Linting autocorrect * Adding the new setting * Remove un-needed yaml changes * Removed unused setting. * Revert "Removed unused setting." This reverts commit 0131eaa. * Revert "Remove un-needed yaml changes" This reverts commit ea5bf89. * Reapply "Remove un-needed yaml changes" This reverts commit 2a6e34e. * Reapply "Removed unused setting." This reverts commit b931297. * Handle pension * Updated old variable names. * Simplify select email template logic. * Refactor test changes and coverage. * Staging template added. * YAML file tests * Apply suggestion from @sethdarragile6 Co-authored-by: Seth Darr <92405130+sethdarragile6@users.noreply.github.com> * Refactor easier to follow. * Readable version. * Test update. * Test coverage updates and template validaiton. * Lint. * Codeowners. * Template validation moved to a constant. * New feature flag and add actor. * Updated templates. * Add visibility logging. * Move logging functions. * Simple to follow longer function. * Separate match function. * Add visibility back. * Add required templates validation logging. * Updated tests. * Lint. * Template and yaml changes for vets-api specific. * Test and controller update for feedback. * Remove actor. * Updating tests to include YAML tests. * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Test and lint updates. * safe_load_file * Environment to string * Safe backup if file does not exist * Test lint * Remove un-needed freeze --------- Co-authored-by: Seth Darr <92405130+sethdarragile6@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 9096bfc commit 62e3a47

File tree

5 files changed

+1340
-2
lines changed

5 files changed

+1340
-2
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ config/coverband.rb @department-of-veterans-affairs/backend-review-group
719719
config/database.yml @department-of-veterans-affairs/backend-review-group
720720
config/environment.rb @department-of-veterans-affairs/backend-review-group
721721
config/environments @department-of-veterans-affairs/backend-review-group
722+
config/event_bus_gateway/templates.yml @department-of-veterans-affairs/benefits-management-tools-be @department-of-veterans-affairs/backend-review-group
722723
config/features.yml @department-of-veterans-affairs/backend-review-group
723724
config/form_profile_mappings/0873.yml @department-of-veterans-affairs/vfs-virtual-agent-chatbot @department-of-veterans-affairs/backend-review-group
724725
config/form_profile_mappings/10-10EZR.yml @department-of-veterans-affairs/health-apps-backend @department-of-veterans-affairs/backend-review-group

app/controllers/v0/event_bus_gateway_controller.rb

Lines changed: 161 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,50 @@ module V0
44
class EventBusGatewayController < SignIn::ServiceAccountApplicationController
55
service_tag 'event_bus_gateway'
66

7+
def self.deployment_environment
8+
env = Settings.vsp_environment || Rails.env.to_s
9+
%w[development test staging production].include?(env) ? env : 'blank'
10+
end
11+
12+
def self.load_templates
13+
YAML.safe_load_file(
14+
Rails.root.join('config', 'event_bus_gateway', 'templates.yml')
15+
)[deployment_environment]
16+
rescue Errno::ENOENT, Psych::BadAlias => e
17+
Rails.logger.warn("EventBusGatewayController: Failed to load templates.yml: #{e.message}")
18+
{}
19+
end
20+
21+
TEMPLATES = load_templates.freeze
22+
23+
REQUIRED_EMAIL_TEMPLATES = %w[
24+
default_template
25+
mobile_link_template
26+
pension_claims_template
27+
pension_mobile_link_template
28+
].freeze
29+
30+
def self.missing_required_templates
31+
email_templates = TEMPLATES['email']
32+
return REQUIRED_EMAIL_TEMPLATES.dup if email_templates.nil?
33+
34+
missing = []
35+
REQUIRED_EMAIL_TEMPLATES.each do |template_key|
36+
missing << template_key if email_templates[template_key].blank?
37+
end
38+
missing
39+
end
40+
41+
def self.validate_templates
42+
missing_required_templates.empty?
43+
end
44+
45+
TEMPLATES_VALID = validate_templates.freeze
46+
747
def send_email
848
EventBusGateway::LetterReadyEmailJob.perform_async(
949
participant_id,
10-
send_email_params.require(:template_id)
50+
select_email_template(send_email_params.require(:template_id))
1151
)
1252
head :ok
1353
end
@@ -34,7 +74,7 @@ def send_notifications
3474

3575
EventBusGateway::LetterReadyNotificationJob.perform_async(
3676
participant_id,
37-
send_notifications_params[:email_template_id],
77+
select_email_template(send_notifications_params[:email_template_id]),
3878
send_notifications_params[:push_template_id],
3979
send_notifications_params[:sms_template_id]
4080
)
@@ -76,5 +116,124 @@ def validate_at_least_one_template!
76116
}]
77117
}, status: :bad_request
78118
end
119+
120+
def select_email_template(original_template)
121+
if original_template.blank?
122+
log_blank_template
123+
return original_template
124+
end
125+
126+
unless TEMPLATES_VALID
127+
log_invalid_templates
128+
log_required_templates
129+
return original_template
130+
end
131+
132+
unless universal_link_enabled?
133+
log_universal_link_disabled
134+
return original_template
135+
end
136+
137+
match_and_swap_template(original_template)
138+
end
139+
140+
def match_and_swap_template(original_template)
141+
case original_template
142+
when TEMPLATES['email']['default_template']
143+
log_default_template_matched
144+
swap_to_mobile_template('mobile_link_template', 'universal link')
145+
when TEMPLATES['email']['pension_claims_template']
146+
log_pension_template_matched
147+
swap_to_mobile_template('pension_mobile_link_template', 'pension mobile link')
148+
else
149+
log_no_template_matched(original_template)
150+
original_template
151+
end
152+
end
153+
154+
def swap_to_mobile_template(template_key, description)
155+
template_id = TEMPLATES['email'][template_key]
156+
157+
log_template_swap(description, template_id)
158+
159+
template_id
160+
end
161+
162+
def universal_link_enabled?
163+
if participant_id.blank?
164+
log_blank_participant_id
165+
return false
166+
end
167+
168+
Flipper.enabled?(:event_bus_gateway_letter_ready_email_universal_link, Flipper::Actor.new(participant_id))
169+
end
170+
171+
def log_blank_template
172+
return unless Flipper.enabled?(:event_bus_gateway_controller_visibility)
173+
174+
Rails.logger.info('EventBusGatewayController: original_template is blank')
175+
end
176+
177+
def log_universal_link_disabled
178+
return unless Flipper.enabled?(:event_bus_gateway_controller_visibility)
179+
180+
Rails.logger.info('EventBusGatewayController: universal_link feature flag is disabled')
181+
end
182+
183+
def log_blank_participant_id
184+
return unless Flipper.enabled?(:event_bus_gateway_controller_visibility)
185+
186+
Rails.logger.info(
187+
'EventBusGatewayController: participant_id is blank; universal_link feature will not be evaluated'
188+
)
189+
end
190+
191+
def log_invalid_templates
192+
return unless Flipper.enabled?(:event_bus_gateway_controller_visibility)
193+
194+
Rails.logger.info('EventBusGatewayController: templates are invalid')
195+
end
196+
197+
def log_default_template_matched
198+
return unless Flipper.enabled?(:event_bus_gateway_controller_visibility)
199+
200+
Rails.logger.info('EventBusGatewayController: matched default email template')
201+
end
202+
203+
def log_pension_template_matched
204+
return unless Flipper.enabled?(:event_bus_gateway_controller_visibility)
205+
206+
Rails.logger.info('EventBusGatewayController: matched pension email template')
207+
end
208+
209+
def log_no_template_matched(original_template)
210+
return unless Flipper.enabled?(:event_bus_gateway_controller_visibility)
211+
212+
Rails.logger.info(
213+
'EventBusGatewayController: no template case matched',
214+
{ template_id: original_template }
215+
)
216+
end
217+
218+
def log_template_swap(description, template_id)
219+
return unless Flipper.enabled?(:event_bus_gateway_controller_visibility)
220+
221+
Rails.logger.info(
222+
"EventBusGatewayController using #{description} template",
223+
{ swapped_template: template_id }
224+
)
225+
end
226+
227+
def log_required_templates
228+
return unless Flipper.enabled?(:event_bus_gateway_controller_validation_visibility)
229+
230+
missing = self.class.missing_required_templates
231+
return if missing.empty?
232+
233+
Rails.logger.info(
234+
'EventBusGatewayController: missing required templates',
235+
{ missing_templates: missing }
236+
)
237+
end
79238
end
80239
end
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
development:
2+
email:
3+
default_template: 'dev_template123'
4+
pension_claims_template: 'dev_pension_template123'
5+
mobile_link_template: 'dev_mobile_link_template123'
6+
pension_mobile_link_template: 'dev_pension_mobile_link_template123'
7+
push:
8+
default_template: 'dev_push_template123'
9+
sms:
10+
default_template: 'dev_sms_template123'
11+
12+
test:
13+
email:
14+
default_template: 'test_template123'
15+
pension_claims_template: 'test_pension_template123'
16+
mobile_link_template: 'test_mobile_link_template123'
17+
pension_mobile_link_template: 'test_pension_mobile_link_template123'
18+
push:
19+
default_template: 'test_push_template123'
20+
sms:
21+
default_template: 'test_sms_template123'
22+
23+
staging:
24+
email:
25+
default_template: '520c5a6b-a24e-4c94-91e4-2ef50a667876'
26+
pension_claims_template: '0f5f9393-225f-42f4-8773-6fe179ae0707'
27+
mobile_link_template: 'f8982107-1cb2-49e6-bcd2-c4ccd9a3f443'
28+
pension_mobile_link_template: '97f6e9c4-a5cc-4b97-bde8-603ed91911d7'
29+
push:
30+
default_template: '9B25046E39874A21BB8FD4867E6B452D'
31+
sms:
32+
default_template: '705ef1bf-1074-4042-aca8-bbed918c2e52'
33+
34+
production:
35+
email:
36+
default_template: 'b5830306-3339-49ea-a80a-4b5105263aaf'
37+
pension_claims_template: 'b600ae50-07e3-4e2e-81e5-05be8157f714'
38+
mobile_link_template: ''
39+
pension_mobile_link_template: ''
40+
push:
41+
default_template: '5D7D1E2BE5C149B0918E30F7116EC1CA'
42+
sms:
43+
default_template: 'be6761df-f739-4924-b86f-fddb4f501d29'
44+
45+
blank:
46+
email:
47+
default_template: ''
48+
pension_claims_template: ''
49+
mobile_link_template: ''
50+
pension_mobile_link_template: ''
51+
push:
52+
default_template: ''
53+
sms:
54+
default_template: ''

config/features.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ features:
229229
description: "Gateway: Enable decision letter email notifications for EP600 predetermined notice"
230230
event_bus_gateway_ep930_decision_letter_notifications:
231231
description: "Gateway: Enable decision letter email notifications for EP930 review, referrals, and other"
232+
event_bus_gateway_letter_ready_email_universal_link:
233+
description: Percentage rollout flag for universal link in letter ready email notifications
232234
event_bus_gateway_letter_ready_push_notifications:
233235
description: Percentage rollout flag for push notifications in LetterReadyNotificationJob
234236
event_bus_gateway_letter_ready_sms_notifications:
@@ -241,6 +243,10 @@ features:
241243
description: "Gateway: Enable sms notifications"
242244
event_bus_gateway_sign_in_token_validation:
243245
description: Enables SignInService token validation
246+
event_bus_gateway_controller_visibility:
247+
description: Enables detailed logging in EventBusGatewayController for debugging and monitoring
248+
event_bus_gateway_controller_validation_visibility:
249+
description: System-wide flag to enable validation logging in EventBusGatewayController
244250
hca_browser_monitoring_enabled:
245251
actor_type: user
246252
description: Enables browser monitoring for the health care application.

0 commit comments

Comments
 (0)