Commit 8b723776 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'fix_trigger_search' into 'master'

Only trigger search if search string is present

This is a follow up for !296 to prevent the search function from being executed while the query is nil.

Problem was this:
When the search is called, the search controller gets 2 requests.
```
{"action"=>"show", "controller"=>"search"}
```
and
```
{"utf8"=>"✓",
 "search"=>"proj",
 "project_id"=>"",
 "group_id"=>"",
 "snippets"=>"",
 "scope"=>"",
 "button"=>"",
 "action"=>"show",
 "controller"=>"search"}
```

Obviously it doesn't make sense to execute the search for the first request, since that one doesn't have a scope or a search string.

Please review this carefully since this modifies the search and may break things i can't think of.

@dzaporozhets While this fixes the root cause for the failing test, I think we should keep your fix in as a failsafe. What do you think of this?

See merge request !302
parents 479cf892 9487c370
...@@ -2,12 +2,14 @@ class SearchController < ApplicationController ...@@ -2,12 +2,14 @@ class SearchController < ApplicationController
include SearchHelper include SearchHelper
def show def show
return if params[:search].nil? || params[:search].blank?
@project = Project.find_by(id: params[:project_id]) if params[:project_id].present? @project = Project.find_by(id: params[:project_id]) if params[:project_id].present?
@group = Group.find_by(id: params[:group_id]) if params[:group_id].present? @group = Group.find_by(id: params[:group_id]) if params[:group_id].present?
@scope = params[:scope] @scope = params[:scope]
@show_snippets = params[:snippets].eql? 'true' @show_snippets = params[:snippets].eql? 'true'
@search_results = if @project @search_results =
if @project
return access_denied! unless can?(current_user, :download_code, @project) return access_denied! unless can?(current_user, :download_code, @project)
unless %w(blobs notes issues merge_requests wiki_blobs). unless %w(blobs notes issues merge_requests wiki_blobs).
...@@ -26,10 +28,8 @@ class SearchController < ApplicationController ...@@ -26,10 +28,8 @@ class SearchController < ApplicationController
unless %w(projects issues merge_requests).include?(@scope) unless %w(projects issues merge_requests).include?(@scope)
@scope = 'projects' @scope = 'projects'
end end
Search::GlobalService.new(current_user, params).execute Search::GlobalService.new(current_user, params).execute
end end
@objects = @search_results.objects(@scope, params[:page]) @objects = @search_results.objects(@scope, params[:page])
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