Commit 18e0789f authored by Alex Buijs's avatar Alex Buijs

Fix managed_free_namespaces scope

Don’t rely on Namespace#plan_id column, but
instead joing with gitlab_subscriptions
parent 72d37d24
---
title: Fix managed_free_namespaces scope to only groups without a license or a free license
merge_request: 27356
author:
type: fixed
......@@ -37,7 +37,7 @@ module SubscriptionsHelper
end
def group_data
current_user.managed_free_namespaces.map do |namespace|
current_user.managed_free_namespaces.with_counts(archived: false).map do |namespace|
{
id: namespace.id,
name: namespace.name,
......
......@@ -243,7 +243,10 @@ module EE
end
def managed_free_namespaces
manageable_groups.with_counts(archived: false).where(plan: [nil, Plan.free, Plan.default]).order(:name)
manageable_groups
.left_joins(:gitlab_subscription)
.merge(GitlabSubscription.left_joins(:hosted_plan).where(plans: { name: [nil, *Plan::DEFAULT_PLANS] }))
.order(:name)
end
override :has_current_license?
......
......@@ -941,9 +941,9 @@ describe User do
describe '#managed_free_namespaces' do
let_it_be(:user) { create(:user) }
let_it_be(:licensed_group) { create(:group, plan: :bronze_plan) }
let_it_be(:free_group_z) { create(:group, plan: :default_plan, name: 'Z') }
let_it_be(:free_group_a) { create(:group, plan: :default_plan, name: 'A') }
let_it_be(:licensed_group) { create(:group, gitlab_subscription: create(:gitlab_subscription, :bronze)) }
let_it_be(:free_group_z) { create(:group, name: 'Z', gitlab_subscription: create(:gitlab_subscription, :free)) }
let_it_be(:free_group_a) { create(:group, name: 'A', gitlab_subscription: create(:gitlab_subscription, :free)) }
subject { user.managed_free_namespaces }
......
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