Remember user_id in transaction backends (updated_by_id can already be changed at execution time).

This commit is contained in:
Martin Edenhofer 2016-04-27 09:31:11 +02:00
parent acb3a23681
commit 1c1077e115
14 changed files with 55 additions and 32 deletions

View file

@ -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

View file

@ -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
} }

View file

@ -13,6 +13,7 @@ class Transaction::BackgroundJob
'attribute1' => [before,now], 'attribute1' => [before,now],
'attribute2' => [before,now], 'attribute2' => [before,now],
} }
user_id: 123,
}, },
=end =end

View file

@ -11,6 +11,7 @@ class Transaction::ClearbitEnrichment
'attribute1' => [before, now], 'attribute1' => [before, now],
'attribute2' => [before, now], 'attribute2' => [before, now],
} }
user_id: 123,
}, },
=end =end

View file

@ -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

View file

@ -13,6 +13,7 @@ class Transaction::SignatureDetection
'attribute1' => [before, now], 'attribute1' => [before, now],
'attribute2' => [before, now], 'attribute2' => [before, now],
} }
user_id: 123,
}, },
=end =end

View file

@ -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 = {})

View file

@ -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>

View file

@ -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>

View file

@ -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? %>

View file

@ -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? %>

View file

@ -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' %>

View file

@ -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] %>

View file

@ -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)
@ -934,6 +934,7 @@ 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
@ -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])
@ -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