Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/services/account_reset/delete_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,20 @@ def notify_user_via_email_of_deletion
end
# rubocop:enable IdentityIdp/MailLaterLinter

def profile_components
return nil if !user.identity_verified?
ProofingComponent.create_or_find_by(user: user)
Comment thread
aduth marked this conversation as resolved.
Outdated
end

def extra_analytics_attributes
{
user_id: user.uuid,
email: user.email_addresses.take&.email,
account_age_in_days: account_age,
account_confirmed_at: user.confirmed_at,
mfa_method_counts: mfa_method_counts,
proofing_components: profile_components,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate to switch it up at this point, but I'm thinking it may be better off to just use (or at least start with using) the Profile#idv_level value (mentioned in Slack). Looking at some real-world logging, proofing components alone can't tell us if the user was proofed with biometric. Conversely, idv_level can't tell us if they proofed with GPO, but I think it's probably more pertinent to the event that we know "legacy" vs. with biometric vs in-person.

Plus, strings are a bit easier to work with than a hash 😅

Suggested change
proofing_components: profile_components,
profile_idv_level: user.active_profile&.idv_level,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That worked great. Thanks also to @matthinz for the suggestion.

identity_verified: user.identity_verified?,
pii_like_keypaths: [[:mfa_method_counts, :phone]],
}
end
Expand Down
13 changes: 13 additions & 0 deletions app/services/analytics_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,16 @@ def account_reset_cancel_token_validation(
# @param [Integer, nil] account_age_in_days number of days since the account was confirmed
# @param [Time] account_confirmed_at date that account creation was confirmed
# (rounded) or nil if the account was not confirmed
# @param [Hash,nil] proofing_components User's current proofing components
# @option proofing_components [String,nil] 'document_check' Vendor that verified the user's ID
# @option proofing_components [String,nil] 'document_type' Type of ID used to verify
# @option proofing_components [String,nil] 'source_check' Source used to verify user's PII
# @option proofing_components [String,nil] 'resolution_check' Vendor for identity resolution check
# @option proofing_components [String,nil] 'address_check' Method used to verify user's address
# @option proofing_components [Boolean,nil] 'threatmetrix' Whether ThreatMetrix check was done
# @option proofing_components [String,nil] 'threatmetrix_review_status' TMX decision on the user
# @param [Hash] mfa_method_counts Hash of MFA method with the number of that method on the account
# @param [Boolean] identity_verified if the deletion occurs on a verified account
# @param [Hash] errors Errors resulting from form validation
# @param [Hash] error_details Details for errors that occurred in unsuccessful submission
# An account has been deleted through the account reset flow
Expand All @@ -96,7 +105,9 @@ def account_reset_delete(
account_age_in_days:,
account_confirmed_at:,
mfa_method_counts:,
identity_verified:,
errors:,
proofing_components: nil,
error_details: nil,
**extra
)
Expand All @@ -107,6 +118,8 @@ def account_reset_delete(
account_age_in_days:,
account_confirmed_at:,
mfa_method_counts:,
proofing_components: proofing_components,
identity_verified:,
errors:,
error_details:,
**extra,
Expand Down
100 changes: 100 additions & 0 deletions spec/controllers/account_reset/delete_account_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
webauthn: 2,
phone: 2,
},
identity_verified: false,
account_age_in_days: 0,
account_confirmed_at: user.confirmed_at,
)
Expand All @@ -48,6 +49,7 @@
errors: invalid_token_error,
error_details: { token: { granted_token_invalid: true } },
mfa_method_counts: {},
identity_verified: false,
account_age_in_days: 0,
account_confirmed_at: kind_of(Time),
)
Expand All @@ -65,6 +67,7 @@
errors: { token: [t('errors.account_reset.granted_token_missing', app_name: APP_NAME)] },
error_details: { token: { blank: true } },
mfa_method_counts: {},
identity_verified: false,
account_age_in_days: 0,
account_confirmed_at: kind_of(Time),
)
Expand Down Expand Up @@ -92,6 +95,7 @@
errors: { token: [t('errors.account_reset.granted_token_expired', app_name: APP_NAME)] },
error_details: { token: { granted_token_expired: true } },
mfa_method_counts: {},
identity_verified: false,
account_age_in_days: 2,
account_confirmed_at: kind_of(Time),
)
Expand All @@ -100,6 +104,102 @@
t('errors.account_reset.granted_token_expired', app_name: APP_NAME),
)
end

it 'logs info about user verified account' do
user = create(:user, :proofed)
proofing_components = ProofingComponent.create_or_find_by(user: user)
create_account_reset_request_for(user)
grant_request(user)
session[:granted_token] = AccountResetRequest.first.granted_token

delete :delete

expect(@analytics).to have_logged_event(
'Account Reset: delete',
user_id: user.uuid,
success: true,
errors: {},
mfa_method_counts: { phone: 1 },
proofing_components: proofing_components,
identity_verified: true,
account_age_in_days: 0,
account_confirmed_at: user.confirmed_at,
)
expect(response).to redirect_to account_reset_confirm_delete_account_url
end

it 'logs info about user biometrically verified account' do
user = create(:user, :proofed_with_selfie, :with_phone)
proofing_components = ProofingComponent.create_or_find_by(user: user)
create_account_reset_request_for(user)
grant_request(user)
session[:granted_token] = AccountResetRequest.first.granted_token

delete :delete

expect(@analytics).to have_logged_event(
'Account Reset: delete',
user_id: user.uuid,
success: true,
errors: {},
mfa_method_counts: { phone: 1 },
proofing_components: proofing_components,
identity_verified: true,
account_age_in_days: 0,
account_confirmed_at: user.confirmed_at,
)
expect(response).to redirect_to account_reset_confirm_delete_account_url
end

it 'logs info about user with a verified by mail account' do
user = create(:user, :proofed_with_gpo)
proofing_components = ProofingComponent.create_or_find_by(user: user)
create_account_reset_request_for(user)
grant_request(user)
session[:granted_token] = AccountResetRequest.first.granted_token

delete :delete

expect(@analytics).to have_logged_event(
'Account Reset: delete',
user_id: user.uuid,
success: true,
errors: {},
mfa_method_counts: { phone: 1 },
proofing_components: proofing_components,
identity_verified: true,
account_age_in_days: 0,
account_confirmed_at: user.confirmed_at,
)
expect(response).to redirect_to account_reset_confirm_delete_account_url
end

it 'logs info about user pending in person verification account' do
Comment thread
aduth marked this conversation as resolved.
Outdated
user = create(
:user,
:proofed_in_person_enrollment,
:with_phone,
)
proofing_components = ProofingComponent.create_or_find_by(user: user)
create_account_reset_request_for(user)
grant_request(user)
session[:granted_token] = AccountResetRequest.first.granted_token

delete :delete

expect(@analytics).to have_logged_event(
'Account Reset: delete',
user_id: user.uuid,
success: true,
errors: {},
mfa_method_counts: { phone: 1 },
proofing_components: proofing_components,
identity_verified: true,
account_age_in_days: 0,
account_confirmed_at: user.confirmed_at,
)
Comment thread
aduth marked this conversation as resolved.
expect(response).to redirect_to account_reset_confirm_delete_account_url
end
end

describe '#show' do
Expand Down
7 changes: 7 additions & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@
end
end

trait :proofed_in_person_enrollment do
proofed
after :build do |user|
create(:in_person_enrollment, status: 'passed', user: user)
end
end

trait :with_pending_gpo_profile do
transient do
code_sent_at { created_at }
Expand Down