debian-mirror-gitlab/app/finders/metrics/users_starred_dashboards_finder.rb

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

38 lines
870 B
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
module Metrics
class UsersStarredDashboardsFinder
def initialize(user:, project:, params: {})
2021-04-29 21:17:54 +05:30
@user = user
@project = project
@params = params
2020-05-24 23:13:21 +05:30
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