diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index d7f24dfbef803ea1591b5ac75d75a09f2dfdeb58..ab1a1eb09c99399aed051ab1bfca2a58a0a7dcb9 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -265,6 +265,10 @@ def should_show_zoekt_results?(_scope, _search_type) false end + def blob_data_oversize_message + _('The file could not be displayed because it is empty.') + end + private def formatted_count(scope) diff --git a/app/views/search/results/_blob_data.html.haml b/app/views/search/results/_blob_data.html.haml index 8d30c655180a36a9ee6f890ab51a74b3809cb8d7..c0d951516054578f4bd4f383c1d4a097014652cc 100644 --- a/app/views/search/results/_blob_data.html.haml +++ b/app/views/search/results/_blob_data.html.haml @@ -14,5 +14,4 @@ .file-content.code .nothing-here-block .gl-text-subtle.gl-text-sm - - max_file_size_indexed = Gitlab::CurrentSettings.elasticsearch_indexed_file_size_limit_kb.kilobytes - = _('The file could not be displayed because it is empty or larger than the maximum file size indexed (%{size}).') % { size: number_to_human_size(max_file_size_indexed) } + = blob_data_oversize_message diff --git a/ee/app/helpers/ee/search_helper.rb b/ee/app/helpers/ee/search_helper.rb index 42ccdc114b096ba16fa141419ea3b2c4bfe1713b..0415e01ad9b00bd17e5715c2fbb592f930441c38 100644 --- a/ee/app/helpers/ee/search_helper.rb +++ b/ee/app/helpers/ee/search_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module EE module SearchHelper extend ::Gitlab::Utils::Override @@ -125,6 +126,17 @@ def should_show_zoekt_results?(scope, search_type) @group.present? || (@project.present? && @project.default_branch == repository_ref(@project)) || super end + override :blob_data_oversize_message + def blob_data_oversize_message + return super unless ::Gitlab::CurrentSettings.elasticsearch_search? + + max_file_size_indexed = ::Gitlab::CurrentSettings.elasticsearch_indexed_file_size_limit_kb.kilobytes + format( + _('The file could not be displayed because it is empty or larger than the ' \ + 'maximum file size indexed (%{size}).'), size: number_to_human_size(max_file_size_indexed) + ) + end + private def recent_epics_autocomplete(term) diff --git a/ee/spec/helpers/search_helper_spec.rb b/ee/spec/helpers/search_helper_spec.rb index d191305c3e6484a13f072f01c1014492fd1c116a..711621ecba9c42bbfcb0d33670ea2f518f1eecf8 100644 --- a/ee/spec/helpers/search_helper_spec.rb +++ b/ee/spec/helpers/search_helper_spec.rb @@ -522,4 +522,31 @@ end end end + + describe '#blob_data_oversize_message' do + before do + stub_ee_application_setting(elasticsearch_indexed_file_size_limit_kb: 256) + end + + context 'with elasticsearch enabled' do + before do + stub_ee_application_setting(elasticsearch_search: true) + end + + it 'returns the correct message with maximum file size' do + expect(helper.blob_data_oversize_message).to eq('The file could not be ' \ + 'displayed because it is empty or larger than the maximum file size indexed (256 KiB).') + end + end + + context 'with elasticsearch disabled' do + before do + stub_ee_application_setting(elasticsearch_search: false) + end + + it 'returns the correct message with maximum file size' do + expect(helper.blob_data_oversize_message).to eq('The file could not be displayed because it is empty.') + end + end + end end diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 6d4c2787d213023736697aa8a05ed7359da95a28..fb91a0863ee9433a8634083a22d4830459bc41ce 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -55940,6 +55940,9 @@ msgstr "" msgid "The file could not be displayed because it is empty or larger than the maximum file size indexed (%{size})." msgstr "" +msgid "The file could not be displayed because it is empty." +msgstr "" + msgid "The file has been successfully created." msgstr "" diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb index 3bf6951c16d251320e238a91b4c3fcf1dd898ebb..20b8391ee1bf26352e29d8184143ce747c893b1c 100644 --- a/spec/helpers/search_helper_spec.rb +++ b/spec/helpers/search_helper_spec.rb @@ -1457,4 +1457,10 @@ def simple_sanitize(str) end end end + + describe '#blob_data_oversize_message' do + it 'returns the correct message for empty files' do + expect(helper.blob_data_oversize_message).to eq('The file could not be displayed because it is empty.') + end + end end