2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2019-01-29 14:04:47 +00:00
|
|
|
module ChecksPerformValidation
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
before_create :validate_perform
|
|
|
|
before_update :validate_perform
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate_perform
|
|
|
|
# use Marshal to do a deep copy of the perform hash
|
|
|
|
validate_perform = Marshal.load(Marshal.dump(perform))
|
|
|
|
|
|
|
|
check_present = {
|
2020-11-10 10:31:13 +00:00
|
|
|
'article.note' => %w[body subject internal],
|
|
|
|
'notification.email' => %w[body recipient subject],
|
|
|
|
'notification.sms' => %w[body recipient],
|
2021-02-23 14:52:16 +00:00
|
|
|
'notification.webhook' => %w[webhook_id],
|
2019-01-29 14:04:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
check_present.each do |key, values|
|
|
|
|
next if validate_perform[key].blank?
|
|
|
|
|
|
|
|
values.each do |value|
|
|
|
|
raise Exceptions::UnprocessableEntity, "Invalid perform #{key}, #{value} is missing!" if validate_perform[key][value].blank?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|