Welcome to mirror list, hosted at ThFree Co, Russian Federation.

users_starred_dashboards_finder.rb « metrics « finders « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7244c51f9a74698d07a23002f13015330a1d1ef2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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