diff --git a/app/finders/metrics/users_starred_dashboards_finder.rb b/app/finders/metrics/users_starred_dashboards_finder.rb deleted file mode 100644 index 2ef706c1b114f0e84a905787bd089c0ff6309e66..0000000000000000000000000000000000000000 --- a/app/finders/metrics/users_starred_dashboards_finder.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -module Metrics - class UsersStarredDashboardsFinder - def initialize(user:, project:, params: {}) - @user = user - @project = project - @params = 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 diff --git a/spec/finders/metrics/users_starred_dashboards_finder_spec.rb b/spec/finders/metrics/users_starred_dashboards_finder_spec.rb deleted file mode 100644 index 4136cf1123ad3e33f6da5a711fdc6b42a66c1697..0000000000000000000000000000000000000000 --- a/spec/finders/metrics/users_starred_dashboards_finder_spec.rb +++ /dev/null @@ -1,56 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Metrics::UsersStarredDashboardsFinder do - describe '#execute' do - subject(:starred_dashboards) { described_class.new(user: user, project: project, params: params).execute } - - let_it_be(:user) { create(:user) } - - let(:project) { create(:project) } - let(:dashboard_path) { 'config/prometheus/common_metrics.yml' } - let(:params) { {} } - - context 'there are no starred dashboard records' do - it 'returns empty array' do - expect(starred_dashboards).to be_empty - end - end - - context 'with annotation records' do - let!(:starred_dashboard_1) { create(:metrics_users_starred_dashboard, user: user, project: project) } - let!(:starred_dashboard_2) { create(:metrics_users_starred_dashboard, user: user, project: project, dashboard_path: dashboard_path) } - let!(:other_project_dashboard) { create(:metrics_users_starred_dashboard, user: user, dashboard_path: dashboard_path) } - let!(:other_user_dashboard) { create(:metrics_users_starred_dashboard, project: project, dashboard_path: dashboard_path) } - - context 'user without read access to project' do - it 'returns empty relation' do - expect(starred_dashboards).to be_empty - end - end - - context 'user with read access to project' do - before do - project.add_reporter(user) - end - - it 'loads starred dashboards' do - expect(starred_dashboards).to contain_exactly starred_dashboard_1, starred_dashboard_2 - end - - context 'when the dashboard_path filter is present' do - let(:params) do - { - dashboard_path: dashboard_path - } - end - - it 'loads filtered starred dashboards' do - expect(starred_dashboards).to contain_exactly starred_dashboard_2 - end - end - end - end - end -end