From 1a35e03ec5b7775e65bf14b21be15f4b5549f3be Mon Sep 17 00:00:00 2001
From: Sheldon Led <sheldonled@gitlab.com>
Date: Wed, 6 Dec 2023 12:53:36 +0000
Subject: [PATCH] Use dashboard limit on storage alerts

---
 .../namespaces/storage/limit_alert_component.rb   |  8 ++++++--
 .../storage/repository_limit_alert_component.rb   |  8 ++++++--
 .../storage/limit_alert_component_spec.rb         | 15 +++++++++++++--
 3 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/ee/app/components/namespaces/storage/limit_alert_component.rb b/ee/app/components/namespaces/storage/limit_alert_component.rb
index 0f60ef3d2ba2b..f5d8524bec1bf 100644
--- a/ee/app/components/namespaces/storage/limit_alert_component.rb
+++ b/ee/app/components/namespaces/storage/limit_alert_component.rb
@@ -125,6 +125,10 @@ def user_has_access?
         end
       end
 
+      def limit
+        root_storage_size.dashboard_limit
+      end
+
       def namespace_has_additional_storage_purchased?
         root_namespace.additional_purchased_storage_size > 0
       end
@@ -149,7 +153,7 @@ def show_purchase_link?
       def free_tier_alert_title
         text_args = {
           namespace_name: root_namespace.name,
-          free_size_limit: formatted(root_namespace.actual_size_limit)
+          free_size_limit: formatted(limit)
         }
 
         s_(
@@ -162,7 +166,7 @@ def usage_percentage_alert_title
           usage_in_percent: used_storage_percentage(root_storage_size.usage_ratio),
           namespace_name: root_namespace.name,
           used_storage: formatted(root_storage_size.current_size),
-          storage_limit: formatted(root_storage_size.limit)
+          storage_limit: formatted(limit)
         }
 
         s_(
diff --git a/ee/app/components/namespaces/storage/repository_limit_alert_component.rb b/ee/app/components/namespaces/storage/repository_limit_alert_component.rb
index c85c9bf830717..f94f738aefb37 100644
--- a/ee/app/components/namespaces/storage/repository_limit_alert_component.rb
+++ b/ee/app/components/namespaces/storage/repository_limit_alert_component.rb
@@ -45,7 +45,7 @@ def usage_percentage_alert_title
       def free_tier_alert_title
         text_args = {
           readonly_project_count: root_namespace.repository_size_excess_project_count,
-          free_size_limit: formatted(root_namespace.actual_size_limit)
+          free_size_limit: formatted(limit)
         }
 
         ns_(
@@ -59,7 +59,7 @@ def free_tier_alert_title
 
       def alert_message_explanation
         text_args = {
-          free_size_limit: formatted(root_namespace.actual_size_limit)
+          free_size_limit: formatted(limit)
         }
 
         if root_storage_size.above_size_limit?
@@ -114,6 +114,10 @@ def alert_message_cta
           s_("NamespaceStorageSize|To reduce storage usage, reduce git repository and git LFS storage.")
         end
       end
+
+      def limit
+        root_namespace.actual_size_limit
+      end
     end
   end
 end
diff --git a/ee/spec/components/namespaces/storage/limit_alert_component_spec.rb b/ee/spec/components/namespaces/storage/limit_alert_component_spec.rb
index 050e1eed52f12..3295402b4f311 100644
--- a/ee/spec/components/namespaces/storage/limit_alert_component_spec.rb
+++ b/ee/spec/components/namespaces/storage/limit_alert_component_spec.rb
@@ -21,7 +21,7 @@
   let(:usage_ratio) { 0.8 }
   let(:above_size_limit) { false }
   let(:alert_title) { /You have used \d+% of the storage quota for #{group.name}/ }
-  let(:alert_title_free_tier) { "You have reached the free storage limit of 1,000 MiB for #{group.name}" }
+  let(:alert_title_free_tier) { "You have reached the free storage limit of 5 GiB for #{group.name}" }
 
   let(:alert_message_below_limit) do
     "If #{group.name} exceeds the storage quota, your ability to write new data to this namespace will be " \
@@ -56,7 +56,7 @@
         allow(size_checker).to receive(:above_size_limit?).and_return(above_size_limit)
       end
 
-      allow(group).to receive(:actual_size_limit).and_return(1000.megabytes)
+      set_dashboard_limit(group, megabytes: 5120)
       stub_member_access_level(group, owner: user)
     end
 
@@ -137,6 +137,17 @@
         end
       end
     end
+
+    context 'and enforcement_limit is higher than dashboard_limit' do
+      before do
+        set_enforcement_limit(group, megabytes: 10240)
+      end
+
+      it 'renders the title with the dashboard_limit' do
+        render_inline(component)
+        expect(page).to have_content('5 GiB')
+      end
+    end
   end
 
   describe '#render?' do
-- 
GitLab