Commit 346e2698 authored by Igor Drozdov's avatar Igor Drozdov

Merge branch 'nicolasdular/split-first-last-name' into 'master'

Split full name to first and last name for signup

See merge request gitlab-org/gitlab!42346
parents 7d7b7877 9d81df1d
...@@ -11,10 +11,10 @@ ...@@ -11,10 +11,10 @@
.name.form-row .name.form-row
.col.form-group .col.form-group
= f.label :first_name, _('First name'), for: 'new_user_first_name', class: 'label-bold' = f.label :first_name, _('First name'), for: 'new_user_first_name', class: 'label-bold'
= f.text_field :first_name, class: 'form-control top js-block-emoji js-validate-length', :data => { :max_length => max_first_name_length, :max_length_message => _("First Name is too long (maximum is %{max_length} characters).") % { max_length: max_first_name_length }, :qa_selector => 'new_user_firstname_field' }, required: true, title: _("This field is required.") = f.text_field :first_name, class: 'form-control top js-block-emoji js-validate-length', :data => { :max_length => max_first_name_length, :max_length_message => _("First name is too long (maximum is %{max_length} characters).") % { max_length: max_first_name_length }, :qa_selector => 'new_user_firstname_field' }, required: true, title: _("This field is required.")
.col.form-group .col.form-group
= f.label :last_name, _('Last name'), for: 'new_user_last_name', class: 'label-bold' = f.label :last_name, _('Last name'), for: 'new_user_last_name', class: 'label-bold'
= f.text_field :last_name, class: "form-control top js-block-emoji js-validate-length", :data => { :max_length => max_last_name_length, :max_length_message => _("Last Name is too long (maximum is %{max_length} characters).") % { max_length: max_last_name_length }, :qa_selector => 'new_user_lastname_field' }, required: true, title: _("This field is required.") = f.text_field :last_name, class: "form-control top js-block-emoji js-validate-length", :data => { :max_length => max_last_name_length, :max_length_message => _("Last name is too long (maximum is %{max_length} characters).") % { max_length: max_last_name_length }, :qa_selector => 'new_user_lastname_field' }, required: true, title: _("This field is required.")
.username.form-group .username.form-group
= f.label :username, class: 'label-bold' = f.label :username, class: 'label-bold'
= f.text_field :username, class: "form-control middle js-block-emoji js-validate-length js-validate-username", :data => { :min_length => min_username_length, :min_length_message => s_("SignUp|Username is too short (minimum is %{min_length} characters).") % { min_length: min_username_length }, :max_length => max_username_length, :max_length_message => _("Username is too long (maximum is %{max_length} characters).") % { max_length: max_username_length }, :qa_selector => 'new_user_username_field' }, pattern: Gitlab::PathRegex::NAMESPACE_FORMAT_REGEX_JS, required: true, title: _("Please create a username with only alphanumeric characters.") = f.text_field :username, class: "form-control middle js-block-emoji js-validate-length js-validate-username", :data => { :min_length => min_username_length, :min_length_message => s_("SignUp|Username is too short (minimum is %{min_length} characters).") % { min_length: min_username_length }, :max_length => max_username_length, :max_length_message => _("Username is too long (maximum is %{max_length} characters).") % { max_length: max_username_length }, :qa_selector => 'new_user_username_field' }, pattern: Gitlab::PathRegex::NAMESPACE_FORMAT_REGEX_JS, required: true, title: _("Please create a username with only alphanumeric characters.")
......
- max_name_length = 255 - max_first_name_length = max_last_name_length = 127
- max_username_length = 255 - max_username_length = 255
- min_username_length = 2 - min_username_length = 2
#register-pane.tab-pane.login-box{ role: 'tabpanel' } #register-pane.tab-pane.login-box{ role: 'tabpanel' }
...@@ -8,9 +8,13 @@ ...@@ -8,9 +8,13 @@
= render "devise/shared/error_messages", resource: resource = render "devise/shared/error_messages", resource: resource
- if Feature.enabled?(:invisible_captcha) - if Feature.enabled?(:invisible_captcha)
= invisible_captcha = invisible_captcha
.name.form-group .name.form-row
= f.label :name, _('Full name'), class: 'label-bold' .col.form-group
= f.text_field :name, class: "form-control top js-block-emoji js-validate-length", :data => { :max_length => max_name_length, :max_length_message => s_("SignUp|Name is too long (maximum is %{max_length} characters).") % { max_length: max_name_length }, :qa_selector => 'new_user_name_field' }, required: true, title: _("This field is required.") = f.label :first_name, _('First name'), for: 'new_user_first_name', class: 'label-bold'
= f.text_field :first_name, class: 'form-control top js-block-emoji js-validate-length', :data => { :max_length => max_first_name_length, :max_length_message => _("First name is too long (maximum is %{max_length} characters).") % { max_length: max_first_name_length }, :qa_selector => 'new_user_first_name_field' }, required: true, title: _("This field is required.")
.col.form-group
= f.label :last_name, _('Last name'), for: 'new_user_last_name', class: 'label-bold'
= f.text_field :last_name, class: "form-control top js-block-emoji js-validate-length", :data => { :max_length => max_last_name_length, :max_length_message => _("Last name is too long (maximum is %{max_length} characters).") % { max_length: max_last_name_length }, :qa_selector => 'new_user_last_name_field' }, required: true, title: _("This field is required.")
.username.form-group .username.form-group
= f.label :username, class: 'label-bold' = f.label :username, class: 'label-bold'
= f.text_field :username, class: "form-control middle js-block-emoji js-validate-length js-validate-username", :data => { :min_length => min_username_length, :min_length_message => s_("SignUp|Username is too short (minimum is %{min_length} characters).") % { min_length: min_username_length }, :max_length => max_username_length, :max_length_message => s_("SignUp|Username is too long (maximum is %{max_length} characters).") % { max_length: max_username_length }, :qa_selector => 'new_user_username_field' }, pattern: Gitlab::PathRegex::NAMESPACE_FORMAT_REGEX_JS, required: true, title: _("Please create a username with only alphanumeric characters.") = f.text_field :username, class: "form-control middle js-block-emoji js-validate-length js-validate-username", :data => { :min_length => min_username_length, :min_length_message => s_("SignUp|Username is too short (minimum is %{min_length} characters).") % { min_length: min_username_length }, :max_length => max_username_length, :max_length_message => s_("SignUp|Username is too long (maximum is %{max_length} characters).") % { max_length: max_username_length }, :qa_selector => 'new_user_username_field' }, pattern: Gitlab::PathRegex::NAMESPACE_FORMAT_REGEX_JS, required: true, title: _("Please create a username with only alphanumeric characters.")
......
---
title: Split name to first and last name for signup
merge_request: 42346
author:
type: changed
...@@ -6,8 +6,11 @@ RSpec.describe RegistrationsController do ...@@ -6,8 +6,11 @@ RSpec.describe RegistrationsController do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
describe '#create' do describe '#create' do
let(:base_user_params) { build_stubbed(:user).slice(:first_name, :last_name, :username, :email, :password) }
let(:user_params) { { user: base_user_params } }
context 'when the user opted-in' do context 'when the user opted-in' do
let(:user_params) { { user: attributes_for(:user, email_opted_in: '1') } } let(:user_params) { { user: base_user_params.merge(email_opted_in: '1') } }
it 'sets the rest of the email_opted_in fields' do it 'sets the rest of the email_opted_in fields' do
post :create, params: user_params post :create, params: user_params
...@@ -20,7 +23,7 @@ RSpec.describe RegistrationsController do ...@@ -20,7 +23,7 @@ RSpec.describe RegistrationsController do
end end
context 'when the user opted-out' do context 'when the user opted-out' do
let(:user_params) { { user: attributes_for(:user, email_opted_in: '0') } } let(:user_params) { { user: base_user_params.merge(email_opted_in: '0') } }
it 'does not set the rest of the email_opted_in fields' do it 'does not set the rest of the email_opted_in fields' do
post :create, params: user_params post :create, params: user_params
...@@ -34,7 +37,6 @@ RSpec.describe RegistrationsController do ...@@ -34,7 +37,6 @@ RSpec.describe RegistrationsController do
context 'when reCAPTCHA experiment enabled' do context 'when reCAPTCHA experiment enabled' do
it "logs a 'User Created' message including the experiment state" do it "logs a 'User Created' message including the experiment state" do
user_params = { user: attributes_for(:user) }
allow_any_instance_of(EE::RecaptchaExperimentHelper).to receive(:show_recaptcha_sign_up?).and_return(true) allow_any_instance_of(EE::RecaptchaExperimentHelper).to receive(:show_recaptcha_sign_up?).and_return(true)
expect(Gitlab::AppLogger).to receive(:info).with(/\AUser Created: .+experiment_growth_recaptcha\?true\z/).and_call_original expect(Gitlab::AppLogger).to receive(:info).with(/\AUser Created: .+experiment_growth_recaptcha\?true\z/).and_call_original
......
...@@ -16,7 +16,8 @@ RSpec.describe 'Group or Project invitations' do ...@@ -16,7 +16,8 @@ RSpec.describe 'Group or Project invitations' do
end end
def fill_in_sign_up_form(user) def fill_in_sign_up_form(user)
fill_in 'new_user_name', with: user.name fill_in 'new_user_first_name', with: user.first_name
fill_in 'new_user_last_name', with: user.last_name
fill_in 'new_user_username', with: user.username fill_in 'new_user_username', with: user.username
fill_in 'new_user_email', with: user.email fill_in 'new_user_email', with: user.email
fill_in 'new_user_password', with: user.password fill_in 'new_user_password', with: user.password
......
...@@ -3,7 +3,15 @@ ...@@ -3,7 +3,15 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'Signup on EE' do RSpec.describe 'Signup on EE' do
let(:user_attrs) { attributes_for(:user) } let(:new_user) { build_stubbed(:user) }
def fill_in_signup_form
fill_in 'new_user_username', with: new_user.username
fill_in 'new_user_email', with: new_user.email
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_password', with: new_user.password
end
context 'for Gitlab.com' do context 'for Gitlab.com' do
before do before do
...@@ -14,14 +22,11 @@ RSpec.describe 'Signup on EE' do ...@@ -14,14 +22,11 @@ RSpec.describe 'Signup on EE' do
it 'creates the user and sets the email_opted_in field truthy' do it 'creates the user and sets the email_opted_in field truthy' do
visit root_path visit root_path
fill_in 'new_user_name', with: user_attrs[:name] fill_in_signup_form
fill_in 'new_user_username', with: user_attrs[:username]
fill_in 'new_user_email', with: user_attrs[:email]
fill_in 'new_user_password', with: user_attrs[:password]
check 'new_user_email_opted_in' check 'new_user_email_opted_in'
click_button "Register" click_button "Register"
user = User.find_by_username!(user_attrs[:username]) user = User.find_by_username!(new_user[:username])
expect(user.email_opted_in).to be_truthy expect(user.email_opted_in).to be_truthy
expect(user.email_opted_in_ip).to be_present expect(user.email_opted_in_ip).to be_present
expect(user.email_opted_in_source).to eq('GitLab.com') expect(user.email_opted_in_source).to eq('GitLab.com')
...@@ -33,13 +38,10 @@ RSpec.describe 'Signup on EE' do ...@@ -33,13 +38,10 @@ RSpec.describe 'Signup on EE' do
it 'creates the user and sets the email_opted_in field falsey' do it 'creates the user and sets the email_opted_in field falsey' do
visit root_path visit root_path
fill_in 'new_user_name', with: user_attrs[:name] fill_in_signup_form
fill_in 'new_user_username', with: user_attrs[:username]
fill_in 'new_user_email', with: user_attrs[:email]
fill_in 'new_user_password', with: user_attrs[:password]
click_button "Register" click_button "Register"
user = User.find_by_username!(user_attrs[:username]) user = User.find_by_username!(new_user[:username])
expect(user.email_opted_in).to be_falsey expect(user.email_opted_in).to be_falsey
expect(user.email_opted_in_ip).to be_blank expect(user.email_opted_in_ip).to be_blank
expect(user.email_opted_in_source).to be_blank expect(user.email_opted_in_source).to be_blank
...@@ -50,10 +52,7 @@ RSpec.describe 'Signup on EE' do ...@@ -50,10 +52,7 @@ RSpec.describe 'Signup on EE' do
it 'redirects to step 2 of the signup process, sets the role and setup for company and redirects back' do it 'redirects to step 2 of the signup process, sets the role and setup for company and redirects back' do
visit new_user_registration_path visit new_user_registration_path
fill_in 'new_user_name', with: user_attrs[:name].split(' ').first fill_in_signup_form
fill_in 'new_user_username', with: user_attrs[:username]
fill_in 'new_user_email', with: user_attrs[:email]
fill_in 'new_user_password', with: user_attrs[:password]
click_button 'Register' click_button 'Register'
visit new_project_path visit new_project_path
...@@ -62,7 +61,7 @@ RSpec.describe 'Signup on EE' do ...@@ -62,7 +61,7 @@ RSpec.describe 'Signup on EE' do
select 'Software Developer', from: 'user_role' select 'Software Developer', from: 'user_role'
choose 'user_setup_for_company_true' choose 'user_setup_for_company_true'
click_button 'Get started!' click_button 'Get started!'
user = User.find_by_username(user_attrs[:username]) user = User.find_by_username(new_user[:username])
expect(user.software_developer_role?).to be_truthy expect(user.software_developer_role?).to be_truthy
expect(user.setup_for_company).to be_truthy expect(user.setup_for_company).to be_truthy
...@@ -80,13 +79,10 @@ RSpec.describe 'Signup on EE' do ...@@ -80,13 +79,10 @@ RSpec.describe 'Signup on EE' do
expect(page).not_to have_selector("[name='new_user_email_opted_in']") expect(page).not_to have_selector("[name='new_user_email_opted_in']")
fill_in 'new_user_name', with: user_attrs[:name] fill_in_signup_form
fill_in 'new_user_username', with: user_attrs[:username]
fill_in 'new_user_email', with: user_attrs[:email]
fill_in 'new_user_password', with: user_attrs[:password]
click_button "Register" click_button "Register"
user = User.find_by_username!(user_attrs[:username]) user = User.find_by_username!(new_user[:username])
expect(user.email_opted_in).to be_falsey expect(user.email_opted_in).to be_falsey
expect(user.email_opted_in_ip).to be_blank expect(user.email_opted_in_ip).to be_blank
expect(user.email_opted_in_source).to be_blank expect(user.email_opted_in_source).to be_blank
......
...@@ -11398,9 +11398,6 @@ msgstr "" ...@@ -11398,9 +11398,6 @@ msgstr ""
msgid "Finished" msgid "Finished"
msgstr "" msgstr ""
msgid "First Name is too long (maximum is %{max_length} characters)."
msgstr ""
msgid "First Seen" msgid "First Seen"
msgstr "" msgstr ""
...@@ -11410,6 +11407,9 @@ msgstr "" ...@@ -11410,6 +11407,9 @@ msgstr ""
msgid "First name" msgid "First name"
msgstr "" msgstr ""
msgid "First name is too long (maximum is %{max_length} characters)."
msgstr ""
msgid "First seen" msgid "First seen"
msgstr "" msgstr ""
...@@ -14893,9 +14893,6 @@ msgstr "" ...@@ -14893,9 +14893,6 @@ msgstr ""
msgid "Last Accessed On" msgid "Last Accessed On"
msgstr "" msgstr ""
msgid "Last Name is too long (maximum is %{max_length} characters)."
msgstr ""
msgid "Last Pipeline" msgid "Last Pipeline"
msgstr "" msgstr ""
...@@ -14929,6 +14926,9 @@ msgstr "" ...@@ -14929,6 +14926,9 @@ msgstr ""
msgid "Last name" msgid "Last name"
msgstr "" msgstr ""
msgid "Last name is too long (maximum is %{max_length} characters)."
msgstr ""
msgid "Last reply by" msgid "Last reply by"
msgstr "" msgstr ""
...@@ -23918,9 +23918,6 @@ msgstr "" ...@@ -23918,9 +23918,6 @@ msgstr ""
msgid "SignUp|Last Name is too long (maximum is %{max_length} characters)." msgid "SignUp|Last Name is too long (maximum is %{max_length} characters)."
msgstr "" msgstr ""
msgid "SignUp|Name is too long (maximum is %{max_length} characters)."
msgstr ""
msgid "SignUp|Username is too long (maximum is %{max_length} characters)." msgid "SignUp|Username is too long (maximum is %{max_length} characters)."
msgstr "" msgstr ""
......
...@@ -5,7 +5,8 @@ module QA ...@@ -5,7 +5,8 @@ module QA
module Main module Main
class SignUp < Page::Base class SignUp < Page::Base
view 'app/views/devise/shared/_signup_box.html.haml' do view 'app/views/devise/shared/_signup_box.html.haml' do
element :new_user_name_field element :new_user_first_name_field
element :new_user_last_name_field
element :new_user_username_field element :new_user_username_field
element :new_user_email_field element :new_user_email_field
element :new_user_password_field element :new_user_password_field
...@@ -18,7 +19,8 @@ module QA ...@@ -18,7 +19,8 @@ module QA
end end
def sign_up!(user) def sign_up!(user)
fill_element :new_user_name_field, user.name fill_element :new_user_first_name_field, user.first_name
fill_element :new_user_last_name_field, user.last_name
fill_element :new_user_username_field, user.username fill_element :new_user_username_field, user.username
fill_element :new_user_email_field, user.email fill_element :new_user_email_field, user.email
fill_element :new_user_password_field, user.password fill_element :new_user_password_field, user.password
......
...@@ -11,6 +11,8 @@ module QA ...@@ -11,6 +11,8 @@ module QA
attribute :id attribute :id
attribute :name attribute :name
attribute :first_name
attribute :last_name
attribute :email attribute :email
def initialize def initialize
...@@ -34,6 +36,14 @@ module QA ...@@ -34,6 +36,14 @@ module QA
@name ||= api_resource&.dig(:name) || "QA User #{unique_id}" @name ||= api_resource&.dig(:name) || "QA User #{unique_id}"
end end
def first_name
name.split(' ').first
end
def last_name
name.split(' ').drop(1).join(' ')
end
def email def email
@email ||= begin @email ||= begin
api_email = api_resource&.dig(:email) api_email = api_resource&.dig(:email)
......
...@@ -80,7 +80,7 @@ RSpec.describe RegistrationsController do ...@@ -80,7 +80,7 @@ RSpec.describe RegistrationsController do
end end
describe '#create' do describe '#create' do
let(:base_user_params) { { name: 'new_user', username: 'new_username', email: 'new@user.com', password: 'Any_password' } } let(:base_user_params) { { first_name: 'first', last_name: 'last', username: 'new_username', email: 'new@user.com', password: 'Any_password' } }
let(:user_params) { { user: base_user_params } } let(:user_params) { { user: base_user_params } }
context 'email confirmation' do context 'email confirmation' do
...@@ -370,14 +370,6 @@ RSpec.describe RegistrationsController do ...@@ -370,14 +370,6 @@ RSpec.describe RegistrationsController do
expect(subject.current_user).not_to be_nil expect(subject.current_user).not_to be_nil
end end
context 'with the experimental signup flow enabled and the user is part of the experimental group' do
before do
stub_experiment(signup_flow: true)
stub_experiment_for_user(signup_flow: true)
end
let(:base_user_params) { { first_name: 'First', last_name: 'Last', username: 'new_username', email: 'new@user.com', password: 'Any_password' } }
it 'sets name from first and last name' do it 'sets name from first and last name' do
post :create, params: { new_user: base_user_params } post :create, params: { new_user: base_user_params }
...@@ -386,7 +378,6 @@ RSpec.describe RegistrationsController do ...@@ -386,7 +378,6 @@ RSpec.describe RegistrationsController do
expect(User.last.name).to eq("#{base_user_params[:first_name]} #{base_user_params[:last_name]}") expect(User.last.name).to eq("#{base_user_params[:first_name]} #{base_user_params[:last_name]}")
end end
end end
end
describe '#destroy' do describe '#destroy' do
let(:user) { create(:user) } let(:user) { create(:user) }
......
...@@ -23,7 +23,8 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do ...@@ -23,7 +23,8 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do
end end
def fill_in_sign_up_form(new_user) def fill_in_sign_up_form(new_user)
fill_in 'new_user_name', with: new_user.name 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_username', with: new_user.username
fill_in 'new_user_email', with: new_user.email fill_in 'new_user_email', with: new_user.email
fill_in 'new_user_password', with: new_user.password fill_in 'new_user_password', with: new_user.password
......
This diff is collapsed.
...@@ -4,11 +4,11 @@ require 'spec_helper' ...@@ -4,11 +4,11 @@ require 'spec_helper'
RSpec.describe Users::BuildService do RSpec.describe Users::BuildService do
describe '#execute' do describe '#execute' do
let(:params) do let(:params) { build_stubbed(:user).slice(:first_name, :last_name, :username, :email, :password) }
{ name: 'John Doe', username: 'jduser', email: 'jd@example.com', password: 'mydummypass' }
end
context 'with an admin user' do context 'with an admin user' do
let(:params) { build_stubbed(:user).slice(:name, :username, :email, :password) }
let(:admin_user) { create(:admin) } let(:admin_user) { create(:admin) }
let(:service) { described_class.new(admin_user, ActionController::Parameters.new(params).permit!) } let(:service) { described_class.new(admin_user, ActionController::Parameters.new(params).permit!) }
......
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