diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /app/controllers/search_controller.rb | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'app/controllers/search_controller.rb')
-rw-r--r-- | app/controllers/search_controller.rb | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 0380bc1c548..4b21edc98d5 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -9,6 +9,7 @@ class SearchController < ApplicationController SCOPE_PRELOAD_METHOD = { projects: :with_web_entity_associations, issues: :with_web_entity_associations, + merge_requests: :with_web_entity_associations, epics: :with_web_entity_associations }.freeze @@ -35,7 +36,10 @@ class SearchController < ApplicationController return unless search_term_valid? + return if check_single_commit_result? + @search_term = params[:search] + @sort = params[:sort] || default_sort @scope = search_service.scope @show_snippets = search_service.show_snippets? @@ -47,8 +51,6 @@ class SearchController < ApplicationController eager_load_user_status if @scope == 'users' increment_search_counters - - check_single_commit_result end def count @@ -81,6 +83,11 @@ class SearchController < ApplicationController SCOPE_PRELOAD_METHOD[@scope.to_sym] end + # overridden in EE + def default_sort + 'created_desc' + end + def search_term_valid? unless search_service.valid_query_length? flash[:alert] = t('errors.messages.search_chars_too_long', count: SearchService::SEARCH_CHAR_LIMIT) @@ -103,14 +110,23 @@ class SearchController < ApplicationController @search_objects = @search_objects.eager_load(:status) # rubocop:disable CodeReuse/ActiveRecord end - 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) + def check_single_commit_result? + return false if params[:force_search_results] + return false unless @project.present? + # download_code project policy grants user the read_commit ability + return false unless Ability.allowed?(current_user, :download_code, @project) - redirect_to project_commit_path(@project, only_commit) if found_by_commit_sha - end + query = params[:search].strip.downcase + return false unless Commit.valid_hash?(query) + + commit = @project.commit_by(oid: query) + return false unless commit.present? + + link = search_path(safe_params.merge(force_search_results: true)) + flash[:notice] = html_escape(_("You have been redirected to the only result; see the %{a_start}search results%{a_end} instead.")) % { a_start: "<a href=\"#{link}\"><u>".html_safe, a_end: '</u></a>'.html_safe } + redirect_to project_commit_path(@project, commit) + + true end def increment_search_counters @@ -130,6 +146,9 @@ class SearchController < ApplicationController payload[:metadata]['meta.search.project_id'] = params[:project_id] payload[:metadata]['meta.search.search'] = params[:search] payload[:metadata]['meta.search.scope'] = params[:scope] + payload[:metadata]['meta.search.filters.confidential'] = params[:confidential] + payload[:metadata]['meta.search.filters.state'] = params[:state] + payload[:metadata]['meta.search.force_search_results'] = params[:force_search_results] end def block_anonymous_global_searches |