From cf8bab01d8601f645a2171b8303fa21b6f0fa83f Mon Sep 17 00:00:00 2001
From: Vijay Hawoldar <vhawoldar@gitlab.com>
Date: Fri, 16 Feb 2024 23:21:46 +0000
Subject: [PATCH] Refactors gitlab instance check

Removes gitlab instance check via `should_check_namespace_plan` to use
Gitlab::Saas.feature_available?
---
 .rubocop_todo/gitlab/avoid_gitlab_instance_checks.yml |  1 -
 ee/app/models/namespaces/storage/cost_factor.rb       |  2 +-
 ee/spec/models/namespaces/storage/cost_factor_spec.rb | 10 +++++-----
 ee/spec/presenters/ee/project_presenter_spec.rb       |  2 +-
 ee/spec/support/helpers/namespace_storage_helpers.rb  |  2 +-
 5 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/.rubocop_todo/gitlab/avoid_gitlab_instance_checks.yml b/.rubocop_todo/gitlab/avoid_gitlab_instance_checks.yml
index 8a10208663e5..ef5b876b4174 100644
--- a/.rubocop_todo/gitlab/avoid_gitlab_instance_checks.yml
+++ b/.rubocop_todo/gitlab/avoid_gitlab_instance_checks.yml
@@ -78,7 +78,6 @@ Gitlab/AvoidGitlabInstanceChecks:
     - 'ee/app/models/gitlab_subscription.rb'
     - 'ee/app/models/gitlab_subscriptions/add_on_purchase.rb'
     - 'ee/app/models/gitlab_subscriptions/upcoming_reconciliation.rb'
-    - 'ee/app/models/namespaces/storage/cost_factor.rb'
     - 'ee/app/models/namespaces/storage/enforcement.rb'
     - 'ee/app/policies/ee/global_policy.rb'
     - 'ee/app/policies/ee/group_policy.rb'
diff --git a/ee/app/models/namespaces/storage/cost_factor.rb b/ee/app/models/namespaces/storage/cost_factor.rb
index 6b1c0a695df1..5e9e8ca4fe97 100644
--- a/ee/app/models/namespaces/storage/cost_factor.rb
+++ b/ee/app/models/namespaces/storage/cost_factor.rb
@@ -22,7 +22,7 @@ def inverted_cost_factor_for_forks
       private
 
       def forks_cost_factor
-        if ::Gitlab::CurrentSettings.should_check_namespace_plan?
+        if ::Gitlab::Saas.feature_available?(:gitlab_com_subscriptions)
           ::Gitlab::CurrentSettings.namespace_storage_forks_cost_factor
         else
           FULL_COST
diff --git a/ee/spec/models/namespaces/storage/cost_factor_spec.rb b/ee/spec/models/namespaces/storage/cost_factor_spec.rb
index 96eccaeb8111..f746bd87cb00 100644
--- a/ee/spec/models/namespaces/storage/cost_factor_spec.rb
+++ b/ee/spec/models/namespaces/storage/cost_factor_spec.rb
@@ -10,7 +10,7 @@
 
   before do
     stub_ee_application_setting(namespace_storage_forks_cost_factor: forks_cost_factor)
-    stub_ee_application_setting(check_namespace_plan: true)
+    stub_saas_features(gitlab_com_subscriptions: true)
   end
 
   describe '.cost_factor_for' do
@@ -32,8 +32,8 @@
       expect(described_class.cost_factor_for(project)).to eq(full_cost)
     end
 
-    it 'returns full cost when namespace plans are not checked' do
-      stub_ee_application_setting(check_namespace_plan: false)
+    it 'returns full cost when gitlab_com_subscriptions feature is not available' do
+      stub_saas_features(gitlab_com_subscriptions: false)
       project = build_fork(group: paid_group)
 
       expect(described_class.cost_factor_for(project)).to eq(full_cost)
@@ -45,8 +45,8 @@
       expect(described_class.inverted_cost_factor_for_forks).to eq(0.8)
     end
 
-    it 'returns the inverse of full cost when namespace plans are not checked' do
-      stub_ee_application_setting(check_namespace_plan: false)
+    it 'returns the inverse of full cost when gitlab_com_subscriptions feature is not available' do
+      stub_saas_features(gitlab_com_subscriptions: false)
 
       expect(described_class.inverted_cost_factor_for_forks).to eq(0)
     end
diff --git a/ee/spec/presenters/ee/project_presenter_spec.rb b/ee/spec/presenters/ee/project_presenter_spec.rb
index 4ce50bc972bd..e566ce151426 100644
--- a/ee/spec/presenters/ee/project_presenter_spec.rb
+++ b/ee/spec/presenters/ee/project_presenter_spec.rb
@@ -10,7 +10,7 @@
     let(:presenter) { described_class.new(project, current_user: user) }
 
     before do
-      stub_application_setting(check_namespace_plan: true)
+      stub_saas_features(gitlab_com_subscriptions: true)
       stub_application_setting(namespace_storage_forks_cost_factor: 0.1)
       allow(presenter).to receive(:can?).with(user, :admin_project, project).and_return(true)
       allow(project).to receive(:empty_repo?).and_return(false)
diff --git a/ee/spec/support/helpers/namespace_storage_helpers.rb b/ee/spec/support/helpers/namespace_storage_helpers.rb
index e6b5f1f5cf01..7e35f71d415c 100644
--- a/ee/spec/support/helpers/namespace_storage_helpers.rb
+++ b/ee/spec/support/helpers/namespace_storage_helpers.rb
@@ -27,7 +27,7 @@ def enforce_namespace_storage_limit(root_namespace)
     stub_ee_application_setting(enforce_namespace_storage_limit: true)
     stub_ee_application_setting(automatic_purchased_storage_allocation: true)
     stub_feature_flags(namespace_storage_limit: root_namespace)
-    stub_saas_features(namespaces_storage_limit: true)
+    stub_saas_features(namespaces_storage_limit: true, gitlab_com_subscriptions: true)
 
     allow(::Namespaces::Storage::Enforcement).to receive(:enforceable_namespace?).and_return true
   end
-- 
GitLab