summaryrefslogtreecommitdiff
path: root/app/services/metrics/dashboard/annotations/delete_service.rb
blob: 34918c89304fda34e31538954818e7973e2f1c7c (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
34
35
36
37
38
39
40
41
42
43
44
# 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 = user
          @annotation = annotation
        end

        def execute
          execute_steps
        end

        private

        attr_reader :user, :annotation

        def authorize_action(_options)
          if Ability.allowed?(user, :admin_metrics_dashboard_annotation, annotation)
            success
          else
            error(s_('MetricsDashboardAnnotation|You are not authorized to delete this annotation'))
          end
        end

        def delete(_options)
          if annotation.destroy
            success
          else
            error(s_('MetricsDashboardAnnotation|Annotation has not been deleted'))
          end
        end
      end
    end
  end
end