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',
|
||||
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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ class Transaction::BackgroundJob
|
|||
'attribute1' => [before,now],
|
||||
'attribute2' => [before,now],
|
||||
}
|
||||
user_id: 123,
|
||||
},
|
||||
=end
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ class Transaction::ClearbitEnrichment
|
|||
'attribute1' => [before, now],
|
||||
'attribute2' => [before, now],
|
||||
}
|
||||
user_id: 123,
|
||||
},
|
||||
=end
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ class Transaction::SignatureDetection
|
|||
'attribute1' => [before, now],
|
||||
'attribute2' => [before, now],
|
||||
}
|
||||
user_id: 123,
|
||||
},
|
||||
=end
|
||||
|
||||
|
|
|
@ -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 = {})
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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? %>
|
||||
|
|
|
@ -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? %>
|
||||
|
|
|
@ -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' %>
|
||||
|
|
|
@ -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] %>
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
@ -934,6 +934,7 @@ 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
|
||||
|
@ -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])
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue