debian-mirror-gitlab/app/finders/autocomplete/routes_finder.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1,019 B
Ruby
Raw Normal View History

2020-04-22 19:07:51 +05:30
# 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
2023-03-04 22:38:38 +05:30
return Route.none if @search.blank?
2020-04-22 19:07:51 +05:30
Route
.for_routable(routables)
.sort_by_path_length
.fuzzy_search(@search, [:path])
.limit(LIMIT) # rubocop: disable CodeReuse/ActiveRecord
end
private
def routables
raise NotImplementedError
end
class NamespacesOnly < self
def routables
2023-03-04 22:38:38 +05:30
return Namespace.without_project_namespaces if current_user.can_admin_all_resources?
2020-04-22 19:07:51 +05:30
current_user.namespaces
end
end
class ProjectsOnly < self
def routables
2023-03-04 22:38:38 +05:30
return Project.all if current_user.can_admin_all_resources?
2020-04-22 19:07:51 +05:30
current_user.projects
end
end
end
end