Fixed issue #779 - Simple triggers resulting in error condition. Fixed issue #395 - Auto-assign ticket owner on first reply. Fixed issue #389 - Trigger action "Owner" -> "not changed" needed. Fixed issue #298 - trigger "set to public" requested.
This commit is contained in:
parent
fbb3f3841f
commit
5a63106958
5 changed files with 1429 additions and 118 deletions
|
@ -58,6 +58,7 @@ class Observer::Transaction < ActiveRecord::Observer
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.error 'ERROR: ' + backend.inspect
|
Rails.logger.error 'ERROR: ' + backend.inspect
|
||||||
Rails.logger.error 'ERROR: ' + e.inspect
|
Rails.logger.error 'ERROR: ' + e.inspect
|
||||||
|
Rails.logger.error e.backtrace.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -652,11 +652,11 @@ condition example
|
||||||
|
|
||||||
perform changes on ticket
|
perform changes on ticket
|
||||||
|
|
||||||
ticket.perform_changes({}, 'trigger', item)
|
ticket.perform_changes({}, 'trigger', item, current_user_id)
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def perform_changes(perform, perform_origin, item = nil)
|
def perform_changes(perform, perform_origin, item = nil, current_user_id = nil)
|
||||||
logger.debug "Perform #{perform_origin} #{perform.inspect} on Ticket.find(#{id})"
|
logger.debug "Perform #{perform_origin} #{perform.inspect} on Ticket.find(#{id})"
|
||||||
changed = false
|
changed = false
|
||||||
perform.each do |key, value|
|
perform.each do |key, value|
|
||||||
|
@ -785,6 +785,16 @@ perform changes on ticket
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# lookup pre_condition
|
||||||
|
if value['pre_condition']
|
||||||
|
if value['pre_condition'] =~ /^not_set/
|
||||||
|
value['value'] = 1
|
||||||
|
elsif value['pre_condition'] =~ /^current_user\./
|
||||||
|
raise 'Unable to use current_user, got no current_user_id for ticket.perform_changes' if !current_user_id
|
||||||
|
value['value'] = current_user_id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# update ticket
|
# update ticket
|
||||||
next if self[attribute].to_s == value['value'].to_s
|
next if self[attribute].to_s == value['value'].to_s
|
||||||
changed = true
|
changed = true
|
||||||
|
|
|
@ -29,7 +29,11 @@ class Transaction::Trigger
|
||||||
|
|
||||||
return if @item[:object] != 'Ticket'
|
return if @item[:object] != 'Ticket'
|
||||||
|
|
||||||
triggers = Trigger.where(active: true).order('LOWER(name)')
|
triggers = if Rails.configuration.db_case_sensitive
|
||||||
|
Trigger.where(active: true).order('LOWER(name)')
|
||||||
|
else
|
||||||
|
Trigger.where(active: true).order(:name)
|
||||||
|
end
|
||||||
return if triggers.empty?
|
return if triggers.empty?
|
||||||
|
|
||||||
ticket = Ticket.lookup(id: @item[:object_id])
|
ticket = Ticket.lookup(id: @item[:object_id])
|
||||||
|
@ -44,49 +48,8 @@ class Transaction::Trigger
|
||||||
triggers.each { |trigger|
|
triggers.each { |trigger|
|
||||||
condition = trigger.condition
|
condition = trigger.condition
|
||||||
|
|
||||||
# check action
|
# check if one article attribute is used
|
||||||
if condition['ticket.action']
|
one_has_changed_done = false
|
||||||
next if condition['ticket.action']['operator'] == 'is' && condition['ticket.action']['value'] != @item[:type]
|
|
||||||
next if condition['ticket.action']['operator'] != 'is' && condition['ticket.action']['value'] == @item[:type]
|
|
||||||
condition.delete('ticket.action')
|
|
||||||
end
|
|
||||||
|
|
||||||
# check action
|
|
||||||
if condition['article.action']
|
|
||||||
next if !article
|
|
||||||
condition.delete('article.action')
|
|
||||||
end
|
|
||||||
|
|
||||||
# check "has changed" options
|
|
||||||
has_changed_condition_exists = false
|
|
||||||
has_changed = false
|
|
||||||
condition.each do |key, value|
|
|
||||||
next if !value
|
|
||||||
next if !value['operator']
|
|
||||||
next if !value['operator']['has changed']
|
|
||||||
has_changed_condition_exists = true
|
|
||||||
|
|
||||||
# next if has changed? && !@item[:changes][attribute]
|
|
||||||
(object_name, attribute) = key.split('.', 2)
|
|
||||||
|
|
||||||
# remove condition item, because it has changed
|
|
||||||
if @item[:changes][attribute]
|
|
||||||
has_changed = true
|
|
||||||
condition.delete(key)
|
|
||||||
next
|
|
||||||
end
|
|
||||||
break
|
|
||||||
end
|
|
||||||
|
|
||||||
next if has_changed_condition_exists && !has_changed
|
|
||||||
|
|
||||||
# check if selector is matching
|
|
||||||
condition['ticket.id'] = {
|
|
||||||
operator: 'is',
|
|
||||||
value: ticket.id,
|
|
||||||
}
|
|
||||||
|
|
||||||
# check if min one article attribute is used
|
|
||||||
article_selector = false
|
article_selector = false
|
||||||
trigger.condition.each do |key, _value|
|
trigger.condition.each do |key, _value|
|
||||||
(object_name, attribute) = key.split('.', 2)
|
(object_name, attribute) = key.split('.', 2)
|
||||||
|
@ -94,8 +57,70 @@ class Transaction::Trigger
|
||||||
next if attribute == 'id'
|
next if attribute == 'id'
|
||||||
article_selector = true
|
article_selector = true
|
||||||
end
|
end
|
||||||
|
if article && article_selector
|
||||||
|
one_has_changed_done = true
|
||||||
|
end
|
||||||
|
if article && @item[:type] == 'update'
|
||||||
|
one_has_changed_done = true
|
||||||
|
end
|
||||||
|
|
||||||
|
# check ticket "has changed" options
|
||||||
|
has_changed_done = true
|
||||||
|
condition.each do |key, value|
|
||||||
|
next if !value
|
||||||
|
next if !value['operator']
|
||||||
|
next if !value['operator']['has changed']
|
||||||
|
|
||||||
|
# remove condition item, because it has changed
|
||||||
|
(object_name, attribute) = key.split('.', 2)
|
||||||
|
next if object_name != 'ticket'
|
||||||
|
next if !@item[:changes]
|
||||||
|
next if !@item[:changes].key?(attribute)
|
||||||
|
condition.delete(key)
|
||||||
|
one_has_changed_done = true
|
||||||
|
end
|
||||||
|
|
||||||
|
# check if we have not matching "has changed" attributes
|
||||||
|
condition.each do |_key, value|
|
||||||
|
next if !value
|
||||||
|
next if !value['operator']
|
||||||
|
next if !value['operator']['has changed']
|
||||||
|
has_changed_done = false
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
# check ticket action
|
||||||
|
if condition['ticket.action']
|
||||||
|
next if condition['ticket.action']['operator'] == 'is' && condition['ticket.action']['value'] != @item[:type]
|
||||||
|
next if condition['ticket.action']['operator'] != 'is' && condition['ticket.action']['value'] == @item[:type]
|
||||||
|
condition.delete('ticket.action')
|
||||||
|
end
|
||||||
|
next if !has_changed_done
|
||||||
|
|
||||||
|
# check in min one attribute of condition has changed on update
|
||||||
|
one_has_changed_condition = false
|
||||||
|
if @item[:type] == 'update'
|
||||||
|
|
||||||
|
# verify if ticket condition exists
|
||||||
|
condition.each do |key, _value|
|
||||||
|
(object_name, attribute) = key.split('.', 2)
|
||||||
|
next if object_name != 'ticket'
|
||||||
|
one_has_changed_condition = true
|
||||||
|
next if !@item[:changes] || !@item[:changes].key?(attribute)
|
||||||
|
one_has_changed_done = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
next if one_has_changed_condition && !one_has_changed_done
|
||||||
|
end
|
||||||
|
|
||||||
|
# check if ticket selector is matching
|
||||||
|
condition['ticket.id'] = {
|
||||||
|
operator: 'is',
|
||||||
|
value: ticket.id,
|
||||||
|
}
|
||||||
next if article_selector && !article
|
next if article_selector && !article
|
||||||
|
|
||||||
|
# check if article selector is matching
|
||||||
if article_selector
|
if article_selector
|
||||||
condition['article.id'] = {
|
condition['article.id'] = {
|
||||||
operator: 'is',
|
operator: 'is',
|
||||||
|
@ -103,28 +128,15 @@ class Transaction::Trigger
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# verify is condition is matching
|
||||||
ticket_count, tickets = Ticket.selectors(condition, 1)
|
ticket_count, tickets = Ticket.selectors(condition, 1)
|
||||||
next if ticket_count.zero?
|
next if ticket_count.zero?
|
||||||
next if tickets.first.id != ticket.id
|
next if tickets.first.id != ticket.id
|
||||||
|
user_id = ticket.updated_by_id
|
||||||
# check in min one attribute has changed
|
if article
|
||||||
if @item[:type] == 'update' && !article_selector
|
user_id = article.updated_by_id
|
||||||
match = false
|
|
||||||
if has_changed_condition_exists && has_changed
|
|
||||||
match = true
|
|
||||||
else
|
|
||||||
trigger.condition.each do |key, _value|
|
|
||||||
(object_name, attribute) = key.split('.', 2)
|
|
||||||
next if object_name != 'ticket'
|
|
||||||
next if !@item[:changes][attribute]
|
|
||||||
match = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
next if !match
|
|
||||||
end
|
end
|
||||||
|
ticket.perform_changes(trigger.perform, 'trigger', @item, user_id)
|
||||||
ticket.perform_changes(trigger.perform, 'trigger', @item)
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
UserInfo.current_user_id = original_user_id
|
UserInfo.current_user_id = original_user_id
|
||||||
|
|
|
@ -44,6 +44,7 @@ class ActiveSupport::TestCase
|
||||||
|
|
||||||
# remove background jobs
|
# remove background jobs
|
||||||
Delayed::Job.destroy_all
|
Delayed::Job.destroy_all
|
||||||
|
Trigger.destroy_all
|
||||||
ActivityStream.destroy_all
|
ActivityStream.destroy_all
|
||||||
PostmasterFilter.destroy_all
|
PostmasterFilter.destroy_all
|
||||||
Ticket.destroy_all
|
Ticket.destroy_all
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue