Commit e5c92e94 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'growth-60-apply-license-to-selected-group-redo' into 'master'

Apply license to selected group

Closes #207970

See merge request gitlab-org/gitlab!25895
parents 6f54d919 70666b14
......@@ -13,7 +13,12 @@ module Subscriptions
def update
if Groups::UpdateService.new(@group, current_user, group_params).execute
notice = _('Welcome to GitLab, %{first_name}!' % { first_name: current_user.first_name })
notice = if params[:new_user] == 'true'
_('Welcome to GitLab, %{first_name}!' % { first_name: current_user.first_name })
else
_('Subscription successfully applied to "%{group_name}"' % { group_name: @group.name })
end
redirect_to group_path(@group), notice: notice
else
@group.path = @group.path_before_last_save || @group.path_was
......
......@@ -47,10 +47,15 @@ class SubscriptionsController < ApplicationController
def create
current_user.update(setup_for_company: true) if params[:setup_for_company]
group_name = params[:setup_for_company] ? customer_params[:company] : "#{current_user.name}'s Group"
path = Namespace.clean_path(group_name)
group = Groups::CreateService.new(current_user, name: group_name, path: path).execute
return render json: group.errors.to_json unless group.persisted?
if params[:selected_group]
group = current_user.managed_free_namespaces.find(params[:selected_group])
else
group_name = params[:setup_for_company] ? customer_params[:company] : "#{current_user.name}'s Group"
path = Namespace.clean_path(group_name)
group = Groups::CreateService.new(current_user, name: group_name, path: path).execute
return render json: group.errors.to_json unless group.persisted?
end
response = Subscriptions::CreateService.new(
current_user,
......@@ -60,9 +65,14 @@ class SubscriptionsController < ApplicationController
).execute
if response[:success]
plan_id, quantity = subscription_params.values_at(:plan_id, :quantity)
response[:data] = { location: edit_subscriptions_group_path(group.path, plan_id: plan_id, quantity: quantity) }
redirect_location = if params[:selected_group]
group_path(group)
else
plan_id, quantity = subscription_params.values_at(:plan_id, :quantity)
edit_subscriptions_group_path(group.path, plan_id: plan_id, quantity: quantity, new_user: params[:new_user])
end
response[:data] = { location: redirect_location }
track_paid_signup_flow_event('end', label: plan_id, value: quantity)
end
......
......@@ -10,13 +10,15 @@
- number_of_users = n_('1 user', '%{num} users', params[:quantity].to_i) % { num: params[:quantity] }
%p= _('You have successfully purchased a %{plan} plan subscription for %{seats}. You’ll receive a receipt via email.') % { plan: plan_title, seats: number_of_users }
.edit-group.d-flex.flex-column.align-items-center.gl-pt-5
#progress-bar
- if params[:new_user]
#progress-bar
%h2.center= _('Create a group for your organization')
%p
%div= _('A group represents your organization in GitLab.')
%div= _('Your %{plan} plan will be applied to your group.' % { plan: plan_title })
= form_for [:subscriptions, @group], html: { class: 'gl-show-field-errors card w-100 gl-p-3' } do |f|
= hidden_field_tag :new_user, params[:new_user]
= form_errors(@group)
.row
.form-group.group-name-holder.col-sm-12
......
......@@ -68,6 +68,14 @@ describe Subscriptions::GroupsController do
expect(subject).to have_gitlab_http_status(:redirect)
expect(subject).to redirect_to('/new-path')
end
it { is_expected.to set_flash[:notice].to('Subscription successfully applied to "New name"') }
context 'with new_user param' do
subject { post :update, params: { id: group.to_param, group: params, new_user: 'true' } }
it { is_expected.to set_flash[:notice].to("Welcome to GitLab, #{user.first_name}!") }
end
end
context 'when the group cannot be saved' do
......
......@@ -212,6 +212,43 @@ describe SubscriptionsController do
expect(response.body).to eq('{"errors":"error message"}')
end
end
context 'when selecting an existing group' do
let_it_be(:selected_group) { create(:group) }
let(:params) do
{
selected_group: selected_group.id,
customer: { country: 'NL' },
subscription: { plan_id: 'x', quantity: 1 }
}
end
before do
selected_group.add_owner(user)
end
it 'does not create a group' do
expect { subject }.to not_change { Group.count }
end
it 'returns the selected group location in JSON format' do
subject
expect(response.body).to eq({ location: "/#{selected_group.path}" }.to_json)
end
end
context 'when selecting a non existing group' do
let(:params) do
{
selected_group: 999,
customer: { country: 'NL' },
subscription: { plan_id: 'x', quantity: 1 }
}
end
it { is_expected.to have_gitlab_http_status(:not_found) }
end
end
end
end
......@@ -13,9 +13,9 @@ describe 'subscriptions/groups/edit' do
allow(view).to receive(:current_user).and_return(User.new)
end
context 'a single user' do
let(:quantity) { '1' }
let(:quantity) { '1' }
context 'a single user' do
it 'displays the correct notification for 1 user' do
render
......@@ -32,4 +32,24 @@ describe 'subscriptions/groups/edit' do
expect(rendered).to have_text('You have successfully purchased a Bronze plan subscription for 2 users. You’ll receive a receipt via email.')
end
end
context 'with new_user in the params' do
before do
allow(view).to receive(:params).and_return(new_user: 'true')
end
it 'displays the progress bar' do
render
expect(rendered).to have_selector('#progress-bar')
end
end
context 'without new_user in the params' do
it 'does not display the progress bar' do
render
expect(rendered).not_to have_selector('#progress-bar')
end
end
end
......@@ -18609,6 +18609,9 @@ msgstr ""
msgid "Subscription deletion failed."
msgstr ""
msgid "Subscription successfully applied to \"%{group_name}\""
msgstr ""
msgid "Subscription successfully created."
msgstr ""
......
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