Skip to content
代码片段 群组 项目
提交 138f3d1a 编辑于 作者: Patrick Bajao's avatar Patrick Bajao
浏览文件

Don't allow filtering by `in` alone on issue/MR dashboard

When `in` param is set while no `search` param is set, the issues
and MRs finder won't use the `in` param. It'll instead skip the
filter check and can result to SQL statement timeout.

The fix is to check that if `in` param is set but no search, show
the "Please select at least one filter to see results" message.

Changelog: fixed
上级 1b9dbdc9
No related branches found
No related tags found
无相关合并请求
......@@ -74,7 +74,12 @@ def check_filters_presence!
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
# The `in` param is a modifier of `search`. If it's present while the `search`
# param isn't, the finder won't use the `in` param. We consider this as a no
# filter scenario.
no_search_filter_set = params[:in].present? && params[:search].blank?
@no_filters_set = (no_scalar_filters_set && no_array_filters_set) || no_search_filter_set
return unless @no_filters_set
......
......@@ -111,22 +111,36 @@
it_behaves_like 'no filters are set'
end
end
context "scalar filters" do
let(:params) { { author_id: user.id } }
context 'when in param is set but no search' do
let(:params) { { in: 'title' } }
it_behaves_like 'no filters are set'
end
end
shared_examples_for 'filters are set' do
it 'sets @no_filters_set to false' do
expect(assigns[:no_filters_set]).to eq(false)
end
end
context "scalar filters" do
let(:params) { { author_id: user.id } }
it_behaves_like 'filters are set'
end
context "array filters" do
let(:params) { { label_name: ['bug'] } }
it 'sets @no_filters_set to false' do
expect(assigns[:no_filters_set]).to eq(false)
end
it_behaves_like 'filters are set'
end
context 'search' do
let(:params) { { search: 'test' } }
it_behaves_like 'filters are set'
end
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册