2018-07-18 16:03:33 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-01-09 10:36:55 +00:00
|
|
|
module Search
|
2014-01-16 17:03:42 +00:00
|
|
|
class GlobalService
|
2019-02-04 17:59:34 +00:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2020-10-01 03:09:55 +00:00
|
|
|
ALLOWED_SCOPES = %w(issues merge_requests milestones users).freeze
|
|
|
|
|
2014-01-09 10:36:55 +00:00
|
|
|
attr_accessor :current_user, :params
|
|
|
|
|
|
|
|
def initialize(user, params)
|
2021-04-19 21:09:27 +00:00
|
|
|
@current_user = user
|
|
|
|
@params = params.dup
|
2014-01-09 10:36:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2020-08-21 03:10:16 +00:00
|
|
|
Gitlab::SearchResults.new(current_user,
|
|
|
|
params[:search],
|
2020-09-03 21:08:18 +00:00
|
|
|
projects,
|
2020-11-05 00:09:16 +00:00
|
|
|
order_by: params[:order_by],
|
2020-10-01 03:09:55 +00:00
|
|
|
sort: params[:sort],
|
2020-09-25 09:09:40 +00:00
|
|
|
filters: { state: params[:state], confidential: params[:confidential] })
|
2014-01-09 10:36:55 +00:00
|
|
|
end
|
2017-03-31 13:03:55 +00:00
|
|
|
|
2021-08-09 09:22:41 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-04-13 15:20:04 +00:00
|
|
|
def projects
|
2021-09-28 09:11:19 +00:00
|
|
|
@projects ||= ProjectsFinder.new(params: { non_archived: true }, current_user: current_user).execute.preload(:topics, :project_topics)
|
2017-04-13 15:20:04 +00:00
|
|
|
end
|
|
|
|
|
2019-02-04 17:59:34 +00:00
|
|
|
def allowed_scopes
|
2020-10-01 03:09:55 +00:00
|
|
|
ALLOWED_SCOPES
|
2019-02-04 17:59:34 +00:00
|
|
|
end
|
2017-04-04 11:57:16 +00:00
|
|
|
|
2019-02-04 17:59:34 +00:00
|
|
|
def scope
|
|
|
|
strong_memoize(:scope) do
|
|
|
|
allowed_scopes.include?(params[:scope]) ? params[:scope] : 'projects'
|
2017-04-04 11:57:16 +00:00
|
|
|
end
|
2017-03-31 13:03:55 +00:00
|
|
|
end
|
2014-01-09 10:36:55 +00:00
|
|
|
end
|
|
|
|
end
|
2019-09-13 13:26:31 +00:00
|
|
|
|
2021-05-11 21:10:21 +00:00
|
|
|
Search::GlobalService.prepend_mod_with('Search::GlobalService')
|