Commit 07de2c2d authored by Sean McGivern's avatar Sean McGivern

Merge branch 'nicolasdular/root-namespaces-for-paid-signup' into 'master'

Show only root namespaces for subscriptions

See merge request gitlab-org/gitlab!38481
parents cf683ab9 5f868a06
......@@ -42,7 +42,7 @@ class SubscriptionsController < ApplicationController
current_user.update(setup_for_company: true) if params[:setup_for_company]
if params[:selected_group]
group = current_user.managed_free_namespaces.find(params[:selected_group])
group = current_user.manageable_groups_eligible_for_subscription.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)
......
......@@ -39,7 +39,7 @@ module SubscriptionsHelper
end
def group_data
current_user.managed_free_namespaces.with_counts(archived: false).map do |namespace|
current_user.manageable_groups_eligible_for_subscription.with_counts(archived: false).map do |namespace|
{
id: namespace.id,
name: namespace.name,
......
......@@ -250,8 +250,9 @@ module EE
.any?
end
def managed_free_namespaces
def manageable_groups_eligible_for_subscription
manageable_groups
.where(parent_id: nil)
.left_joins(:gitlab_subscription)
.merge(GitlabSubscription.left_joins(:hosted_plan).where(plans: { name: [nil, *::Plan.default_plans] }))
.order(:name)
......
---
title: Show only root namespaces for subscriptions
merge_request: 38481
author:
type: fixed
......@@ -205,6 +205,12 @@ RSpec.describe SubscriptionsController do
expect(response.body).to eq({ location: "/#{selected_group.path}" }.to_json)
end
context 'when selected group is a sub group' do
let(:selected_group) { create(:group, parent: create(:group))}
it { is_expected.to have_gitlab_http_status(:not_found) }
end
end
context 'when selecting a non existing group' do
......
......@@ -996,13 +996,14 @@ RSpec.describe User do
end
end
describe '#managed_free_namespaces' do
describe '#manageable_groups_eligible_for_subscription' do
let_it_be(:user) { create(:user) }
let_it_be(:licensed_group) { create(:group, gitlab_subscription: create(:gitlab_subscription, :bronze)) }
let_it_be(:free_group_z) { create(:group, name: 'AZ', gitlab_subscription: create(:gitlab_subscription, :free)) }
let_it_be(:free_group_a) { create(:group, name: 'AA', gitlab_subscription: create(:gitlab_subscription, :free)) }
let_it_be(:sub_group) { create(:group, name: 'SubGroup', parent: free_group_a) }
subject { user.managed_free_namespaces }
subject { user.manageable_groups_eligible_for_subscription }
context 'user with no groups' do
it { is_expected.to eq [] }
......@@ -1047,6 +1048,8 @@ RSpec.describe User do
end
it { is_expected.to eq [free_group_a, free_group_z] }
it { is_expected.not_to include(sub_group) }
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