Commit 89249af3 authored by James Lopez's avatar James Lopez

Merge branch '231177-replace-gl-com-checks-with-app-setting' into 'master'

Replace .com checks with app setting checks

See merge request gitlab-org/gitlab!39150
parents 2a219b40 093f4dea
...@@ -56,6 +56,7 @@ module EE ...@@ -56,6 +56,7 @@ module EE
def purchase_storage_url def purchase_storage_url
return unless ::Gitlab.dev_env_or_com? return unless ::Gitlab.dev_env_or_com?
return unless ::Gitlab::CurrentSettings.enforce_namespace_storage_limit?
return unless ::Feature.enabled?(:buy_storage_link) return unless ::Feature.enabled?(:buy_storage_link)
EE::SUBSCRIPTIONS_MORE_STORAGE_URL EE::SUBSCRIPTIONS_MORE_STORAGE_URL
......
...@@ -33,7 +33,7 @@ module EE ...@@ -33,7 +33,7 @@ module EE
end end
def temporary_storage_increase_visible?(namespace) def temporary_storage_increase_visible?(namespace)
return false unless ::Gitlab.dev_env_or_com? return false unless ::Gitlab::CurrentSettings.enforce_namespace_storage_limit?
return false unless ::Feature.enabled?(:temporary_storage_increase, namespace) return false unless ::Feature.enabled?(:temporary_storage_increase, namespace)
current_user.can?(:admin_namespace, namespace.root_ancestor) current_user.can?(:admin_namespace, namespace.root_ancestor)
......
...@@ -187,7 +187,7 @@ module EE ...@@ -187,7 +187,7 @@ module EE
end end
def over_storage_limit? def over_storage_limit?
::Gitlab.dev_env_or_com? && ::Gitlab::CurrentSettings.enforce_namespace_storage_limit? &&
::Feature.enabled?(:namespace_storage_limit, root_ancestor) && ::Feature.enabled?(:namespace_storage_limit, root_ancestor) &&
RootStorageSize.new(root_ancestor).above_size_limit? RootStorageSize.new(root_ancestor).above_size_limit?
end end
......
---
title: Replace .com check with an app setting to enforce namespace storage limit
merge_request: 39150
author:
type: changed
...@@ -35,28 +35,25 @@ RSpec.describe EE::NamespaceStorageLimitAlertHelper do ...@@ -35,28 +35,25 @@ RSpec.describe EE::NamespaceStorageLimitAlertHelper do
describe '#purchase_storage_url' do describe '#purchase_storage_url' do
subject { helper.purchase_storage_url } subject { helper.purchase_storage_url }
context 'when on .com' do where(:is_dot_com, :enforcement_setting_enabled, :feature_enabled, :result) do
before do false | false | false | nil
allow(::Gitlab).to receive(:com?).and_return(true) false | false | true | nil
end false | true | false | nil
true | false | false | nil
it { is_expected.to eq(EE::SUBSCRIPTIONS_MORE_STORAGE_URL) } false | true | true | nil
true | true | false | nil
context 'when feature flag disabled' do true | false | true | nil
before do true | true | true | EE::SUBSCRIPTIONS_MORE_STORAGE_URL
stub_feature_flags(buy_storage_link: false)
end
it { is_expected.to be_nil }
end
end end
context 'when not on .com' do with_them do
before do before do
allow(::Gitlab).to receive(:com?).and_return(false) allow(::Gitlab).to receive(:com?).and_return(is_dot_com)
stub_application_setting(enforce_namespace_storage_limit: enforcement_setting_enabled)
stub_feature_flags(buy_storage_link: feature_enabled)
end end
it { is_expected.to be_nil } it { is_expected.to eq(result) }
end end
end end
......
...@@ -112,9 +112,9 @@ RSpec.describe EE::NamespacesHelper do ...@@ -112,9 +112,9 @@ RSpec.describe EE::NamespacesHelper do
let_it_be(:admin) { create(:user, namespace: namespace) } let_it_be(:admin) { create(:user, namespace: namespace) }
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
context 'when on .com' do context 'when enforce_namespace_storage_limit setting enabled' do
before do before do
allow(::Gitlab).to receive(:com?).and_return(true) stub_application_setting(enforce_namespace_storage_limit: true)
end end
context 'when current_user is admin of namespace' do context 'when current_user is admin of namespace' do
...@@ -142,7 +142,11 @@ RSpec.describe EE::NamespacesHelper do ...@@ -142,7 +142,11 @@ RSpec.describe EE::NamespacesHelper do
end end
end end
context 'when not on .com' do context 'when enforce_namespace_storage_limit setting disabled' do
before do
stub_application_setting(enforce_namespace_storage_limit: false)
end
context 'when current_user is admin of namespace' do context 'when current_user is admin of namespace' do
before do before do
allow(helper).to receive(:current_user).and_return(admin) allow(helper).to receive(:current_user).and_return(admin)
......
...@@ -1400,7 +1400,7 @@ RSpec.describe Namespace do ...@@ -1400,7 +1400,7 @@ RSpec.describe Namespace do
describe '#over_storage_limit?' do describe '#over_storage_limit?' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
where(:is_dot_com, :feature_enabled, :above_size_limit, :result) do where(:enforcement_setting_enabled, :feature_enabled, :above_size_limit, :result) do
false | false | false | false false | false | false | false
false | false | true | false false | false | true | false
false | true | false | false false | true | false | false
...@@ -1413,7 +1413,7 @@ RSpec.describe Namespace do ...@@ -1413,7 +1413,7 @@ RSpec.describe Namespace do
with_them do with_them do
before do before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(is_dot_com) stub_application_setting(enforce_namespace_storage_limit: enforcement_setting_enabled)
stub_feature_flags(namespace_storage_limit: feature_enabled) stub_feature_flags(namespace_storage_limit: feature_enabled)
allow_next_instance_of(EE::Namespace::RootStorageSize, namespace.root_ancestor) do |project| allow_next_instance_of(EE::Namespace::RootStorageSize, namespace.root_ancestor) do |project|
allow(project).to receive(:above_size_limit?).and_return(above_size_limit) allow(project).to receive(:above_size_limit?).and_return(above_size_limit)
......
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