blob: ed807d3a295333cd9061f88ecd6108551e707115 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# frozen_string_literal: true
module Autocomplete
# Finder that returns a list of routes that match on the `path` attribute.
class RoutesFinder
attr_reader :current_user, :search
LIMIT = 20
def initialize(current_user, params = {})
@current_user = current_user
@search = params[:search]
end
def execute
return Route.none if @search.blank?
Route
.for_routable(routables)
.sort_by_path_length
.fuzzy_search(@search, [:path])
.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/421843')
.limit(LIMIT) # rubocop: disable CodeReuse/ActiveRecord
end
private
def routables
raise NotImplementedError
end
class NamespacesOnly < self
def routables
if current_user.can_admin_all_resources?
Namespace.without_project_namespaces
else
current_user.namespaces
end.allow_cross_joins_across_databases(url: "https://gitlab.com/gitlab-org/gitlab/-/issues/420046")
end
end
class ProjectsOnly < self
def routables
return Project.all if current_user.can_admin_all_resources?
current_user.projects
end
end
end
end
|