diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-20 18:38:24 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-20 18:38:24 +0000 |
commit | 983a0bba5d2a042c4a3bbb22432ec192c7501d82 (patch) | |
tree | b153cd387c14ba23bd5a07514c7c01fddf6a78a0 /app/finders | |
parent | a2bddee2cdb38673df0e004d5b32d9f77797de64 (diff) | |
download | gitlab-ce-983a0bba5d2a042c4a3bbb22432ec192c7501d82.tar.gz |
Add latest changes from gitlab-org/gitlab@12-10-stable-ee
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/autocomplete/move_to_project_finder.rb | 3 | ||||
-rw-r--r-- | app/finders/autocomplete/routes_finder.rb | 47 | ||||
-rw-r--r-- | app/finders/metrics/dashboards/annotations_finder.rb | 42 |
3 files changed, 91 insertions, 1 deletions
diff --git a/app/finders/autocomplete/move_to_project_finder.rb b/app/finders/autocomplete/move_to_project_finder.rb index af6defc1fc6..f1c1eacafe6 100644 --- a/app/finders/autocomplete/move_to_project_finder.rb +++ b/app/finders/autocomplete/move_to_project_finder.rb @@ -28,7 +28,8 @@ module Autocomplete .optionally_search(search, include_namespace: true) .excluding_project(project_id) .eager_load_namespace_and_owner - .sorted_by_name_asc_limited(LIMIT) + .sorted_by_stars_desc + .limit(LIMIT) # rubocop: disable CodeReuse/ActiveRecord end end end 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 diff --git a/app/finders/metrics/dashboards/annotations_finder.rb b/app/finders/metrics/dashboards/annotations_finder.rb new file mode 100644 index 00000000000..c42b8bf40e5 --- /dev/null +++ b/app/finders/metrics/dashboards/annotations_finder.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +module Metrics + module Dashboards + class AnnotationsFinder + def initialize(dashboard:, params:) + @dashboard, @params = dashboard, params + end + + def execute + if dashboard.environment + apply_filters_to(annotations_for_environment) + else + Metrics::Dashboard::Annotation.none + end + end + + private + + attr_reader :dashboard, :params + + def apply_filters_to(annotations) + annotations = annotations.after(params[:from]) if params[:from].present? + annotations = annotations.before(params[:to]) if params[:to].present? && valid_timespan_boundaries? + + by_dashboard(annotations) + end + + def annotations_for_environment + dashboard.environment.metrics_dashboard_annotations + end + + def by_dashboard(annotations) + annotations.for_dashboard(dashboard.path) + end + + def valid_timespan_boundaries? + params[:from].blank? || params[:to] >= params[:from] + end + end + end +end |