From 983a0bba5d2a042c4a3bbb22432ec192c7501d82 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Mon, 20 Apr 2020 18:38:24 +0000 Subject: Add latest changes from gitlab-org/gitlab@12-10-stable-ee --- app/finders/autocomplete/routes_finder.rb | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 app/finders/autocomplete/routes_finder.rb (limited to 'app/finders/autocomplete/routes_finder.rb') diff --git a/app/finders/autocomplete/routes_finder.rb b/app/finders/autocomplete/routes_finder.rb new file mode 100644 index 00000000000..b3f2693b273 --- /dev/null +++ b/app/finders/autocomplete/routes_finder.rb @@ -0,0 +1,47 @@ +# 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 [] if @search.blank? + + 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 + return Namespace.all if current_user.admin? + + current_user.namespaces + end + end + + class ProjectsOnly < self + def routables + return Project.all if current_user.admin? + + current_user.projects + end + end + end +end -- cgit v1.2.3