-
Notifications
You must be signed in to change notification settings - Fork 166
LG-7185: Send email reminders for in-person proofing enrollments #7256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
52a160d
email job
svalexander 3f8fec7
moving email job file and fixing missing end
svalexander 8db4ad5
send partially working
svalexander 66b08e9
email job working
svalexander d536f5e
include test for needs email reminder
svalexander c0154ef
add test for excluded enrollments
svalexander 0710531
make methods private
svalexander aa49e4f
fall back to app name if sp_name is not available
svalexander 8e00e96
changelog:Improvement, Job, add email reminder job
svalexander 954080e
db migration
svalexander 0899ca0
update email reminder so it covers a range of dates
svalexander ad5c6a2
can be equal to end interval
svalexander bf98edd
adjust interval
svalexander cfd6bfc
update config names
svalexander f449be2
make input param names clearer and change time to make sure correct d…
svalexander 10d2f19
update email reminder tests
svalexander 7d2def4
lint fix
svalexander b00584a
update calculation so excludes enrollments on late benchmark and incl…
svalexander 66b107d
fix test so correct enrollments are picked based on established_at time
svalexander 2d83d45
fix lint issue
svalexander 867f059
check flags are false and remove unneeded test
svalexander 1625881
move email reminder job to in person folder
svalexander 68cfd92
Merge branch 'main' into shannon/lg-7185-email-reminders-job-new
svalexander fa69523
fix lint
svalexander a22443a
job spec
svalexander 36794ea
continued work on job spec
svalexander 33bd16b
check enrollment code
svalexander fb93206
update to email job
svalexander d9e1190
some tests pass and others fail
svalexander d97c606
tests working and lint changes
svalexander 406031d
update naming
svalexander a4fe8dd
refactor based on feedback
svalexander 9ca2b5a
update tests
svalexander 8a3e5b3
remove unneeded nil check
svalexander 959ba8d
Merge remote-tracking branch 'origin/main' into shannon/lg-7185-email…
d805490
LG-7185: Add error handling and analytics to in-person proofing email…
d244335
Merge remote-tracking branch 'origin/main' into shannon/lg-7185-email…
5841d1f
Merge remote-tracking branch 'origin/main' into shannon/lg-7185-email…
14783a4
pluralize email subject and header by days left
f231d34
Merge remote-tracking branch 'origin/main' into shannon/lg-7185-email…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,95 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module InPerson | ||
|
svalexander marked this conversation as resolved.
|
||
| class EmailReminderJob < ApplicationJob | ||
| EMAIL_TYPE_EARLY = 'early' | ||
| EMAIL_TYPE_LATE = 'late' | ||
|
|
||
| queue_as :low | ||
|
|
||
| include GoodJob::ActiveJobExtensions::Concurrency | ||
|
|
||
|
svalexander marked this conversation as resolved.
|
||
| good_job_control_concurrency_with( | ||
| total_limit: 1, | ||
| key: 'in_person_email_reminder_job', | ||
| ) | ||
|
|
||
| discard_on GoodJob::ActiveJobExtensions::Concurrency::ConcurrencyExceededError | ||
|
|
||
| def perform(_now) | ||
|
svalexander marked this conversation as resolved.
|
||
| return true unless IdentityConfig.store.in_person_proofing_enabled | ||
|
|
||
| # send late emails first in case of job failure | ||
| late_enrollments = InPersonEnrollment.needs_late_email_reminder( | ||
| late_benchmark, | ||
| final_benchmark, | ||
| ) | ||
| send_emails_for_enrollments(enrollments: late_enrollments, email_type: EMAIL_TYPE_LATE) | ||
|
|
||
| early_enrollments = InPersonEnrollment.needs_early_email_reminder( | ||
| early_benchmark, | ||
| late_benchmark, | ||
| ) | ||
| send_emails_for_enrollments(enrollments: early_enrollments, email_type: EMAIL_TYPE_EARLY) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def analytics(user: AnonymousUser.new) | ||
| Analytics.new(user: user, request: nil, session: {}, sp: nil) | ||
| end | ||
|
|
||
| def send_emails_for_enrollments(enrollments:, email_type:) | ||
| enrollments.each do |enrollment| | ||
| send_reminder_email(enrollment.user, enrollment) | ||
| rescue StandardError => err | ||
| NewRelic::Agent.notice_error(err) | ||
| analytics(user: enrollment.user).idv_in_person_email_reminder_job_exception( | ||
| enrollment_id: enrollment.id, | ||
| exception_class: err.class.to_s, | ||
| exception_message: err.message, | ||
| ) | ||
| else | ||
| analytics(user: enrollment.user).idv_in_person_email_reminder_job_email_initiated( | ||
| email_type: email_type, | ||
| enrollment_id: enrollment.id, | ||
| ) | ||
| if email_type == EMAIL_TYPE_EARLY | ||
| enrollment.update!(early_reminder_sent: true) | ||
| elsif email_type == EMAIL_TYPE_LATE | ||
| enrollment.update!(late_reminder_sent: true) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def calculate_interval(benchmark) | ||
| days_until_expired = IdentityConfig.store.in_person_enrollment_validity_in_days.days | ||
| (Time.zone.now - days_until_expired) + benchmark.days | ||
| end | ||
|
|
||
| def early_benchmark | ||
| calculate_interval(IdentityConfig.store.in_person_email_reminder_early_benchmark_in_days) | ||
| end | ||
|
|
||
| def late_benchmark | ||
| calculate_interval(IdentityConfig.store.in_person_email_reminder_late_benchmark_in_days) | ||
| end | ||
|
|
||
| def final_benchmark | ||
| calculate_interval(IdentityConfig.store.in_person_email_reminder_final_benchmark_in_days) | ||
| end | ||
|
|
||
| def send_reminder_email(user, enrollment) | ||
| user.confirmed_email_addresses.each do |email_address| | ||
| # rubocop:disable IdentityIdp/MailLaterLinter | ||
| UserMailer.with( | ||
| user: user, | ||
| email_address: email_address, | ||
| ).in_person_ready_to_verify_reminder( | ||
| enrollment: enrollment, | ||
| ).deliver_later | ||
| # rubocop:enable IdentityIdp/MailLaterLinter | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
6 changes: 6 additions & 0 deletions
6
...20221031203041_add_early_reminder_sent_and_late_reminder_sent_to_in_person_enrollments.rb
This file contains hidden or 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,6 @@ | ||
| class AddEarlyReminderSentAndLateReminderSentToInPersonEnrollments < ActiveRecord::Migration[7.0] | ||
| def change | ||
| add_column :in_person_enrollments, :early_reminder_sent, :boolean, default: false, comment: "early reminder to complete IPP before deadline sent" | ||
| add_column :in_person_enrollments, :late_reminder_sent, :boolean, default: false, comment: "late reminder to complete IPP before deadline sent" | ||
| end | ||
| end |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good! starting a thread here arbitrarily for small design comments @tomas-nava
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created LG-8207 to track this work