Skip to content
代码片段 群组 项目
未验证 提交 8fc0f58c 编辑于 作者: Rodrigo Tomonari's avatar Rodrigo Tomonari 提交者: GitLab
浏览文件

Merge branch '501646-consolidate-scopes' into 'master'

Consolidate to use specific plans scope for Namespaces

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/173306



Merged-by: default avatarRodrigo Tomonari <rtomonari@gitlab.com>
Approved-by: default avatarMax Woolf <mwoolf@gitlab.com>
Approved-by: default avatarTiger Watson <twatson@gitlab.com>
Approved-by: default avatarMichał Zając <mzajac@gitlab.com>
Approved-by: default avatarRodrigo Tomonari <rtomonari@gitlab.com>
Reviewed-by: default avatarMax Woolf <mwoolf@gitlab.com>
Co-authored-by: default avatarDoug Stull <dstull@gitlab.com>
No related branches found
No related tags found
无相关合并请求
......@@ -18,12 +18,20 @@ def initial_scope
if params[:user] && params[:namespace]
raise ArgumentError, 'Only User or Namespace can be provided, not both'
elsif params[:user]
params[:user].owned_groups.eligible_for_trial.ordered_by_name
params[:user]
.owned_groups
.in_specific_plans([no_subscription_plan_name, *::Plan::PLANS_ELIGIBLE_FOR_TRIAL])
.ordered_by_name
elsif params[:namespace]
Namespace.id_in(params[:namespace])
else
raise ArgumentError, 'User or Namespace must be provided'
end
end
def no_subscription_plan_name
# Subscriptions aren't created until needed/looked at
nil
end
end
end
......@@ -77,14 +77,9 @@ module Namespace
.allow_cross_joins_across_databases(url: "https://gitlab.com/gitlab-org/gitlab/-/issues/419988")
end
scope :not_in_default_plan, -> do
left_joins(gitlab_subscription: :hosted_plan)
.where.not(plans: { name: [nil, *::Plan.default_plans] })
.allow_cross_joins_across_databases(url: "https://gitlab.com/gitlab-org/gitlab/-/issues/419988")
end
scope :in_specific_plans, ->(plan_names) do
left_joins(gitlab_subscription: :hosted_plan)
top_level
.left_joins(gitlab_subscription: :hosted_plan)
.where(plans: { name: plan_names })
.allow_cross_joins_across_databases(url: "https://gitlab.com/gitlab-org/gitlab/-/issues/419988")
end
......@@ -126,14 +121,6 @@ module Namespace
.where(no_add_on.or(not_started_yet.or(not_a_trial.or(not_duo_pro.or(is_expired)))))
end
scope :eligible_for_trial, -> do
left_joins(gitlab_subscription: :hosted_plan)
.top_level
.where(
plans: { name: [nil, *::Plan::PLANS_ELIGIBLE_FOR_TRIAL] }
).allow_cross_joins_across_databases(url: "https://gitlab.com/gitlab-org/gitlab/-/issues/419988")
end
scope :with_feature_available_in_plan, ->(feature) do
plans = GitlabSubscriptions::Features.saas_plans_with_feature(feature)
matcher = ::Plan.by_name(plans)
......
......@@ -350,38 +350,10 @@
end
end
describe '.not_in_default_plan', :saas do
subject { described_class.not_in_default_plan.ids }
where(:plan_name, :expect_in_default_plan) do
::Plan::FREE | true
::Plan::DEFAULT | true
::Plan::BRONZE | false
::Plan::SILVER | false
::Plan::PREMIUM | false
::Plan::GOLD | false
::Plan::ULTIMATE | false
end
with_them do
it 'returns expected result' do
namespace = create(:namespace_with_plan, plan: "#{plan_name}_plan")
is_expected.to eq(expect_in_default_plan ? [] : [namespace.id])
end
end
it 'does not include namespace without subscription' do
create(:namespace)
is_expected.to eq([])
end
end
describe '.in_specific_plans', :saas do
let_it_be(:free_namespace) { create(:namespace_with_plan, plan: :free_plan) }
let_it_be(:premium_namespace) { create(:namespace_with_plan, plan: :premium_plan) }
let_it_be(:ultimate_namespace) { create(:namespace_with_plan, plan: :ultimate_plan) }
let_it_be(:free_namespace) { create(:group_with_plan, plan: :free_plan) }
let_it_be(:premium_namespace) { create(:group_with_plan, plan: :premium_plan) }
let_it_be(:ultimate_namespace) { create(:group_with_plan, plan: :ultimate_plan) }
it 'returns namespaces with the specified plan names' do
result = described_class.in_specific_plans(%w[ultimate premium])
......@@ -414,6 +386,14 @@
expect(result).to contain_exactly(ultimate_namespace)
end
it 'does not return subgroups' do
subgroup = create(:group, parent: ultimate_namespace)
result = described_class.id_in(subgroup).in_specific_plans([nil])
expect(result).to be_empty
end
end
describe '.not_duo_pro_or_no_add_on', :saas do
......@@ -486,42 +466,6 @@
end
end
describe '.eligible_for_trial', :saas do
let_it_be(:namespace) { create :namespace }
subject { described_class.eligible_for_trial }
context 'when there is no subscription' do
it { is_expected.to contain_exactly(namespace) }
end
context 'when there is a subscription' do
context 'with a plan that is eligible for a trial' do
where(plan: ::Plan::PLANS_ELIGIBLE_FOR_TRIAL)
with_them do
before do
create :gitlab_subscription, plan, namespace: namespace
end
it { is_expected.to contain_exactly(namespace) }
end
end
context 'with a plan that is ineligible for a trial' do
where(plan: ::Plan::PAID_HOSTED_PLANS.without(::Plan::PREMIUM))
with_them do
before do
create :gitlab_subscription, plan, namespace: namespace
end
it { is_expected.to be_empty }
end
end
end
end
describe '.namespace_settings_with_ai_features_enabled' do
subject { described_class.namespace_settings_with_ai_features_enabled }
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册