trabajo-afectivo/app/models/concerns/checks_perform_validation.rb
2022-01-01 14:38:12 +01:00

32 lines
905 B
Ruby

# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
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 = {
'article.note' => %w[body subject internal],
'notification.email' => %w[body recipient subject],
'notification.sms' => %w[body recipient],
'notification.webhook' => %w[webhook_id],
}
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