diff options
Diffstat (limited to 'app/controllers/search_controller.rb')
-rw-r--r-- | app/controllers/search_controller.rb | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index b639a9dda3f..64d9db41a1b 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -27,7 +27,10 @@ class SearchController < ApplicationController around_action :allow_gitaly_ref_name_caching - before_action :block_anonymous_global_searches, :check_scope_global_search_enabled, except: :opensearch + before_action :block_all_anonymous_searches, + :block_anonymous_global_searches, + :check_scope_global_search_enabled, + except: :opensearch skip_before_action :authenticate_user! requires_cross_project_access if: -> do @@ -191,17 +194,7 @@ class SearchController < ApplicationController # Merging to :metadata will ensure these are logged as top level keys payload[:metadata] ||= {} - payload[:metadata]['meta.search.group_id'] = params[:group_id] - payload[:metadata]['meta.search.project_id'] = params[:project_id] - payload[:metadata]['meta.search.scope'] = params[:scope] || @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] - payload[:metadata]['meta.search.project_ids'] = params[:project_ids] - payload[:metadata]['meta.search.filters.language'] = params[:language] - payload[:metadata]['meta.search.type'] = @search_type if @search_type.present? - payload[:metadata]['meta.search.level'] = @search_level if @search_level.present? - payload[:metadata][:global_search_duration_s] = @global_search_duration_s if @global_search_duration_s.present? + payload[:metadata].merge!(payload_metadata) if search_service.abuse_detected? payload[:metadata]['abuse.confidence'] = Gitlab::Abuse.confidence(:certain) @@ -209,6 +202,23 @@ class SearchController < ApplicationController end end + def payload_metadata + {}.tap do |metadata| + metadata['meta.search.group_id'] = params[:group_id] + metadata['meta.search.project_id'] = params[:project_id] + metadata['meta.search.scope'] = params[:scope] || @scope + metadata['meta.search.page'] = params[:page] || '1' + metadata['meta.search.filters.confidential'] = params[:confidential] + metadata['meta.search.filters.state'] = params[:state] + metadata['meta.search.force_search_results'] = params[:force_search_results] + metadata['meta.search.project_ids'] = params[:project_ids] + metadata['meta.search.filters.language'] = params[:language] + metadata['meta.search.type'] = @search_type if @search_type.present? + metadata['meta.search.level'] = @search_level if @search_level.present? + metadata[:global_search_duration_s] = @global_search_duration_s if @global_search_duration_s.present? + end + end + def block_anonymous_global_searches return unless search_service.global_search? return if current_user @@ -219,6 +229,14 @@ class SearchController < ApplicationController redirect_to new_user_session_path, alert: _('You must be logged in to search across all of GitLab') end + def block_all_anonymous_searches + return if current_user || ::Feature.enabled?(:allow_anonymous_searches, type: :ops) + + store_location_for(:user, request.fullpath) + + redirect_to new_user_session_path, alert: _('You must be logged in to search') + end + def check_scope_global_search_enabled return unless search_service.global_search? |