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