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:
parent
c5ba4f39cb
commit
fb99b5cb08
3 changed files with 186 additions and 106 deletions
|
@ -17,12 +17,17 @@ class Observer::Ticket::Notification < ActiveRecord::Observer
|
||||||
# reset buffer
|
# reset buffer
|
||||||
EventBuffer.reset
|
EventBuffer.reset
|
||||||
|
|
||||||
|
via_web = false
|
||||||
|
if ENV['SERVER_NAME']
|
||||||
|
via_web = true
|
||||||
|
end
|
||||||
|
|
||||||
# get uniq objects
|
# get uniq objects
|
||||||
list_objects = get_uniq_changes(list)
|
list_objects = get_uniq_changes(list)
|
||||||
list_objects.each {|_ticket_id, item|
|
list_objects.each {|_ticket_id, item|
|
||||||
|
|
||||||
# send background job
|
# send background job
|
||||||
Delayed::Job.enqueue( Observer::Ticket::Notification::BackgroundJob.new( item ) )
|
Delayed::Job.enqueue( Observer::Ticket::Notification::BackgroundJob.new( item, via_web ) )
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
class Observer::Ticket::Notification::BackgroundJob
|
class Observer::Ticket::Notification::BackgroundJob
|
||||||
def initialize(params)
|
def initialize(params, via_web = false)
|
||||||
@p = params
|
@p = params
|
||||||
|
@via_web = via_web
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
|
@ -52,15 +53,15 @@ class Observer::Ticket::Notification::BackgroundJob
|
||||||
recipient_list = ''
|
recipient_list = ''
|
||||||
recipients.each do |user|
|
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 && article.updated_by_id == user.id
|
||||||
next if !article && ticket.updated_by_id == user.id
|
next if !article && ticket.updated_by_id == user.id
|
||||||
|
end
|
||||||
|
|
||||||
# ignore inactive users
|
# ignore inactive users
|
||||||
next if !user.active
|
next if !user.active
|
||||||
|
|
||||||
# create desktop notification
|
|
||||||
|
|
||||||
# create online notification
|
# create online notification
|
||||||
seen = ticket.online_notification_seen_state(user.id)
|
seen = ticket.online_notification_seen_state(user.id)
|
||||||
OnlineNotification.add(
|
OnlineNotification.add(
|
||||||
|
|
|
@ -58,7 +58,80 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
created_by_id: 1,
|
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
|
# create ticket in group
|
||||||
ticket1 = Ticket.create(
|
ticket1 = Ticket.create(
|
||||||
|
@ -86,6 +159,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
assert( ticket1, 'ticket created - ticket notification simple' )
|
assert( ticket1, 'ticket created - ticket notification simple' )
|
||||||
|
|
||||||
# execute ticket events
|
# execute ticket events
|
||||||
|
ENV['SERVER_NAME'] = 'some_host'
|
||||||
Observer::Ticket::Notification.transaction
|
Observer::Ticket::Notification.transaction
|
||||||
#puts Delayed::Job.all.inspect
|
#puts Delayed::Job.all.inspect
|
||||||
Delayed::Worker.new.work_off
|
Delayed::Worker.new.work_off
|
||||||
|
|
Loading…
Reference in a new issue