2014-09-02 18:07:02 +05:30
|
|
|
class SearchController < ApplicationController
|
2016-09-13 17:45:13 +05:30
|
|
|
skip_before_action :authenticate_user!, :reject_blocked!
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
include SearchHelper
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
layout 'search'
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def show
|
2015-04-26 12:48:37 +05:30
|
|
|
return if params[:search].nil? || params[:search].blank?
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
if params[:project_id].present?
|
|
|
|
@project = Project.find_by(id: params[:project_id])
|
|
|
|
@project = nil unless can?(current_user, :download_code, @project)
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
if params[:group_id].present?
|
2015-09-11 14:41:01 +05:30
|
|
|
@group = Group.find_by(id: params[:group_id])
|
2015-04-26 12:48:37 +05:30
|
|
|
@group = nil unless can?(current_user, :read_group, @group)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
@search_term = params[:search]
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
@scope = params[:scope]
|
|
|
|
@show_snippets = params[:snippets].eql? 'true'
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
@search_results =
|
2015-04-26 12:48:37 +05:30
|
|
|
if @project
|
2015-11-26 14:37:03 +05:30
|
|
|
unless %w(blobs notes issues merge_requests milestones wiki_blobs
|
|
|
|
commits).include?(@scope)
|
2015-04-26 12:48:37 +05:30
|
|
|
@scope = 'blobs'
|
|
|
|
end
|
|
|
|
|
|
|
|
Search::ProjectService.new(@project, current_user, params).execute
|
|
|
|
elsif @show_snippets
|
|
|
|
unless %w(snippet_blobs snippet_titles).include?(@scope)
|
|
|
|
@scope = 'snippet_blobs'
|
|
|
|
end
|
|
|
|
|
|
|
|
Search::SnippetService.new(current_user, params).execute
|
|
|
|
else
|
2015-09-25 12:07:36 +05:30
|
|
|
unless %w(projects issues merge_requests milestones).include?(@scope)
|
2015-04-26 12:48:37 +05:30
|
|
|
@scope = 'projects'
|
|
|
|
end
|
|
|
|
Search::GlobalService.new(current_user, params).execute
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
@search_objects = @search_results.objects(@scope, params[:page])
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def autocomplete
|
|
|
|
term = params[:term]
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
if params[:project_id].present?
|
|
|
|
@project = Project.find_by(id: params[:project_id])
|
|
|
|
@project = nil unless can?(current_user, :read_project, @project)
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
@ref = params[:project_ref] if params[:project_ref].present?
|
|
|
|
|
|
|
|
render json: search_autocomplete_opts(term).to_json
|
|
|
|
end
|
|
|
|
end
|