Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
390d185
Make the generic failure template a partial
davemcorwin Jun 14, 2018
22c5862
Update jurisdiction fail screens
davemcorwin Jun 14, 2018
a4a746f
Fix translations;
davemcorwin Jun 14, 2018
02d7622
Explicitly set translations as used
davemcorwin Jun 14, 2018
377dacc
Lint fixes
davemcorwin Jun 15, 2018
901e994
Merge branch 'master' into LG-362-idv-attempts-fail-screen
davemcorwin Jun 15, 2018
c27fdf9
Update profile attempts fail screen
davemcorwin Jun 16, 2018
541a955
Update specs
davemcorwin Jun 16, 2018
041db2d
Merge branch 'master' into LG-362-idv-attempts-fail-screen
davemcorwin Jun 16, 2018
7ad119a
WIP
davemcorwin Jun 19, 2018
530e8f4
A lot of cleanup
davemcorwin Jun 19, 2018
9f0d483
Fix specs
davemcorwin Jun 19, 2018
5c857ee
Merge branch 'master' into LG-362-idv-attempts-fail-screen
davemcorwin Jun 20, 2018
b9dff27
Rubocop fixes
davemcorwin Jun 20, 2018
556762d
Rubocop fix
davemcorwin Jun 20, 2018
eef8367
Add presenter specs
davemcorwin Jun 20, 2018
3173d54
Update spec, i18n path
davemcorwin Jun 20, 2018
fd88f8c
More presenter specs
davemcorwin Jun 20, 2018
cdd535d
Merge branch 'master' into LG-362-idv-attempts-fail-screen
davemcorwin Jun 20, 2018
11539dd
Add failure specs to sessions controller spec
davemcorwin Jun 20, 2018
551d914
Fix SP return urls
davemcorwin Jun 21, 2018
66a287c
Add timeout example to moc resolution proofer
davemcorwin Jun 21, 2018
4b388b2
Fix spec
davemcorwin Jun 21, 2018
429211c
Fix spec again
davemcorwin Jun 21, 2018
aa4f705
Exclude proofer mocks from test coverage
davemcorwin Jun 25, 2018
800c5e7
Merge branch 'master' into LG-362-idv-attempts-fail-screen
davemcorwin Jun 26, 2018
ea0a130
Merge branch 'master' into LG-362-idv-attempts-fail-screen
jmhooper Jul 11, 2018
da4ba0e
clean up failure urls and add form before actions
jmhooper Jul 11, 2018
081f08b
fix some tests
jmhooper Jul 11, 2018
b6c1384
reduce cognition
jmhooper Jul 11, 2018
9c79ef1
rename other failure to verification failure
jmhooper Jul 11, 2018
d8d26cb
Use the accessor for `idv_form` not the instance variable
davemcorwin Jul 16, 2018
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
1 change: 1 addition & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ plugins:
exclude_patterns:
- 'db/schema.rb'
- 'node_modules/'
- 'lib/proofer_mocks/'
- 'lib/rspec/formatters/user_flow_formatter.rb'
- 'lib/tasks/create_test_accounts.rb'
- 'lib/user_flow_exporter.rb'
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/i18n-strings.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ window.LoginGov = window.LoginGov || {};
'idv.errors.pattern_mismatch.personal_key',
'idv.errors.pattern_mismatch.ssn',
'idv.errors.pattern_mismatch.zipcode',
'idv.modal.button.warning',
'idv.failure.button.warning',
'instructions.password.strength.i',
'instructions.password.strength.ii',
'instructions.password.strength.iii',
Expand Down
77 changes: 47 additions & 30 deletions app/controllers/concerns/idv_failure_concern.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,54 @@
module IdvFailureConcern
extend ActiveSupport::Concern

# rubocop:disable Metrics/MethodLength
def render_failure
if step_attempts_exceeded?
@view_model = view_model(error: 'fail')
flash_message(type: :error)
elsif step.vendor_validator_job_failed?
@view_model = view_model(error: 'jobfail')
flash_message(type: :warning)
elsif form_valid_but_vendor_validation_failed?
@view_model = view_model(error: 'warning', timed_out: step.vendor_validation_timed_out?)
flash_message(type: :warning)
else
@view_model = view_model
end
end
# rubocop:enable Metrics/MethodLength

def form_valid_but_vendor_validation_failed?
idv_form.valid? && !step.vendor_validation_passed?
end

def flash_message(type:)
flash.now[type.to_sym] = @view_model.flash_message
end

def view_model(error: nil, timed_out: nil)
view_model_class.new(
error: error,
def idv_step_failure_reason
return :fail if fail?
return :jobfail if jobfail?
return :timeout if timeout?
return :warning if warning?
end

def render_idv_step_failure(step, reason)
return render_failure('shared/_failure', failure_presenter(step)) if reason == :fail
render_failure('idv/shared/verification_failure', warning_presenter(step, reason))
end

def render_failure(template, presenter)
render_full_width(template, locals: { presenter: presenter })
end

private

def fail?
idv_attempter.exceeded? || step_attempts_exceeded?
end

def jobfail?
step.vendor_validator_job_failed?
end

def timeout?
!step.vendor_validation_passed? && step.vendor_validation_timed_out?
end

def warning?
!step.vendor_validation_passed? && !step.vendor_validation_timed_out?
end

def failure_presenter(step)
Idv::MaxAttemptsFailurePresenter.new(
decorated_session: decorated_session,
step_name: step,
view_context: view_context
)
end

def warning_presenter(step, reason)
Idv::WarningPresenter.new(
reason: reason,
remaining_attempts: remaining_step_attempts,
idv_form: idv_form,
timed_out: timed_out
step_name: step,
view_context: view_context
)
end
end
3 changes: 1 addition & 2 deletions app/controllers/concerns/idv_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ def confirm_idv_session_started

def confirm_idv_attempts_allowed
if idv_attempter.exceeded?
flash[:error] = t('idv.errors.hardfail')
analytics.track_event(Analytics::IDV_MAX_ATTEMPTS_EXCEEDED, request_path: request.path)
redirect_to idv_fail_url
redirect_to failure_url(:fail)
elsif idv_attempter.reset_attempts?
idv_attempter.reset
end
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/concerns/idv_step_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def confirm_step_allowed
end

def redirect_to_fail_url
flash[:max_attempts_exceeded] = true
redirect_to idv_fail_url
redirect_to failure_url(:fail)
end
end
12 changes: 8 additions & 4 deletions app/controllers/idv/jurisdiction_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class JurisdictionController < ApplicationController
before_action :confirm_two_factor_authenticated
before_action :confirm_idv_attempts_allowed
before_action :confirm_idv_needed
before_action :set_jurisdiction_form, only: %i[new create]
before_action :set_jurisdiction_form, except: [:failure]

def new
analytics.track_event(Analytics::IDV_JURISDICTION_VISIT)
Expand All @@ -22,12 +22,12 @@ def create
# The only invalid result here is due to an unsupported jurisdiction
# and if it is missing from the params, it will be stopped by
# `strong_params`.
redirect_to idv_jurisdiction_fail_url(:unsupported_jurisdiction)
redirect_to failure_url(:unsupported_jurisdiction)
end
end

def show
presenter = JurisdictionFailurePresenter.new(
def failure
presenter = Idv::JurisdictionFailurePresenter.new(
reason: params[:reason],
jurisdiction: user_session[:idv_jurisdiction],
view_context: view_context
Expand All @@ -44,5 +44,9 @@ def jurisdiction_params
def set_jurisdiction_form
@jurisdiction_form ||= Idv::JurisdictionForm.new
end

def failure_url(reason)
idv_jurisdiction_failure_url(reason)
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.

Doesn't look like we have cases that need a failure_url?

Copy link
Copy Markdown
Contributor

@jmhooper jmhooper Jul 11, 2018

Choose a reason for hiding this comment

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

This is used by a few of the IdV concerns:

end
end
end
31 changes: 16 additions & 15 deletions app/controllers/idv/phone_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ class PhoneController < ApplicationController
include IdvStepConcern
include IdvFailureConcern

attr_reader :idv_form

before_action :confirm_step_needed
before_action :confirm_step_allowed
before_action :confirm_step_allowed, except: [:failure]
before_action :refresh_if_not_ready, only: [:show]
before_action :set_idv_form, except: [:failure]

def new
@view_model = view_model
analytics.track_event(Analytics::IDV_PHONE_RECORD_VISIT)
end

Expand All @@ -20,7 +22,6 @@ def create
Idv::Job.submit(idv_session, [:address])
redirect_to idv_phone_result_url
else
@view_model = view_model
render :new
end
end
Expand All @@ -30,12 +31,12 @@ def show
analytics.track_event(Analytics::IDV_PHONE_CONFIRMATION_VENDOR, result.to_h)
increment_step_attempts

if result.success?
redirect_to_next_step
else
render_failure
render :new
end
redirect_to_next_step and return if result.success?
redirect_to idv_phone_failure_url(idv_step_failure_reason)
end

def failure
render_idv_step_failure(:phone, params[:reason].to_sym)
end

private
Expand Down Expand Up @@ -64,10 +65,6 @@ def step
)
end

def view_model_class
Idv::PhoneNew
end

def step_params
params.require(:idv_phone_form).permit(:phone)
end
Expand All @@ -76,8 +73,12 @@ def confirm_step_needed
redirect_to_next_step if idv_session.user_phone_confirmation == true
end

def idv_form
@_idv_form ||= Idv::PhoneForm.new(idv_session.params, current_user)
def set_idv_form
@idv_form ||= Idv::PhoneForm.new(idv_session.params, current_user)
end

def failure_url(reason)
idv_phone_failure_url(reason)
end
end
end
56 changes: 32 additions & 24 deletions app/controllers/idv/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ class SessionsController < ApplicationController
include IdvFailureConcern
include PersonalKeyConcern

attr_reader :idv_form

before_action :confirm_two_factor_authenticated, except: [:destroy]
before_action :confirm_idv_attempts_allowed, except: %i[destroy success]
before_action :confirm_idv_attempts_allowed, except: %i[destroy success failure]
before_action :confirm_idv_needed
before_action :confirm_step_needed, except: %i[destroy success]
before_action :initialize_idv_session, only: [:create]
Expand All @@ -15,32 +17,36 @@ class SessionsController < ApplicationController

def new
user_session[:context] = 'idv'
@view_model = view_model
@view_model.selected_state = user_session[:idv_jurisdiction]
set_idv_form
@selected_state = user_session[:idv_jurisdiction]
analytics.track_event(Analytics::IDV_BASIC_INFO_VISIT)
end

def create
set_idv_form
result = idv_form.submit(profile_params)
analytics.track_event(Analytics::IDV_BASIC_INFO_SUBMITTED_FORM, result.to_h)

if result.success?
Idv::Job.submit(idv_session, %i[resolution state_id])
redirect_to idv_session_result_url
else
process_failure
process_form_failure
end
end

def show
result = step.submit
analytics.track_event(Analytics::IDV_BASIC_INFO_SUBMITTED_VENDOR, result.to_h)

if result.success?
process_success
else
process_failure
end
redirect_to idv_session_success_url and return if result.success?
redirect_to idv_session_failure_url(idv_step_failure_reason)
end

def failure
reason = params[:reason].to_sym
render_dupe_ssn_failure and return if reason == :dupe_ssn
render_idv_step_failure(:sessions, reason)
end

def success; end
Expand Down Expand Up @@ -71,31 +77,29 @@ def handle_idv_redirect
redirect_to manage_personal_key_url
end

def process_success
redirect_to idv_session_success_url
def process_form_failure
redirect_to idv_session_failure_url(:dupe_ssn) and return if idv_form.duplicate_ssn?
if (sp_name = decorated_session.sp_name) && idv_form.unsupported_jurisdiction?
idv_form.add_sp_unsupported_jurisdiction_error(sp_name)
end
render :new
end

def process_failure
if idv_form.duplicate_ssn?
flash[:error] = t('idv.errors.duplicate_ssn')
redirect_to idv_session_dupe_url
else
render_failure
@view_model.unsupported_jurisdiction_error(decorated_session.sp_name)
render :new
end
def render_dupe_ssn_failure
presenter = Idv::SsnFailurePresenter.new(view_context: view_context)
render_failure('shared/_failure', presenter)
end

def view_model_class
Idv::SessionsNew
def step_name
:sessions
end

def remaining_step_attempts
Idv::Attempter.idv_max_attempts - current_user.idv_attempts
end

def idv_form
@_idv_form ||= Idv::ProfileForm.new((idv_session.params || {}), current_user)
def set_idv_form
@idv_form ||= Idv::ProfileForm.new((idv_session.params || {}), current_user)
end

def initialize_idv_session
Expand All @@ -107,5 +111,9 @@ def initialize_idv_session
def profile_params
params.require(:profile).permit(Idv::ProfileForm::PROFILE_ATTRIBUTES)
end

def failure_url(reason)
idv_session_failure_url(reason)
end
end
end
10 changes: 5 additions & 5 deletions app/controllers/idv_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ def activated
def cancel; end

def fail
redirect_to idv_url unless ok_to_fail?
redirect_to idv_url and return unless idv_attempter.exceeded?
presenter = Idv::IdvFailurePresenter.new(
view_context: view_context
)
render_full_width('shared/_failure', locals: { presenter: presenter })
end

private
Expand All @@ -40,8 +44,4 @@ def profile_needs_reactivation?
def active_profile?
current_user.active_profile.present?
end

def ok_to_fail?
idv_attempter.exceeded? || flash[:max_attempts_exceeded]
end
end
8 changes: 2 additions & 6 deletions app/decorators/service_provider_session_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ def verification_method_choice
I18n.t('idv.messages.select_verification_with_sp', sp_name: sp_name)
end

def idv_hardfail4_partial
'idv/hardfail4'
end

def requested_attributes
sp_session[:requested_attributes].sort
end
Expand Down Expand Up @@ -111,11 +107,11 @@ def sp_alert?
end

def sp_alert_name
sp_alert? ? SP_ALERTS[sp_name][:i18n_name] : nil
SP_ALERTS.dig(sp_name, :i18n_name)
end

def sp_alert_learn_more
sp_alert? ? SP_ALERTS[sp_name][:learn_more] : nil
SP_ALERTS.dig(sp_name, :learn_more)
end

private
Expand Down
4 changes: 0 additions & 4 deletions app/decorators/session_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ def verification_method_choice
I18n.t('idv.messages.select_verification_without_sp')
end

def idv_hardfail4_partial
'idv/no_sp_hardfail'
end

def cancel_link_url
view_context.root_url
end
Expand Down
Loading