2018-07-18 12:03:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-01-09 05:36:55 -05:00
|
|
|
module Search
|
2014-01-16 12:03:42 -05:00
|
|
|
class GlobalService
|
2019-02-04 12:59:34 -05:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2014-01-09 05:36:55 -05:00
|
|
|
attr_accessor :current_user, :params
|
2017-12-15 05:21:12 -05:00
|
|
|
attr_reader :default_project_filter
|
2014-01-09 05:36:55 -05:00
|
|
|
|
|
|
|
def initialize(user, params)
|
|
|
|
@current_user, @params = user, params.dup
|
2017-12-15 05:21:12 -05:00
|
|
|
@default_project_filter = true
|
2014-01-09 05:36:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2017-12-15 05:21:12 -05:00
|
|
|
Gitlab::SearchResults.new(current_user, projects, params[:search],
|
|
|
|
default_project_filter: default_project_filter)
|
2014-01-09 05:36:55 -05:00
|
|
|
end
|
2017-03-31 09:03:55 -04:00
|
|
|
|
2017-04-13 11:20:04 -04:00
|
|
|
def projects
|
|
|
|
@projects ||= ProjectsFinder.new(current_user: current_user).execute
|
|
|
|
end
|
|
|
|
|
2019-02-04 12:59:34 -05:00
|
|
|
def allowed_scopes
|
|
|
|
strong_memoize(:allowed_scopes) do
|
2018-12-19 09:24:46 -05:00
|
|
|
allowed_scopes = %w[issues merge_requests milestones]
|
|
|
|
allowed_scopes << 'users' if Feature.enabled?(:users_search, default_enabled: true)
|
2019-02-04 12:59:34 -05:00
|
|
|
end
|
|
|
|
end
|
2017-04-04 07:57:16 -04:00
|
|
|
|
2019-02-04 12:59:34 -05:00
|
|
|
def scope
|
|
|
|
strong_memoize(:scope) do
|
|
|
|
allowed_scopes.include?(params[:scope]) ? params[:scope] : 'projects'
|
2017-04-04 07:57:16 -04:00
|
|
|
end
|
2017-03-31 09:03:55 -04:00
|
|
|
end
|
2014-01-09 05:36:55 -05:00
|
|
|
end
|
|
|
|
end
|