debian-mirror-gitlab/app/services/metrics/users_starred_dashboards/delete_service.rb

34 lines
1 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# 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