Welcome to mirror list, hosted at ThFree Co, Russian Federation.

base_service.rb « timeline_events « incident_management « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e0ca43200910ad96606d5ee895bc2f1e574dc42f (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true

module IncidentManagement
  module TimelineEvents
    class BaseService
      include Gitlab::Utils::UsageData

      AUTOCREATE_TAGS = [TimelineEventTag::START_TIME_TAG_NAME, TimelineEventTag::END_TIME_TAG_NAME].freeze

      def allowed?
        user&.can?(:admin_incident_management_timeline_event, incident)
      end

      def success(timeline_event)
        ServiceResponse.success(payload: { timeline_event: timeline_event })
      end

      def error(message)
        ServiceResponse.error(message: message)
      end

      def error_no_permissions
        error(_('You have insufficient permissions to manage timeline events for this incident'))
      end

      def error_in_save(timeline_event)
        error(timeline_event.errors.full_messages.to_sentence)
      end

      def track_timeline_event(event, project)
        namespace = project.namespace
        track_usage_event(event, user.id)

        return unless Feature.enabled?(:route_hll_to_snowplow_phase2, namespace)

        Gitlab::Tracking.event(
          self.class.to_s,
          event,
          project: project,
          namespace: namespace,
          user: user,
          label: 'redis_hll_counters.incident_management.incident_management_total_unique_counts_monthly',
          context: [Gitlab::Tracking::ServicePingContext.new(data_source: :redis_hll, event: event).to_context]
        )
      end

      def auto_create_predefined_tags(new_tags)
        new_tags = new_tags.map(&:downcase)

        tags_to_create = AUTOCREATE_TAGS.select { |tag| tag.downcase.in?(new_tags) }

        tags_to_create.each do |name|
          project.incident_management_timeline_event_tags.create(name: name)
        end
      end
    end
  end
end