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',
object_id: 123,
article_id: 123,
user_id: 123,
},
9 => {
object: 'Ticket',
@ -55,6 +56,7 @@ class Observer::Transaction < ActiveRecord::Observer
attribute1: [before, now],
attribute2: [before, now],
},
user_id: 123,
},
},
}
@ -70,6 +72,7 @@ class Observer::Transaction < ActiveRecord::Observer
attribute1: [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[:object] = event[:object]
store[:object_id] = object.id
store[:user_id] = event[:user_id]
if !store[:type] || store[:type] == 'update'
store[:type] = event[:type]
@ -148,6 +152,7 @@ class Observer::Transaction < ActiveRecord::Observer
type: 'create',
data: record,
id: record.id,
user_id: record.created_by_id,
}
EventBuffer.add('transaction', e)
end
@ -181,6 +186,7 @@ class Observer::Transaction < ActiveRecord::Observer
data: record,
changes: real_changes,
id: record.id,
user_id: record.updated_by_id,
}
EventBuffer.add('transaction', e)
end

View file

@ -185,6 +185,7 @@ returns
type: 'reminder_reached',
object_id: ticket.id,
article_id: ticket.articles.last.id,
user_id: 1,
)
result.push ticket
@ -225,6 +226,7 @@ returns
type: 'escalation',
object_id: ticket.id,
article_id: ticket.articles.last.id,
user_id: 1,
)
result.push ticket
next
@ -236,6 +238,7 @@ returns
type: 'escalation_warning',
object_id: ticket.id,
article_id: ticket.articles.last.id,
user_id: 1,
)
result.push ticket
}

View file

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

View file

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

View file

@ -12,6 +12,7 @@ class Transaction::Notification
'attribute1' => [before, now],
'attribute2' => [before, now],
}
user_id: 123,
},
=end
@ -88,7 +89,7 @@ class Transaction::Notification
# ignore user who changed it by him self via web
if @params[:via_web]
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
# ignore inactive users
@ -120,7 +121,7 @@ class Transaction::Notification
if channels['online']
used_channels.push 'online'
created_by_id = ticket.updated_by_id || 1
created_by_id = @item[:user_id] || 1
# delete old notifications
if @item[:type] == 'reminder_reached'
@ -178,6 +179,11 @@ class Transaction::Notification
raise "unknown type for notification #{@item[:type]}"
end
current_user = User.lookup(id: @item[:user_id] || 1)
if !current_user
current_user = User.lookup(id: 1)
end
NotificationFactory::Mailer.notification(
template: template,
user: user,
@ -185,6 +191,7 @@ class Transaction::Notification
ticket: ticket,
article: article,
recipient: user,
current_user: current_user,
changes: changes,
},
references: ticket.get_references,
@ -207,7 +214,7 @@ class Transaction::Notification
history_type: 'notification',
history_object: 'Ticket',
value_to: recipient_list,
created_by_id: ticket.updated_by_id || 1
created_by_id: @item[:user_id] || 1
)
end

View file

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

View file

@ -7,6 +7,7 @@ backend = Transaction::Slack.new(
object: 'Ticket',
type: 'create',
object_id: 1,
user_id: 123,
)
backend.perform
@ -19,6 +20,7 @@ backend.perform
'attribute1' => [before, now],
'attribute2' => [before, now],
}
user_id: 123,
},
=end
def initialize(item, params = {})

View file

@ -2,7 +2,7 @@ Neues Ticket (<%= d 'ticket.title' %>)
<p>Hallo <%= d 'recipient.firstname' %>,</p>
<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>
<p>
<%= t 'Group' %>: <%= d 'ticket.group.name' %><br>

View file

@ -2,7 +2,7 @@ New Ticket (<%= d 'ticket.title' %>)
<p>Hi <%= d 'recipient.firstname' %>,</p>
<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>
<p>
<%= t 'Group' %>: <%= d 'ticket.group.name' %><br>

View file

@ -3,7 +3,7 @@ Ticket aktualisiert (<%= d 'ticket.title' %>)
<p>Hi <%= d 'recipient.firstname' %>,</p>
<br>
<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>
<br>
<% if @objects[:changes] && !@objects[:changes].empty? %>

View file

@ -3,7 +3,7 @@ Updated Ticket (<%= d 'ticket.title' %>)
<p>Hi <%= d 'recipient.firstname' %>,</p>
<br>
<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>
<br>
<% if @objects[:changes] && !@objects[:changes].empty? %>

View file

@ -1,5 +1,5 @@
# <%= 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 'Owner' %>: <%= d 'ticket.owner.fullname' %>
* <%= t 'State' %>: <%= t d 'ticket.state.name' %>

View file

@ -1,5 +1,5 @@
# <%= 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? %>
<% @objects[:changes].each do |key, value| %>
* <%= t key %>: <%= h value[0] %> -> <%= h value[1] %>

View file

@ -154,7 +154,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
updated_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
Rails.configuration.webserver_is_active = true
@ -267,7 +267,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
Observer::Transaction.commit
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, agent2, 'email'), ticket2.id)
@ -395,7 +395,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
updated_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
Observer::Transaction.commit(disable_notification: true)
@ -934,19 +934,20 @@ class TicketNotificationTest < ActiveSupport::TestCase
'priority_id' => [1, 2],
'pending_time' => [nil, Time.zone.parse('2015-01-11 23:33:47 UTC')],
},
user_id: ticket1.updated_by_id,
)
# check changed attributes
human_changes = bg.human_changes(agent2, ticket1)
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_equal( '1 low', human_changes['Priority'][0] )
assert_equal( '2 normal', human_changes['Priority'][1] )
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_not( human_changes['priority_id'] )
assert_not( human_changes['pending_time'] )
assert_not( human_changes['pending_till'] )
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_equal('1 low', human_changes['Priority'][0])
assert_equal('2 normal', human_changes['Priority'][1])
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_not(human_changes['priority_id'])
assert_not(human_changes['pending_time'])
assert_not(human_changes['pending_till'])
# en notification
result = NotificationFactory::Mailer.template(
@ -957,7 +958,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
article: article,
recipient: agent2,
changes: human_changes,
}
},
)
assert_match(/Bobs's resumé/, result[:subject])
assert_match(/Priority/, result[:body])
@ -970,15 +971,15 @@ class TicketNotificationTest < ActiveSupport::TestCase
assert_no_match(/i18n/, result[:body])
human_changes = bg.human_changes(agent1, ticket1)
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_equal( '1 niedrig', human_changes['Priority'][0] )
assert_equal( '2 normal', human_changes['Priority'][1] )
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_not( human_changes['priority_id'] )
assert_not( human_changes['pending_time'] )
assert_not( human_changes['pending_till'] )
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_equal('1 niedrig', human_changes['Priority'][0])
assert_equal('2 normal', human_changes['Priority'][1])
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_not(human_changes['priority_id'])
assert_not(human_changes['pending_time'])
assert_not(human_changes['pending_till'])
# de notification
result = NotificationFactory::Mailer.template(
@ -989,7 +990,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
article: article,
recipient: agent1,
changes: human_changes,
}
},
)
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'],
priority_id: [2, 3],
},
user_id: customer.id,
)
# check changed attributes