Added history logging of notifications.

This commit is contained in:
Martin Edenhofer 2012-08-08 01:26:57 +02:00
parent ce6317c520
commit faaec79977
2 changed files with 23 additions and 2 deletions

View file

@ -69,7 +69,7 @@ class History < ActiveRecord::Base
if !related_history_object if !related_history_object
history = History.where( :history_object_id => History::Object.where( :name => requested_object ) ). history = History.where( :history_object_id => History::Object.where( :name => requested_object ) ).
where( :o_id => requested_object_id ). 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') order('created_at ASC, id ASC')
else else
history = History.where( history = History.where(
@ -78,7 +78,7 @@ class History < ActiveRecord::Base
requested_object_id, requested_object_id,
History::Object.where( :name => related_history_object ).first.id, History::Object.where( :name => related_history_object ).first.id,
requested_object_id, requested_object_id,
History::Type.where( :name => ['created', 'updated'] ) History::Type.where( :name => ['created', 'updated', 'notification'] )
). ).
order('created_at ASC, id ASC') order('created_at ASC, id ASC')
end end

View file

@ -178,9 +178,17 @@ From: #{article.from}
end end
# send notifications # send notifications
recipient_list = ''
notification_subject = ''
recipients.each do |user| recipients.each do |user|
next if !user.email || user.email == '' next if !user.email || user.email == ''
# add recipient_list
if recipient_list != ''
recipient_list += ','
end
recipient_list += user.email.to_s
# prepare subject & body # prepare subject & body
notification = {} notification = {}
[:subject, :body].each { |key| [:subject, :body].each { |key|
@ -193,6 +201,7 @@ From: #{article.from}
} }
) )
} }
notification_subject = notification[:subject]
# rebuild subject # rebuild subject
notification[:subject] = ticket.subject_build( notification[:subject] ) notification[:subject] = ticket.subject_build( notification[:subject] )
@ -204,6 +213,18 @@ From: #{article.from}
:body => notification[:body] :body => notification[:body]
) )
end 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 end
def after_create(record) def after_create(record)