-
Notifications
You must be signed in to change notification settings - Fork 166
LG-13421 | Adds GpoVerifyByMailPolicy #10844
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
Changes from all commits
cf8425f
7960db0
d9b21f7
cc0be4d
e0dd0e4
410ea50
fa08123
3927ea1
64a3a94
b3bf27a
84a9b05
78b9da5
a04a88c
82e4875
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,8 +16,8 @@ def from_idv_phone? | |
| end | ||
|
|
||
| def gpo_letter_available? | ||
| FeatureManagement.gpo_verification_enabled? && | ||
| current_user && | ||
| !Idv::GpoMail.new(current_user).rate_limited? | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this became |
||
| return false unless current_user | ||
| policy = Idv::GpoVerifyByMailPolicy.new(current_user) | ||
| policy.send_letter_available? | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 20 and 21 (and many instances of this across these files) could be inclined to |
||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,35 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Idv | ||
| class GpoMail | ||
| attr_reader :current_user | ||
| class GpoVerifyByMailPolicy | ||
| attr_reader :user | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fun: initially this was a new class, but then I moved over enough from GpoMail that GitHub has solved the Ship of Theseus problem for us. |
||
|
|
||
| def initialize(current_user) | ||
| @current_user = current_user | ||
| def initialize(user) | ||
| @user = user | ||
| end | ||
|
|
||
| def resend_letter_available? | ||
| FeatureManagement.gpo_verification_enabled? && | ||
| !rate_limited? && | ||
| !profile_too_old? | ||
| end | ||
|
|
||
| def send_letter_available? | ||
| FeatureManagement.gpo_verification_enabled? && | ||
| !rate_limited? | ||
| end | ||
|
|
||
| def rate_limited? | ||
| too_many_letter_requests_within_window? || last_letter_request_too_recent? | ||
| end | ||
|
|
||
| def profile_too_old? | ||
| return false if !current_user.pending_profile | ||
| return false if !user.pending_profile | ||
|
|
||
| min_creation_date = IdentityConfig.store. | ||
| gpo_max_profile_age_to_send_letter_in_days.days.ago | ||
|
|
||
| current_user.pending_profile.created_at < min_creation_date | ||
| user.pending_profile.created_at < min_creation_date | ||
| end | ||
|
|
||
| private | ||
|
|
@@ -34,16 +45,16 @@ def last_not_too_recent_enabled? | |
|
|
||
| def too_many_letter_requests_within_window? | ||
| return false unless window_limit_enabled? | ||
| current_user.gpo_confirmation_codes.where( | ||
| user.gpo_confirmation_codes.where( | ||
| created_at: IdentityConfig.store.max_mail_events_window_in_days.days.ago..Time.zone.now, | ||
| ).count >= IdentityConfig.store.max_mail_events | ||
| end | ||
|
|
||
| def last_letter_request_too_recent? | ||
| return false unless last_not_too_recent_enabled? | ||
| return false unless current_user.gpo_verification_pending_profile? | ||
| return false unless user.gpo_verification_pending_profile? | ||
|
|
||
| current_user.gpo_verification_pending_profile.gpo_confirmation_codes.exists?( | ||
| user.gpo_verification_pending_profile.gpo_confirmation_codes.exists?( | ||
| [ | ||
| 'created_at > ?', | ||
| IdentityConfig.store.minimum_wait_before_another_usps_letter_in_hours.hours.ago, | ||
|
|
||
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.
153-155 became the
resend_letter_available?method.I am not convinced this memoization ever saves us anything, but 🤷