diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /app/finders/metrics/users_starred_dashboards_finder.rb | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'app/finders/metrics/users_starred_dashboards_finder.rb')
-rw-r--r-- | app/finders/metrics/users_starred_dashboards_finder.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/app/finders/metrics/users_starred_dashboards_finder.rb b/app/finders/metrics/users_starred_dashboards_finder.rb new file mode 100644 index 00000000000..7244c51f9a7 --- /dev/null +++ b/app/finders/metrics/users_starred_dashboards_finder.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module Metrics + class UsersStarredDashboardsFinder + def initialize(user:, project:, params: {}) + @user, @project, @params = user, project, params + end + + def execute + return ::Metrics::UsersStarredDashboard.none unless Ability.allowed?(user, :read_metrics_user_starred_dashboard, project) + + items = starred_dashboards + items = by_project(items) + by_dashboard(items) + end + + private + + attr_reader :user, :project, :params + + def by_project(items) + items.for_project(project) + end + + def by_dashboard(items) + return items unless params[:dashboard_path] + + items.merge(starred_dashboards.for_project_dashboard(project, params[:dashboard_path])) + end + + def starred_dashboards + @starred_dashboards ||= user.metrics_users_starred_dashboards + end + end +end |