From 1b9dbdc99817b0dc7a516fcf46c1bf9b18e0b539 Mon Sep 17 00:00:00 2001 From: Patrick Bajao <ebajao@gitlab.com> Date: Wed, 9 Mar 2022 13:35:42 +0800 Subject: [PATCH] Fix filters presence check to take value into consideration This fixes a bug in the issues/MRs dashboard filter check which allows filtering by empty value. It can result to SQL statement timeout. The fix is to check if the value of the filter is present. If not, the dashboard will show the "Please select at least one filter to see results" message. Changelog: fixed --- app/controllers/dashboard_controller.rb | 4 ++-- spec/controllers/dashboard_controller_spec.rb | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index f94da77609fab..76e4db84f888a 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -71,8 +71,8 @@ def set_show_full_reference end def check_filters_presence! - no_scalar_filters_set = finder_type.scalar_params.none? { |k| params.key?(k) } - no_array_filters_set = finder_type.array_params.none? { |k, _| params.key?(k) } + no_scalar_filters_set = finder_type.scalar_params.none? { |k| params[k].present? } + no_array_filters_set = finder_type.array_params.none? { |k, _| params[k].present? } @no_filters_set = no_scalar_filters_set && no_array_filters_set diff --git a/spec/controllers/dashboard_controller_spec.rb b/spec/controllers/dashboard_controller_spec.rb index dbeac9fd24080..2a34ac9f923aa 100644 --- a/spec/controllers/dashboard_controller_spec.rb +++ b/spec/controllers/dashboard_controller_spec.rb @@ -98,8 +98,18 @@ context "no filters" do let(:params) { {} } - it 'sets @no_filters_set to false' do - expect(assigns[:no_filters_set]).to eq(true) + shared_examples_for 'no filters are set' do + it 'sets @no_filters_set to true' do + expect(assigns[:no_filters_set]).to eq(true) + end + end + + it_behaves_like 'no filters are set' + + context 'when key is present but value is not' do + let(:params) { { author_username: nil } } + + it_behaves_like 'no filters are set' end end -- GitLab