Commit d580d4e1 authored by Sean McGivern's avatar Sean McGivern Committed by Heinrich Lee Yu

Fix EE::User#has_paid_namespace? plan check

parent a2982624
...@@ -231,8 +231,9 @@ module EE ...@@ -231,8 +231,9 @@ module EE
def has_paid_namespace? def has_paid_namespace?
::Namespace ::Namespace
.from("(#{namespace_union_for_reporter_developer_maintainer_owned(:plan_id)}) #{::Namespace.table_name}") .from("(#{namespace_union_for_reporter_developer_maintainer_owned}) #{::Namespace.table_name}")
.where(plan_id: Plan.where(name: Plan::PAID_HOSTED_PLANS).select(:id)) .include_gitlab_subscription
.where(gitlab_subscriptions: { hosted_plan_id: Plan.where(name: Plan::PAID_HOSTED_PLANS) })
.any? .any?
end end
......
...@@ -1029,4 +1029,39 @@ describe User do ...@@ -1029,4 +1029,39 @@ describe User do
end end
end end
end end
describe '#has_paid_namespace?' do
let_it_be(:user) { create(:user) }
let_it_be(:gold_group) { create(:group_with_plan, plan: :gold_plan) }
let_it_be(:bronze_group) { create(:group_with_plan, plan: :bronze_plan) }
let_it_be(:free_group) { create(:group_with_plan, plan: :free_plan) }
let_it_be(:group_without_plan) { create(:group) }
context 'when the user has Reporter or higher on at least one paid group' do
it 'returns true' do
gold_group.add_reporter(user)
bronze_group.add_guest(user)
expect(user.has_paid_namespace?).to eq(true)
end
end
context 'when the user is only a Guest on paid groups' do
it 'returns false' do
gold_group.add_guest(user)
bronze_group.add_guest(user)
free_group.add_owner(user)
expect(user.has_paid_namespace?).to eq(false)
end
end
context 'when the user is not a member of any groups with plans' do
it 'returns false' do
group_without_plan.add_owner(user)
expect(user.has_paid_namespace?).to eq(false)
end
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