diff --git a/config/locales/en.yml b/config/locales/en.yml
index c60e6c4e5..04944a6bc 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1197,7 +1197,6 @@ en:
Groups is a feature which for now is used only to manage access of private spaces.
A user being part of a group has access to every private space which requires the group.
Each group has multiple owners. A owner can add and remove people to the group.
- orcid:
orcid:
error: 'An error occurred whilst trying to authenticate your ORCID.'
link: 'Link your ORCID'
@@ -1240,4 +1239,7 @@ en:
info: "This %{resource_type} originated from another TeSS registry. For complete, up-to-date information, please visit the original entry:"
link: Go to original entry
other_space:
- link: View in space
\ No newline at end of file
+ link: View in space
+ search:
+ errors:
+ filter_limit_reached: Filter limit reached, please log in to apply additional filters.
\ No newline at end of file
diff --git a/config/tess.example.yml b/config/tess.example.yml
index c8a51db5e..7e05df924 100644
--- a/config/tess.example.yml
+++ b/config/tess.example.yml
@@ -288,6 +288,7 @@ default: &default
space:
primary: '#260252'
secondary: '#5c29b1'
+ filter_limit: # Maximum number of filter values allowed for anonymous users
development:
<<: *default
diff --git a/test/controllers/materials_controller_test.rb b/test/controllers/materials_controller_test.rb
index c667f058c..6c181f12a 100644
--- a/test/controllers/materials_controller_test.rb
+++ b/test/controllers/materials_controller_test.rb
@@ -1763,4 +1763,83 @@ class MaterialsControllerTest < ActionController::TestCase
assert_select '#space-info', count: 0
end
end
+
+ test 'displays warning when filter limit reached for anonymous users' do
+ with_settings(solr_enabled: true, filter_limit: 2) do
+ Material.stub(:search_and_filter, MockSearch.new(Material.all)) do
+ get :index, params: { keywords: ['dancing', 'singing'] }
+
+ assert_response :success
+ end
+ end
+
+ assert_select 'div.alert', text: /Filter limit reached/
+ assert_select '.facet-option.filter-limit-reached'
+ end
+
+ test 'does not display filter limit warning for logged-in users' do
+ sign_in(@user)
+
+ with_settings(solr_enabled: true, filter_limit: 2) do
+ Material.stub(:search_and_filter, MockSearch.new(Material.all)) do
+ get :index, params: { keywords: ['dancing', 'singing'] }
+
+ assert_response :success
+ end
+ end
+
+ assert_select 'div.alert', text: /Filter limit reached/, count: 0
+ assert_select '.facet-option.filter-limit-reached', count: 0
+ end
+
+ test 'throws error if filter limit exceeded for anonymous users' do
+ with_settings(solr_enabled: true, filter_limit: 2) do
+ Material.stub(:search_and_filter, MockSearch.new(Material.all)) do
+ get :index, params: { keywords: ['dancing', 'singing', 'acrobatics'] }
+
+ assert_response :bad_request
+ end
+ end
+
+ assert_select '#error-message', text: /Filter limit reached/
+ end
+
+ test 'does not throw error if filter limit exceeded for logged-in users' do
+ sign_in(@user)
+
+ with_settings(solr_enabled: true, filter_limit: 2) do
+ Material.stub(:search_and_filter, MockSearch.new(Material.all)) do
+ get :index, params: { keywords: ['dancing', 'singing', 'acrobatics'] }
+
+ assert_response :success
+ end
+ end
+
+ assert_select '#error-message', count: 0
+ assert_select 'div.alert', text: /Filter limit reached/, count: 0
+ assert_select '.facet-option.filter-limit-reached', count: 0
+ end
+
+ test 'does not throw error if filter limit exceeded for API requests' do
+ with_settings(solr_enabled: true, filter_limit: 2) do
+ Material.stub(:search_and_filter, MockSearch.new(Material.all)) do
+ get :index, params: { keywords: ['dancing', 'singing', 'acrobatics'], format: :json_api }
+
+ assert_response :success
+ assert_not_nil assigns(:materials)
+ assert_valid_json_api_response
+ body = nil
+ assert_nothing_raised do
+ body = JSON.parse(response.body)
+ end
+
+ assert body['data'].any?
+ assert body['meta']['results-count'] > 0
+ assert_includes body['meta']['facets']['keywords'], 'acrobatics'
+ assert body['meta']['available-facets'].keys.any?
+ assert body['meta']['available-facets'].values.any?
+ assert body['links']['self'].include?('acrobatics')
+ end
+ end
+ end
end