2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
2013-06-12 15:59:58 +00:00
|
|
|
|
2013-02-01 08:53:14 +00:00
|
|
|
class Sla < ApplicationModel
|
2017-05-02 15:21:13 +00:00
|
|
|
include ChecksClientNotification
|
|
|
|
include ChecksConditionValidation
|
2021-08-25 12:24:42 +00:00
|
|
|
include ChecksCoreWorkflow
|
2021-02-15 13:55:00 +00:00
|
|
|
include HasEscalationCalculationImpact
|
2017-01-31 17:13:45 +00:00
|
|
|
|
2016-03-20 19:09:52 +00:00
|
|
|
include Sla::Assets
|
|
|
|
|
2015-12-11 16:00:04 +00:00
|
|
|
store :condition
|
|
|
|
store :data
|
|
|
|
validates :name, presence: true
|
2019-07-04 11:16:55 +00:00
|
|
|
belongs_to :calendar, optional: true
|
2021-02-15 13:55:00 +00:00
|
|
|
|
|
|
|
def condition_matches?(ticket)
|
|
|
|
query_condition, bind_condition, tables = Ticket.selector2sql(condition)
|
|
|
|
Ticket.where(query_condition, *bind_condition).joins(tables).exists?(ticket.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.for_ticket(ticket)
|
|
|
|
fallback = nil
|
|
|
|
all.order(:name, :created_at).find_each do |record|
|
|
|
|
if record.condition.present?
|
|
|
|
return record if record.condition_matches?(ticket)
|
|
|
|
else
|
|
|
|
fallback = record
|
|
|
|
end
|
|
|
|
end
|
|
|
|
fallback
|
|
|
|
end
|
2013-06-12 15:59:58 +00:00
|
|
|
end
|