2017-04-27 14:57:19 +00:00
|
|
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
2017-05-02 15:21:13 +00:00
|
|
|
module ChecksConditionValidation
|
2017-04-27 14:57:19 +00:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
before_create :validate_condition
|
|
|
|
before_update :validate_condition
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate_condition
|
|
|
|
# use Marshal to do a deep copy of the condition hash
|
|
|
|
validate_condition = Marshal.load(Marshal.dump(condition))
|
|
|
|
|
|
|
|
# check if a valid condition got inserted.
|
|
|
|
validate_condition.delete('ticket.action')
|
|
|
|
validate_condition.each do |key, value|
|
|
|
|
next if !value
|
|
|
|
next if !value['operator']
|
|
|
|
next if !value['operator']['has changed']
|
|
|
|
|
|
|
|
validate_condition.delete(key)
|
|
|
|
end
|
|
|
|
|
|
|
|
validate_condition['ticket.id'] = {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: 1,
|
2017-04-27 14:57:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ticket_count, tickets = Ticket.selectors(validate_condition, 1, User.find(1))
|
2017-06-16 22:53:20 +00:00
|
|
|
return true if ticket_count.present?
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-04-27 14:57:19 +00:00
|
|
|
raise Exceptions::UnprocessableEntity, 'Invalid ticket selector conditions'
|
|
|
|
end
|
|
|
|
end
|