Do no self notification if changes are done via we. If I create a new ticket via email, do self notification.

This commit is contained in:
Martin Edenhofer 2016-02-03 08:58:51 +01:00
parent c5ba4f39cb
commit fb99b5cb08
3 changed files with 186 additions and 106 deletions

View file

@ -17,12 +17,17 @@ class Observer::Ticket::Notification < ActiveRecord::Observer
# reset buffer
EventBuffer.reset
via_web = false
if ENV['SERVER_NAME']
via_web = true
end
# get uniq objects
list_objects = get_uniq_changes(list)
list_objects.each {|_ticket_id, item|
# send background job
Delayed::Job.enqueue( Observer::Ticket::Notification::BackgroundJob.new( item ) )
Delayed::Job.enqueue( Observer::Ticket::Notification::BackgroundJob.new( item, via_web ) )
}
end

View file

@ -1,8 +1,9 @@
# encoding: utf-8
class Observer::Ticket::Notification::BackgroundJob
def initialize(params)
def initialize(params, via_web = false)
@p = params
@via_web = via_web
end
def perform
@ -52,15 +53,15 @@ class Observer::Ticket::Notification::BackgroundJob
recipient_list = ''
recipients.each do |user|
# ignore user who changed it by him self
# ignore user who changed it by him self via web
if @via_web
next if article && article.updated_by_id == user.id
next if !article && ticket.updated_by_id == user.id
end
# ignore inactive users
next if !user.active
# create desktop notification
# create online notification
seen = ticket.online_notification_seen_state(user.id)
OnlineNotification.add(

View file

@ -58,7 +58,80 @@ class TicketNotificationTest < ActiveSupport::TestCase
created_by_id: 1,
)
test 'ticket notification simple' do
test 'ticket notification - to all agents / to explicit agents' do
# create ticket in group
ticket1 = Ticket.create(
title: 'some notification test 1',
group: Group.lookup(name: 'Users'),
customer: agent1,
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '2 normal'),
updated_by_id: agent1.id,
created_by_id: agent1.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: agent1.id,
created_by_id: agent1.id,
)
assert(ticket1)
# execute ticket events
ENV['SERVER_NAME'] = nil
Observer::Ticket::Notification.transaction
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
# verify notifications to agent1 + agent2
assert_equal(1, notification_check(ticket1, agent1), ticket1.id)
assert_equal(1, notification_check(ticket1, agent2), ticket1.id)
# create ticket in group
ticket1 = Ticket.create(
title: 'some notification test 1',
group: Group.lookup(name: 'Users'),
customer: agent1,
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '2 normal'),
updated_by_id: agent1.id,
created_by_id: agent1.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: agent1.id,
created_by_id: agent1.id,
)
assert(ticket1)
# execute ticket events
ENV['SERVER_NAME'] = 'some_host'
Observer::Ticket::Notification.transaction
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
# verify notifications to agent1 + agent2
assert_equal(0, notification_check(ticket1, agent1), ticket1.id)
assert_equal(1, notification_check(ticket1, agent2), ticket1.id)
end
test 'ticket notification - simple' do
# create ticket in group
ticket1 = Ticket.create(
@ -86,6 +159,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
assert( ticket1, 'ticket created - ticket notification simple' )
# execute ticket events
ENV['SERVER_NAME'] = 'some_host'
Observer::Ticket::Notification.transaction
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off