Skip to content

Commit

Permalink
Merge pull request #25201 from code-dot-org/cancel-signup-link
Browse files Browse the repository at this point in the history
Cancel signup link
  • Loading branch information
Madelyn Kasula committed Oct 4, 2018
2 parents d714e65 + 835c569 commit 84fa147
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 6 deletions.
16 changes: 16 additions & 0 deletions dashboard/app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class RegistrationsController < Devise::RegistrationsController
skip_before_action :verify_authenticity_token, only: [:set_age]
skip_before_action :clear_sign_up_session_vars, only: [:new, :create]

#
# GET /users/sign_up
#
def new
session[:user_return_to] ||= params[:user_return_to]

Expand All @@ -22,6 +25,16 @@ def new
end
end

#
# GET /users/cancel
#
# Cancels the in-progress partial user registration and redirects to sign-up page.
#
def cancel
PartialRegistration.cancel(session)
redirect_to new_user_registration_path
end

#
# PUT /users
#
Expand All @@ -48,6 +61,9 @@ def update
respond_to_account_update(successfully_updated)
end

#
# POST /users
#
def create
Retryable.retryable on: [Mysql2::Error, ActiveRecord::RecordNotUnique], matching: /Duplicate entry/ do
super
Expand Down
7 changes: 7 additions & 0 deletions dashboard/app/models/concerns/partial_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ def self.persist_attributes(session, user)
session[USER_ATTRIBUTES_SESSION_KEY] = user.attributes
end

def self.cancel(session)
SignUpTracking.log_cancel_finish_sign_up(session)
SignUpTracking.end_sign_up_tracking(session)
session.delete(USER_ATTRIBUTES_SESSION_KEY)
session
end

def self.cache_key(param_name, user)
if user.uid.present?
"#{user.provider}-#{user.uid}-#{param_name}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@

= form_for(@user, url: registration_path(@user), html: {class: "finish-signup"}) do |f|
%p
= t('activerecord.attributes.user.finish_sign_up_subheader')
- if @user.provider.present? && @user.email.present?
%span= t('activerecord.attributes.user.finish_sign_up_subheader_provider', provider: t("auth.#{@user.provider}"), email: @user.email).html_safe
- if @user.provider.present?
- provider = t("auth.#{@user.provider}")
= t('activerecord.attributes.user.finish_sign_up_subheader_provider', provider: provider, email: @user.email).html_safe
- else
= t('activerecord.attributes.user.finish_sign_up_subheader', email: @user.email).html_safe
%span= link_to 'Cancel', users_cancel_path

= f.hidden_field :locale, value: locale

Expand Down
4 changes: 2 additions & 2 deletions dashboard/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ en:
gender: 'Gender'
edit_header: 'Edit Account Details'
finish_sign_up_header: 'Finish creating your account'
finish_sign_up_subheader: 'Fill out the following information to finish creating a Code.org account'
finish_sign_up_subheader_provider: 'using your <strong>%{provider}</strong> for <strong>%{email}</strong>'
finish_sign_up_subheader: 'Fill out the following information to finish creating a Code.org account for <strong>%{email}</strong>.'
finish_sign_up_subheader_provider: 'Fill out the following information to finish creating a Code.org account using your <strong>%{provider}</strong> for <strong>%{email}</strong>.'
error:
future: can't be in the future

Expand Down
1 change: 1 addition & 0 deletions dashboard/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
patch '/users/set_age', to: 'registrations#set_age'
patch '/users/email', to: 'registrations#set_email'
patch '/users/user_type', to: 'registrations#set_user_type'
get '/users/cancel', to: 'registrations#cancel'
get '/users/clever_takeover', to: 'sessions#clever_takeover'
get '/users/clever_modal_dismissed', to: 'sessions#clever_modal_dismissed'
get '/users/auth/:provider/connect', to: 'authentication_options#connect'
Expand Down
9 changes: 9 additions & 0 deletions dashboard/lib/sign_up_tracking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ def self.log_load_finish_sign_up(session)
)
end

def self.log_cancel_finish_sign_up(session)
FirehoseClient.instance.put_record(
study: STUDY_NAME,
study_group: study_group(session),
event: 'cancel-finish-sign-up',
data_string: session[:sign_up_uid]
)
end

def self.log_oauth_callback(provider, session)
return unless provider && session
if session[:sign_up_tracking_expiration]&.future?
Expand Down
18 changes: 18 additions & 0 deletions dashboard/test/controllers/registrations_controller/cancel_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'test_helper'

module RegistrationsControllerTests
#
# Tests over GET /users/cancel
#
class CancelTest < ActionDispatch::IntegrationTest
test 'cancels partial registration and redirects to signup' do
PartialRegistration.expects(:cancel)
get '/users/cancel'
assert_redirected_to new_user_registration_path
follow_redirect!
# User should currently see old signup flow if they
# cancel an in-progress registration and want to start over.
assert_template partial: '_sign_up'
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class NewTest < ActionDispatch::IntegrationTest
assert_template partial: '_finish_sign_up'
end

# Note: The analogous for the old signup flow is in registrations_controller_test.rb because
# Note: The analogous test for the old signup flow is in registrations_controller_test.rb because
# it requires access to the session, which ActionDispatch::IntegrationTest does not provide
test "signup does not display errors on pageload in new flow" do
SignUpTracking.expects(:new_sign_up_experience?).returns(true).twice
Expand Down
11 changes: 11 additions & 0 deletions dashboard/test/models/concerns/partial_registration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ class PartialRegistrationTest < ActiveSupport::TestCase
assert_equal user.oauth_refresh_token, result_user.oauth_refresh_token
end

test 'cancel ends signup tracking and deletes user attributes from the session' do
user = build :user, :unmigrated_google_sso
session = fake_session user.attributes

SignUpTracking.expects(:log_cancel_finish_sign_up)
SignUpTracking.expects(:end_sign_up_tracking)
new_session = PartialRegistration.cancel(session)

assert_nil new_session[PartialRegistration::USER_ATTRIBUTES_SESSION_KEY]
end

private

def fake_empty_session
Expand Down

0 comments on commit 84fa147

Please sign in to comment.