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 ProjectService
|
2020-10-01 03:09:55 +00:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
|
|
|
ALLOWED_SCOPES = %w(notes issues merge_requests milestones wiki_blobs commits users).freeze
|
|
|
|
|
2014-01-09 10:36:55 +00:00
|
|
|
attr_accessor :project, :current_user, :params
|
|
|
|
|
2021-06-15 12:10:11 +00:00
|
|
|
def initialize(project_or_projects, user, params)
|
|
|
|
@project = project_or_projects
|
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
|
2016-03-17 20:48:19 +00:00
|
|
|
Gitlab::ProjectSearchResults.new(current_user,
|
2014-08-27 06:57:50 +00:00
|
|
|
params[:search],
|
2020-08-21 03:10:16 +00:00
|
|
|
project: project,
|
2020-09-03 21:08:18 +00:00
|
|
|
repository_ref: params[:repository_ref],
|
2020-11-05 00:09:16 +00:00
|
|
|
order_by: params[:order_by],
|
2020-10-07 06:09:03 +00:00
|
|
|
sort: params[:sort],
|
2020-09-25 09:09:40 +00:00
|
|
|
filters: { confidential: params[:confidential], state: params[:state] }
|
|
|
|
)
|
2014-01-09 10:36:55 +00:00
|
|
|
end
|
2017-03-31 13:03:55 +00:00
|
|
|
|
2020-10-01 03:09:55 +00:00
|
|
|
def allowed_scopes
|
|
|
|
ALLOWED_SCOPES
|
|
|
|
end
|
2018-12-19 14:24:46 +00:00
|
|
|
|
2020-10-01 03:09:55 +00:00
|
|
|
def scope
|
|
|
|
strong_memoize(:scope) do
|
|
|
|
allowed_scopes.include?(params[:scope]) ? params[:scope] : 'blobs'
|
2018-12-19 14:24:46 +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::ProjectService.prepend_mod_with('Search::ProjectService')
|