Skip to content
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

Update screen when user verifies directly on login #1774

Merged
merged 1 commit into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 20 additions & 10 deletions app/controllers/sign_up/completions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,18 @@ class CompletionsController < ApplicationController

def show
@view_model = view_model

if user_fully_authenticated? && session[:sp].present?
analytics.track_event(
Analytics::USER_REGISTRATION_AGENCY_HANDOFF_PAGE_VISIT,
service_provider_attributes
if show_completions_page?
track_agency_handoff(
Analytics::USER_REGISTRATION_AGENCY_HANDOFF_PAGE_VISIT
)
else
redirect_to new_user_session_url
redirect_to account_url
end
end

def update
analytics.track_event(
Analytics::USER_REGISTRATION_AGENCY_HANDOFF_COMPLETE,
service_provider_attributes
track_agency_handoff(
Analytics::USER_REGISTRATION_AGENCY_HANDOFF_COMPLETE
)

if decider.go_back_to_mobile_app?
Expand All @@ -33,10 +30,16 @@ def update

private

def show_completions_page?
service_providers = session[:sp].present? || @view_model.user_has_identities?
user_fully_authenticated? && service_providers
end

def view_model
SignUpCompletionsShow.new(
loa3_requested: loa3?,
decorated_session: decorated_session
decorated_session: decorated_session,
current_user: current_user
)
end

Expand Down Expand Up @@ -66,5 +69,12 @@ def sign_user_out_and_instruct_to_go_back_to_mobile_app
)
redirect_to new_user_session_url
end

def track_agency_handoff(analytic)
analytics.track_event(
analytic,
service_provider_attributes
)
end
end
end
1 change: 0 additions & 1 deletion app/controllers/users/verify_account_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ def index
usps_mail = Idv::UspsMail.new(current_user)
@mail_spammed = usps_mail.mail_spammed?
@verify_account_form = VerifyAccountForm.new(user: current_user)

return unless FeatureManagement.reveal_usps_code?
@code = session[:last_usps_confirmation_code]
end
Expand Down
1 change: 1 addition & 0 deletions app/decorators/identity_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
IdentityDecorator = Struct.new(:identity) do
delegate :display_name, to: :identity
delegate :agency_name, to: :identity

def event_partial
'accounts/identity_item'
Expand Down
4 changes: 4 additions & 0 deletions app/models/identity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def display_name
sp_metadata[:friendly_name] || sp_metadata[:agency] || service_provider
end

def agency_name
sp_metadata[:agency] || sp_metadata[:friendly_name] || service_provider
end

def decorate
IdentityDecorator.new(self)
end
Expand Down
35 changes: 34 additions & 1 deletion app/view_models/sign_up_completions_show.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
class SignUpCompletionsShow
include ActionView::Helpers::TagHelper

def initialize(loa3_requested:, decorated_session:)
def initialize(loa3_requested:, decorated_session:, current_user:)
@loa3_requested = loa3_requested
@decorated_session = decorated_session
@current_user = current_user
end

attr_reader :loa3_requested, :decorated_session
Expand All @@ -17,6 +18,8 @@ def initialize(loa3_requested:, decorated_session:)
[[:social_security_number], :social_security_number],
].freeze

MAX_RECENT_IDENTITIES = 5

# rubocop:disable Rails/OutputSafety
def heading
safe_join([I18n.t(
Expand Down Expand Up @@ -49,6 +52,36 @@ def requested_attributes_sorted
end.compact
end

def identities_partial
'shared/user_identities'
end

def service_provider_partial
if @decorated_session.is_a?(ServiceProviderSessionDecorator)
'sign_up/completions/show_sp'
else
'sign_up/completions/show_identities'
end
end

def identities
if @current_user
@identities ||= @current_user.identities.order(
last_authenticated_at: :desc
).limit(MAX_RECENT_IDENTITIES).map(&:decorate)
else
false
end
end

def user_has_identities?
if identities
identities.length.positive?
else
false
end
end

private

def requested_attributes
Expand Down
11 changes: 11 additions & 0 deletions app/views/sign_up/completions/_show_identities.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- identities = @view_model.identities
.mt2.mb3.p3.col-12.center.border-box.border.border-teal.rounded-xl
p
- if identities.length > 1
= t('idv.messages.agencies_login')
- else
= t('idv.messages.agency_login_html', sp: identities.first.display_name)
ul.list-reset
- identities.each do |identity|
li
= link_to identity.agency_name, identity.return_to_sp_url
12 changes: 12 additions & 0 deletions app/views/sign_up/completions/_show_sp.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.mt2.p3.col-12.center.border-box.border.border-teal.rounded-xl
p = t('idv.messages.return_to_sp_html', sp: decorated_session.sp_name)
p
= button_to t('forms.buttons.continue'), sign_up_completed_path, \
class: 'btn btn-primary btn-wide'
p.mr5.ml5.mt3.mb3
= t('help_text.requested_attributes.intro_html', app_name: APP_NAME,
sp: content_tag(:strong, decorated_session.sp_agency))

<div class='ml5 mr5' >
= render @view_model.requested_attributes_partial, view_model: @view_model
</div>
13 changes: 1 addition & 12 deletions app/views/sign_up/completions/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@
= image_tag(asset_url(@view_model.image_name), width: 97, alt: '', class: 'mb2')
h1.h3.mb3.my0.regular = @view_model.heading

.mt2.p3.col-12.center.border-box.border.border-teal.rounded-xl
p = t('idv.messages.return_to_sp_html', sp: decorated_session.sp_name)
p
= button_to t('forms.buttons.continue'), sign_up_completed_path, \
class: 'btn btn-primary btn-wide'
p.mr5.ml5.mt3.mb3
= t('help_text.requested_attributes.intro_html', app_name: APP_NAME,
sp: content_tag(:strong, decorated_session.sp_agency))

<div class='ml5 mr5' >
= render @view_model.requested_attributes_partial, view_model: @view_model
</div>
= render @view_model.service_provider_partial

= link_to t('idv.messages.return_to_profile'), profile_path
1 change: 0 additions & 1 deletion app/views/users/verify_account/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

h1.h3.my0 = t('forms.verify_profile.title')
p.mt-tiny.mb0 = t('forms.verify_profile.instructions')

= simple_form_for(@verify_account_form, url: verify_account_path,
html: { autocomplete: 'off', method: :post, role: 'form' }) do |f|
= f.error :base
Expand Down
2 changes: 2 additions & 0 deletions config/locales/idv/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ en:
on file.
resend: Send me another letter.
success: It should arrive in 5 to 10 business days.
agencies_login: You can now continue to and log into these agencies.
agency_login_html: You can now continue to and into <br><strong>%{sp}</strong>.
modal:
attempts:
one: You have <strong>1 attempt remaining.</strong>
Expand Down
2 changes: 2 additions & 0 deletions config/locales/idv/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ es:
verificada en el archivo.
resend: Envíeme otra carta.
success: Debe llegar en 5 a 10 días laborales.
agencies_login: NOT TRANSLATED YET
agency_login_html: NOT TRANSLATED YET
modal:
attempts:
one: Tiene usted <strong> 1 intento restante.</ strong>
Expand Down
2 changes: 2 additions & 0 deletions config/locales/idv/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ fr:
Celle-ci contient un code de confirmation.
resend: Envoyez-moi une autre lettre.
success: Elle devrait arriver dans 5 à 10 jours ouvrables.
agencies_login: NOT TRANSLATED YET
agency_login_html: NOT TRANSLATED YET
modal:
attempts:
one: Il ne vous reste qu' strongune tentative./strong
Expand Down
32 changes: 28 additions & 4 deletions spec/controllers/sign_up/completions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,44 @@
end
end

it 'requires user to be logged in' do
it 'requires user with session to be logged in' do
subject.session[:sp] = { dog: 'max' }
get :show

expect(response).to redirect_to(new_user_session_url)
expect(response).to redirect_to(account_url)
end

it 'requires service provider info in session' do
it 'requires user with no session to be logged in' do
get :show

expect(response).to redirect_to(account_url)
end

it 'requires service provider or identity info in session' do
stub_sign_in
subject.session[:sp] = {}

get :show

expect(response).to redirect_to(new_user_session_url)
expect(response).to redirect_to(account_url)
end

it 'renders show if the user has an sp in the active session' do
stub_sign_in
subject.session[:sp] = { loa3: false }
get :show

expect(response).to render_template(:show)
end

it 'renders show if the user has identities and no active session' do
user = create(:user)
create(:identity, user: user)
stub_sign_in(user)
subject.session[:sp] = {}
get :show

expect(response).to render_template(:show)
end
end

Expand Down
49 changes: 49 additions & 0 deletions spec/models/identity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,53 @@
expect(identity.decorate).to be_a(IdentityDecorator)
end
end

let(:service_provider) do
create(:service_provider)
end

let(:identity_with_sp) do
Identity.create(
user_id: user.id,
service_provider: service_provider.issuer
)
end

describe '#display_name' do
it 'returns service provider friendly name first' do
expect(identity_with_sp.display_name).to eq(service_provider.friendly_name)
end

it 'returns service_provider agency if friendly_name is missing' do
service_provider.friendly_name = nil
service_provider.save
expect(identity_with_sp.display_name).to eq(service_provider.agency)
end

it 'returns service_provider issuer if friendly_name and agency are missing' do
service_provider.friendly_name = nil
service_provider.agency = nil
service_provider.save
expect(identity_with_sp.display_name).to eq(service_provider.issuer)
end
end

describe '#agency_name' do
it 'returns service provider agency first' do
expect(identity_with_sp.agency_name).to eq(service_provider.agency)
end

it 'returns service_provider friendly_name if agency is missing' do
service_provider.agency = nil
service_provider.save
expect(identity_with_sp.agency_name).to eq(service_provider.friendly_name)
end

it 'returns service_provider issuer if friendly_name and agency are missing' do
service_provider.friendly_name = nil
service_provider.agency = nil
service_provider.save
expect(identity_with_sp.agency_name).to eq(service_provider.issuer)
end
end
end
66 changes: 66 additions & 0 deletions spec/view_models/sign_up_completions_show_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
require 'rails_helper'

describe SignUpCompletionsShow do
before do
@user = create(:user)
end

subject do
SignUpCompletionsShow.new(
current_user: @user,
loa3_requested: false,
decorated_session: decorated_session
)
end

context 'with an sp session' do
let(:decorated_session) do
ServiceProviderSessionDecorator.new(
sp: build_stubbed(:service_provider),
view_context: ActionController::Base.new.view_context,
sp_session: {},
service_provider_request: ServiceProviderRequest.new
)
end

describe '#service_provider_partial' do
it 'returns show_sp path' do
expect(subject.service_provider_partial).to eq('sign_up/completions/show_sp')
end
end
end

context 'with no sp session' do
let(:decorated_session) do
SessionDecorator.new
end

let(:create_identity) do
create(:identity, user_id: @user.id)
end

describe '#service_provider_partial' do
it 'returns show_identities path' do
expect(subject.service_provider_partial).to eq('sign_up/completions/show_identities')
end
end

describe '#identities' do
it 'returns a users identities decorated' do
identity = create_identity
expect(subject.identities).to eq([identity.decorate])
end
end

describe '#user_has_identities?' do
it 'returns true if user has identities' do
create_identity
expect(subject.user_has_identities?).to eq(true)
end

it 'returns false if user has no identities' do
expect(subject.user_has_identities?).to eq(false)
end
end
end
end
Loading