Commit e0af07e7 authored by Jay Swain's avatar Jay Swain

Combined Registration validations and defaults

Because the combined_registration experiment doesn't have a field for
namespace path, it's hard to validate before the user submits using FE
validation. So here I'm suggesting a path name in case the user does
something wild like uses only an emoji for the group name.

part of:
https://gitlab.com/gitlab-org/gitlab/-/issues/285563
parent caaa7778
......@@ -22,7 +22,7 @@ module Registrations
@group = if group_id = params[:group][:id]
Group.find_by_id(group_id)
else
Groups::CreateService.new(current_user, group_params).execute
Groups::CreateService.new(current_user, modified_group_params).execute
end
if @group.persisted?
......@@ -59,7 +59,7 @@ module Registrations
end
def import
@group = Groups::CreateService.new(current_user, group_params).execute
@group = Groups::CreateService.new(current_user, modified_group_params).execute
if @group.persisted?
combined_registration_experiment.track(:create_group, namespace: @group)
experiment(:jobs_to_be_done, user: current_user).track(:create_group, namespace: @group)
......@@ -81,5 +81,15 @@ module Registrations
def project_params
params.require(:project).permit(project_params_attributes).merge(namespace_id: @group.id)
end
def modified_group_params
group_name = params.dig(:group, :name)
if group_name.present? && params.dig(:group, :path).blank?
group_params.compact_blank.with_defaults(path: Namespace.clean_path(group_name))
else
group_params
end
end
end
end
......@@ -8,8 +8,8 @@
= f.label :setup_for_company, setup_for_company_label_text, class: 'label-bold'
.gl-display-flex.gl-flex-direction-column.gl-lg-flex-direction-row
.gl-flex-grow-1
= f.radio_button :setup_for_company, true, class: 'js-setup-for-company'
= f.radio_button :setup_for_company, true, class: 'js-setup-for-company', required: true
= f.label :setup_for_company, _('My company or team'), class: 'normal', value: 'true'
.gl-flex-grow-1
= f.radio_button :setup_for_company, false, class: 'js-setup-for-me'
= f.radio_button :setup_for_company, false, class: 'js-setup-for-me', required: true
= f.label :setup_for_company, _('Just me'), class: 'normal', value: 'false'
......@@ -94,6 +94,14 @@ RSpec.describe Registrations::GroupsProjectsController, :experiment do
end
end
context 'when there is no suggested path based from the name' do
let(:group_params) { { name: '⛄⛄⛄', path: '' } }
it 'creates a group' do
expect { subject }.to change { Group.count }.by(1)
end
end
context 'when the group cannot be created' do
let(:group_params) { { name: '', path: '' } }
......@@ -252,6 +260,15 @@ RSpec.describe Registrations::GroupsProjectsController, :experiment do
it { is_expected.to render_template(:new) }
end
context 'when there is no suggested path based from the group name' do
let(:group_params) { { name: '⛄⛄⛄', path: '' } }
it 'creates a group, and redirects' do
expect { subject }.to change { Group.count }.by(1)
expect(subject).to have_gitlab_http_status(:redirect)
end
end
context 'when group can be created' do
it 'creates a group' do
expect { subject }.to change { Group.count }.by(1)
......
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