Skip to content
Snippets Groups Projects
Commit bf79370d authored by Doug Stull's avatar Doug Stull :two:
Browse files

Merge branch 'vij-move-enforcement-class' into 'master'

Moves EE::Gitlab::Namespaces::Storage::Enforcement

See merge request !119035



Merged-by: Doug Stull's avatarDoug Stull <dstull@gitlab.com>
Approved-by: Doug Stull's avatarDoug Stull <dstull@gitlab.com>
Approved-by: default avatarMohamed Hamda <mhamda@gitlab.com>
Reviewed-by: Doug Stull's avatarDoug Stull <dstull@gitlab.com>
Reviewed-by: default avatarMohamed Hamda <mhamda@gitlab.com>
Co-authored-by: default avatarVijay Hawoldar <vhawoldar@gitlab.com>
parents 78d17d87 7528895f
No related branches found
No related tags found
2 merge requests!122597doc/gitaly: Remove references to removed metrics,!119035Moves EE::Gitlab::Namespaces::Storage::Enforcement
Pipeline #853808203 passed
Showing
with 85 additions and 90 deletions
......@@ -713,7 +713,6 @@ RSpec/MissingFeatureCategory:
- 'ee/spec/lib/ee/gitlab/metrics/samplers/database_sampler_spec.rb'
- 'ee/spec/lib/ee/gitlab/middleware/read_only_spec.rb'
- 'ee/spec/lib/ee/gitlab/namespace_storage_size_error_message_spec.rb'
- 'ee/spec/lib/ee/gitlab/namespaces/storage/enforcement_spec.rb'
- 'ee/spec/lib/ee/gitlab/omniauth_initializer_spec.rb'
- 'ee/spec/lib/ee/gitlab/pages/deployment_update_spec.rb'
- 'ee/spec/lib/ee/gitlab/prometheus/metric_group_spec.rb'
......
......@@ -127,7 +127,7 @@ def show_purchase_link?
def enforcement_type
@enforcement_type ||=
if ::EE::Gitlab::Namespaces::Storage::Enforcement.enforce_limit?(root_namespace)
if ::Namespaces::Storage::Enforcement.enforce_limit?(root_namespace)
:namespace
else
:repository
......
......@@ -13,7 +13,7 @@ def initialize(context:, user:)
def render?
return false unless user_allowed?
return false unless ::EE::Gitlab::Namespaces::Storage::Enforcement.show_pre_enforcement_alert?(root_namespace)
return false unless ::Namespaces::Storage::Enforcement.show_pre_enforcement_alert?(root_namespace)
!dismissed?
end
......
......@@ -63,7 +63,7 @@ def storage_usage_app_data(namespace)
super.merge({
purchase_storage_url: buy_storage_path(namespace),
buy_addon_target_attr: buy_addon_target_attr(namespace),
storage_limit_enforced: ::EE::Gitlab::Namespaces::Storage::Enforcement.enforce_limit?(namespace).to_s,
storage_limit_enforced: ::Namespaces::Storage::Enforcement.enforce_limit?(namespace).to_s,
can_show_inline_alert: project_storage_limit_enforced?(namespace).to_s
})
end
......
......@@ -441,7 +441,7 @@ def enable_temporary_storage_increase!
end
def root_storage_size
if ::EE::Gitlab::Namespaces::Storage::Enforcement.enforce_limit?(root_ancestor)
if ::Namespaces::Storage::Enforcement.enforce_limit?(root_ancestor)
::Namespaces::Storage::RootSize.new(root_ancestor)
else
::Namespaces::Storage::RootExcessSize.new(root_ancestor)
......
......@@ -755,7 +755,7 @@ def repository_size_checker
strong_memoize(:repository_size_checker) do
root_namespace = namespace.root_ancestor
if ::EE::Gitlab::Namespaces::Storage::Enforcement.enforce_limit?(root_namespace)
if ::Namespaces::Storage::Enforcement.enforce_limit?(root_namespace)
::Namespaces::Storage::RootSize.new(root_namespace)
else
::Gitlab::RepositorySizeChecker.new(
......
# frozen_string_literal: true
module Namespaces
module Storage
class Enforcement
ENFORCEMENT_DATE = 100.years.from_now.to_date
EFFECTIVE_DATE = 99.years.from_now.to_date
def self.enforce_limit?(namespace)
root_namespace = namespace.root_ancestor
::Gitlab::CurrentSettings.enforce_namespace_storage_limit? &&
::Gitlab::CurrentSettings.automatic_purchased_storage_allocation? &&
::Feature.enabled?(:namespace_storage_limit, root_namespace) &&
enforceable_plan?(root_namespace) &&
enforceable_dates?(root_namespace)
end
def self.show_pre_enforcement_alert?(namespace)
root_namespace = namespace.root_ancestor
if ::Gitlab::CurrentSettings.should_check_namespace_plan? &&
!root_namespace.paid? &&
reached_pre_enforcement_notification_limit?(root_namespace)
return ::Feature.enabled?(:namespace_storage_limit_show_preenforcement_banner, root_namespace)
end
false
end
def self.reached_pre_enforcement_notification_limit?(root_namespace)
return false if root_namespace.storage_limit_exclusion.present?
notification_limit = root_namespace.actual_plan.actual_limits.notification_limit.megabytes
return false unless notification_limit > 0
total_storage = ::Namespaces::Storage::RootSize.new(root_namespace).current_size
purchased_storage = (root_namespace.additional_purchased_storage_size || 0)
total_storage >= (notification_limit + purchased_storage)
end
private_class_method def self.enforceable_plan?(root_namespace)
return false if root_namespace.opensource_plan?
if root_namespace.paid?
::Feature.enabled?(:enforce_storage_limit_for_paid, root_namespace)
else
::Feature.enabled?(:enforce_storage_limit_for_free, root_namespace)
end
end
private_class_method def self.enforceable_dates?(root_namespace)
::Feature.enabled?(:namespace_storage_limit_bypass_date_check, root_namespace) ||
(Date.current >= ENFORCEMENT_DATE && root_namespace.gitlab_subscription.start_date >= EFFECTIVE_DATE)
end
end
end
end
......@@ -55,7 +55,7 @@ def valid_enforcement?
end
def enforce_limit?
::EE::Gitlab::Namespaces::Storage::Enforcement.enforce_limit?(root_namespace)
::Namespaces::Storage::Enforcement.enforce_limit?(root_namespace)
end
alias_method :enabled?, :enforce_limit?
......
......@@ -9,7 +9,7 @@ module RootStatisticsWorker
override :notify_storage_usage
def notify_storage_usage(namespace)
return unless ::EE::Gitlab::Namespaces::Storage::Enforcement.enforce_limit?(namespace)
return unless ::Namespaces::Storage::Enforcement.enforce_limit?(namespace)
mailer = ::Emails::NamespaceStorageUsageMailer
::Namespaces::Storage::EmailNotificationService.new(mailer).execute(namespace)
......
# frozen_string_literal: true
module EE
module Gitlab
module Namespaces
module Storage
class Enforcement
ENFORCEMENT_DATE = 100.years.from_now.to_date
EFFECTIVE_DATE = 99.years.from_now.to_date
def self.enforce_limit?(namespace)
root_namespace = namespace.root_ancestor
::Gitlab::CurrentSettings.enforce_namespace_storage_limit? &&
::Gitlab::CurrentSettings.automatic_purchased_storage_allocation? &&
::Feature.enabled?(:namespace_storage_limit, root_namespace) &&
enforceable_plan?(root_namespace) &&
enforceable_dates?(root_namespace)
end
def self.show_pre_enforcement_alert?(namespace)
root_namespace = namespace.root_ancestor
if ::Gitlab::CurrentSettings.should_check_namespace_plan? &&
!root_namespace.paid? &&
reached_pre_enforcement_notification_limit?(root_namespace)
return ::Feature.enabled?(:namespace_storage_limit_show_preenforcement_banner, root_namespace)
end
false
end
def self.reached_pre_enforcement_notification_limit?(root_namespace)
return false if root_namespace.storage_limit_exclusion.present?
notification_limit = root_namespace.actual_plan.actual_limits.notification_limit.megabytes
return false unless notification_limit > 0
total_storage = ::Namespaces::Storage::RootSize.new(root_namespace).current_size
purchased_storage = (root_namespace.additional_purchased_storage_size || 0)
total_storage >= (notification_limit + purchased_storage)
end
private_class_method def self.enforceable_plan?(root_namespace)
return false if root_namespace.opensource_plan?
if root_namespace.paid?
::Feature.enabled?(:enforce_storage_limit_for_paid, root_namespace)
else
::Feature.enabled?(:enforce_storage_limit_for_free, root_namespace)
end
end
private_class_method def self.enforceable_dates?(root_namespace)
::Feature.enabled?(:namespace_storage_limit_bypass_date_check, root_namespace) ||
(Date.current >= ENFORCEMENT_DATE && root_namespace.gitlab_subscription.start_date >= EFFECTIVE_DATE)
end
end
end
end
end
end
......@@ -140,7 +140,7 @@
group: group,
feature_name: 'namespace_storage_pre_enforcement_banner'
)
allow(::EE::Gitlab::Namespaces::Storage::Enforcement).to receive(:show_pre_enforcement_alert?).and_return(false)
allow(::Namespaces::Storage::Enforcement).to receive(:show_pre_enforcement_alert?).and_return(false)
end
it 'does not render' do
......@@ -168,7 +168,7 @@
context 'when group does not meet the criteria to render the alert' do
it 'does not render' do
allow(::EE::Gitlab::Namespaces::Storage::Enforcement)
allow(::Namespaces::Storage::Enforcement)
.to receive(:show_pre_enforcement_alert?).and_return(false)
render_inline(component)
......
......@@ -271,7 +271,7 @@
context 'when project-level storage limits are enabled' do
before do
allow(::EE::Gitlab::Namespaces::Storage::Enforcement).to receive(:enforce_limit?).with(group).and_return(false)
allow(::Namespaces::Storage::Enforcement).to receive(:enforce_limit?).with(group).and_return(false)
end
context 'when the project limit is enforced' do
......@@ -293,7 +293,7 @@
context 'when namespace-level storage limits are enabled' do
before do
allow(::EE::Gitlab::Namespaces::Storage::Enforcement).to receive(:enforce_limit?).with(group).and_return(true)
allow(::Namespaces::Storage::Enforcement).to receive(:enforce_limit?).with(group).and_return(true)
end
it { is_expected.to be false }
......
......@@ -1541,8 +1541,8 @@
before do
stub_application_setting(enforce_namespace_storage_limit: true)
stub_application_setting(automatic_purchased_storage_allocation: true)
stub_const('::EE::Gitlab::Namespaces::Storage::Enforcement::EFFECTIVE_DATE', 2.years.ago.to_date)
stub_const('::EE::Gitlab::Namespaces::Storage::Enforcement::ENFORCEMENT_DATE', 1.year.ago.to_date)
stub_const('::Namespaces::Storage::Enforcement::EFFECTIVE_DATE', 2.years.ago.to_date)
stub_const('::Namespaces::Storage::Enforcement::ENFORCEMENT_DATE', 1.year.ago.to_date)
stub_feature_flags(
namespace_storage_limit: true,
enforce_storage_limit_for_paid: false,
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe ::EE::Gitlab::Namespaces::Storage::Enforcement, :saas do
RSpec.describe Namespaces::Storage::Enforcement, :saas, feature_category: :consumables_cost_management do
include NamespaceStorageHelpers
using RSpec::Parameterized::TableSyntax
......@@ -302,10 +302,10 @@
end
def stub_enforcement_date(date)
stub_const('::EE::Gitlab::Namespaces::Storage::Enforcement::ENFORCEMENT_DATE', date)
stub_const('::Namespaces::Storage::Enforcement::ENFORCEMENT_DATE', date)
end
def stub_effective_date(date)
stub_const('::EE::Gitlab::Namespaces::Storage::Enforcement::EFFECTIVE_DATE', date)
stub_const('::Namespaces::Storage::Enforcement::EFFECTIVE_DATE', date)
end
end
......@@ -277,7 +277,7 @@
end
context 'when current date is before enforcement date' do
let(:current_date) { ::EE::Gitlab::Namespaces::Storage::Enforcement::ENFORCEMENT_DATE - 1.day }
let(:current_date) { ::Namespaces::Storage::Enforcement::ENFORCEMENT_DATE - 1.day }
it { is_expected.to eq(false) }
......@@ -285,7 +285,7 @@
end
context 'when current date is on or after enforcement date' do
let(:current_date) { ::EE::Gitlab::Namespaces::Storage::Enforcement::ENFORCEMENT_DATE }
let(:current_date) { ::Namespaces::Storage::Enforcement::ENFORCEMENT_DATE }
context 'when no subscription is found for namespace' do
let(:namespace_without_subscription) { create(:namespace) }
......@@ -303,7 +303,7 @@
end
context 'when subscription start date is before effective date' do
let(:start_date) { ::EE::Gitlab::Namespaces::Storage::Enforcement::EFFECTIVE_DATE - 1.day }
let(:start_date) { ::Namespaces::Storage::Enforcement::EFFECTIVE_DATE - 1.day }
before do
allow(subscription).to receive(:start_date).and_return(start_date)
......
......@@ -427,8 +427,8 @@ def check_access_by_alias(alias_name)
before do
stub_application_setting(enforce_namespace_storage_limit: true)
stub_application_setting(automatic_purchased_storage_allocation: true)
stub_const('::EE::Gitlab::Namespaces::Storage::Enforcement::EFFECTIVE_DATE', 2.years.ago.to_date)
stub_const('::EE::Gitlab::Namespaces::Storage::Enforcement::ENFORCEMENT_DATE', 1.year.ago.to_date)
stub_const('::Namespaces::Storage::Enforcement::EFFECTIVE_DATE', 2.years.ago.to_date)
stub_const('::Namespaces::Storage::Enforcement::ENFORCEMENT_DATE', 1.year.ago.to_date)
stub_feature_flags(
namespace_storage_limit: true,
enforce_storage_limit_for_paid: false,
......
......@@ -16,8 +16,8 @@ def set_notification_limit(namespace, megabytes:)
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_const('::EE::Gitlab::Namespaces::Storage::Enforcement::EFFECTIVE_DATE', 2.years.ago.to_date)
stub_const('::EE::Gitlab::Namespaces::Storage::Enforcement::ENFORCEMENT_DATE', 1.year.ago.to_date)
stub_const('::Namespaces::Storage::Enforcement::EFFECTIVE_DATE', 2.years.ago.to_date)
stub_const('::Namespaces::Storage::Enforcement::ENFORCEMENT_DATE', 1.year.ago.to_date)
stub_feature_flags(
namespace_storage_limit: root_namespace,
enforce_storage_limit_for_paid: root_namespace,
......
......@@ -20,7 +20,7 @@
context 'when storage limits are enforced for the namespace' do
before do
allow(::EE::Gitlab::Namespaces::Storage::Enforcement).to receive(:enforce_limit?).with(group).and_return(true)
allow(::Namespaces::Storage::Enforcement).to receive(:enforce_limit?).with(group).and_return(true)
end
context 'when the namespace is running low on storage' do
......@@ -84,7 +84,7 @@
context 'when storage limits are not enforced for the namespace' do
before do
allow(::EE::Gitlab::Namespaces::Storage::Enforcement).to receive(:enforce_limit?).with(group).and_return(false)
allow(::Namespaces::Storage::Enforcement).to receive(:enforce_limit?).with(group).and_return(false)
end
context 'when the namespace is running low on storage' do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment