-
Notifications
You must be signed in to change notification settings - Fork 166
LG-16298 bug fix for Create Job to Track Deletion Workflow Drop-offs #12277
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
kevinsmaster5
merged 10 commits into
main
from
LG-16298-kmas-bug-fix-track-deletion-drop-off
Jun 30, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
48e9e91
add job class and spec
kevinsmaster5 03c61f8
revert query changes
kevinsmaster5 57c3e8d
use correct predicate for querying expired resets and update test
kevinsmaster5 7036536
added test to delete controller spec
kevinsmaster5 d6d8b29
changelog: Bug Fixes, Account Deletion Workflow, fix bug in previous …
kevinsmaster5 a9a6787
consolidate test and leverage account reset helper
kevinsmaster5 5cd9b9c
clean up superfluous test setup and clarify it does statement
kevinsmaster5 e04791c
rename affected table column
kevinsmaster5 1ed33cf
update spec with new column
kevinsmaster5 bc6b569
removes dependency on storing an expired date when the job runs
kevinsmaster5 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,49 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class ExpireAccountResetRequestsJob < ApplicationJob | ||
| queue_as :long_running | ||
|
|
||
| def perform(now) | ||
| resets = 0 | ||
| expired_days = ( | ||
| IdentityConfig.store.account_reset_wait_period_days + | ||
| IdentityConfig.store.account_reset_token_valid_for_days | ||
| ).days | ||
| AccountResetRequest.where( | ||
| sql_query_for_users_with_expired_requests, | ||
| tvalue: now - expired_days, | ||
| ).order('requested_at ASC').limit(1_000).each do |arr| | ||
| resets += 1 if expire_request(arr) | ||
| end | ||
|
|
||
| analytics.account_reset_request_expired(count: resets) | ||
|
|
||
| resets | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def analytics | ||
| @analytics ||= Analytics.new( | ||
| user: AnonymousUser.new, | ||
| request: nil, | ||
| sp: nil, | ||
| session: {}, | ||
| ) | ||
| end | ||
|
|
||
| def sql_query_for_users_with_expired_requests | ||
| <<~SQL | ||
| request_token IS NOT NULL AND | ||
| cancelled_at IS NULL AND | ||
| granted_at < :tvalue | ||
mdiarra3 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| SQL | ||
| end | ||
|
|
||
| def expire_request(arr) | ||
| arr.update!( | ||
| request_token: nil, | ||
| granted_token: nil, | ||
| ) | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe ExpireAccountResetRequestsJob do | ||
| include AccountResetHelper | ||
| describe '#perform' do | ||
| subject(:perform) { job.perform(now) } | ||
| let(:job) { ExpireAccountResetRequestsJob.new } | ||
| let(:job_analytics) { FakeAnalytics.new } | ||
| let(:now) { Time.zone.now } | ||
|
|
||
| before do | ||
| allow(IdentityConfig.store).to receive(:account_reset_token_valid_for_days) | ||
| .and_return(0) | ||
| allow(Analytics).to receive(:new).and_return(job_analytics) | ||
| end | ||
|
|
||
| it 'it expires requests with expired grant tokens and ignores valid grant tokens' do | ||
| user = create(:user, :fully_registered, confirmed_at: Time.zone.now.round) | ||
| create_account_reset_request_for(user) | ||
| grant_request(user) | ||
|
|
||
| travel_to(Time.zone.now + 2.days) do | ||
| user2 = create( | ||
| :user, :fully_registered, | ||
| confirmed_at: Time.zone.now.round | ||
| ) | ||
| create_account_reset_request_for(user2) | ||
| grant_request(user2) | ||
|
|
||
| notification_sent = perform | ||
|
|
||
| expect(job_analytics).to have_logged_event( | ||
| :account_reset_request_expired, | ||
| count: 1, | ||
| ) | ||
| expect(notification_sent).to eq(1) | ||
|
|
||
| expect(AccountResetRequest.first.request_token).to be(nil) | ||
| expect(AccountResetRequest.second.request_token).to_not be(nil) | ||
| end | ||
| end | ||
| end | ||
| end |
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.
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.
Why a SQL query? Why not https://guides.rubyonrails.org/active_record_querying.html#and-conditions?
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.
I referred to prior art with this worker job https://github.com/18F/identity-idp/blob/main/app/jobs/grant_account_reset_requests_and_send_emails_job.rb#L31-L39 using SQL. I assumed it was more efficient to use a SQL query.