diff --git a/ee/app/components/namespaces/storage/pre_enforcement_alert_component.rb b/ee/app/components/namespaces/storage/pre_enforcement_alert_component.rb index ac3cce2818e0d89041880a7271323d6186242433..06786af559a5f718d1cd9973dd2acaeaf2a3a53a 100644 --- a/ee/app/components/namespaces/storage/pre_enforcement_alert_component.rb +++ b/ee/app/components/namespaces/storage/pre_enforcement_alert_component.rb @@ -3,6 +3,7 @@ module Namespaces module Storage class PreEnforcementAlertComponent < ViewComponent::Base + include ActiveSupport::NumberHelper include SafeFormatHelper include ::Namespaces::CombinedStorageUsers::PreEnforcement @@ -63,18 +64,25 @@ def text_paragraph_1 namespace_name: root_namespace.name, extra_message: paragraph_1_extra_message, storage_limit_link_start: Kernel.format('<a href="%{url}" >', { url: storage_limit_docs_link }).html_safe, - link_end: "</a>".html_safe + link_end: "</a>".html_safe, + limit: dashboard_limit }.merge(strong_tags) safe_format( s_( - "UsageQuota|%{storage_limit_link_start}A namespace storage limit%{link_end} will soon " \ + "UsageQuota|%{storage_limit_link_start}A namespace storage limit%{link_end} of %{limit} will soon " \ "be enforced for the %{strong_start}%{namespace_name}%{strong_end} namespace. %{extra_message}" ), text_args ) end + def dashboard_limit + limit = Namespaces::Storage::RootSize.new(root_namespace).dashboard_limit + + number_to_human_size(limit, delimiter: ',', precision: 2) + end + def usage_quotas_nav_instruction message = if root_namespace.user_namespace? s_("UsageQuota|User settings %{gt} Usage quotas") diff --git a/ee/spec/components/namespaces/storage/pre_enforcement_alert_component_spec.rb b/ee/spec/components/namespaces/storage/pre_enforcement_alert_component_spec.rb index c16f431675797141c7f711ebe600196e6a366689..e8b3e40466eafe88459045d2b7ca5363f56d2418 100644 --- a/ee/spec/components/namespaces/storage/pre_enforcement_alert_component_spec.rb +++ b/ee/spec/components/namespaces/storage/pre_enforcement_alert_component_spec.rb @@ -8,7 +8,7 @@ include NamespaceStorageHelpers include FreeUserCapHelpers - let_it_be(:group) { create(:group_with_plan, :with_root_storage_statistics, plan: :free_plan) } + let_it_be_with_refind(:group) { create(:group_with_plan, :with_root_storage_statistics, plan: :free_plan) } let_it_be_with_refind(:user) { create(:user) } subject(:component) { described_class.new(context: group, user: user) } @@ -17,9 +17,10 @@ stub_ee_application_setting(should_check_namespace_plan: true, automatic_purchased_storage_allocation: true) set_notification_limit(group, megabytes: 5_000) set_used_storage(group, megabytes: 5_100) + set_dashboard_limit(group, megabytes: 5_120, enabled: false) end - describe 'when qalifies for combnined users and storage alert' do + describe 'when qualifies for combined users and storage alert' do let_it_be(:group) do create(:group_with_plan, :with_root_storage_statistics, :private, plan: :free_plan, name: 'over_users_and_storage') @@ -34,7 +35,7 @@ it 'does not render the alert' do render_inline(component) - expect(page).not_to have_text "A namespace storage limit will soon be enforced" + expect(page).not_to have_text "A namespace storage limit of 5 GiB will soon be enforced" end end @@ -110,7 +111,15 @@ it 'indicates the storage limit will be enforced soon in the alert text' do render_inline(component) - expect(page).to have_text "A namespace storage limit will soon be enforced" + expect(page).to have_text "A namespace storage limit of 5 GiB will soon be enforced" + end + + it 'includes any purchased storage in the alert limit' do + set_used_storage(group, megabytes: 16_000) + group.additional_purchased_storage_size = 10_240 + render_inline(component) + + expect(page).to have_text "A namespace storage limit of 15 GiB will soon be enforced" end it 'includes the namespace name in the alert text' do @@ -148,7 +157,7 @@ it 'does not render the alert' do render_inline(component) - expect(page).not_to have_text "A namespace storage limit will soon be enforced" + expect(page).not_to have_text "A namespace storage limit of 5 GiB will soon be enforced" end end @@ -166,7 +175,7 @@ it 'does render the alert' do render_inline(component) - expect(page).to have_text "A namespace storage limit will soon be enforced" + expect(page).to have_text "A namespace storage limit of 5 GiB will soon be enforced" end end diff --git a/ee/spec/components/namespaces/storage/project_pre_enforcement_alert_component_spec.rb b/ee/spec/components/namespaces/storage/project_pre_enforcement_alert_component_spec.rb index b081cbed3057ef7bd6683ae95cd7cc5beb2537d8..ccb843fe3d087e313f5a3bad1a616c9310df3004 100644 --- a/ee/spec/components/namespaces/storage/project_pre_enforcement_alert_component_spec.rb +++ b/ee/spec/components/namespaces/storage/project_pre_enforcement_alert_component_spec.rb @@ -3,6 +3,8 @@ require "spec_helper" RSpec.describe Namespaces::Storage::ProjectPreEnforcementAlertComponent, :saas, feature_category: :consumables_cost_management, type: :component do + include NamespaceStorageHelpers + let_it_be_with_refind(:group) { create(:group, :with_root_storage_statistics) } let_it_be_with_refind(:user) { create(:user) } @@ -10,9 +12,10 @@ before do stub_ee_application_setting(should_check_namespace_plan: true, automatic_purchased_storage_allocation: true) + set_dashboard_limit(group, megabytes: 5_120, enabled: false) + set_notification_limit(group, megabytes: 500) project.add_guest(user) - create(:plan_limits, plan: group.root_ancestor.actual_plan, notification_limit: 500) end shared_examples 'dismissible alert' do @@ -24,7 +27,7 @@ it 'does not render the alert' do render_inline(component) - expect(page).not_to have_text "A namespace storage limit will soon be enforced" + expect(page).not_to have_text "A namespace storage limit of 5 GiB will soon be enforced" end end @@ -36,7 +39,7 @@ it 'does render the alert' do render_inline(component) - expect(page).to have_text "A namespace storage limit will soon be enforced" + expect(page).to have_text "A namespace storage limit of 5 GiB will soon be enforced" end end diff --git a/ee/spec/components/namespaces/storage/user_pre_enforcement_alert_component_spec.rb b/ee/spec/components/namespaces/storage/user_pre_enforcement_alert_component_spec.rb index d4eccbb9a9169dab65e355c2d16599260934f509..be150c8b2023900c7c65deae2aa6466ff46e3343 100644 --- a/ee/spec/components/namespaces/storage/user_pre_enforcement_alert_component_spec.rb +++ b/ee/spec/components/namespaces/storage/user_pre_enforcement_alert_component_spec.rb @@ -4,6 +4,7 @@ RSpec.describe Namespaces::Storage::UserPreEnforcementAlertComponent, :saas, feature_category: :consumables_cost_management, type: :component do include ActionView::Helpers::NumberHelper + include NamespaceStorageHelpers include StorageHelper let_it_be_with_refind(:user) { create(:user) } @@ -36,6 +37,7 @@ context 'when a notification limit has been set' do before do create(:plan_limits, plan: user.namespace.root_ancestor.actual_plan, notification_limit: 500) + set_dashboard_limit(user.namespace, megabytes: 5_120, enabled: false) end it 'includes used storage in the alert text' do @@ -63,7 +65,7 @@ it 'does not render the alert' do render_inline(component) - expect(page).not_to have_text "A namespace storage limit will soon be enforced" + expect(page).not_to have_text "A namespace storage limit of 5 GiB will soon be enforced" end end @@ -80,7 +82,7 @@ it 'does render the alert' do render_inline(component) - expect(page).to have_text "A namespace storage limit will soon be enforced" + expect(page).to have_text "A namespace storage limit of 5 GiB will soon be enforced" end end end diff --git a/ee/spec/features/groups_spec.rb b/ee/spec/features/groups_spec.rb index 160afac169d92f3ddd07e2ab571e28263c3cf2b8..0190a687b0f2efef77cbaa3cee38a48bd314e526 100644 --- a/ee/spec/features/groups_spec.rb +++ b/ee/spec/features/groups_spec.rb @@ -55,12 +55,13 @@ describe 'storage pre-enforcement alert', :js do let_it_be_with_refind(:group) { create(:group, :with_root_storage_statistics) } let_it_be_with_refind(:user) { create(:user) } - let_it_be(:storage_banner_text) { "A namespace storage limit will soon be enforced" } + let_it_be(:storage_banner_text) { "A namespace storage limit of 5 GiB will soon be enforced" } before do stub_ee_application_setting(should_check_namespace_plan: true, automatic_purchased_storage_allocation: true) set_used_storage(group, megabytes: 13) set_notification_limit(group, megabytes: 12) + set_dashboard_limit(group, megabytes: 5_120, enabled: false) group.add_guest(user) sign_in(user) end diff --git a/ee/spec/features/profiles/user_visits_profile_spec.rb b/ee/spec/features/profiles/user_visits_profile_spec.rb index d106e183501156af5535acf84fb1fb5c068bab91..a4a5e54f21dfe120482df71c5aff70669f7029bc 100644 --- a/ee/spec/features/profiles/user_visits_profile_spec.rb +++ b/ee/spec/features/profiles/user_visits_profile_spec.rb @@ -13,7 +13,7 @@ end describe 'storage pre_enforcement banner', :js do - let_it_be(:storage_banner_text) { "A namespace storage limit will soon be enforced" } + let_it_be(:storage_banner_text) { "A namespace storage limit of 5 GiB will soon be enforced" } context 'when storage is over the notification limit' do let_it_be(:root_storage_statistics) do @@ -26,6 +26,7 @@ before do set_notification_limit(user.namespace, megabytes: 500) + set_dashboard_limit(user.namespace, megabytes: 5_120, enabled: false) end it 'displays the banner in the profile page' do diff --git a/ee/spec/features/projects/show_project_spec.rb b/ee/spec/features/projects/show_project_spec.rb index a6b3ac080477466b32cfe7e7effbee34c4a06fd3..7ef217322ca3315d66efdb478444940e06851832 100644 --- a/ee/spec/features/projects/show_project_spec.rb +++ b/ee/spec/features/projects/show_project_spec.rb @@ -72,7 +72,7 @@ context 'with group namespace' do let(:role) { :owner } - let_it_be(:group) { create(:group_with_plan, :private, plan: :free_plan) } + let_it_be_with_refind(:group) { create(:group_with_plan, :private, plan: :free_plan) } before do group.add_member(user, role) diff --git a/ee/spec/features/projects_spec.rb b/ee/spec/features/projects_spec.rb index 582573540c01974308ed317c457023e5201651b8..f6a5536297d1e2b311b57b0ef4593327ff75996c 100644 --- a/ee/spec/features/projects_spec.rb +++ b/ee/spec/features/projects_spec.rb @@ -82,11 +82,12 @@ def remove_with_confirm(button_text, confirm_with, confirm_button_text = 'Confir let_it_be_with_refind(:group) { create(:group, :with_root_storage_statistics) } let_it_be_with_refind(:user) { create(:user) } let_it_be(:project) { create(:project, group: group) } - let_it_be(:storage_banner_text) { "A namespace storage limit will soon be enforced" } + let_it_be(:storage_banner_text) { "A namespace storage limit of 5 GiB will soon be enforced" } before do stub_ee_application_setting(should_check_namespace_plan: true, automatic_purchased_storage_allocation: true) set_notification_limit(group, megabytes: 1000) + set_dashboard_limit(group, megabytes: 5_120) group.root_storage_statistics.update!( storage_size: 5.gigabytes diff --git a/ee/spec/support/helpers/namespace_storage_helpers.rb b/ee/spec/support/helpers/namespace_storage_helpers.rb index d2e46c516ed8966dc3602a56b9440967821ee767..e6b5f1f5cf0163b684c2be73b19dab6e6170af49 100644 --- a/ee/spec/support/helpers/namespace_storage_helpers.rb +++ b/ee/spec/support/helpers/namespace_storage_helpers.rb @@ -9,11 +9,13 @@ def set_used_storage(namespace, megabytes:) namespace.root_storage_statistics.update!(storage_size: megabytes.megabytes) end - def set_dashboard_limit(namespace, megabytes:) - namespace.gitlab_subscription.hosted_plan.actual_limits.update!( - storage_size_limit: megabytes, - dashboard_limit_enabled_at: namespace.created_at - 1.day - ) + def set_dashboard_limit(namespace, megabytes:, enabled: true) + limits = namespace.actual_limits + + limits.storage_size_limit = megabytes + limits.dashboard_limit_enabled_at = namespace.created_at - 1.day if enabled + + limits.save! end def set_notification_limit(namespace, megabytes:) diff --git a/ee/spec/support/shared_examples/features/over_free_user_limit_shared_examples.rb b/ee/spec/support/shared_examples/features/over_free_user_limit_shared_examples.rb index b93b290d8fa459c0beedb16ec7d0c7af9a4ff7f9..0aa7b9800c0b309aa43249399fc3a5a6825be21e 100644 --- a/ee/spec/support/shared_examples/features/over_free_user_limit_shared_examples.rb +++ b/ee/spec/support/shared_examples/features/over_free_user_limit_shared_examples.rb @@ -61,7 +61,7 @@ end context 'without storage size check' do - it 'does not show alerts' do + it 'does show alerts' do stub_feature_flags(free_user_cap_without_storage_check: true) visit_page diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 8cf0c45c7a7e9b4ac4457dc8b063a90a3cc88d8a..a7c5ee47b4423843f522b06a947679629a00a2b0 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -51943,7 +51943,7 @@ msgstr "" msgid "UsageQuota|%{percentageRemaining}%% purchased storage remaining." msgstr "" -msgid "UsageQuota|%{storage_limit_link_start}A namespace storage limit%{link_end} will soon be enforced for the %{strong_start}%{namespace_name}%{strong_end} namespace. %{extra_message}" +msgid "UsageQuota|%{storage_limit_link_start}A namespace storage limit%{link_end} of %{limit} will soon be enforced for the %{strong_start}%{namespace_name}%{strong_end} namespace. %{extra_message}" msgstr "" msgid "UsageQuota|Any additional purchased storage will be displayed here."