summaryrefslogtreecommitdiff
path: root/app/services/metrics/dashboard/annotations/delete_service.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/metrics/dashboard/annotations/delete_service.rb')
-rw-r--r--app/services/metrics/dashboard/annotations/delete_service.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/app/services/metrics/dashboard/annotations/delete_service.rb b/app/services/metrics/dashboard/annotations/delete_service.rb
new file mode 100644
index 00000000000..c6a6c4f5fbf
--- /dev/null
+++ b/app/services/metrics/dashboard/annotations/delete_service.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+# Delete Metrics::Dashboard::Annotation entry
+module Metrics
+ module Dashboard
+ module Annotations
+ class DeleteService < ::BaseService
+ include Stepable
+
+ steps :authorize_action,
+ :delete
+
+ def initialize(user, annotation)
+ @user, @annotation = user, annotation
+ end
+
+ def execute
+ execute_steps
+ end
+
+ private
+
+ attr_reader :user, :annotation
+
+ def authorize_action(_options)
+ if Ability.allowed?(user, :delete_metrics_dashboard_annotation, annotation)
+ success
+ else
+ error(s_('Metrics::Dashboard::Annotation|You are not authorized to delete this annotation'))
+ end
+ end
+
+ def delete(_options)
+ if annotation.destroy
+ success
+ else
+ error(s_('Metrics::Dashboard::Annotation|Annotation has not been deleted'))
+ end
+ end
+ end
+ end
+ end
+end