Commit b26758e0 authored by Dylan Griffith's avatar Dylan Griffith

Disallow switch to basic search on some tabs

Only some tabs support basic search and others need Elasticsearch
parent 7a8be270
......@@ -3,6 +3,8 @@ module EE
module SearchHelper
extend ::Gitlab::Utils::Override
SWITCH_TO_BASIC_SEARCHABLE_TABS = %w[projects issues merge_requests milestones users].freeze
override :search_filter_input_options
def search_filter_input_options(type)
options = super
......@@ -68,6 +70,16 @@ module EE
search_path(search_params)
end
# Switching to basic search should only be possible for a subset of
# scopes. This method assumes you're already allowed to search within
# this scope but it's just here to determine if you can switch to basic
# search.
def switch_to_basic_searchable_tab?(scope)
return true if @project
scope.in?(SWITCH_TO_BASIC_SEARCHABLE_TABS)
end
private
def search_multiple_assignees?(type)
......
- if search_service.use_elasticsearch?
- if search_service.use_elasticsearch? && switch_to_basic_searchable_tab?(search_service.scope)
- begin_link = '<a href="%{url}">'.html_safe % { url: revert_to_basic_search_filter_url }
- end_link = '</a>'.html_safe
%p.text-center
......
......@@ -220,10 +220,8 @@ describe 'Global elastic search', :elastic do
end
end
describe 'When requesting basic search' do
it 'does not use Elasticsearch' do
create(:issue, project: project, title: 'project issue')
context 'when no results are returned' do
it 'allows basic search without Elasticsearch' do
visit dashboard_projects_path
submit_search('project')
......@@ -238,5 +236,16 @@ describe 'Global elastic search', :elastic do
# Project is found now that we are using basic search
expect(page).to have_content('Projects 1')
end
context 'when performing Commits search' do
it 'does not allow basic search' do
visit dashboard_projects_path
submit_search('project')
select_search_scope('Commits')
expect(page).not_to have_link('basic search')
end
end
end
end
......@@ -175,4 +175,27 @@ describe SearchHelper do
it_behaves_like 'returns old message'
end
end
describe '#switch_to_basic_searchable_tab?' do
let(:scope) { 'commits' }
subject { switch_to_basic_searchable_tab?(scope) }
context 'when project scope' do
before do
@project = create(:project)
end
it { is_expected.to eq(true) }
end
context 'when commits tab' do
it { is_expected.to eq(false) }
end
context 'when issues tab' do
let(:scope) { 'issues' }
it { is_expected.to eq(true) }
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