Commit 5f868a06 authored by Nicolas Dular's avatar Nicolas Dular

Show only root namespaces for subscriptions

We only allow subscriptions for root namespaces. However, we also
rendered sub-groups when creating a subscription.
This was not an issue so far, because we only used the new
subscription sites for sign up, therefore users were not able to
create sub-groups beforehand.

This will change in the future, where we also want to use the
new subscription page design for upgrades.
parent 40fff8cc
...@@ -42,7 +42,7 @@ class SubscriptionsController < ApplicationController ...@@ -42,7 +42,7 @@ class SubscriptionsController < ApplicationController
current_user.update(setup_for_company: true) if params[:setup_for_company] current_user.update(setup_for_company: true) if params[:setup_for_company]
if params[:selected_group] 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 else
group_name = params[:setup_for_company] ? customer_params[:company] : "#{current_user.name}'s Group" group_name = params[:setup_for_company] ? customer_params[:company] : "#{current_user.name}'s Group"
path = Namespace.clean_path(group_name) path = Namespace.clean_path(group_name)
......
...@@ -39,7 +39,7 @@ module SubscriptionsHelper ...@@ -39,7 +39,7 @@ module SubscriptionsHelper
end end
def group_data 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, id: namespace.id,
name: namespace.name, name: namespace.name,
......
...@@ -250,8 +250,9 @@ module EE ...@@ -250,8 +250,9 @@ module EE
.any? .any?
end end
def managed_free_namespaces def manageable_groups_eligible_for_subscription
manageable_groups manageable_groups
.where(parent_id: nil)
.left_joins(:gitlab_subscription) .left_joins(:gitlab_subscription)
.merge(GitlabSubscription.left_joins(:hosted_plan).where(plans: { name: [nil, *::Plan.default_plans] })) .merge(GitlabSubscription.left_joins(:hosted_plan).where(plans: { name: [nil, *::Plan.default_plans] }))
.order(:name) .order(:name)
......
---
title: Show only root namespaces for subscriptions
merge_request: 38481
author:
type: fixed
...@@ -205,6 +205,12 @@ RSpec.describe SubscriptionsController do ...@@ -205,6 +205,12 @@ RSpec.describe SubscriptionsController do
expect(response.body).to eq({ location: "/#{selected_group.path}" }.to_json) expect(response.body).to eq({ location: "/#{selected_group.path}" }.to_json)
end 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 end
context 'when selecting a non existing group' do context 'when selecting a non existing group' do
......
...@@ -996,13 +996,14 @@ RSpec.describe User do ...@@ -996,13 +996,14 @@ RSpec.describe User do
end end
end end
describe '#managed_free_namespaces' do describe '#manageable_groups_eligible_for_subscription' do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:licensed_group) { create(:group, gitlab_subscription: create(:gitlab_subscription, :bronze)) } 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_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(: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 context 'user with no groups' do
it { is_expected.to eq [] } it { is_expected.to eq [] }
...@@ -1047,6 +1048,8 @@ RSpec.describe User do ...@@ -1047,6 +1048,8 @@ RSpec.describe User do
end end
it { is_expected.to eq [free_group_a, free_group_z] } it { is_expected.to eq [free_group_a, free_group_z] }
it { is_expected.not_to include(sub_group) }
end end
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