Commit 9a56deac authored by manojmj's avatar manojmj

Do not use ES for Global Search when not enabled

This change makes sure that ES is not used when
it is not enabled for search
parent 2ceaff37
---
title: Fix 500 error in global search for blob, wiki_blob and commit search
merge_request: 23326
author:
type: fixed
...@@ -12,14 +12,14 @@ module EE ...@@ -12,14 +12,14 @@ module EE
ELASTICSEARCH_SCOPES = %w(wiki_blobs blobs commits).freeze ELASTICSEARCH_SCOPES = %w(wiki_blobs blobs commits).freeze
override :verify_search_scope! override :verify_search_scope!
def verify_search_scope! def verify_search_scope!(resource:)
if ELASTICSEARCH_SCOPES.include?(params[:scope]) && !elasticsearch? if ELASTICSEARCH_SCOPES.include?(params[:scope]) && !use_elasticsearch?(resource)
render_api_error!({ error: 'Scope not supported without Elasticsearch!' }, 400) render_api_error!({ error: 'Scope not supported without Elasticsearch!' }, 400)
end end
end end
def elasticsearch? def use_elasticsearch?(resource)
::Gitlab::CurrentSettings.elasticsearch_search? ::Gitlab::CurrentSettings.search_using_elasticsearch?(scope: resource)
end end
override :process_results override :process_results
......
This diff is collapsed.
...@@ -47,7 +47,7 @@ module API ...@@ -47,7 +47,7 @@ module API
SCOPE_ENTITY[params[:scope].to_sym] SCOPE_ENTITY[params[:scope].to_sym]
end end
def verify_search_scope! def verify_search_scope!(resource:)
# In EE we have additional validation requirements for searches. # In EE we have additional validation requirements for searches.
# Defining this method here as a noop allows us to easily extend it in # Defining this method here as a noop allows us to easily extend it in
# EE, without having to modify this file directly. # EE, without having to modify this file directly.
...@@ -73,7 +73,7 @@ module API ...@@ -73,7 +73,7 @@ module API
use :pagination use :pagination
end end
get do get do
verify_search_scope! verify_search_scope!(resource: nil)
check_users_search_allowed! check_users_search_allowed!
present search, with: entity present search, with: entity
...@@ -94,7 +94,7 @@ module API ...@@ -94,7 +94,7 @@ module API
use :pagination use :pagination
end end
get ':id/(-/)search' do get ':id/(-/)search' do
verify_search_scope! verify_search_scope!(resource: user_group)
check_users_search_allowed! check_users_search_allowed!
present search(group_id: user_group.id), with: entity present search(group_id: user_group.id), with: entity
......
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