Commit 9e5bc432 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Pass scope and page to Gitlab::SearchResults#objects instead of initialize

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 5d9a5c02
...@@ -2,19 +2,13 @@ module Gitlab ...@@ -2,19 +2,13 @@ module Gitlab
class ProjectSearchResults < SearchResults class ProjectSearchResults < SearchResults
attr_reader :project, :repository_ref attr_reader :project, :repository_ref
def initialize(project_id, query, scope = nil, page = nil, repository_ref = nil) def initialize(project_id, query, repository_ref = nil)
@project = Project.find(project_id) @project = Project.find(project_id)
@repository_ref = repository_ref @repository_ref = repository_ref
@page = page
@query = Shellwords.shellescape(query) if query.present? @query = Shellwords.shellescape(query) if query.present?
@scope = scope
unless %w(blobs notes issues merge_requests).include?(@scope)
@scope = default_scope
end
end end
def objects def objects(scope, page)
case scope case scope
when 'notes' when 'notes'
notes.page(page).per(per_page) notes.page(page).per(per_page)
...@@ -51,10 +45,6 @@ module Gitlab ...@@ -51,10 +45,6 @@ module Gitlab
Note.where(project_id: limit_project_ids).search(query).order('updated_at DESC') Note.where(project_id: limit_project_ids).search(query).order('updated_at DESC')
end end
def default_scope
'blobs'
end
def limit_project_ids def limit_project_ids
[project.id] [project.id]
end end
......
module Gitlab module Gitlab
class SearchResults class SearchResults
attr_reader :scope, :objects, :query, :page attr_reader :query
# Limit search results by passed project ids # Limit search results by passed project ids
# It allows us to search only for projects user has access to # It allows us to search only for projects user has access to
attr_reader :limit_project_ids attr_reader :limit_project_ids
def initialize(limit_project_ids, query, scope = nil, page = nil) def initialize(limit_project_ids, query)
@limit_project_ids = limit_project_ids || Project.all @limit_project_ids = limit_project_ids || Project.all
@page = page
@query = Shellwords.shellescape(query) if query.present? @query = Shellwords.shellescape(query) if query.present?
@scope = scope
unless %w(projects issues merge_requests).include?(@scope)
@scope = default_scope
end
end end
def objects def objects(scope, page)
case scope case scope
when 'projects' when 'projects'
projects.page(page).per(per_page) projects.page(page).per(per_page)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment