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

Move confirmation_for_phone_change into presenter #1334

Merged
merged 1 commit into from
Apr 7, 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
6 changes: 6 additions & 0 deletions app/controllers/concerns/two_factor_authenticatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ def unconfirmed_phone?

def phone_view_data
{
confirmation_for_phone_change: confirmation_for_phone_change?,
phone_number: display_phone_to_deliver_to,
code_value: direct_otp_code,
otp_delivery_preference: two_factor_authentication_method,
Expand All @@ -235,6 +236,7 @@ def phone_view_data

def authenticator_view_data
{
confirmation_for_phone_change: confirmation_for_phone_change?,
two_factor_authentication_method: two_factor_authentication_method,
user_email: current_user.email,
personal_key_unavailable: personal_key_unavailable?,
Expand Down Expand Up @@ -268,6 +270,10 @@ def reenter_phone_number_path
end
end

def confirmation_for_phone_change?
confirmation_context? && current_user.phone.present?
end

def presenter_for_two_factor_authentication_method
type = DELIVERY_METHOD_MAP[two_factor_authentication_method.to_sym]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ class OtpVerificationController < ApplicationController

skip_before_action :handle_two_factor_authentication

helper_method :confirmation_for_phone_change?

def show
analytics.track_event(Analytics::MULTI_FACTOR_AUTH_ENTER_OTP_VISIT, analytics_properties)

Expand Down Expand Up @@ -37,9 +35,5 @@ def analytics_properties
confirmation_for_phone_change: confirmation_for_phone_change?,
}
end

def confirmation_for_phone_change?
confirmation_context? && current_user.phone.present?
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class GenericDeliveryPresenter
include ActionView::Helpers::TranslationHelper
include Rails.application.routes.url_helpers

attr_reader :code_value
attr_reader :code_value, :confirmation_for_phone_change

def initialize(data:, view:)
data.each do |key, value|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ h1.h3.my0 = @presenter.header

= render 'shared/fallback_links', presenter: @presenter

- if confirmation_for_phone_change? || reauthn?
- if @presenter.confirmation_for_phone_change || reauthn?
= render 'shared/cancel', link: profile_path
- else
= render 'shared/cancel', link: destroy_user_session_path
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
context 'user has a phone' do
before do
allow(view).to receive(:reauthn?).and_return(false)
allow(view).to receive(:confirmation_for_phone_change?).and_return(false)
allow(view).to receive(:user_session).and_return({})
allow(view).to receive(:current_user).and_return(User.new)
controller.request.path_parameters[:otp_delivery_preference] =
Expand Down Expand Up @@ -103,14 +102,17 @@
end

context 'user is changing phone number' do
before do
it 'provides a cancel link to return to profile' do
user = build_stubbed(:user, :signed_up, personal_key: '1')
allow(view).to receive(:current_user).and_return(user)
allow(view).to receive(:confirmation_for_phone_change?).and_return(true)
data = presenter_data.merge(confirmation_for_phone_change: true)
@presenter = TwoFactorAuthCode::PhoneDeliveryPresenter.new(
data: data,
view: view
)

render
end

it 'provides a cancel link to return to profile' do
expect(rendered).to have_link(
t('links.cancel'),
href: profile_path
Expand Down