Commit 0067aaa2 authored by Doug Stull's avatar Doug Stull

Remove closest_gitlab_subscription in favor of root_ancestor

- logic is being duplicated and is memoized already.
parent 1bb6a4ab
......@@ -65,7 +65,7 @@ module EE
entity = @project || @group
return unless entity && entity.persisted?
subscription = entity.closest_gitlab_subscription
subscription = entity.root_ancestor.gitlab_subscription
return unless subscription
......
......@@ -211,16 +211,6 @@ module EE
end
end
def closest_gitlab_subscription
strong_memoize(:closest_gitlab_subscription) do
if parent_id
root_ancestor.gitlab_subscription
else
gitlab_subscription
end
end
end
def plan_name_for_upgrading
return ::Plan::FREE if trial_active?
......
......@@ -41,15 +41,15 @@ module EE
def enforce_limit?
return false if Date.current < ENFORCEMENT_DATE
return true unless closest_gitlab_subscription&.has_a_paid_hosted_plan?
return true unless gitlab_subscription&.has_a_paid_hosted_plan?
closest_gitlab_subscription.start_date >= EFFECTIVE_DATE
gitlab_subscription.start_date >= EFFECTIVE_DATE
end
private
attr_reader :root_namespace
delegate :closest_gitlab_subscription, to: :root_namespace
delegate :gitlab_subscription, to: :root_namespace
end
end
......@@ -198,7 +198,6 @@ module EE
delegate :merge_trains_enabled, :merge_trains_enabled=, to: :ci_cd_settings, allow_nil: true
delegate :auto_rollback_enabled, :auto_rollback_enabled=, to: :ci_cd_settings, allow_nil: true
delegate :closest_gitlab_subscription, to: :namespace
delegate :requirements_access_level, to: :project_feature, allow_nil: true
delegate :pipeline_configuration_full_path, to: :compliance_management_framework, allow_nil: true
......
......@@ -129,7 +129,7 @@ module Gitlab
end
def subscription_future_renewal?
return if self_managed? || namespace.nil? || !namespace.closest_gitlab_subscription.present?
return if self_managed? || namespace.nil? || !namespace.root_ancestor.gitlab_subscription.present?
::GitlabSubscriptions::CheckFutureRenewalService.new(namespace: namespace).execute
end
......
......@@ -23,9 +23,10 @@ RSpec.describe EE::SubscribableBannerHelper, :saas do
shared_examples 'when a subscription exists' do
let(:gitlab_subscription) { build_stubbed(:gitlab_subscription) }
let(:root_ancestor) { entity.root_ancestor }
it 'returns a decorator' do
allow(entity).to receive(:closest_gitlab_subscription).and_return(gitlab_subscription)
allow(root_ancestor).to receive(:gitlab_subscription).and_return(gitlab_subscription)
expect(subject).to be_a(SubscriptionPresenter)
end
......@@ -117,7 +118,7 @@ RSpec.describe EE::SubscribableBannerHelper, :saas do
allow(::Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?).and_return(true)
end
let(:gitlab_subscription) { entity.closest_gitlab_subscription }
let(:gitlab_subscription) { entity.root_ancestor.gitlab_subscription }
let(:decorated_mock) { double(:decorated_mock) }
let(:message_mock) { double(:message_mock) }
let(:user) { double(:user_mock) }
......
......@@ -2119,58 +2119,6 @@ RSpec.describe Namespace do
end
end
describe '#closest_gitlab_subscription', :saas do
subject { group.closest_gitlab_subscription }
context 'when there is a root ancestor' do
let(:group) { create(:group, parent: root) }
context 'when root has a subscription' do
let(:root) { create(:group_with_plan) }
it { is_expected.to be_a(GitlabSubscription) }
end
context 'when root has no subscription' do
let(:root) { create(:group) }
it { is_expected.to be_nil }
end
end
context 'when there is no root ancestor' do
context 'for groups' do
context 'has a subscription' do
let(:group) { create(:group_with_plan) }
it { is_expected.to be_a(GitlabSubscription) }
end
context 'it has no subscription' do
let(:group) { create(:group) }
it { is_expected.to be_nil }
end
end
context 'for personal namespaces' do
subject { namespace.closest_gitlab_subscription }
context 'has a subscription' do
let(:namespace) { create(:namespace_with_plan) }
it { is_expected.to be_a(GitlabSubscription) }
end
context 'it has no subscription' do
let(:namespace) { create(:namespace) }
it { is_expected.to be_nil }
end
end
end
end
describe '#namespace_limit' do
let(:group) { create(:group, parent: parent) }
......
......@@ -15,8 +15,6 @@ RSpec.describe Project do
it { is_expected.to delegate_method(:ci_minutes_quota).to(:shared_runners_limit_namespace) }
it { is_expected.to delegate_method(:shared_runners_minutes_limit_enabled?).to(:shared_runners_limit_namespace) }
it { is_expected.to delegate_method(:closest_gitlab_subscription).to(:namespace) }
it { is_expected.to delegate_method(:pipeline_configuration_full_path).to(:compliance_management_framework) }
it { is_expected.to delegate_method(:prevent_merge_without_jira_issue).to(:project_setting) }
......
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