Skip to content
Closed
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
1 change: 1 addition & 0 deletions app/controllers/sign_up/completions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def update
if decider.go_back_to_mobile_app?
sign_user_out_and_instruct_to_go_back_to_mobile_app
else
user_session.delete(:pending_completions_consent)
redirect_to(
sp_session_request_url_with_updated_params || account_url,
allow_other_host: true,
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/users/email_confirmations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ def process_successful_confirmation(email_address)
confirm_and_notify(email_address)
if current_user
flash[:success] = t('devise.confirmations.confirmed')
redirect_to account_url
if user_session[:pending_completions_consent] == true
redirect_to sign_up_select_email_url
else
redirect_to account_url
end
else
flash[:success] = t('devise.confirmations.confirmed_but_sign_in')
redirect_to root_url
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/users/emails_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def add
result = @add_user_email_form.submit(current_user, permitted_params)
analytics.add_email_request(**result.to_h)

if pending_completions_consent?
user_session[:pending_completions_consent] = true
end

Comment on lines +25 to +28
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.

Can you explain what this code is for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It sets a session value that will help determine the redirect in the email confirmations controller

if user_session[:pending_completions_consent] == true
redirect_to sign_up_select_email_url
else
redirect_to account_url
end

it will be deleted in the completions controller when they get redirected finally to the SP

user_session.delete(:pending_completions_consent)

if result.success?
process_successful_creation
else
Expand Down
34 changes: 34 additions & 0 deletions spec/controllers/users/email_confirmations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,39 @@
expect(flash[:error]).to eq t('errors.messages.confirmation_invalid_token')
end
end

describe '#process_successful_confirmation' do
let(:user) { create(:user) }

before do
stub_sign_in(user)
end

it 'adds an email from the service provider consent flow' do
new_email = Faker::Internet.email

controller.user_session[:pending_completions_consent] = true

add_email_form = AddUserEmailForm.new
add_email_form.submit(user, email: new_email)
email_record = add_email_form.email_address_record(new_email)

get :create, params: { confirmation_token: email_record.reload.confirmation_token }

expect(response).to redirect_to(sign_up_select_email_url)
end

it 'adds an email from the account page' do
new_email = Faker::Internet.email

add_email_form = AddUserEmailForm.new
add_email_form.submit(user, email: new_email)
email_record = add_email_form.email_address_record(new_email)

get :create, params: { confirmation_token: email_record.reload.confirmation_token }

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