From 675a6d1d0c8638b2be8de196636375ff3e2c53a1 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 10 Feb 2015 13:37:47 +0100 Subject: [PATCH] Do not send notifications of article update / only on article create. --- app/models/observer/ticket/notification.rb | 3 ++ test/unit/ticket_notification_test.rb | 39 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/app/models/observer/ticket/notification.rb b/app/models/observer/ticket/notification.rb index 6306a819f..9d393718c 100644 --- a/app/models/observer/ticket/notification.rb +++ b/app/models/observer/ticket/notification.rb @@ -128,6 +128,9 @@ class Observer::Ticket::Notification < ActiveRecord::Observer # return if we run import mode return if Setting.get('import_mode') + # ignore updates on articles / we just want send notifications on ticket updates + return if record.class.name == 'Ticket::Article' + # ignore certain attributes real_changes = {} record.changes.each {|key, value| diff --git a/test/unit/ticket_notification_test.rb b/test/unit/ticket_notification_test.rb index ad3134599..688031a82 100644 --- a/test/unit/ticket_notification_test.rb +++ b/test/unit/ticket_notification_test.rb @@ -288,6 +288,20 @@ class TicketNotificationTest < ActiveSupport::TestCase assert_equal( 0, notification_check(ticket3, agent2), ticket3.id ) + # update article / not notification should be sent + article_inbound.internal = true + article_inbound.save + + # execute ticket events + Observer::Ticket::Notification.transaction + #puts Delayed::Job.all.inspect + Delayed::Worker.new.work_off + + # verify notifications not to agent1 and not to agent2 + assert_equal( 2, notification_check(ticket3, agent1), ticket3.id ) + assert_equal( 0, notification_check(ticket3, agent2), ticket3.id ) + + delete = ticket1.destroy assert( delete, "ticket1 destroy" ) @@ -472,6 +486,31 @@ class TicketNotificationTest < ActiveSupport::TestCase assert_match( /2 normal/, body ) assert_match( /aktualis/, body ) + bg = Observer::Ticket::Notification::BackgroundJob.new( + :ticket_id => ticket1.id, + :article_id => article.id, + :type => 'update', + :changes => { + :title => ['some notification template test 1', 'some notification template test 1 #2'], + :priority_id => [2, 3], + }, + ) + + human_changes = bg.human_changes(agent1,ticket1) + puts "hc #{human_changes.inspect}" + + + human_changes = bg.human_changes(agent2,ticket1) + puts "hc2 #{human_changes.inspect}" + + template = bg.template_update(agent1, ticket1, article, human_changes) + puts "t1 #{template.inspect}" + + template = bg.template_update(agent2, ticket1, article, human_changes) + puts "t2 #{template.inspect}" + + + end def notification_check(ticket, recipient)