Commit bb98b3b7 authored by Adam Hegyi's avatar Adam Hegyi

Merge branch '208894-fix-showing-only-free-namespaces-when-applying-licenses' into 'master'

Resolve "Fix showing only free namespaces when applying licenses"

Closes #208894

See merge request gitlab-org/gitlab!27356
parents 3eed57f6 18e0789f
---
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 ...@@ -37,7 +37,7 @@ module SubscriptionsHelper
end end
def group_data 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, id: namespace.id,
name: namespace.name, name: namespace.name,
......
...@@ -243,7 +243,10 @@ module EE ...@@ -243,7 +243,10 @@ module EE
end end
def managed_free_namespaces 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 end
override :has_current_license? override :has_current_license?
......
...@@ -954,9 +954,9 @@ describe User do ...@@ -954,9 +954,9 @@ describe User do
describe '#managed_free_namespaces' do describe '#managed_free_namespaces' do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:licensed_group) { create(:group, plan: :bronze_plan) } let_it_be(:licensed_group) { create(:group, gitlab_subscription: create(:gitlab_subscription, :bronze)) }
let_it_be(:free_group_z) { create(:group, plan: :default_plan, name: 'Z') } let_it_be(:free_group_z) { create(:group, name: 'Z', gitlab_subscription: create(:gitlab_subscription, :free)) }
let_it_be(:free_group_a) { create(:group, plan: :default_plan, name: 'A') } let_it_be(:free_group_a) { create(:group, name: 'A', gitlab_subscription: create(:gitlab_subscription, :free)) }
subject { user.managed_free_namespaces } 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