Fixed issue #1149 - Trigger: Wrong behaviour for condition "is not" "not set".

This commit is contained in:
Rolf Schmidt 2017-07-06 15:58:10 +02:00
parent 164aa47e57
commit 74ebb10d2c
2 changed files with 225 additions and 3 deletions

View file

@ -504,7 +504,7 @@ condition example
query += "#{attribute} IN (?)"
bind_params.push 1
else
query += "#{attribute} IS NOT NULL"
query += "#{attribute} IS NULL"
end
elsif selector['pre_condition'] == 'current_user.id'
raise "Use current_user.id in selector, but no current_user is set #{selector.inspect}" if !current_user_id
@ -518,7 +518,7 @@ condition example
else
# rubocop:disable Style/IfInsideElse
if selector['value'].nil?
query += "#{attribute} IS NOT NULL"
query += "#{attribute} IS NULL"
else
query += "#{attribute} IN (?)"
bind_params.push selector['value']
@ -531,7 +531,7 @@ condition example
query += "#{attribute} NOT IN (?)"
bind_params.push 1
else
query += "#{attribute} IS NULL"
query += "#{attribute} IS NOT NULL"
end
elsif selector['pre_condition'] == 'current_user.id'
query += "#{attribute} NOT IN (?)"

View file

@ -1414,6 +1414,228 @@ class TicketTriggerTest < ActiveSupport::TestCase
end
test '6.1 owner auto assignment based on organization' do
trigger1 = Trigger.create_or_update(
name: 'aaa auto assignment',
condition: {
'ticket.organization_id' => {
'operator' => 'is not',
'pre_condition' => 'not_set',
'value' => '',
'value_completion' => '',
},
'ticket.action' => {
'operator' => 'is',
'value' => 'update',
},
},
perform: {
'ticket.owner_id' => {
'pre_condition' => 'current_user.id',
'value' => '',
'value_completion' => '',
},
},
disable_notification: true,
active: true,
created_by_id: 1,
updated_by_id: 1,
)
roles = Role.where(name: 'Agent')
agent = User.create_or_update(
login: 'agent@example.com',
firstname: 'Trigger',
lastname: 'Agent1',
email: 'agent@example.com',
password: 'agentpw',
active: true,
roles: roles,
updated_by_id: 1,
created_by_id: 1,
)
roles = Role.where(name: 'Customer')
customer = User.create_or_update(
login: 'customer@example.com',
firstname: 'Trigger',
lastname: 'Customer1',
email: 'customer@example.com',
password: 'customerpw',
vip: true,
active: true,
roles: roles,
updated_by_id: 1,
created_by_id: 1,
)
ticket1 = Ticket.create(
title: 'test 123',
group: Group.lookup(name: 'Users'),
customer: customer,
updated_by_id: 1,
created_by_id: 1,
)
Ticket::Article.create(
ticket_id: ticket1.id,
from: 'some_sender@example.com',
to: 'some_recipient@example.com',
subject: 'some subject',
message_id: 'some@id',
body: "some message <b>note</b>\nnew line",
internal: false,
sender: Ticket::Article::Sender.find_by(name: 'Agent'),
type: Ticket::Article::Type.find_by(name: 'note'),
updated_by_id: 1,
created_by_id: 1,
)
Observer::Transaction.commit
assert_equal('test 123', ticket1.title, 'ticket1.title verify')
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
assert_equal('new', ticket1.state.name, 'ticket1.state verify')
assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
assert_equal([], ticket1.tag_list)
ticket1.update_attribute(:customer, User.lookup(email: 'nicole.braun@zammad.org') )
UserInfo.current_user_id = agent.id
Ticket::Article.create(
ticket_id: ticket1.id,
from: 'some_sender@example.com',
to: 'some_recipient@example.com',
subject: 'update',
message_id: 'some@id',
content_type: 'text/html',
body: 'update',
internal: false,
sender: Ticket::Article::Sender.find_by(name: 'Agent'),
type: Ticket::Article::Type.find_by(name: 'note'),
)
Observer::Transaction.commit
UserInfo.current_user_id = nil
ticket1.reload
assert_equal('test 123', ticket1.title, 'ticket1.title verify')
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
assert_equal('new', ticket1.state.name, 'ticket1.state verify')
assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
assert_equal([], ticket1.tag_list)
end
test '6.2 owner auto assignment based on organization' do
trigger1 = Trigger.create_or_update(
name: 'aaa auto assignment',
condition: {
'ticket.organization_id' => {
'operator' => 'is',
'pre_condition' => 'not_set',
'value' => '',
'value_completion' => '',
},
'ticket.action' => {
'operator' => 'is',
'value' => 'update',
},
},
perform: {
'ticket.owner_id' => {
'pre_condition' => 'current_user.id',
'value' => '',
'value_completion' => '',
},
},
disable_notification: true,
active: true,
created_by_id: 1,
updated_by_id: 1,
)
roles = Role.where(name: 'Agent')
agent = User.create_or_update(
login: 'agent@example.com',
firstname: 'Trigger',
lastname: 'Agent1',
email: 'agent@example.com',
password: 'agentpw',
active: true,
roles: roles,
updated_by_id: 1,
created_by_id: 1,
)
roles = Role.where(name: 'Customer')
customer = User.create_or_update(
login: 'customer@example.com',
firstname: 'Trigger',
lastname: 'Customer1',
email: 'customer@example.com',
password: 'customerpw',
vip: true,
active: true,
roles: roles,
updated_by_id: 1,
created_by_id: 1,
)
ticket1 = Ticket.create(
title: 'test 123',
group: Group.lookup(name: 'Users'),
customer: User.lookup(email: 'nicole.braun@zammad.org'),
updated_by_id: 1,
created_by_id: 1,
)
Ticket::Article.create(
ticket_id: ticket1.id,
from: 'some_sender@example.com',
to: 'some_recipient@example.com',
subject: 'some subject',
message_id: 'some@id',
body: "some message <b>note</b>\nnew line",
internal: false,
sender: Ticket::Article::Sender.find_by(name: 'Agent'),
type: Ticket::Article::Type.find_by(name: 'note'),
updated_by_id: 1,
created_by_id: 1,
)
Observer::Transaction.commit
assert_equal('test 123', ticket1.title, 'ticket1.title verify')
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
assert_equal(1, ticket1.owner_id, 'ticket1.owner_id verify')
assert_equal('new', ticket1.state.name, 'ticket1.state verify')
assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
assert_equal([], ticket1.tag_list)
ticket1.update_attribute(:customer, customer )
UserInfo.current_user_id = agent.id
Ticket::Article.create(
ticket_id: ticket1.id,
from: 'some_sender@example.com',
to: 'some_recipient@example.com',
subject: 'update',
message_id: 'some@id',
content_type: 'text/html',
body: 'update',
internal: false,
sender: Ticket::Article::Sender.find_by(name: 'Agent'),
type: Ticket::Article::Type.find_by(name: 'note'),
)
Observer::Transaction.commit
UserInfo.current_user_id = nil
ticket1.reload
assert_equal('test 123', ticket1.title, 'ticket1.title verify')
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
assert_equal(agent.id, ticket1.owner_id, 'ticket1.owner_id verify')
assert_equal('new', ticket1.state.name, 'ticket1.state verify')
assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
assert_equal([], ticket1.tag_list)
end
test '7 owner auto assignment' do
trigger1 = Trigger.create_or_update(
name: 'aaa auto assignment',