Skip to content
Snippets Groups Projects
Verified Commit 01355b58 authored by Serhii Yarynovskyi Parental Leave from 2025-02-21 to 2025-06-09's avatar Serhii Yarynovskyi Parental Leave from 2025-02-21 to 2025-06-09 :palm_tree: Committed by GitLab
Browse files

Remove create group functionality from Duo Pro trial

parent 8042fe8e
No related branches found
No related tags found
2 merge requests!158455Backport Release Environments notification pipeline change to 16.11,!149990Remove create group functionality from Duo Pro trial
Showing with 149 additions and 145 deletions
......@@ -48,11 +48,6 @@ def create
render_404
elsif @result.reason == GitlabSubscriptions::Trials::CreateDuoProService::LEAD_FAILED
render :step_lead_failed
elsif @result.reason == GitlabSubscriptions::Trials::CreateDuoProService::NAMESPACE_CREATE_FAILED
# namespace creation failed
params[:namespace_id] = @result.payload[:namespace_id]
render :step_namespace_failed
else
# trial creation failed
params[:namespace_id] = @result.payload[:namespace_id]
......@@ -94,7 +89,7 @@ def lead_params
end
def trial_params
params.permit(:new_group_name, :namespace_id, :trial_entity, :glm_source, :glm_content).to_h
params.permit(:namespace_id, :trial_entity, :glm_source, :glm_content).to_h
end
def success_flash_message
......
......@@ -8,7 +8,6 @@ class BaseCreateService
LEAD_FAILED = :lead_failed
TRIAL_FAILED = :trial_failed
NOT_FOUND = :not_found
NAMESPACE_CREATE_FAILED = :namespace_create_failed
NO_SINGLE_NAMESPACE = :no_single_namespace
def initialize(step:, lead_params:, trial_params:, user:)
......@@ -130,16 +129,7 @@ def apply_trial_service_class
end
def trial_flow
# The value of 0 is the option in the select for creating a new group
create_new_group_selected = trial_params[:namespace_id] == '0'
if trial_params[:namespace_id].present? && !create_new_group_selected
existing_namespace_flow
elsif trial_params.key?(:new_group_name)
create_group_flow
else
not_found
end
raise NoMethodError, 'Subclasses must implement the trial_flow method'
end
def existing_namespace_flow
......@@ -152,27 +142,6 @@ def existing_namespace_flow
end
end
def create_group_flow
# Instance admins can disable user's ability to create top level groups.
# See https://docs.gitlab.com/ee/administration/admin_area.html#prevent-a-user-from-creating-groups
return not_found unless user.can_create_group?
name = ActionController::Base.helpers.sanitize(trial_params[:new_group_name])
path = Namespace.clean_path(name.parameterize)
response = Groups::CreateService.new(user, name: name, path: path).execute
@namespace = response[:group]
if response.success?
apply_trial_flow
else
ServiceResponse.error(
message: namespace.errors.full_messages,
payload: { namespace_id: trial_params[:namespace_id] },
reason: NAMESPACE_CREATE_FAILED
)
end
end
def trial_user_information_params
gl_com_params = { gitlab_com_trial: true, sync_to_gl: true }
namespace_params = {
......
......@@ -5,6 +5,12 @@ module Trials
class CreateDuoProService < ::GitlabSubscriptions::Trials::BaseCreateService
private
def trial_flow
return not_found if trial_params[:namespace_id].blank?
existing_namespace_flow
end
def after_lead_success_hook
track_event('duo_pro_lead_creation_success')
......
......@@ -3,8 +3,44 @@
module GitlabSubscriptions
module Trials
class CreateService < BaseCreateService
NAMESPACE_CREATE_FAILED = :namespace_create_failed
private
def trial_flow
# The value of 0 is the option in the select for creating a new group
create_new_group_selected = trial_params[:namespace_id] == '0'
if trial_params[:namespace_id].present? && !create_new_group_selected
existing_namespace_flow
elsif trial_params.key?(:new_group_name)
create_group_flow
else
not_found
end
end
def create_group_flow
# Instance admins can disable user's ability to create top level groups.
# See https://docs.gitlab.com/ee/administration/admin_area.html#prevent-a-user-from-creating-groups
return not_found unless user.can_create_group?
name = ActionController::Base.helpers.sanitize(trial_params[:new_group_name])
path = Namespace.clean_path(name.parameterize)
response = Groups::CreateService.new(user, name: name, path: path).execute
@namespace = response[:group]
if response.success?
apply_trial_flow
else
ServiceResponse.error(
message: namespace.errors.full_messages,
payload: { namespace_id: trial_params[:namespace_id] },
reason: NAMESPACE_CREATE_FAILED
)
end
end
def lead_service_class
GitlabSubscriptions::CreateLeadService
end
......
= render 'select_namespace_form', namespace_create_errors: @result.errors.to_sentence
......@@ -194,19 +194,6 @@
end
end
context 'with namespace creation failure' do
let(:failure_reason) { :namespace_create_failed }
let(:namespace) { build_stubbed(:namespace) }
let(:payload) { { namespace: namespace.id } }
it 'renders the select namespace form again with namespace creation errors only' do
expect(post_create).to render_select_namespace
expect(response.body).to include('data-namespace-create-errors="_error_"')
expect(response.body).not_to include(_('your GitLab Duo Pro trial could not be created'))
end
end
context 'with trial failure' do
let(:failure_reason) { :trial_failed }
let(:namespace) { build_stubbed(:namespace) }
......
......@@ -47,6 +47,13 @@ def lead_service_class
it_behaves_like 'raises NoMethodError', 'Subclasses must implement the namespaces_eligible_for_trial method'
end
context 'when trial_flow is not implemented' do
let(:step) { 'trial' }
let(:test_class) { described_class }
it_behaves_like 'raises NoMethodError', 'Subclasses must implement the trial_flow method'
end
context 'when apply_trial_service_class is not implemented' do
let(:step) { 'trial' }
......@@ -55,6 +62,10 @@ def lead_service_class
def namespaces_eligible_for_trial
Group
end
def trial_flow
existing_namespace_flow
end
end
end
......
......@@ -26,6 +26,100 @@
it_behaves_like 'when on trial step', :free_plan
it_behaves_like 'with an unknown step'
it_behaves_like 'with no step'
context 'when in the create group flow' do
let(:step) { described_class::TRIAL }
let(:extra_params) { { trial_entity: '_entity_' } }
let(:trial_params) { { new_group_name: 'gitlab', namespace_id: '0' }.merge(extra_params) }
context 'when group is successfully created' do
context 'when trial creation is successful' do
it 'return success with the namespace' do
expect_next_instance_of(apply_trial_service_class) do |instance|
expect(instance).to receive(:execute).and_return(ServiceResponse.success)
end
expect { execute }.to change { Group.count }.by(1)
expect(execute).to be_success
expect(execute.payload).to eq({ namespace: Group.last })
end
end
context 'when trial creation fails' do
it 'returns an error indicating trial failed' do
stub_apply_trial(
user, namespace_id: anything, success: false, extra_params: extra_params.merge(new_group_attrs)
)
expect { execute }.to change { Group.count }.by(1)
expect(execute).to be_error
expect(execute.payload).to eq({ namespace_id: Group.last.id })
end
end
context 'when group name needs sanitized' do
it 'return success with the namespace path sanitized for duplication' do
create(:group_with_plan, plan: :free_plan, name: 'gitlab')
stub_apply_trial(
user, namespace_id: anything, success: true,
extra_params: extra_params.merge(new_group_attrs(path: 'gitlab1'))
)
expect { execute }.to change { Group.count }.by(1)
expect(execute).to be_success
expect(execute.payload[:namespace].path).to eq('gitlab1')
end
end
end
context 'when user is not allowed to create groups' do
before do
user.can_create_group = false
end
it 'returns not_found' do
expect(apply_trial_service_class).not_to receive(:new)
expect { execute }.not_to change { Group.count }
expect(execute).to be_error
expect(execute.reason).to eq(:not_found)
end
end
context 'when group creation had an error' do
context 'when there are invalid characters used' do
let(:trial_params) { { new_group_name: ' _invalid_ ', namespace_id: '0' } }
it 'returns namespace_create_failed' do
expect(apply_trial_service_class).not_to receive(:new)
expect { execute }.not_to change { Group.count }
expect(execute).to be_error
expect(execute.reason).to eq(:namespace_create_failed)
expect(execute.message.to_sentence).to match(/^Group URL can only include non-accented letters/)
expect(execute.payload[:namespace_id]).to eq('0')
end
end
context 'when name is entered with blank spaces' do
let(:trial_params) { { new_group_name: ' ', namespace_id: '0' } }
it 'returns namespace_create_failed' do
expect(apply_trial_service_class).not_to receive(:new)
expect { execute }.not_to change { Group.count }
expect(execute).to be_error
expect(execute.reason).to eq(:namespace_create_failed)
expect(execute.message.to_sentence).to match(/^Name can't be blank/)
expect(execute.payload[:namespace_id]).to eq('0')
end
end
end
end
end
def lead_params(user, extra_lead_params)
......
......@@ -190,99 +190,6 @@ def expect_to_trigger_trial_step(execution, lead_payload_params, trial_payload_p
end
end
context 'in the create group flow' do
let(:extra_params) { { trial_entity: '_entity_' } }
let(:trial_params) { { new_group_name: 'gitlab', namespace_id: '0' }.merge(extra_params) }
context 'when group is successfully created' do
context 'when trial creation is successful' do
it 'return success with the namespace' do
expect_next_instance_of(apply_trial_service_class) do |instance|
expect(instance).to receive(:execute).and_return(ServiceResponse.success)
end
expect { execute }.to change { Group.count }.by(1)
expect(execute).to be_success
expect(execute.payload).to eq({ namespace: Group.last })
end
end
context 'when trial creation fails' do
it 'returns an error indicating trial failed' do
stub_apply_trial(
user, namespace_id: anything, success: false, extra_params: extra_params.merge(new_group_attrs)
)
expect { execute }.to change { Group.count }.by(1)
expect(execute).to be_error
expect(execute.payload).to eq({ namespace_id: Group.last.id })
end
end
context 'when group name needs sanitized' do
it 'return success with the namespace path sanitized for duplication' do
create(:group_with_plan, plan: plan_name, name: 'gitlab')
stub_apply_trial(
user, namespace_id: anything, success: true,
extra_params: extra_params.merge(new_group_attrs(path: 'gitlab1'))
)
expect { execute }.to change { Group.count }.by(1)
expect(execute).to be_success
expect(execute.payload[:namespace].path).to eq('gitlab1')
end
end
end
context 'when user is not allowed to create groups' do
before do
user.can_create_group = false
end
it 'returns not_found' do
expect(apply_trial_service_class).not_to receive(:new)
expect { execute }.not_to change { Group.count }
expect(execute).to be_error
expect(execute.reason).to eq(:not_found)
end
end
context 'when group creation had an error' do
context 'when there are invalid characters used' do
let(:trial_params) { { new_group_name: ' _invalid_ ', namespace_id: '0' } }
it 'returns namespace_create_failed' do
expect(apply_trial_service_class).not_to receive(:new)
expect { execute }.not_to change { Group.count }
expect(execute).to be_error
expect(execute.reason).to eq(:namespace_create_failed)
expect(execute.message.to_sentence).to match(/^Group URL can only include non-accented letters/)
expect(execute.payload[:namespace_id]).to eq('0')
end
end
context 'when name is entered with blank spaces' do
let(:trial_params) { { new_group_name: ' ', namespace_id: '0' } }
it 'returns namespace_create_failed' do
expect(apply_trial_service_class).not_to receive(:new)
expect { execute }.not_to change { Group.count }
expect(execute).to be_error
expect(execute.reason).to eq(:namespace_create_failed)
expect(execute.message.to_sentence).to match(/^Name can't be blank/)
expect(execute.payload[:namespace_id]).to eq('0')
end
end
end
end
context 'when namespace_id is 0 without a new_group_name' do
let(:trial_params) { { namespace_id: '0' } }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment