Commit f7384cc8 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '247846-global-storage-alert-text' into 'master'

Make storage alert text more dynamic

See merge request gitlab-org/gitlab!45570
parents a8067094 70cb290e
...@@ -15,11 +15,16 @@ module Namespaces ...@@ -15,11 +15,16 @@ module Namespaces
def usage_message def usage_message
if root_namespace.contains_locked_projects? if root_namespace.contains_locked_projects?
params = { namespace_name: root_namespace.name,
locked_project_count: root_namespace.repository_size_excess_project_count,
free_size_limit: formatted(root_namespace.actual_size_limit) }
if root_namespace.additional_purchased_storage_size == 0 if root_namespace.additional_purchased_storage_size == 0
params = { locked_project_count: root_namespace.repository_size_excess_project_count } ns_("NamespaceStorageSize|You have reached the free storage limit of %{free_size_limit} on %{locked_project_count} project. To unlock it, please purchase additional storage",
s_("NamespaceStorageSize|You have reached the free storage limit of 10GB on %{locked_project_count} projects. To unlock them, please purchase additional storage" % params) "NamespaceStorageSize|You have reached the free storage limit of %{free_size_limit} on %{locked_project_count} projects. To unlock them, please purchase additional storage",
params[:locked_project_count]) % params
else else
s_("NamespaceStorageSize|%{namespace_name} contains a locked project" % { namespace_name: root_namespace.name }) ns_("NamespaceStorageSize|%{namespace_name} contains %{locked_project_count} locked project", "NamespaceStorageSize|%{namespace_name} contains %{locked_project_count} locked projects", params[:locked_project_count]) % params
end end
else else
s_("NamespaceStorageSize|You have reached %{usage_in_percent} of %{namespace_name}'s storage capacity (%{used_storage} of %{storage_limit})" % current_usage_params) s_("NamespaceStorageSize|You have reached %{usage_in_percent} of %{namespace_name}'s storage capacity (%{used_storage} of %{storage_limit})" % current_usage_params)
...@@ -28,10 +33,14 @@ module Namespaces ...@@ -28,10 +33,14 @@ module Namespaces
def above_size_limit_message def above_size_limit_message
if root_namespace.additional_purchased_storage_size > 0 if root_namespace.additional_purchased_storage_size > 0
s_("NamespaceStorageSize|You have consumed all of your additional storage, please purchase more to unlock your projects over the free 10GB limit. You can't %{base_message}" % { base_message: base_message }) s_("NamespaceStorageSize|You have consumed all of your additional storage, please purchase more to unlock your projects over the free %{free_size_limit} limit. You can't %{base_message}" % { base_message: base_message, free_size_limit: formatted(root_namespace.actual_size_limit) })
else else
s_("NamespaceStorageSize|Please purchase additional storage to unlock your projects over the free 10GB project limit. You can't %{base_message}" % { base_message: base_message }) s_("NamespaceStorageSize|Please purchase additional storage to unlock your projects over the free %{free_size_limit} project limit. You can't %{base_message}" % { base_message: base_message, free_size_limit: formatted(root_namespace.actual_size_limit) })
end
end end
def formatted(number)
number_to_human_size(number, delimiter: ',', precision: 2)
end end
end end
end end
...@@ -9,6 +9,8 @@ RSpec.describe Namespaces::CheckExcessStorageSizeService, '#execute' do ...@@ -9,6 +9,8 @@ RSpec.describe Namespaces::CheckExcessStorageSizeService, '#execute' do
let(:total_repository_size_excess) { 150.megabytes } let(:total_repository_size_excess) { 150.megabytes }
let(:additional_purchased_storage_size) { 100 } let(:additional_purchased_storage_size) { 100 }
let(:storage_allocation_enabled) { true } let(:storage_allocation_enabled) { true }
let(:actual_size_limit) { 10.gigabytes }
let(:locked_project_count) { 1 }
subject(:response) { service.execute } subject(:response) { service.execute }
...@@ -17,6 +19,8 @@ RSpec.describe Namespaces::CheckExcessStorageSizeService, '#execute' do ...@@ -17,6 +19,8 @@ RSpec.describe Namespaces::CheckExcessStorageSizeService, '#execute' do
allow(namespace).to receive(:root_ancestor).and_return(namespace) allow(namespace).to receive(:root_ancestor).and_return(namespace)
allow(namespace).to receive(:total_repository_size_excess).and_return(total_repository_size_excess) allow(namespace).to receive(:total_repository_size_excess).and_return(total_repository_size_excess)
allow(namespace).to receive(:actual_size_limit).and_return(actual_size_limit)
allow(namespace).to receive(:repository_size_excess_project_count).and_return(locked_project_count)
end end
context 'without limit enforcement' do context 'without limit enforcement' do
...@@ -165,21 +169,27 @@ RSpec.describe Namespaces::CheckExcessStorageSizeService, '#execute' do ...@@ -165,21 +169,27 @@ RSpec.describe Namespaces::CheckExcessStorageSizeService, '#execute' do
let(:contains_locked_projects) { true } let(:contains_locked_projects) { true }
context 'when there is additional storage' do context 'when there is additional storage' do
context 'with one locked project' do
it 'returns message about containing a locked project' do it 'returns message about containing a locked project' do
expect(response).to include("contains a locked project") expect(response).to include("#{locked_project_count} locked project")
end end
end end
context 'when there is no additional storage' do context 'with multiple projects' do
let(:additional_purchased_storage_size) { 0 }
let(:locked_project_count) { 3 } let(:locked_project_count) { 3 }
before do it 'returns a pluralized message about locked projects' do
allow(namespace).to receive(:repository_size_excess_project_count).and_return(locked_project_count) expect(response).to include("#{locked_project_count} locked projects")
end
end end
end
context 'when there is no additional storage' do
let(:additional_purchased_storage_size) { 0 }
let(:locked_project_count) { 3 }
it 'returns message to have reached the free storage limit' do it 'returns message to have reached the free storage limit' do
expect(response).to include("You have reached the free storage limit of 10GB") expect(response).to include("You have reached the free storage limit of 10 GB")
expect(response).to include("#{locked_project_count} projects") expect(response).to include("#{locked_project_count} projects")
end end
end end
......
...@@ -17394,8 +17394,10 @@ msgstr "" ...@@ -17394,8 +17394,10 @@ msgstr ""
msgid "Namespace:" msgid "Namespace:"
msgstr "" msgstr ""
msgid "NamespaceStorageSize|%{namespace_name} contains a locked project" msgid "NamespaceStorageSize|%{namespace_name} contains %{locked_project_count} locked project"
msgstr "" msgid_plural "NamespaceStorageSize|%{namespace_name} contains %{locked_project_count} locked projects"
msgstr[0] ""
msgstr[1] ""
msgid "NamespaceStorageSize|%{namespace_name} is now read-only. You cannot: %{base_message}" msgid "NamespaceStorageSize|%{namespace_name} is now read-only. You cannot: %{base_message}"
msgstr "" msgstr ""
...@@ -17403,17 +17405,19 @@ msgstr "" ...@@ -17403,17 +17405,19 @@ msgstr ""
msgid "NamespaceStorageSize|If you reach 100%% storage capacity, you will not be able to: %{base_message}" msgid "NamespaceStorageSize|If you reach 100%% storage capacity, you will not be able to: %{base_message}"
msgstr "" msgstr ""
msgid "NamespaceStorageSize|Please purchase additional storage to unlock your projects over the free 10GB project limit. You can't %{base_message}" msgid "NamespaceStorageSize|Please purchase additional storage to unlock your projects over the free %{free_size_limit} project limit. You can't %{base_message}"
msgstr "" msgstr ""
msgid "NamespaceStorageSize|You have consumed all of your additional storage, please purchase more to unlock your projects over the free 10GB limit. You can't %{base_message}" msgid "NamespaceStorageSize|You have consumed all of your additional storage, please purchase more to unlock your projects over the free %{free_size_limit} limit. You can't %{base_message}"
msgstr "" msgstr ""
msgid "NamespaceStorageSize|You have reached %{usage_in_percent} of %{namespace_name}'s storage capacity (%{used_storage} of %{storage_limit})" msgid "NamespaceStorageSize|You have reached %{usage_in_percent} of %{namespace_name}'s storage capacity (%{used_storage} of %{storage_limit})"
msgstr "" msgstr ""
msgid "NamespaceStorageSize|You have reached the free storage limit of 10GB on %{locked_project_count} projects. To unlock them, please purchase additional storage" msgid "NamespaceStorageSize|You have reached the free storage limit of %{free_size_limit} on %{locked_project_count} project. To unlock it, please purchase additional storage"
msgstr "" msgid_plural "NamespaceStorageSize|You have reached the free storage limit of %{free_size_limit} on %{locked_project_count} projects. To unlock them, please purchase additional storage"
msgstr[0] ""
msgstr[1] ""
msgid "NamespaceStorageSize|push to your repository, create pipelines, create issues or add comments. To reduce storage capacity, delete unused repositories, artifacts, wikis, issues, and pipelines." msgid "NamespaceStorageSize|push to your repository, create pipelines, create issues or add comments. To reduce storage capacity, delete unused repositories, artifacts, wikis, issues, and pipelines."
msgstr "" msgstr ""
......
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