debian-mirror-gitlab/app/controllers/search_controller.rb

61 lines
1.7 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
class SearchController < ApplicationController
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-09-11 14:41:01 +05:30
@search_term = params[:search]
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
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-09-25 12:07:36 +05:30
unless %w(blobs notes issues merge_requests milestones wiki_blobs).
2015-04-26 12:48:37 +05:30
include?(@scope)
@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
2015-04-26 12:48:37 +05:30
@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