From faaec79977b0319e49a9c98e30bb7d6fd07ec433 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 8 Aug 2012 01:26:57 +0200 Subject: [PATCH] Added history logging of notifications. --- app/models/history.rb | 4 ++-- app/models/ticket/observer/notification.rb | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/models/history.rb b/app/models/history.rb index 1025652f7..a46286fdc 100644 --- a/app/models/history.rb +++ b/app/models/history.rb @@ -69,7 +69,7 @@ class History < ActiveRecord::Base if !related_history_object history = History.where( :history_object_id => History::Object.where( :name => requested_object ) ). where( :o_id => requested_object_id ). - where( :history_type_id => History::Type.where( :name => ['created', 'updated']) ). + where( :history_type_id => History::Type.where( :name => ['created', 'updated', 'notification'] ) ). order('created_at ASC, id ASC') else history = History.where( @@ -78,7 +78,7 @@ class History < ActiveRecord::Base requested_object_id, History::Object.where( :name => related_history_object ).first.id, requested_object_id, - History::Type.where( :name => ['created', 'updated'] ) + History::Type.where( :name => ['created', 'updated', 'notification'] ) ). order('created_at ASC, id ASC') end diff --git a/app/models/ticket/observer/notification.rb b/app/models/ticket/observer/notification.rb index 732a7b4b3..11d13a624 100644 --- a/app/models/ticket/observer/notification.rb +++ b/app/models/ticket/observer/notification.rb @@ -178,9 +178,17 @@ From: #{article.from} end # send notifications + recipient_list = '' + notification_subject = '' recipients.each do |user| next if !user.email || user.email == '' + # add recipient_list + if recipient_list != '' + recipient_list += ',' + end + recipient_list += user.email.to_s + # prepare subject & body notification = {} [:subject, :body].each { |key| @@ -193,6 +201,7 @@ From: #{article.from} } ) } + notification_subject = notification[:subject] # rebuild subject notification[:subject] = ticket.subject_build( notification[:subject] ) @@ -204,6 +213,18 @@ From: #{article.from} :body => notification[:body] ) end + + # add history record + if recipient_list != '' + History.history_create( + :o_id => ticket.id, + :history_type => 'notification', + :history_object => 'Ticket', + :value_from => notification_subject, + :value_to => recipient_list, + :created_by_id => ticket.created_by_id || 1 + ) + end end def after_create(record)