Remember user_id in transaction backends (updated_by_id can already be changed at execution time).
This commit is contained in:
parent
acb3a23681
commit
1c1077e115
14 changed files with 55 additions and 32 deletions
|
@ -46,6 +46,7 @@ class Observer::Transaction < ActiveRecord::Observer
|
||||||
type: 'create',
|
type: 'create',
|
||||||
object_id: 123,
|
object_id: 123,
|
||||||
article_id: 123,
|
article_id: 123,
|
||||||
|
user_id: 123,
|
||||||
},
|
},
|
||||||
9 => {
|
9 => {
|
||||||
object: 'Ticket',
|
object: 'Ticket',
|
||||||
|
@ -55,6 +56,7 @@ class Observer::Transaction < ActiveRecord::Observer
|
||||||
attribute1: [before, now],
|
attribute1: [before, now],
|
||||||
attribute2: [before, now],
|
attribute2: [before, now],
|
||||||
},
|
},
|
||||||
|
user_id: 123,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -70,6 +72,7 @@ class Observer::Transaction < ActiveRecord::Observer
|
||||||
attribute1: [before, now],
|
attribute1: [before, now],
|
||||||
attribute2: [before, now],
|
attribute2: [before, now],
|
||||||
},
|
},
|
||||||
|
user_id: 123,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -110,6 +113,7 @@ class Observer::Transaction < ActiveRecord::Observer
|
||||||
store = list_objects[event[:object]][object.id]
|
store = list_objects[event[:object]][object.id]
|
||||||
store[:object] = event[:object]
|
store[:object] = event[:object]
|
||||||
store[:object_id] = object.id
|
store[:object_id] = object.id
|
||||||
|
store[:user_id] = event[:user_id]
|
||||||
|
|
||||||
if !store[:type] || store[:type] == 'update'
|
if !store[:type] || store[:type] == 'update'
|
||||||
store[:type] = event[:type]
|
store[:type] = event[:type]
|
||||||
|
@ -148,6 +152,7 @@ class Observer::Transaction < ActiveRecord::Observer
|
||||||
type: 'create',
|
type: 'create',
|
||||||
data: record,
|
data: record,
|
||||||
id: record.id,
|
id: record.id,
|
||||||
|
user_id: record.created_by_id,
|
||||||
}
|
}
|
||||||
EventBuffer.add('transaction', e)
|
EventBuffer.add('transaction', e)
|
||||||
end
|
end
|
||||||
|
@ -181,6 +186,7 @@ class Observer::Transaction < ActiveRecord::Observer
|
||||||
data: record,
|
data: record,
|
||||||
changes: real_changes,
|
changes: real_changes,
|
||||||
id: record.id,
|
id: record.id,
|
||||||
|
user_id: record.updated_by_id,
|
||||||
}
|
}
|
||||||
EventBuffer.add('transaction', e)
|
EventBuffer.add('transaction', e)
|
||||||
end
|
end
|
||||||
|
|
|
@ -185,6 +185,7 @@ returns
|
||||||
type: 'reminder_reached',
|
type: 'reminder_reached',
|
||||||
object_id: ticket.id,
|
object_id: ticket.id,
|
||||||
article_id: ticket.articles.last.id,
|
article_id: ticket.articles.last.id,
|
||||||
|
user_id: 1,
|
||||||
)
|
)
|
||||||
|
|
||||||
result.push ticket
|
result.push ticket
|
||||||
|
@ -225,6 +226,7 @@ returns
|
||||||
type: 'escalation',
|
type: 'escalation',
|
||||||
object_id: ticket.id,
|
object_id: ticket.id,
|
||||||
article_id: ticket.articles.last.id,
|
article_id: ticket.articles.last.id,
|
||||||
|
user_id: 1,
|
||||||
)
|
)
|
||||||
result.push ticket
|
result.push ticket
|
||||||
next
|
next
|
||||||
|
@ -236,6 +238,7 @@ returns
|
||||||
type: 'escalation_warning',
|
type: 'escalation_warning',
|
||||||
object_id: ticket.id,
|
object_id: ticket.id,
|
||||||
article_id: ticket.articles.last.id,
|
article_id: ticket.articles.last.id,
|
||||||
|
user_id: 1,
|
||||||
)
|
)
|
||||||
result.push ticket
|
result.push ticket
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ class Transaction::BackgroundJob
|
||||||
'attribute1' => [before,now],
|
'attribute1' => [before,now],
|
||||||
'attribute2' => [before,now],
|
'attribute2' => [before,now],
|
||||||
}
|
}
|
||||||
|
user_id: 123,
|
||||||
},
|
},
|
||||||
=end
|
=end
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ class Transaction::ClearbitEnrichment
|
||||||
'attribute1' => [before, now],
|
'attribute1' => [before, now],
|
||||||
'attribute2' => [before, now],
|
'attribute2' => [before, now],
|
||||||
}
|
}
|
||||||
|
user_id: 123,
|
||||||
},
|
},
|
||||||
=end
|
=end
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ class Transaction::Notification
|
||||||
'attribute1' => [before, now],
|
'attribute1' => [before, now],
|
||||||
'attribute2' => [before, now],
|
'attribute2' => [before, now],
|
||||||
}
|
}
|
||||||
|
user_id: 123,
|
||||||
},
|
},
|
||||||
=end
|
=end
|
||||||
|
|
||||||
|
@ -88,7 +89,7 @@ class Transaction::Notification
|
||||||
# ignore user who changed it by him self via web
|
# ignore user who changed it by him self via web
|
||||||
if @params[:via_web]
|
if @params[:via_web]
|
||||||
next if article && article.updated_by_id == user.id
|
next if article && article.updated_by_id == user.id
|
||||||
next if !article && ticket.updated_by_id == user.id
|
next if !article && @item[:user_id] == user.id
|
||||||
end
|
end
|
||||||
|
|
||||||
# ignore inactive users
|
# ignore inactive users
|
||||||
|
@ -120,7 +121,7 @@ class Transaction::Notification
|
||||||
if channels['online']
|
if channels['online']
|
||||||
used_channels.push 'online'
|
used_channels.push 'online'
|
||||||
|
|
||||||
created_by_id = ticket.updated_by_id || 1
|
created_by_id = @item[:user_id] || 1
|
||||||
|
|
||||||
# delete old notifications
|
# delete old notifications
|
||||||
if @item[:type] == 'reminder_reached'
|
if @item[:type] == 'reminder_reached'
|
||||||
|
@ -178,6 +179,11 @@ class Transaction::Notification
|
||||||
raise "unknown type for notification #{@item[:type]}"
|
raise "unknown type for notification #{@item[:type]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
current_user = User.lookup(id: @item[:user_id] || 1)
|
||||||
|
if !current_user
|
||||||
|
current_user = User.lookup(id: 1)
|
||||||
|
end
|
||||||
|
|
||||||
NotificationFactory::Mailer.notification(
|
NotificationFactory::Mailer.notification(
|
||||||
template: template,
|
template: template,
|
||||||
user: user,
|
user: user,
|
||||||
|
@ -185,6 +191,7 @@ class Transaction::Notification
|
||||||
ticket: ticket,
|
ticket: ticket,
|
||||||
article: article,
|
article: article,
|
||||||
recipient: user,
|
recipient: user,
|
||||||
|
current_user: current_user,
|
||||||
changes: changes,
|
changes: changes,
|
||||||
},
|
},
|
||||||
references: ticket.get_references,
|
references: ticket.get_references,
|
||||||
|
@ -207,7 +214,7 @@ class Transaction::Notification
|
||||||
history_type: 'notification',
|
history_type: 'notification',
|
||||||
history_object: 'Ticket',
|
history_object: 'Ticket',
|
||||||
value_to: recipient_list,
|
value_to: recipient_list,
|
||||||
created_by_id: ticket.updated_by_id || 1
|
created_by_id: @item[:user_id] || 1
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ class Transaction::SignatureDetection
|
||||||
'attribute1' => [before, now],
|
'attribute1' => [before, now],
|
||||||
'attribute2' => [before, now],
|
'attribute2' => [before, now],
|
||||||
}
|
}
|
||||||
|
user_id: 123,
|
||||||
},
|
},
|
||||||
=end
|
=end
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ backend = Transaction::Slack.new(
|
||||||
object: 'Ticket',
|
object: 'Ticket',
|
||||||
type: 'create',
|
type: 'create',
|
||||||
object_id: 1,
|
object_id: 1,
|
||||||
|
user_id: 123,
|
||||||
)
|
)
|
||||||
backend.perform
|
backend.perform
|
||||||
|
|
||||||
|
@ -19,6 +20,7 @@ backend.perform
|
||||||
'attribute1' => [before, now],
|
'attribute1' => [before, now],
|
||||||
'attribute2' => [before, now],
|
'attribute2' => [before, now],
|
||||||
}
|
}
|
||||||
|
user_id: 123,
|
||||||
},
|
},
|
||||||
=end
|
=end
|
||||||
def initialize(item, params = {})
|
def initialize(item, params = {})
|
||||||
|
|
|
@ -2,7 +2,7 @@ Neues Ticket (<%= d 'ticket.title' %>)
|
||||||
|
|
||||||
<p>Hallo <%= d 'recipient.firstname' %>,</p>
|
<p>Hallo <%= d 'recipient.firstname' %>,</p>
|
||||||
<br>
|
<br>
|
||||||
<p>es wurde ein neues Ticket (<%= d 'ticket.title' %>) von "<b><%= d 'ticket.updated_by.longname' %></b>" erstellt.</p>
|
<p>es wurde ein neues Ticket (<%= d 'ticket.title' %>) von "<b><%= d 'current_user.longname' %></b>" erstellt.</p>
|
||||||
<br>
|
<br>
|
||||||
<p>
|
<p>
|
||||||
<%= t 'Group' %>: <%= d 'ticket.group.name' %><br>
|
<%= t 'Group' %>: <%= d 'ticket.group.name' %><br>
|
||||||
|
|
|
@ -2,7 +2,7 @@ New Ticket (<%= d 'ticket.title' %>)
|
||||||
|
|
||||||
<p>Hi <%= d 'recipient.firstname' %>,</p>
|
<p>Hi <%= d 'recipient.firstname' %>,</p>
|
||||||
<br>
|
<br>
|
||||||
<p>A new ticket (<%= d 'ticket.title' %>) has been created by "<b><%= d 'ticket.updated_by.longname' %></b>".</p>
|
<p>A new ticket (<%= d 'ticket.title' %>) has been created by "<b><%= d 'current_user.longname' %></b>".</p>
|
||||||
<br>
|
<br>
|
||||||
<p>
|
<p>
|
||||||
<%= t 'Group' %>: <%= d 'ticket.group.name' %><br>
|
<%= t 'Group' %>: <%= d 'ticket.group.name' %><br>
|
||||||
|
|
|
@ -3,7 +3,7 @@ Ticket aktualisiert (<%= d 'ticket.title' %>)
|
||||||
<p>Hi <%= d 'recipient.firstname' %>,</p>
|
<p>Hi <%= d 'recipient.firstname' %>,</p>
|
||||||
<br>
|
<br>
|
||||||
<div>
|
<div>
|
||||||
Ticket (<%= d 'ticket.title' %>) wurde von "<b><%= d 'ticket.updated_by.longname' %></b>" aktualisiert.
|
Ticket (<%= d 'ticket.title' %>) wurde von "<b><%= d 'current_user.longname' %></b>" aktualisiert.
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<% if @objects[:changes] && !@objects[:changes].empty? %>
|
<% if @objects[:changes] && !@objects[:changes].empty? %>
|
||||||
|
|
|
@ -3,7 +3,7 @@ Updated Ticket (<%= d 'ticket.title' %>)
|
||||||
<p>Hi <%= d 'recipient.firstname' %>,</p>
|
<p>Hi <%= d 'recipient.firstname' %>,</p>
|
||||||
<br>
|
<br>
|
||||||
<div>
|
<div>
|
||||||
Ticket (<%= d 'ticket.title' %>) has been updated by "<b><%= d 'ticket.updated_by.longname' %></b>".
|
Ticket (<%= d 'ticket.title' %>) has been updated by "<b><%= d 'current_user.longname' %></b>".
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<% if @objects[:changes] && !@objects[:changes].empty? %>
|
<% if @objects[:changes] && !@objects[:changes].empty? %>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# <%= d 'ticket.title' %>
|
# <%= d 'ticket.title' %>
|
||||||
_<<%= c 'http_type' %>://<%= c 'fqdn' %>/#ticket/zoom/<%= d 'ticket.id' %>|Ticket#<%= d 'ticket.number' %>>: Created by <%= d 'ticket.updated_by.longname' %> at <%= d 'ticket.updated_at' %>_
|
_<<%= c 'http_type' %>://<%= c 'fqdn' %>/#ticket/zoom/<%= d 'ticket.id' %>|Ticket#<%= d 'ticket.number' %>>: Created by <%= d 'current_user.longname' %> at <%= d 'ticket.updated_at' %>_
|
||||||
* <%= t 'Group' %>: <%= d 'ticket.group.name' %>
|
* <%= t 'Group' %>: <%= d 'ticket.group.name' %>
|
||||||
* <%= t 'Owner' %>: <%= d 'ticket.owner.fullname' %>
|
* <%= t 'Owner' %>: <%= d 'ticket.owner.fullname' %>
|
||||||
* <%= t 'State' %>: <%= t d 'ticket.state.name' %>
|
* <%= t 'State' %>: <%= t d 'ticket.state.name' %>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# <%= d 'ticket.title' %>
|
# <%= d 'ticket.title' %>
|
||||||
_<<%= c 'http_type' %>://<%= c 'fqdn' %>/#ticket/zoom/<%= d 'ticket.id' %>|Ticket#<%= d 'ticket.number' %>>: Updated by <%= d 'ticket.updated_by.longname' %> at <%= d 'ticket.updated_at' %>_
|
_<<%= c 'http_type' %>://<%= c 'fqdn' %>/#ticket/zoom/<%= d 'ticket.id' %>|Ticket#<%= d 'ticket.number' %>>: Updated by <%= d 'current_user.longname' %> at <%= d 'ticket.updated_at' %>_
|
||||||
<% if @objects[:changes] && !@objects[:changes].empty? %>
|
<% if @objects[:changes] && !@objects[:changes].empty? %>
|
||||||
<% @objects[:changes].each do |key, value| %>
|
<% @objects[:changes].each do |key, value| %>
|
||||||
* <%= t key %>: <%= h value[0] %> -> <%= h value[1] %>
|
* <%= t key %>: <%= h value[0] %> -> <%= h value[1] %>
|
||||||
|
|
|
@ -154,7 +154,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
updated_by_id: customer.id,
|
updated_by_id: customer.id,
|
||||||
created_by_id: customer.id,
|
created_by_id: customer.id,
|
||||||
)
|
)
|
||||||
assert( ticket1, 'ticket created - ticket notification simple' )
|
assert(ticket1, 'ticket created - ticket notification simple')
|
||||||
|
|
||||||
# execute object transaction
|
# execute object transaction
|
||||||
Rails.configuration.webserver_is_active = true
|
Rails.configuration.webserver_is_active = true
|
||||||
|
@ -267,7 +267,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
Observer::Transaction.commit
|
Observer::Transaction.commit
|
||||||
Scheduler.worker(true)
|
Scheduler.worker(true)
|
||||||
|
|
||||||
# verify notifications to no one
|
# verify notifications to none
|
||||||
assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, agent1, 'email'), ticket2.id)
|
assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, agent1, 'email'), ticket2.id)
|
||||||
assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, agent2, 'email'), ticket2.id)
|
assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, agent2, 'email'), ticket2.id)
|
||||||
|
|
||||||
|
@ -395,7 +395,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
updated_by_id: customer.id,
|
updated_by_id: customer.id,
|
||||||
created_by_id: customer.id,
|
created_by_id: customer.id,
|
||||||
)
|
)
|
||||||
assert( ticket1, 'ticket created - ticket no notification' )
|
assert(ticket1, 'ticket created - ticket no notification')
|
||||||
|
|
||||||
# execute object transaction
|
# execute object transaction
|
||||||
Observer::Transaction.commit(disable_notification: true)
|
Observer::Transaction.commit(disable_notification: true)
|
||||||
|
@ -934,19 +934,20 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
'priority_id' => [1, 2],
|
'priority_id' => [1, 2],
|
||||||
'pending_time' => [nil, Time.zone.parse('2015-01-11 23:33:47 UTC')],
|
'pending_time' => [nil, Time.zone.parse('2015-01-11 23:33:47 UTC')],
|
||||||
},
|
},
|
||||||
|
user_id: ticket1.updated_by_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
# check changed attributes
|
# check changed attributes
|
||||||
human_changes = bg.human_changes(agent2, ticket1)
|
human_changes = bg.human_changes(agent2, ticket1)
|
||||||
assert( human_changes['Priority'], 'Check if attributes translated based on ObjectManager::Attribute' )
|
assert(human_changes['Priority'], 'Check if attributes translated based on ObjectManager::Attribute')
|
||||||
assert( human_changes['Pending till'], 'Check if attributes translated based on ObjectManager::Attribute' )
|
assert(human_changes['Pending till'], 'Check if attributes translated based on ObjectManager::Attribute')
|
||||||
assert_equal( '1 low', human_changes['Priority'][0] )
|
assert_equal('1 low', human_changes['Priority'][0])
|
||||||
assert_equal( '2 normal', human_changes['Priority'][1] )
|
assert_equal('2 normal', human_changes['Priority'][1])
|
||||||
assert_equal( '', human_changes['Pending till'][0].to_s )
|
assert_equal('', human_changes['Pending till'][0].to_s)
|
||||||
assert_equal( '2015-01-11 23:33:47 UTC', human_changes['Pending till'][1].to_s )
|
assert_equal('2015-01-11 23:33:47 UTC', human_changes['Pending till'][1].to_s)
|
||||||
assert_not( human_changes['priority_id'] )
|
assert_not(human_changes['priority_id'])
|
||||||
assert_not( human_changes['pending_time'] )
|
assert_not(human_changes['pending_time'])
|
||||||
assert_not( human_changes['pending_till'] )
|
assert_not(human_changes['pending_till'])
|
||||||
|
|
||||||
# en notification
|
# en notification
|
||||||
result = NotificationFactory::Mailer.template(
|
result = NotificationFactory::Mailer.template(
|
||||||
|
@ -957,7 +958,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
article: article,
|
article: article,
|
||||||
recipient: agent2,
|
recipient: agent2,
|
||||||
changes: human_changes,
|
changes: human_changes,
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
assert_match(/Bobs's resumé/, result[:subject])
|
assert_match(/Bobs's resumé/, result[:subject])
|
||||||
assert_match(/Priority/, result[:body])
|
assert_match(/Priority/, result[:body])
|
||||||
|
@ -970,15 +971,15 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
assert_no_match(/i18n/, result[:body])
|
assert_no_match(/i18n/, result[:body])
|
||||||
|
|
||||||
human_changes = bg.human_changes(agent1, ticket1)
|
human_changes = bg.human_changes(agent1, ticket1)
|
||||||
assert( human_changes['Priority'], 'Check if attributes translated based on ObjectManager::Attribute' )
|
assert(human_changes['Priority'], 'Check if attributes translated based on ObjectManager::Attribute')
|
||||||
assert( human_changes['Pending till'], 'Check if attributes translated based on ObjectManager::Attribute' )
|
assert(human_changes['Pending till'], 'Check if attributes translated based on ObjectManager::Attribute')
|
||||||
assert_equal( '1 niedrig', human_changes['Priority'][0] )
|
assert_equal('1 niedrig', human_changes['Priority'][0])
|
||||||
assert_equal( '2 normal', human_changes['Priority'][1] )
|
assert_equal('2 normal', human_changes['Priority'][1])
|
||||||
assert_equal( '', human_changes['Pending till'][0].to_s )
|
assert_equal('', human_changes['Pending till'][0].to_s)
|
||||||
assert_equal( '2015-01-11 23:33:47 UTC', human_changes['Pending till'][1].to_s )
|
assert_equal('2015-01-11 23:33:47 UTC', human_changes['Pending till'][1].to_s)
|
||||||
assert_not( human_changes['priority_id'] )
|
assert_not(human_changes['priority_id'])
|
||||||
assert_not( human_changes['pending_time'] )
|
assert_not(human_changes['pending_time'])
|
||||||
assert_not( human_changes['pending_till'] )
|
assert_not(human_changes['pending_till'])
|
||||||
|
|
||||||
# de notification
|
# de notification
|
||||||
result = NotificationFactory::Mailer.template(
|
result = NotificationFactory::Mailer.template(
|
||||||
|
@ -989,7 +990,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
article: article,
|
article: article,
|
||||||
recipient: agent1,
|
recipient: agent1,
|
||||||
changes: human_changes,
|
changes: human_changes,
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert_match(/Bobs's resumé/, result[:subject])
|
assert_match(/Bobs's resumé/, result[:subject])
|
||||||
|
@ -1010,6 +1011,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
title: ['some notification template test old 1', 'some notification template test 1 #2'],
|
title: ['some notification template test old 1', 'some notification template test 1 #2'],
|
||||||
priority_id: [2, 3],
|
priority_id: [2, 3],
|
||||||
},
|
},
|
||||||
|
user_id: customer.id,
|
||||||
)
|
)
|
||||||
|
|
||||||
# check changed attributes
|
# check changed attributes
|
||||||
|
|
Loading…
Reference in a new issue