diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /app/services/metrics/users_starred_dashboards/delete_service.rb | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'app/services/metrics/users_starred_dashboards/delete_service.rb')
-rw-r--r-- | app/services/metrics/users_starred_dashboards/delete_service.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/services/metrics/users_starred_dashboards/delete_service.rb b/app/services/metrics/users_starred_dashboards/delete_service.rb new file mode 100644 index 00000000000..579715bd49f --- /dev/null +++ b/app/services/metrics/users_starred_dashboards/delete_service.rb @@ -0,0 +1,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 |