Commit de4e9d3f authored by James Lopez's avatar James Lopez

Merge branch 'nicolasdular/introduce-welcome-page' into 'master'

Show welcome page after sign up

See merge request gitlab-org/gitlab!41662
parents 3cae13f0 a165a94f
...@@ -551,13 +551,9 @@ class ApplicationController < ActionController::Base ...@@ -551,13 +551,9 @@ class ApplicationController < ActionController::Base
"#{self.class.name}##{action_name}" "#{self.class.name}##{action_name}"
end end
# A user requires a role and have the setup_for_company attribute set when they are part of the experimental signup
# flow (executed by the Growth team). Users are redirected to the welcome page when their role is required and the
# experiment is enabled for the current user.
def required_signup_info def required_signup_info
return unless current_user return unless current_user
return unless current_user.role_required? return unless current_user.role_required?
return unless experiment_enabled?(:signup_flow)
store_location_for :user, request.fullpath store_location_for :user, request.fullpath
......
...@@ -35,9 +35,9 @@ class RegistrationsController < Devise::RegistrationsController ...@@ -35,9 +35,9 @@ class RegistrationsController < Devise::RegistrationsController
yield new_user if block_given? yield new_user if block_given?
end end
# Do not show the signed_up notice message when the signup_flow experiment is enabled. # Devise sets a flash message on `create` for a successful signup,
# Instead, show it after successfully updating the role. # we want to show this message after the welcome page.
flash[:notice] = nil if experiment_enabled?(:signup_flow) flash[:notice] = nil
rescue Gitlab::Access::AccessDeniedError rescue Gitlab::Access::AccessDeniedError
redirect_to(new_user_session_path) redirect_to(new_user_session_path)
end end
...@@ -89,7 +89,7 @@ class RegistrationsController < Devise::RegistrationsController ...@@ -89,7 +89,7 @@ class RegistrationsController < Devise::RegistrationsController
end end
def set_role_required(new_user) def set_role_required(new_user)
new_user.set_role_required! if new_user.persisted? && experiment_enabled?(:signup_flow) new_user.set_role_required! if new_user.persisted?
end end
def destroy_confirmation_valid? def destroy_confirmation_valid?
...@@ -115,9 +115,7 @@ class RegistrationsController < Devise::RegistrationsController ...@@ -115,9 +115,7 @@ class RegistrationsController < Devise::RegistrationsController
def after_sign_up_path_for(user) def after_sign_up_path_for(user)
Gitlab::AppLogger.info(user_created_message(confirmed: user.confirmed?)) Gitlab::AppLogger.info(user_created_message(confirmed: user.confirmed?))
return users_sign_up_welcome_path if experiment_enabled?(:signup_flow) users_sign_up_welcome_path
path_for_signed_in_user(user)
end end
def after_inactive_sign_up_path_for(resource) def after_inactive_sign_up_path_for(resource)
...@@ -215,7 +213,7 @@ class RegistrationsController < Devise::RegistrationsController ...@@ -215,7 +213,7 @@ class RegistrationsController < Devise::RegistrationsController
# Part of an experiment to build a new sign up flow. Will be resolved # Part of an experiment to build a new sign up flow. Will be resolved
# with https://gitlab.com/gitlab-org/growth/engineering/issues/64 # with https://gitlab.com/gitlab-org/growth/engineering/issues/64
def choose_layout def choose_layout
if experiment_enabled?(:signup_flow) if %w(welcome update_registration).include?(action_name) || experiment_enabled?(:signup_flow)
'devise_experimental_separate_sign_up_flow' 'devise_experimental_separate_sign_up_flow'
else else
'devise' 'devise'
......
...@@ -1715,9 +1715,6 @@ class User < ApplicationRecord ...@@ -1715,9 +1715,6 @@ class User < ApplicationRecord
[last_activity, last_sign_in].compact.max [last_activity, last_sign_in].compact.max
end end
# Below is used for the signup_flow experiment. Should be removed
# when experiment finishes.
# See https://gitlab.com/gitlab-org/growth/engineering/issues/64
REQUIRES_ROLE_VALUE = 99 REQUIRES_ROLE_VALUE = 99
def role_required? def role_required?
...@@ -1727,7 +1724,6 @@ class User < ApplicationRecord ...@@ -1727,7 +1724,6 @@ class User < ApplicationRecord
def set_role_required! def set_role_required!
update_column(:role, REQUIRES_ROLE_VALUE) update_column(:role, REQUIRES_ROLE_VALUE)
end end
# End of signup_flow experiment methods
def dismissed_callout?(feature_name:, ignore_dismissal_earlier_than: nil) def dismissed_callout?(feature_name:, ignore_dismissal_earlier_than: nil)
callouts = self.callouts.with_feature_name(feature_name) callouts = self.callouts.with_feature_name(feature_name)
......
---
title: Show welcome page after sign up
merge_request: 41662
author:
type: added
...@@ -49,34 +49,27 @@ RSpec.describe 'Signup on EE' do ...@@ -49,34 +49,27 @@ RSpec.describe 'Signup on EE' do
end end
end end
context 'when role is required' do it 'redirects to step 2 of the signup process, sets the role and setup for company and redirects back' do
before do visit new_user_registration_path
stub_experiment(signup_flow: true)
stub_experiment_for_user(signup_flow: true) fill_in 'new_user_name', with: user_attrs[:name].split(' ').first
end fill_in 'new_user_username', with: user_attrs[:username]
fill_in 'new_user_email', with: user_attrs[:email]
it 'redirects to step 2 of the signup process, sets the role and setup for company and redirects back' do fill_in 'new_user_email_confirmation', with: user_attrs[:email]
visit new_user_registration_path fill_in 'new_user_password', with: user_attrs[:password]
click_button 'Register'
fill_in 'new_user_first_name', with: user_attrs[:name].split(' ').first visit new_project_path
fill_in 'new_user_last_name', with: user_attrs[:name].split(' ').last
fill_in 'new_user_username', with: user_attrs[:username] expect(page).to have_current_path(users_sign_up_welcome_path)
fill_in 'new_user_email', with: user_attrs[:email]
fill_in 'new_user_password', with: user_attrs[:password] select 'Software Developer', from: 'user_role'
click_button 'Register' choose 'user_setup_for_company_true'
visit new_project_path click_button 'Get started!'
user = User.find_by_username(user_attrs[:username])
expect(page).to have_current_path(users_sign_up_welcome_path)
expect(user.software_developer_role?).to be_truthy
select 'Software Developer', from: 'user_role' expect(user.setup_for_company).to be_truthy
choose 'user_setup_for_company_true' expect(page).to have_current_path(new_project_path)
click_button 'Get started!'
user = User.find_by_username(user_attrs[:username])
expect(user.software_developer_role?).to be_truthy
expect(user.setup_for_company).to be_truthy
expect(page).to have_current_path(new_project_path)
end
end end
end end
......
...@@ -44,6 +44,10 @@ RSpec.describe 'Trial Sign Up', :js do ...@@ -44,6 +44,10 @@ RSpec.describe 'Trial Sign Up', :js do
wait_for_requests wait_for_requests
select 'Software Developer', from: 'user_role'
choose 'user_setup_for_company_true'
click_button 'Continue'
expect(current_path).to eq(new_trial_path) expect(current_path).to eq(new_trial_path)
expect(page).to have_content('Start your Free Gold Trial') expect(page).to have_content('Start your Free Gold Trial')
end end
......
...@@ -795,13 +795,8 @@ RSpec.describe ApplicationController do ...@@ -795,13 +795,8 @@ RSpec.describe ApplicationController do
end end
let(:user) { create(:user) } let(:user) { create(:user) }
let(:experiment_enabled) { true }
before do context 'user with required role' do
stub_experiment_for_user(signup_flow: experiment_enabled)
end
context 'experiment enabled and user with required role' do
before do before do
user.set_role_required! user.set_role_required!
sign_in(user) sign_in(user)
...@@ -811,7 +806,7 @@ RSpec.describe ApplicationController do ...@@ -811,7 +806,7 @@ RSpec.describe ApplicationController do
it { is_expected.to redirect_to users_sign_up_welcome_path } it { is_expected.to redirect_to users_sign_up_welcome_path }
end end
context 'experiment enabled and user without a required role' do context 'user without a required role' do
before do before do
sign_in(user) sign_in(user)
get :index get :index
...@@ -819,43 +814,31 @@ RSpec.describe ApplicationController do ...@@ -819,43 +814,31 @@ RSpec.describe ApplicationController do
it { is_expected.not_to redirect_to users_sign_up_welcome_path } it { is_expected.not_to redirect_to users_sign_up_welcome_path }
end end
end
context 'experiment disabled' do describe 'rescue_from Gitlab::Auth::IpBlacklisted' do
let(:experiment_enabled) { false } controller(described_class) do
skip_before_action :authenticate_user!
before do def index
user.set_role_required! raise Gitlab::Auth::IpBlacklisted
sign_in(user)
get :index
end end
it { is_expected.not_to redirect_to users_sign_up_welcome_path }
end end
describe 'rescue_from Gitlab::Auth::IpBlacklisted' do it 'returns a 403 and logs the request' do
controller(described_class) do expect(Gitlab::AuthLogger).to receive(:error).with({
skip_before_action :authenticate_user! message: 'Rack_Attack',
env: :blocklist,
def index remote_ip: '1.2.3.4',
raise Gitlab::Auth::IpBlacklisted request_method: 'GET',
end path: '/anonymous'
end })
it 'returns a 403 and logs the request' do
expect(Gitlab::AuthLogger).to receive(:error).with({
message: 'Rack_Attack',
env: :blocklist,
remote_ip: '1.2.3.4',
request_method: 'GET',
path: '/anonymous'
})
request.remote_addr = '1.2.3.4' request.remote_addr = '1.2.3.4'
get :index get :index
expect(response).to have_gitlab_http_status(:forbidden) expect(response).to have_gitlab_http_status(:forbidden)
end
end end
end end
......
...@@ -128,7 +128,7 @@ RSpec.describe RegistrationsController do ...@@ -128,7 +128,7 @@ RSpec.describe RegistrationsController do
post(:create, params: user_params) post(:create, params: user_params)
expect(ActionMailer::Base.deliveries.last.to.first).to eq(user_params[:user][:email]) expect(ActionMailer::Base.deliveries.last.to.first).to eq(user_params[:user][:email])
expect(response).to redirect_to(dashboard_projects_path) expect(response).to redirect_to(users_sign_up_welcome_path)
end end
end end
end end
...@@ -164,10 +164,10 @@ RSpec.describe RegistrationsController do ...@@ -164,10 +164,10 @@ RSpec.describe RegistrationsController do
expect(flash[:alert]).to eq(_('There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.')) expect(flash[:alert]).to eq(_('There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.'))
end end
it 'redirects to the dashboard when the reCAPTCHA is solved' do it 'redirects to the welcome page when the reCAPTCHA is solved' do
post(:create, params: user_params) post(:create, params: user_params)
expect(flash[:notice]).to eq(I18n.t('devise.registrations.signed_up')) expect(response).to redirect_to(users_sign_up_welcome_path)
end end
end end
...@@ -464,42 +464,39 @@ RSpec.describe RegistrationsController do ...@@ -464,42 +464,39 @@ RSpec.describe RegistrationsController do
describe '#welcome' do describe '#welcome' do
subject { get :welcome } subject { get :welcome }
context 'signup_flow experiment enabled' do it 'renders the devise_experimental_separate_sign_up_flow layout' do
before do sign_in(create(:user))
stub_experiment_for_user(signup_flow: true)
end
it 'renders the devise_experimental_separate_sign_up_flow layout' do expected_layout = Gitlab.ee? ? :checkout : :devise_experimental_separate_sign_up_flow
sign_in(create(:user))
expected_layout = Gitlab.ee? ? :checkout : :devise_experimental_separate_sign_up_flow expect(subject).to render_template(expected_layout)
end
expect(subject).to render_template(expected_layout) context '2FA is required from group' do
before do
user = create(:user, require_two_factor_authentication_from_group: true)
sign_in(user)
end end
context '2FA is required from group' do it 'does not perform a redirect' do
before do expect(subject).not_to redirect_to(profile_two_factor_auth_path)
user = create(:user, require_two_factor_authentication_from_group: true)
sign_in(user)
end
it 'does not perform a redirect' do
expect(subject).not_to redirect_to(profile_two_factor_auth_path)
end
end end
end end
end
context 'signup_flow experiment disabled' do describe '#update_registration' do
before do subject(:update_registration) do
sign_in(create(:user)) patch :update_registration, params: { user: { role: 'software_developer', setup_for_company: 'false' } }
stub_experiment_for_user(signup_flow: false) end
end
it 'renders the devise layout' do before do
expected_layout = Gitlab.ee? ? :checkout : :devise sign_in(create(:user))
end
expect(subject).to render_template(expected_layout) it 'sets flash message' do
end subject
expect(flash[:notice]).to eq(I18n.t('devise.registrations.signed_up'))
end end
end end
end end
...@@ -38,6 +38,11 @@ RSpec.describe 'Invites', :aggregate_failures do ...@@ -38,6 +38,11 @@ RSpec.describe 'Invites', :aggregate_failures do
click_button 'Sign in' click_button 'Sign in'
end end
def fill_in_welcome_form
select 'Software Developer', from: 'user_role'
click_button 'Get started!'
end
context 'when signed out' do context 'when signed out' do
before do before do
visit invite_path(group_invite.raw_invite_token) visit invite_path(group_invite.raw_invite_token)
...@@ -94,6 +99,7 @@ RSpec.describe 'Invites', :aggregate_failures do ...@@ -94,6 +99,7 @@ RSpec.describe 'Invites', :aggregate_failures do
it 'signs up and redirects to the dashboard page with all the projects/groups invitations automatically accepted' do it 'signs up and redirects to the dashboard page with all the projects/groups invitations automatically accepted' do
fill_in_sign_up_form(new_user) fill_in_sign_up_form(new_user)
fill_in_welcome_form
expect(current_path).to eq(dashboard_projects_path) expect(current_path).to eq(dashboard_projects_path)
expect(page).to have_content(project.full_name) expect(page).to have_content(project.full_name)
...@@ -108,6 +114,7 @@ RSpec.describe 'Invites', :aggregate_failures do ...@@ -108,6 +114,7 @@ RSpec.describe 'Invites', :aggregate_failures do
it 'signs up and redirects to the invitation page' do it 'signs up and redirects to the invitation page' do
fill_in_sign_up_form(new_user) fill_in_sign_up_form(new_user)
fill_in_welcome_form
expect(current_path).to eq(invite_path(group_invite.raw_invite_token)) expect(current_path).to eq(invite_path(group_invite.raw_invite_token))
end end
...@@ -126,6 +133,7 @@ RSpec.describe 'Invites', :aggregate_failures do ...@@ -126,6 +133,7 @@ RSpec.describe 'Invites', :aggregate_failures do
fill_in_sign_up_form(new_user) fill_in_sign_up_form(new_user)
confirm_email(new_user) confirm_email(new_user)
fill_in_sign_in_form(new_user) fill_in_sign_in_form(new_user)
fill_in_welcome_form
expect(current_path).to eq(root_path) expect(current_path).to eq(root_path)
expect(page).to have_content(project.full_name) expect(page).to have_content(project.full_name)
...@@ -143,6 +151,7 @@ RSpec.describe 'Invites', :aggregate_failures do ...@@ -143,6 +151,7 @@ RSpec.describe 'Invites', :aggregate_failures do
it 'signs up and redirects to root page with all the project/groups invitation automatically accepted' do it 'signs up and redirects to root page with all the project/groups invitation automatically accepted' do
fill_in_sign_up_form(new_user) fill_in_sign_up_form(new_user)
fill_in_welcome_form
confirm_email(new_user) confirm_email(new_user)
expect(current_path).to eq(root_path) expect(current_path).to eq(root_path)
...@@ -156,6 +165,7 @@ RSpec.describe 'Invites', :aggregate_failures do ...@@ -156,6 +165,7 @@ RSpec.describe 'Invites', :aggregate_failures do
it "doesn't accept invitations until the user confirms their email" do it "doesn't accept invitations until the user confirms their email" do
fill_in_sign_up_form(new_user) fill_in_sign_up_form(new_user)
fill_in_welcome_form
sign_in(owner) sign_in(owner)
visit project_project_members_path(project) visit project_project_members_path(project)
...@@ -175,6 +185,7 @@ RSpec.describe 'Invites', :aggregate_failures do ...@@ -175,6 +185,7 @@ RSpec.describe 'Invites', :aggregate_failures do
fill_in_sign_up_form(new_user) fill_in_sign_up_form(new_user)
confirm_email(new_user) confirm_email(new_user)
fill_in_sign_in_form(new_user) fill_in_sign_in_form(new_user)
fill_in_welcome_form
expect(current_path).to eq(invite_path(group_invite.raw_invite_token)) expect(current_path).to eq(invite_path(group_invite.raw_invite_token))
end end
...@@ -188,6 +199,7 @@ RSpec.describe 'Invites', :aggregate_failures do ...@@ -188,6 +199,7 @@ RSpec.describe 'Invites', :aggregate_failures do
it 'signs up and redirects to the invitation page' do it 'signs up and redirects to the invitation page' do
fill_in_sign_up_form(new_user) fill_in_sign_up_form(new_user)
fill_in_welcome_form
expect(current_path).to eq(invite_path(group_invite.raw_invite_token)) expect(current_path).to eq(invite_path(group_invite.raw_invite_token))
end end
......
...@@ -187,12 +187,7 @@ RSpec.shared_examples 'Signup' do ...@@ -187,12 +187,7 @@ RSpec.shared_examples 'Signup' do
expect { click_button 'Register' }.to change { User.count }.by(1) expect { click_button 'Register' }.to change { User.count }.by(1)
if Gitlab::Experimentation.enabled?(:signup_flow) expect(current_path).to eq users_sign_up_welcome_path
expect(current_path).to eq users_sign_up_welcome_path
else
expect(current_path).to eq dashboard_projects_path
expect(page).to have_content("Please check your email (#{new_user.email}) to verify that you own this address and unlock the power of CI/CD.")
end
end end
end end
end end
...@@ -215,12 +210,7 @@ RSpec.shared_examples 'Signup' do ...@@ -215,12 +210,7 @@ RSpec.shared_examples 'Signup' do
fill_in 'new_user_password', with: new_user.password fill_in 'new_user_password', with: new_user.password
click_button "Register" click_button "Register"
if Gitlab::Experimentation.enabled?(:signup_flow) expect(current_path).to eq users_sign_up_welcome_path
expect(current_path).to eq users_sign_up_welcome_path
else
expect(current_path).to eq dashboard_projects_path
expect(page).to have_content("Welcome! You have signed up successfully.")
end
end end
end end
...@@ -246,12 +236,7 @@ RSpec.shared_examples 'Signup' do ...@@ -246,12 +236,7 @@ RSpec.shared_examples 'Signup' do
fill_in 'new_user_password', with: new_user.password fill_in 'new_user_password', with: new_user.password
click_button "Register" click_button "Register"
if Gitlab::Experimentation.enabled?(:signup_flow) expect(current_path).to eq users_sign_up_welcome_path
expect(current_path).to eq users_sign_up_welcome_path
else
expect(current_path).to eq dashboard_projects_path
expect(page).to have_content("Welcome! You have signed up successfully.")
end
end end
end end
end end
...@@ -354,11 +339,7 @@ RSpec.shared_examples 'Signup' do ...@@ -354,11 +339,7 @@ RSpec.shared_examples 'Signup' do
click_button "Register" click_button "Register"
if Gitlab::Experimentation.enabled?(:signup_flow) expect(current_path).to eq users_sign_up_welcome_path
expect(current_path).to eq users_sign_up_welcome_path
else
expect(current_path).to eq dashboard_projects_path
end
end end
end end
...@@ -425,6 +406,37 @@ RSpec.shared_examples 'Signup' do ...@@ -425,6 +406,37 @@ RSpec.shared_examples 'Signup' do
end end
end end
end end
it 'redirects to step 2 of the signup process, sets the role and redirects back' do
new_user = build_stubbed(:user)
visit new_user_registration_path
fill_in 'new_user_username', with: new_user.username
fill_in 'new_user_email', with: new_user.email
if Gitlab::Experimentation.enabled?(:signup_flow)
fill_in 'new_user_first_name', with: new_user.first_name
fill_in 'new_user_last_name', with: new_user.last_name
else
fill_in 'new_user_name', with: new_user.name
fill_in 'new_user_email_confirmation', with: new_user.email
end
fill_in 'new_user_password', with: new_user.password
click_button 'Register'
visit new_project_path
expect(page).to have_current_path(users_sign_up_welcome_path)
select 'Software Developer', from: 'user_role'
click_button 'Get started!'
new_user = User.find_by_username(new_user.username)
expect(new_user.software_developer_role?).to be_truthy
expect(new_user.setup_for_company).to be_nil
expect(page).to have_current_path(new_project_path)
expect(page).to have_content("Welcome! You have signed up successfully.")
end
end end
RSpec.shared_examples 'Signup name validation' do |field, max_length| RSpec.shared_examples 'Signup name validation' do |field, max_length|
...@@ -485,30 +497,6 @@ RSpec.describe 'With experimental flow' do ...@@ -485,30 +497,6 @@ RSpec.describe 'With experimental flow' do
it_behaves_like 'Signup name validation', 'new_user_first_name', 127 it_behaves_like 'Signup name validation', 'new_user_first_name', 127
it_behaves_like 'Signup name validation', 'new_user_last_name', 127 it_behaves_like 'Signup name validation', 'new_user_last_name', 127
context 'when role is required' do
it 'redirects to step 2 of the signup process, sets the role and redirects back' do
new_user = build_stubbed(:user)
visit new_user_registration_path
fill_in 'new_user_first_name', with: new_user.first_name
fill_in 'new_user_last_name', with: new_user.last_name
fill_in 'new_user_username', with: new_user.username
fill_in 'new_user_email', with: new_user.email
fill_in 'new_user_password', with: new_user.password
click_button 'Register'
visit new_project_path
expect(page).to have_current_path(users_sign_up_welcome_path)
select 'Software Developer', from: 'user_role'
click_button 'Get started!'
new_user = User.find_by_username(new_user.username)
expect(new_user.software_developer_role?).to be_truthy
expect(new_user.setup_for_company).to be_nil
expect(page).to have_current_path(new_project_path)
end
end
context 'when terms_opt_in experimental is enabled' do context 'when terms_opt_in experimental is enabled' do
include TermsHelper include TermsHelper
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment