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

58 lines
1.4 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
class SearchController < ApplicationController
2017-08-17 22:00:37 +05:30
skip_before_action :authenticate_user!
2016-06-02 11:05:42 +05:30
2014-09-02 18:07:02 +05:30
include SearchHelper
2018-03-17 18:26:18 +05:30
include RendersCommits
2014-09-02 18:07:02 +05:30
2015-09-11 14:41:01 +05:30
layout 'search'
2014-09-02 18:07:02 +05:30
def show
2017-08-17 22:00:37 +05:30
search_service = SearchService.new(current_user, params)
2014-09-02 18:07:02 +05:30
2017-08-17 22:00:37 +05:30
@project = search_service.project
@group = search_service.group
2015-09-11 14:41:01 +05:30
2017-08-17 22:00:37 +05:30
return if params[:search].blank?
2016-09-29 09:46:39 +05:30
2016-06-02 11:05:42 +05:30
@search_term = params[:search]
2017-08-17 22:00:37 +05:30
@scope = search_service.scope
@show_snippets = search_service.show_snippets?
@search_results = search_service.search_results
@search_objects = search_service.search_objects
2018-03-17 18:26:18 +05:30
render_commits if @scope == 'commits'
2017-08-17 22:00:37 +05:30
check_single_commit_result
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
2017-08-17 22:00:37 +05:30
private
2018-03-17 18:26:18 +05:30
def render_commits
@search_objects = prepare_commits_for_rendering(@search_objects)
end
2017-08-17 22:00:37 +05:30
def check_single_commit_result
if @search_results.single_commit_result?
only_commit = @search_results.objects('commits').first
query = params[:search].strip.downcase
found_by_commit_sha = Commit.valid_hash?(query) && only_commit.sha.start_with?(query)
2017-09-10 17:25:29 +05:30
redirect_to project_commit_path(@project, only_commit) if found_by_commit_sha
2017-08-17 22:00:37 +05:30
end
end
2014-09-02 18:07:02 +05:30
end