blob: 579715bd49f767995df874322e05806d7b97a8fc (
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
|
# frozen_string_literal: true
# Delete all matching Metrics::UsersStarredDashboard entries for given user based on matched dashboard_path, project
module Metrics
module UsersStarredDashboards
class DeleteService < ::BaseService
def initialize(user, project, dashboard_path = nil)
@user, @project, @dashboard_path = user, project, dashboard_path
end
def execute
ServiceResponse.success(payload: { deleted_rows: starred_dashboards.delete_all })
end
private
attr_reader :user, :project, :dashboard_path
def starred_dashboards
# since deleted records are scoped to their owner there is no need to
# check if that user can delete them, also if user lost access to
# project it shouldn't block that user from removing them
dashboards = user.metrics_users_starred_dashboards
if dashboard_path.present?
dashboards.for_project_dashboard(project, dashboard_path)
else
dashboards.for_project(project)
end
end
end
end
end
|