diff --git a/app/models/observer/transaction.rb b/app/models/observer/transaction.rb index 8f403d38e..26437c192 100644 --- a/app/models/observer/transaction.rb +++ b/app/models/observer/transaction.rb @@ -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 diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 30a38888c..5cba7da75 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -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 } diff --git a/app/models/transaction/background_job.rb b/app/models/transaction/background_job.rb index fcb580b44..9bde30da4 100644 --- a/app/models/transaction/background_job.rb +++ b/app/models/transaction/background_job.rb @@ -13,6 +13,7 @@ class Transaction::BackgroundJob 'attribute1' => [before,now], 'attribute2' => [before,now], } + user_id: 123, }, =end diff --git a/app/models/transaction/clearbit_enrichment.rb b/app/models/transaction/clearbit_enrichment.rb index 80d8fb78a..6c04b3830 100644 --- a/app/models/transaction/clearbit_enrichment.rb +++ b/app/models/transaction/clearbit_enrichment.rb @@ -11,6 +11,7 @@ class Transaction::ClearbitEnrichment 'attribute1' => [before, now], 'attribute2' => [before, now], } + user_id: 123, }, =end diff --git a/app/models/transaction/notification.rb b/app/models/transaction/notification.rb index 5c9cca837..c52b04a88 100644 --- a/app/models/transaction/notification.rb +++ b/app/models/transaction/notification.rb @@ -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 diff --git a/app/models/transaction/signature_detection.rb b/app/models/transaction/signature_detection.rb index 3c14b74e5..349ee34e6 100644 --- a/app/models/transaction/signature_detection.rb +++ b/app/models/transaction/signature_detection.rb @@ -13,6 +13,7 @@ class Transaction::SignatureDetection 'attribute1' => [before, now], 'attribute2' => [before, now], } + user_id: 123, }, =end diff --git a/app/models/transaction/slack.rb b/app/models/transaction/slack.rb index a4c331b00..f27995e77 100644 --- a/app/models/transaction/slack.rb +++ b/app/models/transaction/slack.rb @@ -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 = {}) diff --git a/app/views/mailer/ticket_create/de.html.erb b/app/views/mailer/ticket_create/de.html.erb index 8806b0875..a1704c0f5 100644 --- a/app/views/mailer/ticket_create/de.html.erb +++ b/app/views/mailer/ticket_create/de.html.erb @@ -2,7 +2,7 @@ Neues Ticket (<%= d 'ticket.title' %>)

Hallo <%= d 'recipient.firstname' %>,


-

es wurde ein neues Ticket (<%= d 'ticket.title' %>) von "<%= d 'ticket.updated_by.longname' %>" erstellt.

+

es wurde ein neues Ticket (<%= d 'ticket.title' %>) von "<%= d 'current_user.longname' %>" erstellt.


<%= t 'Group' %>: <%= d 'ticket.group.name' %>
diff --git a/app/views/mailer/ticket_create/en.html.erb b/app/views/mailer/ticket_create/en.html.erb index 7a71d711d..ef6b039a2 100644 --- a/app/views/mailer/ticket_create/en.html.erb +++ b/app/views/mailer/ticket_create/en.html.erb @@ -2,7 +2,7 @@ New Ticket (<%= d 'ticket.title' %>)

Hi <%= d 'recipient.firstname' %>,


-

A new ticket (<%= d 'ticket.title' %>) has been created by "<%= d 'ticket.updated_by.longname' %>".

+

A new ticket (<%= d 'ticket.title' %>) has been created by "<%= d 'current_user.longname' %>".


<%= t 'Group' %>: <%= d 'ticket.group.name' %>
diff --git a/app/views/mailer/ticket_update/de.html.erb b/app/views/mailer/ticket_update/de.html.erb index 576be3f21..b2159b7ff 100644 --- a/app/views/mailer/ticket_update/de.html.erb +++ b/app/views/mailer/ticket_update/de.html.erb @@ -3,7 +3,7 @@ Ticket aktualisiert (<%= d 'ticket.title' %>)

Hi <%= d 'recipient.firstname' %>,


-Ticket (<%= d 'ticket.title' %>) wurde von "<%= d 'ticket.updated_by.longname' %>" aktualisiert. +Ticket (<%= d 'ticket.title' %>) wurde von "<%= d 'current_user.longname' %>" aktualisiert.

<% if @objects[:changes] && !@objects[:changes].empty? %> diff --git a/app/views/mailer/ticket_update/en.html.erb b/app/views/mailer/ticket_update/en.html.erb index df29d9ac0..4ff310d31 100644 --- a/app/views/mailer/ticket_update/en.html.erb +++ b/app/views/mailer/ticket_update/en.html.erb @@ -3,7 +3,7 @@ Updated Ticket (<%= d 'ticket.title' %>)

Hi <%= d 'recipient.firstname' %>,


-Ticket (<%= d 'ticket.title' %>) has been updated by "<%= d 'ticket.updated_by.longname' %>". +Ticket (<%= d 'ticket.title' %>) has been updated by "<%= d 'current_user.longname' %>".

<% if @objects[:changes] && !@objects[:changes].empty? %> diff --git a/app/views/slack/ticket_create/en.md.erb b/app/views/slack/ticket_create/en.md.erb index 594fac928..0d8268e39 100644 --- a/app/views/slack/ticket_create/en.md.erb +++ b/app/views/slack/ticket_create/en.md.erb @@ -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' %> diff --git a/app/views/slack/ticket_update/en.md.erb b/app/views/slack/ticket_update/en.md.erb index e391ad115..fe1a80e29 100644 --- a/app/views/slack/ticket_update/en.md.erb +++ b/app/views/slack/ticket_update/en.md.erb @@ -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] %> diff --git a/test/unit/ticket_notification_test.rb b/test/unit/ticket_notification_test.rb index 6339634ea..0f2fc5ee6 100644 --- a/test/unit/ticket_notification_test.rb +++ b/test/unit/ticket_notification_test.rb @@ -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