From 5b8be81ef5cdcd3e691c890aea7a4ee93b34e56c Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sat, 16 Apr 2016 11:13:12 +0200 Subject: [PATCH] Fixed disable_notification attribute to prevent sending notifications. --- app/models/transaction/notification.rb | 2 ++ db/seeds.rb | 2 +- test/unit/ticket_notification_test.rb | 37 ++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/app/models/transaction/notification.rb b/app/models/transaction/notification.rb index 1d2780faa..b28d06b55 100644 --- a/app/models/transaction/notification.rb +++ b/app/models/transaction/notification.rb @@ -21,6 +21,8 @@ class Transaction::Notification end def perform + return if @params[:disable_notification] + ticket = Ticket.find(@item[:ticket_id]) if @item[:article_id] article = Ticket::Article.find(@item[:article_id]) diff --git a/db/seeds.rb b/db/seeds.rb index f13859168..b0b2556e9 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1806,7 +1806,7 @@ Setting.create_if_not_exists( }, ], }, - state: true, + state: false, preferences: { prio: 1 }, frontend: false ) diff --git a/test/unit/ticket_notification_test.rb b/test/unit/ticket_notification_test.rb index 2193d50ab..4ae1a26a4 100644 --- a/test/unit/ticket_notification_test.rb +++ b/test/unit/ticket_notification_test.rb @@ -383,6 +383,43 @@ class TicketNotificationTest < ActiveSupport::TestCase end + test 'ticket notification - no notification' do + + # create ticket in group + ticket1 = Ticket.create( + title: 'some notification test 1 - no notification', + group: Group.lookup(name: 'Users'), + customer: customer, + state: Ticket::State.lookup(name: 'new'), + priority: Ticket::Priority.lookup(name: '2 normal'), + updated_by_id: customer.id, + created_by_id: customer.id, + ) + Ticket::Article.create( + ticket_id: ticket1.id, + from: 'some_sender@example.com', + to: 'some_recipient@example.com', + subject: 'some subject', + message_id: 'some@id', + body: 'some message', + internal: false, + sender: Ticket::Article::Sender.where(name: 'Customer').first, + type: Ticket::Article::Type.where(name: 'email').first, + updated_by_id: customer.id, + created_by_id: customer.id, + ) + assert( ticket1, 'ticket created - ticket no notification' ) + + # execute object transaction + Observer::Transaction.commit(disable_notification: true) + Delayed::Worker.new.work_off + + # verify notifications to agent1 + agent2 + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id) + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, agent2, 'email'), ticket1.id) + + end + test 'ticket notification - z preferences tests' do agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true