Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
14504d5
Failing spec for hybrid_flow barcode error (redo document capture)
soniaconnolly Sep 20, 2023
a57035b
Add the rest of a hybrid_mobile redo document capture spec (untested)
soniaconnolly Sep 20, 2023
4cad8df
redo hybrid doc capture fixed
amirbey Sep 24, 2023
9fc9da6
hybrid document capture controller determine reload of document
amirbey Sep 24, 2023
b7b48e6
fix tests
amirbey Sep 24, 2023
a6ca7e6
LG-11012
amirbey Sep 24, 2023
1e550eb
resave document capture session
amirbey Sep 25, 2023
7cfd1bc
rename document capture session result created_at to captured_at
amirbey Sep 25, 2023
540e87e
add captured_at attr to DocumentCaptureSessionResult in spec
amirbey Sep 25, 2023
7c31b32
confirm_ocr refactor
amirbey Sep 25, 2023
4545aea
add tests for confirming hybrid document capture needed
amirbey Sep 26, 2023
e2740b6
unset redo_document_capture in idv_session during hybrid
amirbey Sep 25, 2023
e031646
unsets redo document capture in idv session with successful doc auth
amirbey Sep 26, 2023
6ed1278
ensure hybrid doc capture can occur after successful standard doc cap…
amirbey Sep 26, 2023
8e0e912
test redo document hybrid after doc auth desktop
amirbey Sep 26, 2023
d74080d
guard no longer needed
amirbey Sep 26, 2023
2b2166c
happy linting
amirbey Sep 27, 2023
b69c16b
remove unused store_doc_auth_result
amirbey Sep 27, 2023
62dd008
move confirm_ocr to document capture session and call in standard flow
amirbey Sep 27, 2023
7c25830
create doc cap session for doc cap controller spec
amirbey Sep 27, 2023
f7da966
make sessio result private
amirbey Sep 28, 2023
0fd5164
create new session result for every doc auth response
amirbey Sep 29, 2023
55f6482
fix init assignment
amirbey Sep 29, 2023
a1df755
test that a new result is created when a doc auth is result is stored…
amirbey Sep 29, 2023
862cc5d
happy linting
amirbey Sep 29, 2023
e3a9312
undo session_result changes
amirbey Oct 2, 2023
42b9eda
add test to verify failed images are retained in document capture ses…
amirbey Oct 2, 2023
ca3f12e
remove unused variable assignment
amirbey Oct 2, 2023
3ec054a
Update app/controllers/idv/hybrid_mobile/document_capture_controller.rb
amirbey Oct 2, 2023
7266674
happy linting
amirbey Oct 2, 2023
4f0ba64
reset idv_sesson.redo_document capture in link_sent#update
amirbey Oct 3, 2023
2293105
test that pii pon verify _info is changesd upon redo_document_capture
amirbey Oct 3, 2023
bf1f93a
fix text check
amirbey Oct 3, 2023
34385da
barcode attention if not redoing document capture
amirbey Oct 4, 2023
9b0447e
happy linting
amirbey Oct 4, 2023
637ab57
add guard for document_capture_session requested at
amirbey Oct 4, 2023
246b239
remove unused new_session_result method
amirbey Oct 4, 2023
37e0b83
Update app/controllers/idv/document_capture_controller.rb
amirbey Oct 4, 2023
33356f3
Merge branch 'amirbey/sonia-hybrid-mobile-redo-document-capture' of g…
amirbey Oct 4, 2023
4668cc1
add pii value checks to document capture orig on desktop and redo on …
amirbey Oct 4, 2023
e3ee502
guard incase barcode attention doc auth occurred before the release a…
amirbey Oct 4, 2023
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
16 changes: 13 additions & 3 deletions app/controllers/idv/capture_doc_status_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def status
:too_many_requests
elsif confirmed_barcode_attention_result? || user_has_establishing_in_person_enrollment?
:ok
elsif session_result.blank? || pending_barcode_attention_confirmation?
elsif session_result.blank? || pending_barcode_attention_confirmation? ||
redo_document_capture_pending?
:accepted
elsif !session_result.success?
:unauthorized
Expand Down Expand Up @@ -68,11 +69,13 @@ def user_has_establishing_in_person_enrollment?
end

def confirmed_barcode_attention_result?
had_barcode_attention_result? && !document_capture_session.ocr_confirmation_pending?
!redo_document_capture_pending? && had_barcode_attention_result? &&
!document_capture_session.ocr_confirmation_pending?
end

def pending_barcode_attention_confirmation?
had_barcode_attention_result? && document_capture_session.ocr_confirmation_pending?
!redo_document_capture_pending? && had_barcode_attention_result? &&
document_capture_session.ocr_confirmation_pending?
end

def had_barcode_attention_result?
Expand All @@ -90,5 +93,12 @@ def idv_session
service_provider: current_sp,
)
end

def redo_document_capture_pending?
return unless session_result&.dig(:captured_at)
return unless document_capture_session.requested_at

document_capture_session.requested_at > session_result.captured_at
Copy link
Contributor

@soniaconnolly soniaconnolly Sep 28, 2023

Choose a reason for hiding this comment

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

I like this definition, very practical. "Have we done this already?" I think it will be resilient as we enable the back button, too.

Would it make sense to define it as DocumentCaptureSession#redo?(captured_at:) to avoid repeating the definition in DocumentCaptureController ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes i wanted to do that. however, this line is the blocker ... do you knowi is this load_async still necessary? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't know off-hand. @aduth might know if it's part of the doc auth async code. Happy to dig in with you if that would be helpful.

Copy link
Contributor

@aduth aduth Oct 3, 2023

Choose a reason for hiding this comment

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

Yes, I think the load_doc_auth_async_result is related to the now-defunct (as of #8377) async document capture code. So it would probably be safe to remove all of that.

Copy link
Contributor Author

@amirbey amirbey Oct 4, 2023

Choose a reason for hiding this comment

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

thanks @aduth ... after briefly testing out the removal of load_doc_auth_async_result .. i think it'd be best to remove it in a follow up PR

end
end
end
3 changes: 3 additions & 0 deletions app/controllers/idv/document_capture_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def show

def update
idv_session.redo_document_capture = nil # done with this redo
# Not used in standard flow, here for data consistency with hybrid flow.
document_capture_session.confirm_ocr

result = handle_stored_result
analytics.idv_doc_auth_document_capture_submitted(**result.to_h.merge(analytics_arguments))

Expand Down
21 changes: 16 additions & 5 deletions app/controllers/idv/hybrid_mobile/document_capture_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ class DocumentCaptureController < ApplicationController

before_action :check_valid_document_capture_session
before_action :override_csp_to_allow_acuant
before_action :confirm_document_capture_needed, only: :show

def show
if document_capture_session&.load_result&.success?
redirect_to idv_hybrid_mobile_capture_complete_url
return
end

analytics.idv_doc_auth_document_capture_visited(**analytics_arguments)

Funnel::DocAuth::RegisterStep.new(document_capture_user.id, sp_session[:issuer]).
Expand All @@ -22,6 +18,7 @@ def show
end

def update
document_capture_session.confirm_ocr
result = handle_stored_result

analytics.idv_doc_auth_document_capture_submitted(**result.to_h.merge(analytics_arguments))
Expand Down Expand Up @@ -69,6 +66,20 @@ def handle_stored_result
failure(I18n.t('doc_auth.errors.general.network_error'), extra)
end
end

def confirm_document_capture_needed
return unless stored_result&.success?
return if redo_document_capture_pending?

redirect_to idv_hybrid_mobile_capture_complete_url
end

def redo_document_capture_pending?
return unless stored_result&.dig(:captured_at)
return unless document_capture_session.requested_at

document_capture_session.requested_at > stored_result.captured_at
end
end
end
end
1 change: 1 addition & 0 deletions app/controllers/idv/link_sent_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def update
# The doc capture flow will have fetched the results already. We need
# to fetch them again here to add the PII to this session
handle_document_verification_success(document_capture_session_result)
idv_session.redo_document_capture = nil

redirect_to idv_ssn_url
end
Expand Down
22 changes: 8 additions & 14 deletions app/models/document_capture_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def store_result_from_response(doc_auth_response)
)
session_result.success = doc_auth_response.success?
session_result.pii = doc_auth_response.pii_from_doc
session_result.captured_at = Time.zone.now
session_result.attention_with_barcode = doc_auth_response.attention_with_barcode?
EncryptedRedisStructStorage.store(
session_result,
Expand All @@ -28,6 +29,7 @@ def store_failed_auth_image_fingerprint(front_image_fingerprint, back_image_fing
id: generate_result_id,
)
session_result.success = false
session_result.captured_at = Time.zone.now
session_result.add_failed_front_image!(front_image_fingerprint) if front_image_fingerprint
session_result.add_failed_back_image!(back_image_fingerprint) if back_image_fingerprint
EncryptedRedisStructStorage.store(
Expand All @@ -52,20 +54,6 @@ def create_doc_auth_session
save!
end

def store_doc_auth_result(result:, pii:)
EncryptedRedisStructStorage.store(
DocumentCaptureSessionAsyncResult.new(
id: result_id,
pii: pii,
result: result,
status: DocumentCaptureSessionAsyncResult::DONE,
),
expires_in: IdentityConfig.store.async_wait_timeout_seconds,
)
self.ocr_confirmation_pending = result[:attention_with_barcode]
save!
end

def load_proofing_result
EncryptedRedisStructStorage.load(result_id, type: ProofingSessionAsyncResult)
end
Expand Down Expand Up @@ -99,6 +87,12 @@ def expired?
Time.zone.now
end

def confirm_ocr
return unless self.ocr_confirmation_pending

update!(ocr_confirmation_pending: false)
end

private

def generate_result_id
Expand Down
3 changes: 2 additions & 1 deletion app/services/document_capture_session_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
:attention_with_barcode,
:failed_front_image_fingerprints,
:failed_back_image_fingerprints,
:captured_at,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any issue with existing document_capture_sessions in redis not having this attribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great catch ... added dig(:captured_at) to check if it exists before evaluating 👍🏿

keyword_init: true,
allowed_members: [:id, :success, :attention_with_barcode, :failed_front_image_fingerprints,
:failed_back_image_fingerprints],
:failed_back_image_fingerprints, :captured_at],
) do
def self.redis_key_prefix
'dcs:result'
Expand Down
22 changes: 21 additions & 1 deletion spec/controllers/idv/document_capture_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
RSpec.describe Idv::DocumentCaptureController do
include IdvHelper

let(:document_capture_session_uuid) { 'fd14e181-6fb1-4cdc-92e0-ef66dad0df4e' }
let(:document_capture_session_requested_at) { Time.zone.now }

let!(:document_capture_session) do
DocumentCaptureSession.create!(
user: user,
requested_at: document_capture_session_requested_at,
)
end

let(:document_capture_session_uuid) { document_capture_session&.uuid }

let(:user) { create(:user) }

Expand Down Expand Up @@ -184,5 +193,16 @@
expect(user.reload.establishing_in_person_enrollment).to be_nil
end
end

context 'ocr confirmation pending' do
before do
subject.document_capture_session.ocr_confirmation_pending = true
end

it 'confirms ocr' do
put :update
expect(subject.document_capture_session.ocr_confirmation_pending).to be_falsey
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
let(:document_capture_session_uuid) { document_capture_session&.uuid }

let(:document_capture_session_requested_at) { Time.zone.now }
let(:document_capture_session_result_captured_at) { Time.zone.now + 1.second }
let(:document_capture_session_result_success) { true }

let(:ab_test_args) do
{ sample_bucket1: :sample_value1, sample_bucket2: :sample_value2 }
Expand Down Expand Up @@ -102,20 +104,42 @@
end
end
end

context 'stored_result already exists' do
before do
stub_document_capture_session_result
end

it 'redirects to document capture complete' do
get :show
expect(response).to redirect_to idv_hybrid_mobile_capture_complete_url
end

context 'document capture re-requested' do
let(:document_capture_session_result_captured_at) do
document_capture_session_requested_at - 5.minutes
end
context 'with successful stored_result' do
it 'renders the show template' do
get :show
expect(response).to render_template :show
end
end

context 'with failed stored_result' do
let(:document_capture_session_result_success) { false }
it 'renders the show template' do
get :show
expect(response).to render_template :show
end
end
end
end
end

describe '#update' do
before do
allow_any_instance_of(DocumentCaptureSession).to receive(:load_result).and_return(
DocumentCaptureSessionResult.new(
id: 1234,
success: true,
pii: {
state: 'WA',
},
attention_with_barcode: true,
),
)
stub_document_capture_session_result
end

context 'with no user id in session' do
Expand Down Expand Up @@ -161,6 +185,17 @@
put :update
expect(response).to redirect_to idv_hybrid_mobile_capture_complete_url
end

context 'ocr confirmation pending' do
before do
subject.document_capture_session.ocr_confirmation_pending = true
end

it 'confirms ocr' do
put :update
expect(subject.document_capture_session.ocr_confirmation_pending).to be_falsey
end
end
end
end

Expand All @@ -172,4 +207,18 @@
controller.extra_view_variables
end
end

def stub_document_capture_session_result
allow_any_instance_of(DocumentCaptureSession).to receive(:load_result).and_return(
DocumentCaptureSessionResult.new(
id: 1234,
success: document_capture_session_result_success,
pii: {
state: 'WA',
},
attention_with_barcode: true,
captured_at: document_capture_session_result_captured_at,
),
)
end
end
24 changes: 18 additions & 6 deletions spec/controllers/idv/link_sent_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,26 @@
allow(subject).to receive(:document_capture_session).and_return(document_capture_session)
end

it 'redirects to ssn page when successful' do
put :update
context 'document capture session successful' do
it 'redirects to ssn page' do
put :update

expect(response).to redirect_to(idv_ssn_url)
expect(response).to redirect_to(idv_ssn_url)

pc = ProofingComponent.find_by(user_id: user.id)
expect(pc.document_check).to eq('mock')
expect(pc.document_type).to eq('state_id')
pc = ProofingComponent.find_by(user_id: user.id)
expect(pc.document_check).to eq('mock')
expect(pc.document_type).to eq('state_id')
end

context 'redo document capture' do
before do
subject.idv_session.redo_document_capture = true
end
it 'resets redo_document capture to nil in idv_session' do
put :update
expect(subject.idv_session.redo_document_capture).to be_nil
end
end
end

context 'document capture session canceled' do
Expand Down
Loading