Commit cd1907a9 authored by Michael Kozono's avatar Michael Kozono

Merge branch '271555_make_warning_message_for_reaching_storage_limit_clearer' into 'master'

Make messages for reaching storage limit clearer

See merge request gitlab-org/gitlab!47498
parents b2eee38c 74c88733
...@@ -39,6 +39,10 @@ module Namespaces ...@@ -39,6 +39,10 @@ module Namespaces
end end
end end
def base_message
s_("NamespaceStorageSize|push to your repository, create pipelines, create issues or add comments. To learn more about reducing storage capacity please visit our docs.")
end
def formatted(number) def formatted(number)
number_to_human_size(number, delimiter: ',', precision: 2) number_to_human_size(number, delimiter: ',', precision: 2)
end end
......
...@@ -23,12 +23,13 @@ module EE ...@@ -23,12 +23,13 @@ module EE
[size, 0].max [size, 0].max
end end
private override :additional_repo_storage_available?
def additional_repo_storage_available? def additional_repo_storage_available?
!!namespace&.additional_repo_storage_by_namespace_enabled? !!namespace&.additional_repo_storage_by_namespace_enabled?
end end
private
def total_repository_size_excess def total_repository_size_excess
namespace&.total_repository_size_excess.to_i namespace&.total_repository_size_excess.to_i
end end
......
...@@ -193,4 +193,20 @@ RSpec.describe Gitlab::RepositorySizeChecker do ...@@ -193,4 +193,20 @@ RSpec.describe Gitlab::RepositorySizeChecker do
include_examples 'checker size exceeded' include_examples 'checker size exceeded'
end end
end end
describe '#additional_repo_storage_available?' do
context 'when additional_repo_storage_by_namespace_enabled is true' do
it 'returns true' do
expect(subject.additional_repo_storage_available?).to eq(true)
end
end
context 'when additional_repo_storage_by_namespace_enabled is false' do
let(:additional_repo_storage_by_namespace_enabled) { false }
it 'returns false' do
expect(subject.additional_repo_storage_available?).to eq(false)
end
end
end
end end
...@@ -46,6 +46,10 @@ module Gitlab ...@@ -46,6 +46,10 @@ module Gitlab
@error_message_object ||= ::Gitlab::RepositorySizeErrorMessage.new(self) @error_message_object ||= ::Gitlab::RepositorySizeErrorMessage.new(self)
end end
def additional_repo_storage_available?
false
end
private private
attr_reader :namespace attr_reader :namespace
......
...@@ -4,7 +4,7 @@ module Gitlab ...@@ -4,7 +4,7 @@ module Gitlab
class RepositorySizeErrorMessage class RepositorySizeErrorMessage
include ActiveSupport::NumberHelper include ActiveSupport::NumberHelper
delegate :current_size, :limit, :exceeded_size, to: :@checker delegate :current_size, :limit, :exceeded_size, :additional_repo_storage_available?, to: :@checker
# @param checher [RepositorySizeChecker] # @param checher [RepositorySizeChecker]
def initialize(checker) def initialize(checker)
...@@ -24,8 +24,12 @@ module Gitlab ...@@ -24,8 +24,12 @@ module Gitlab
end end
def new_changes_error def new_changes_error
if additional_repo_storage_available?
"Your push to this repository has been rejected because it would exceed storage limits. Please contact your GitLab administrator for more information."
else
"Your push to this repository would cause it to exceed the size limit of #{formatted(limit)} so it has been rejected. #{more_info_message}" "Your push to this repository would cause it to exceed the size limit of #{formatted(limit)} so it has been rejected. #{more_info_message}"
end end
end
def more_info_message def more_info_message
'Please contact your GitLab administrator for more information.' 'Please contact your GitLab administrator for more information.'
......
...@@ -17900,6 +17900,9 @@ msgid_plural "NamespaceStorageSize|You have reached the free storage limit of %{ ...@@ -17900,6 +17900,9 @@ msgid_plural "NamespaceStorageSize|You have reached the free storage limit of %{
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
msgid "NamespaceStorageSize|push to your repository, create pipelines, create issues or add comments. To learn more about reducing storage capacity please visit our docs."
msgstr ""
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 ""
......
...@@ -53,4 +53,10 @@ RSpec.describe Gitlab::RepositorySizeChecker do ...@@ -53,4 +53,10 @@ RSpec.describe Gitlab::RepositorySizeChecker do
describe '#exceeded_size' do describe '#exceeded_size' do
include_examples 'checker size exceeded' include_examples 'checker size exceeded'
end end
describe '#additional_repo_storage_available?' do
it 'returns false' do
expect(subject.additional_repo_storage_available?).to eq(false)
end
end
end end
...@@ -53,9 +53,19 @@ RSpec.describe Gitlab::RepositorySizeErrorMessage do ...@@ -53,9 +53,19 @@ RSpec.describe Gitlab::RepositorySizeErrorMessage do
end end
describe '#new_changes_error' do describe '#new_changes_error' do
context 'when additional repo storage is available' do
it 'returns the correct message' do
allow(checker).to receive(:additional_repo_storage_available?).and_return(true)
expect(message.new_changes_error).to eq('Your push to this repository has been rejected because it would exceed storage limits. Please contact your GitLab administrator for more information.')
end
end
context 'when no additional repo storage is available' do
it 'returns the correct message' do it 'returns the correct message' do
expect(message.new_changes_error).to eq("Your push to this repository would cause it to exceed the size limit of 10 MB so it has been rejected. #{message.more_info_message}") expect(message.new_changes_error).to eq("Your push to this repository would cause it to exceed the size limit of 10 MB so it has been rejected. #{message.more_info_message}")
end end
end end
end end
end
end end
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