Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-12-20 16:37:47 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-12-20 16:37:47 +0300
commitaee0a117a889461ce8ced6fcf73207fe017f1d99 (patch)
tree891d9ef189227a8445d83f35c1b0fc99573f4380 /app/controllers/search_controller.rb
parent8d46af3258650d305f53b819eabf7ab18d22f59e (diff)
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'app/controllers/search_controller.rb')
-rw-r--r--app/controllers/search_controller.rb35
1 files changed, 15 insertions, 20 deletions
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb
index 0e285dae089..99a6dfa811e 100644
--- a/app/controllers/search_controller.rb
+++ b/app/controllers/search_controller.rb
@@ -5,14 +5,13 @@ class SearchController < ApplicationController
include SearchHelper
include RedisTracking
- RESCUE_FROM_TIMEOUT_ACTIONS = [:count, :show].freeze
+ RESCUE_FROM_TIMEOUT_ACTIONS = [:count, :show, :autocomplete].freeze
track_redis_hll_event :show, name: 'i_search_total'
around_action :allow_gitaly_ref_name_caching
before_action :block_anonymous_global_searches, :check_scope_global_search_enabled, except: :opensearch
- before_action :strip_surrounding_whitespace_from_search, except: :opensearch
skip_before_action :authenticate_user!
requires_cross_project_access if: -> do
search_term_present = params[:search].present? || params[:term].present?
@@ -74,11 +73,7 @@ class SearchController < ApplicationController
def autocomplete
term = params[:term]
- if params[:project_id].present?
- @project = Project.find_by(id: params[:project_id])
- @project = nil unless can?(current_user, :read_project, @project)
- end
-
+ @project = search_service.project
@ref = params[:project_ref] if params[:project_ref].present?
render json: search_autocomplete_opts(term).to_json
@@ -97,12 +92,12 @@ class SearchController < ApplicationController
def search_term_valid?
unless search_service.valid_query_length?
- flash[:alert] = t('errors.messages.search_chars_too_long', count: SearchService::SEARCH_CHAR_LIMIT)
+ flash[:alert] = t('errors.messages.search_chars_too_long', count: Gitlab::Search::Params::SEARCH_CHAR_LIMIT)
return false
end
unless search_service.valid_terms_count?
- flash[:alert] = t('errors.messages.search_terms_too_long', count: SearchService::SEARCH_TERM_LIMIT)
+ flash[:alert] = t('errors.messages.search_terms_too_long', count: Gitlab::Search::Params::SEARCH_TERM_LIMIT)
return false
end
@@ -147,10 +142,15 @@ class SearchController < ApplicationController
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]
+
+ if search_service.abuse_detected?
+ payload[:metadata]['abuse.confidence'] = Gitlab::Abuse.confidence(:certain)
+ payload[:metadata]['abuse.messages'] = search_service.abuse_messages
+ end
end
def block_anonymous_global_searches
- return if params[:project_id].present? || params[:group_id].present?
+ return unless search_service.global_search?
return if current_user
return unless ::Feature.enabled?(:block_anonymous_global_searches, type: :ops)
@@ -160,7 +160,7 @@ class SearchController < ApplicationController
end
def check_scope_global_search_enabled
- return if params[:project_id].present? || params[:group_id].present?
+ return unless search_service.global_search?
search_allowed = case params[:scope]
when 'blobs'
@@ -189,20 +189,15 @@ class SearchController < ApplicationController
@timeout = true
- if count_action_name?
+ case action_name.to_sym
+ when :count
render json: {}, status: :request_timeout
+ when :autocomplete
+ render json: [], status: :request_timeout
else
render status: :request_timeout
end
end
-
- def count_action_name?
- action_name.to_sym == :count
- end
-
- def strip_surrounding_whitespace_from_search
- %i(term search).each { |param| params[param]&.strip! }
- end
end
SearchController.prepend_mod_with('SearchController')