Ignore system article in notifications.
This commit is contained in:
parent
43bb991f27
commit
dfc5900234
9 changed files with 103 additions and 32 deletions
|
@ -23,6 +23,9 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob
|
|||
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
|
||||
if sender['name'] == 'System'
|
||||
notification = true
|
||||
|
||||
# ignore notifications in developer mode
|
||||
return if Setting.get('developer_mode') == true
|
||||
end
|
||||
|
||||
# get linked channel and send
|
||||
|
|
|
@ -5,42 +5,57 @@ class Observer::Ticket::ArticleChanges < ActiveRecord::Observer
|
|||
|
||||
def after_create(record)
|
||||
|
||||
article_count_update(record)
|
||||
changed = false
|
||||
if article_count_update(record)
|
||||
changed = true
|
||||
end
|
||||
|
||||
first_response_update(record)
|
||||
if first_response_update(record)
|
||||
changed = true
|
||||
end
|
||||
|
||||
sender_type_update(record)
|
||||
if sender_type_update(record)
|
||||
changed = true
|
||||
end
|
||||
|
||||
last_contact_update(record)
|
||||
if last_contact_update(record)
|
||||
changed = true
|
||||
end
|
||||
|
||||
# save ticket
|
||||
return if !changed
|
||||
record.ticket.save
|
||||
end
|
||||
|
||||
# get article count
|
||||
def article_count_update(record)
|
||||
record.ticket.article_count = record.ticket.articles.count
|
||||
current_count = record.ticket.article_count
|
||||
sender = Ticket::Article::Sender.lookup(name: 'System')
|
||||
count = Ticket::Article.where(ticket_id: record.ticket_id).where('sender_id NOT IN (?)', sender.id).count
|
||||
return false if current_count == count
|
||||
record.ticket.article_count = count
|
||||
true
|
||||
end
|
||||
|
||||
# set frist response
|
||||
def first_response_update(record)
|
||||
|
||||
# return if we run import mode
|
||||
return if Setting.get('import_mode')
|
||||
return false if Setting.get('import_mode')
|
||||
|
||||
# if article in internal
|
||||
return true if record.internal
|
||||
return false if record.internal
|
||||
|
||||
# if sender is not agent
|
||||
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
|
||||
type = Ticket::Article::Type.lookup(id: record.type_id)
|
||||
return true if sender.name != 'Agent'
|
||||
return false if sender.name != 'Agent'
|
||||
|
||||
# if article is a message to customer
|
||||
return true if !type.communication
|
||||
type = Ticket::Article::Type.lookup(id: record.type_id)
|
||||
return false if !type.communication
|
||||
|
||||
# check if first_response is already set
|
||||
return true if record.ticket.first_response
|
||||
return false if record.ticket.first_response
|
||||
|
||||
# set first_response
|
||||
record.ticket.first_response = record.created_at
|
||||
|
@ -53,20 +68,25 @@ class Observer::Ticket::ArticleChanges < ActiveRecord::Observer
|
|||
|
||||
# ignore if create channel is already set
|
||||
count = Ticket::Article.where(ticket_id: record.ticket_id).count
|
||||
return if count > 1
|
||||
return false if count > 1
|
||||
|
||||
record.ticket.create_article_type_id = record.type_id
|
||||
record.ticket.create_article_sender_id = record.sender_id
|
||||
true
|
||||
end
|
||||
|
||||
# set last contact
|
||||
def last_contact_update(record)
|
||||
|
||||
# if article in internal
|
||||
return true if record.internal
|
||||
return false if record.internal
|
||||
|
||||
# if sender is system
|
||||
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
|
||||
return false if sender.name == 'System'
|
||||
|
||||
# if article is a message to customer
|
||||
return true if !Ticket::Article::Type.lookup(id: record.type_id).communication
|
||||
return false if !Ticket::Article::Type.lookup(id: record.type_id).communication
|
||||
|
||||
# if sender is customer
|
||||
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
|
||||
|
@ -74,9 +94,9 @@ class Observer::Ticket::ArticleChanges < ActiveRecord::Observer
|
|||
if sender.name == 'Customer'
|
||||
|
||||
# if customer is sending agains, ignore update of last contact (usecase of update escalation)
|
||||
return true if ticket.last_contact_customer &&
|
||||
ticket.last_contact &&
|
||||
ticket.last_contact_customer == ticket.last_contact
|
||||
return false if ticket.last_contact_customer &&
|
||||
ticket.last_contact &&
|
||||
ticket.last_contact_customer == ticket.last_contact
|
||||
|
||||
# check if last communication is done by agent, else do not set last_contact_customer
|
||||
if ticket.last_contact_customer.nil? ||
|
||||
|
@ -94,7 +114,7 @@ class Observer::Ticket::ArticleChanges < ActiveRecord::Observer
|
|||
end
|
||||
|
||||
# if sender is not agent
|
||||
return if sender.name != 'Agent'
|
||||
return false if sender.name != 'Agent'
|
||||
|
||||
# set last_contact_agent
|
||||
record.ticket.last_contact_agent = record.created_at
|
||||
|
|
|
@ -24,7 +24,7 @@ class Observer::Ticket::RefObjectTouch < ActiveRecord::Observer
|
|||
cutomer_id_changed = record.changes['customer_id']
|
||||
if cutomer_id_changed && cutomer_id_changed[0] != cutomer_id_changed[1]
|
||||
if cutomer_id_changed[0]
|
||||
User.find( cutomer_id_changed[0] ).touch
|
||||
User.find(cutomer_id_changed[0]).touch
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -37,7 +37,7 @@ class Observer::Ticket::RefObjectTouch < ActiveRecord::Observer
|
|||
organization_id_changed = record.changes['organization_id']
|
||||
if organization_id_changed && organization_id_changed[0] != organization_id_changed[1]
|
||||
if organization_id_changed[0]
|
||||
Organization.find( organization_id_changed[0] ).touch
|
||||
Organization.find(organization_id_changed[0]).touch
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -265,21 +265,21 @@ returns
|
|||
def merge_to(data)
|
||||
|
||||
# update articles
|
||||
Ticket::Article.where( ticket_id: id ).each(&:touch)
|
||||
Ticket::Article.where(ticket_id: id).each(&:touch)
|
||||
|
||||
# quiet update of reassign of articles
|
||||
Ticket::Article.where( ticket_id: id ).update_all( ['ticket_id = ?', data[:ticket_id] ] )
|
||||
Ticket::Article.where(ticket_id: id).update_all(['ticket_id = ?', data[:ticket_id] ])
|
||||
|
||||
# touch new ticket (to broadcast change)
|
||||
Ticket.find( data[:ticket_id] ).touch
|
||||
Ticket.find(data[:ticket_id]).touch
|
||||
|
||||
# update history
|
||||
|
||||
# create new merge article
|
||||
Ticket::Article.create(
|
||||
ticket_id: id,
|
||||
type_id: Ticket::Article::Type.lookup( name: 'note' ).id,
|
||||
sender_id: Ticket::Article::Sender.lookup( name: Z_ROLENAME_AGENT ).id,
|
||||
type_id: Ticket::Article::Type.lookup(name: 'note').id,
|
||||
sender_id: Ticket::Article::Sender.lookup(name: Z_ROLENAME_AGENT).id,
|
||||
body: 'merged',
|
||||
internal: false,
|
||||
created_by_id: data[:user_id],
|
||||
|
@ -298,10 +298,10 @@ returns
|
|||
)
|
||||
|
||||
# set state to 'merged'
|
||||
self.state_id = Ticket::State.lookup( name: 'merged' ).id
|
||||
self.state_id = Ticket::State.lookup(name: 'merged').id
|
||||
|
||||
# rest owner
|
||||
self.owner_id = User.find_by( login: '-' ).id
|
||||
self.owner_id = User.find_by(login: '-').id
|
||||
|
||||
# save ticket
|
||||
save
|
||||
|
|
|
@ -33,6 +33,13 @@ class Transaction::Notification
|
|||
ticket = Ticket.find(@item[:object_id])
|
||||
if @item[:article_id]
|
||||
article = Ticket::Article.find(@item[:article_id])
|
||||
|
||||
# ignore notifications
|
||||
sender = Ticket::Article::Sender.lookup(id: article.sender_id)
|
||||
if sender && sender.name == 'System'
|
||||
return if @item[:changes].empty?
|
||||
article = nil
|
||||
end
|
||||
end
|
||||
|
||||
# find recipients
|
||||
|
|
|
@ -37,6 +37,7 @@ class Transaction::Trigger
|
|||
article = Ticket::Article.lookup(id: @item[:article_id])
|
||||
end
|
||||
|
||||
original_user_id = UserInfo.current_user_id
|
||||
UserInfo.current_user_id = 1
|
||||
|
||||
triggers.each {|trigger|
|
||||
|
@ -89,6 +90,7 @@ class Transaction::Trigger
|
|||
|
||||
ticket.perform_changes(trigger.perform, 'trigger', @item)
|
||||
}
|
||||
UserInfo.current_user_id = original_user_id
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -3878,7 +3878,7 @@ Trigger.create_or_update(
|
|||
},
|
||||
perform: {
|
||||
'notification.email' => {
|
||||
'body' => '<p>Your request (#{config.ticket_hook}##{ticket.number}) has been received and will be reviewed by our support staff.<p>
|
||||
'body' => '<p>Your request (#{config.ticket_hook}#{ticket.number}) has been received and will be reviewed by our support staff.<p>
|
||||
<br/>
|
||||
<p>To provide additional information, please reply to this email or click on the following link:
|
||||
<a href="#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
|
||||
|
@ -3917,7 +3917,7 @@ Trigger.create_or_update(
|
|||
},
|
||||
perform: {
|
||||
'notification.email' => {
|
||||
'body' => '<p>Your follow up for (#{config.ticket_hook}##{ticket.number}) has been received and will be reviewed by our support staff.<p>
|
||||
'body' => '<p>Your follow up for (#{config.ticket_hook}#{ticket.number}) has been received and will be reviewed by our support staff.<p>
|
||||
<br/>
|
||||
<p>To provide additional information, please reply to this email or click on the following link:
|
||||
<a href="#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
|
||||
|
|
|
@ -3,6 +3,45 @@ require 'test_helper'
|
|||
|
||||
class TicketNotificationTest < ActiveSupport::TestCase
|
||||
|
||||
Trigger.create_or_update(
|
||||
name: 'auto reply - new ticket',
|
||||
condition: {
|
||||
'ticket.action' => {
|
||||
'operator' => 'is',
|
||||
'value' => 'create',
|
||||
},
|
||||
'ticket.state_id' => {
|
||||
'operator' => 'is not',
|
||||
'value' => Ticket::State.lookup(name: 'closed').id,
|
||||
},
|
||||
'article.type_id' => {
|
||||
'operator' => 'is',
|
||||
'value' => [
|
||||
Ticket::Article::Type.lookup(name: 'email').id,
|
||||
Ticket::Article::Type.lookup(name: 'phone').id,
|
||||
Ticket::Article::Type.lookup(name: 'web').id,
|
||||
],
|
||||
},
|
||||
},
|
||||
perform: {
|
||||
'notification.email' => {
|
||||
'body' => '<p>Your request (Ticket##{ticket.number}) has been received and will be reviewed by our support staff.<p>
|
||||
<br/>
|
||||
<p>To provide additional information, please reply to this email or click on the following link:
|
||||
<a href="#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}</a>
|
||||
</p>
|
||||
<br/>
|
||||
<p><i><a href="http://zammad.com">Zammad</a>, your customer support system</i></p>',
|
||||
'recipient' => 'ticket_customer',
|
||||
'subject' => 'Thanks for your inquiry (#{ticket.title})',
|
||||
},
|
||||
},
|
||||
disable_notification: true,
|
||||
active: true,
|
||||
created_by_id: 1,
|
||||
updated_by_id: 1,
|
||||
)
|
||||
|
||||
# create agent1 & agent2
|
||||
groups = Group.where(name: 'Users')
|
||||
roles = Role.where(name: 'Agent')
|
||||
|
@ -64,7 +103,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
|||
ticket1 = Ticket.create(
|
||||
title: 'some notification test 1',
|
||||
group: Group.lookup(name: 'Users'),
|
||||
customer: agent1,
|
||||
customer: customer,
|
||||
state: Ticket::State.lookup(name: 'new'),
|
||||
priority: Ticket::Priority.lookup(name: '2 normal'),
|
||||
updated_by_id: agent1.id,
|
||||
|
@ -98,7 +137,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
|||
ticket1 = Ticket.create(
|
||||
title: 'some notification test 1',
|
||||
group: Group.lookup(name: 'Users'),
|
||||
customer: agent1,
|
||||
customer: customer,
|
||||
state: Ticket::State.lookup(name: 'new'),
|
||||
priority: Ticket::Priority.lookup(name: '2 normal'),
|
||||
updated_by_id: agent1.id,
|
||||
|
|
|
@ -371,7 +371,7 @@ class TicketTriggerTest < ActiveSupport::TestCase
|
|||
},
|
||||
'ticket.state_id' => {
|
||||
'operator' => 'is not',
|
||||
'value' => '4',
|
||||
'value' => Ticket::State.lookup(name: 'closed').id,
|
||||
},
|
||||
'article.type_id' => {
|
||||
'operator' => 'is',
|
||||
|
|
Loading…
Reference in a new issue