2022-07-16 23:28:13 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module IncidentManagement
|
|
|
|
module TimelineEvents
|
|
|
|
class BaseService
|
2022-07-23 23:45:48 +05:30
|
|
|
include Gitlab::Utils::UsageData
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
AUTOCREATE_TAGS = [TimelineEventTag::START_TIME_TAG_NAME, TimelineEventTag::END_TIME_TAG_NAME].freeze
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
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
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
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
|
2022-07-16 23:28:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|