Commit d982a572 authored by Alex Buijs's avatar Alex Buijs

Add company question to profile information

Ask if a user is setting up GitLab for a company
or not during the signup process. This info is
stored in the users table and later used for
experiments by the growth team.
parent 2fad0cea
......@@ -30,7 +30,7 @@ class ApplicationController < ActionController::Base
before_action :active_user_check, unless: :devise_controller?
before_action :set_usage_stats_consent_flag
before_action :check_impersonation_availability
before_action :require_role
before_action :required_signup_info
around_action :set_locale
around_action :set_session_storage
......@@ -536,10 +536,13 @@ class ApplicationController < ActionController::Base
@current_user_mode ||= Gitlab::Auth::CurrentUserMode.new(current_user)
end
# A user requires a role 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 require_role
return unless current_user && current_user.role_required? && experiment_enabled?(:signup_flow)
# 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
return unless current_user
return unless current_user.role_required? || current_user.setup_for_company.nil?
return unless experiment_enabled?(:signup_flow)
store_location_for :user, request.fullpath
......
......@@ -8,7 +8,7 @@ class RegistrationsController < Devise::RegistrationsController
layout :choose_layout
skip_before_action :require_role, only: [:welcome, :update_role]
skip_before_action :required_signup_info, only: [:welcome, :update_registration]
prepend_before_action :check_captcha, only: :create
before_action :whitelist_query_limiting, only: [:destroy]
before_action :ensure_terms_accepted,
......@@ -53,15 +53,15 @@ class RegistrationsController < Devise::RegistrationsController
def welcome
return redirect_to new_user_registration_path unless current_user
return redirect_to stored_location_or_dashboard_or_almost_there_path(current_user) if current_user.role.present?
return redirect_to stored_location_or_dashboard_or_almost_there_path(current_user) if current_user.role.present? && current_user.setup_for_company.present?
current_user.name = nil
render layout: 'devise_experimental_separate_sign_up_flow'
end
def update_role
user_params = params.require(:user).permit(:name, :role)
result = ::Users::UpdateService.new(current_user, user_params.merge(user: current_user)).execute
def update_registration
user_params = params.require(:user).permit(:name, :role, :setup_for_company)
result = ::Users::SignupService.new(current_user, user_params.merge(user: current_user)).execute
if result[:status] == :success
track_experiment_event(:signup_flow, 'end') # We want this event to be tracked when the user is _in_ the experimental group
......
# frozen_string_literal: true
module Users
class SignupService < BaseService
attr_reader :user
def initialize(current_user, params = {})
@current_user = current_user
@user = params.delete(:user)
@params = params.dup
end
def execute(validate: true, &block)
yield(@user) if block_given?
assign_attributes
custom_validations
if @user.errors.empty? && @user.save(validate: validate)
success
else
messages = @user.errors.full_messages + Array(@user.status&.errors&.full_messages)
error(messages.uniq.join('. '))
end
end
private
def assign_attributes
@user.assign_attributes(params) unless params.empty?
end
def custom_validations
@user.errors.add(:base, 'Please fill in your full name') if @user.name.blank?
@user.errors.add(:base, 'Please select your role') if @user.role.blank?
@user.errors.add(:base, 'Please answer "Are you setting up GitLab for a company?"') if @user.setup_for_company.nil?
end
end
end
......@@ -4,7 +4,7 @@
= _('In order to tailor your experience with GitLab<br>we would like to know a bit more about you.').html_safe
.signup-box.p-3.mb-2
.signup-body
= form_for(current_user, url: users_sign_up_update_role_path, html: { class: 'new_new_user gl-show-field-errors', 'aria-live' => 'assertive' }) do |f|
= form_for(current_user, url: users_sign_up_update_registration_path, html: { class: 'new_new_user gl-show-field-errors', 'aria-live' => 'assertive' }) do |f|
.devise-errors.mt-0
= render 'devise/shared/error_messages', resource: current_user
.name.form-group
......@@ -13,5 +13,14 @@
.form-group
= f.label :role, _('Role'), class: 'label-bold'
= f.select :role, ::User.roles.keys.map { |role| [role.titleize, role] }, {}, class: 'form-control'
.form-group
= f.label :setup_for_company, _('Are you setting up GitLab for a company?'), class: 'label-bold'
.d-flex.justify-content-center
.w-25
= f.radio_button :setup_for_company, true
= f.label :setup_for_company, _('Yes'), value: 'true'
.w-25
= f.radio_button :setup_for_company, false
= f.label :setup_for_company, _('No'), value: 'false'
.submit-container.mt-3
= f.submit _('Get started!'), class: 'btn-register btn btn-block mb-0 p-2'
---
title: Ask if the user is setting up GitLab for a company during signup
merge_request: 17999
author:
type: changed
......@@ -57,7 +57,7 @@ Rails.application.routes.draw do
# Sign up
get 'users/sign_up/welcome' => 'registrations#welcome'
patch 'users/sign_up/update_role' => 'registrations#update_role'
patch 'users/sign_up/update_registration' => 'registrations#update_registration'
# Search
get 'search' => 'search#show'
......
# frozen_string_literal: true
class AddSetupForCompanyToUsers < ActiveRecord::Migration[5.2]
DOWNTIME = false
def change
add_column :users, :setup_for_company, :boolean
end
end
......@@ -3858,6 +3858,7 @@ ActiveRecord::Schema.define(version: 2019_11_05_094625) do
t.string "last_name", limit: 255
t.string "static_object_token", limit: 255
t.integer "role", limit: 2
t.boolean "setup_for_company"
t.index "lower((name)::text)", name: "index_on_users_name_lower"
t.index ["accepted_term_id"], name: "index_users_on_accepted_term_id"
t.index ["admin"], name: "index_users_on_admin"
......
......@@ -1947,6 +1947,9 @@ msgstr ""
msgid "Archiving the project will make it entirely read-only. It is hidden from the dashboard and doesn't show up in searches. <strong>The repository cannot be committed to, and no issues, comments or other entities can be created.</strong>"
msgstr ""
msgid "Are you setting up GitLab for a company?"
msgstr ""
msgid "Are you sure that you want to archive this project?"
msgstr ""
......
......@@ -827,13 +827,14 @@ describe ApplicationController do
end
end
describe '#require_role' do
describe '#required_signup_info' do
controller(described_class) do
def index; end
end
let(:user) { create(:user) }
let(:user) { create(:user, setup_for_company: setup_for_company) }
let(:experiment_enabled) { true }
let(:setup_for_company) { true }
before do
stub_experiment_for_user(signup_flow: experiment_enabled)
......@@ -849,7 +850,18 @@ describe ApplicationController do
it { is_expected.to redirect_to users_sign_up_welcome_path }
end
context 'experiment enabled and user without a role' do
context 'experiment enabled and user without the setup_for_company attribute set' do
let(:setup_for_company) { nil }
before do
sign_in(user)
get :index
end
it { is_expected.to redirect_to users_sign_up_welcome_path }
end
context 'experiment enabled and user without a required role and with the setup_for_company attribute set' do
before do
sign_in(user)
get :index
......@@ -858,8 +870,9 @@ describe ApplicationController do
it { is_expected.not_to redirect_to users_sign_up_welcome_path }
end
context 'experiment disabled and user with required role' do
context 'experiment disabled' do
let(:experiment_enabled) { false }
let(:setup_for_company) { nil }
before do
user.set_role_required!
......
......@@ -381,7 +381,7 @@ describe RegistrationsController do
end
end
describe '#update_role' do
describe '#update_registration' do
before do
stub_experiment(signup_flow: true)
stub_experiment_for_user(signup_flow: true)
......@@ -395,7 +395,7 @@ describe RegistrationsController do
label: anything,
property: 'experimental_group'
)
patch :update_role, params: { user: { name: 'New name', role: 'software_developer' } }
patch :update_registration, params: { user: { name: 'New name', role: 'software_developer', setup_for_company: 'false' } }
end
end
end
......@@ -441,6 +441,7 @@ describe 'With experimental flow' do
fill_in 'user_name', with: 'New name'
select 'Software Developer', from: 'user_role'
choose 'user_setup_for_company_false'
click_button 'Get started!'
new_user = User.find_by_username(new_user.username)
......
# frozen_string_literal: true
require 'spec_helper'
describe Users::SignupService do
let(:user) { create(:user, setup_for_company: true) }
describe '#execute' do
it 'updates the name attribute' do
result = update_user(user, name: 'New Name')
expect(result).to eq(status: :success)
expect(user.reload.name).to eq('New Name')
end
it 'updates the role attribute' do
result = update_user(user, role: 'development_team_lead')
expect(result).to eq(status: :success)
expect(user.reload.role).to eq('development_team_lead')
end
it 'updates the setup_for_company attribute' do
result = update_user(user, setup_for_company: 'false')
expect(result).to eq(status: :success)
expect(user.reload.setup_for_company).to be_falsey
end
it 'returns an error result when name is missing' do
result = {}
expect do
result = update_user(user, { name: '' })
end.not_to change { user.reload.name }
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq('Please fill in your full name')
end
it 'returns an error result when role is missing' do
result = {}
expect do
result = update_user(user, { role: '' })
end.not_to change { user.reload.role }
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq('Please select your role')
end
it 'returns an error result when setup_for_company is missing' do
result = {}
expect do
result = update_user(user, { setup_for_company: '' })
end.not_to change { user.reload.setup_for_company }
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq('Please answer "Are you setting up GitLab for a company?"')
end
def update_user(user, opts)
described_class.new(user, opts.merge(user: user)).execute
end
end
end
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