Added support of default preferences and implemented agent notifications based on preferences settings.
This commit is contained in:
parent
34f8604a25
commit
c34a407651
7 changed files with 608 additions and 37 deletions
|
@ -8,6 +8,10 @@ process emails from STDIN
|
|||
|
||||
cat /path/to/mail.eml | rails r 'Channel::Driver::MailStdin.new'
|
||||
|
||||
e. g.
|
||||
|
||||
cat test/fixtures/mail1.box | rails r 'Channel::Driver::MailStdin.new'
|
||||
|
||||
=end
|
||||
|
||||
def initialize
|
||||
|
|
|
@ -13,7 +13,7 @@ class Observer::Ticket::Notification::BackgroundJob
|
|||
end
|
||||
|
||||
# find recipients
|
||||
recipients = []
|
||||
recipients_and_channels = []
|
||||
|
||||
=begin
|
||||
# group of agents to work on
|
||||
|
@ -43,15 +43,68 @@ class Observer::Ticket::Notification::BackgroundJob
|
|||
end
|
||||
=end
|
||||
|
||||
if ticket.owner_id != 1
|
||||
recipients.push ticket.owner
|
||||
else
|
||||
recipients = ticket.agent_of_group()
|
||||
# loop through all users
|
||||
possible_recipients = ticket.agent_of_group
|
||||
if ticket.owner_id == 1
|
||||
possible_recipients.push ticket.owner
|
||||
end
|
||||
already_checked_recipient_ids = {}
|
||||
possible_recipients.each {|user|
|
||||
next if already_checked_recipient_ids[user.id]
|
||||
already_checked_recipient_ids[user.id] = true
|
||||
next if !user.preferences
|
||||
next if !user.preferences['notification_config']
|
||||
matrix = user.preferences['notification_config']['matrix']
|
||||
if ticket.owner_id != user.id
|
||||
if user.preferences['notification_config']['group_ids'] ||
|
||||
(user.preferences['notification_config']['group_ids'].class == Array && (!user.preferences['notification_config']['group_ids'].empty? || user.preferences['notification_config']['group_ids'][0] != '-'))
|
||||
hit = false
|
||||
user.preferences['notification_config']['group_ids'].each {|notify_group_id|
|
||||
user.group_ids.each {|local_group_id|
|
||||
if local_group_id.to_s == notify_group_id.to_s
|
||||
hit = true
|
||||
end
|
||||
}
|
||||
}
|
||||
next if !hit
|
||||
end
|
||||
end
|
||||
next if !matrix
|
||||
next if !matrix[@p[:type]]
|
||||
data = matrix[@p[:type]]
|
||||
next if !data
|
||||
next if !data['criteria']
|
||||
channels = data['channel']
|
||||
if data['criteria']['owned_by_me'] && ticket.owner_id == user.id
|
||||
data = {
|
||||
user: user,
|
||||
channels: channels
|
||||
}
|
||||
recipients_and_channels.push data
|
||||
next
|
||||
end
|
||||
if data['criteria']['owned_by_nobody'] && ticket.owner_id == 1
|
||||
data = {
|
||||
user: user,
|
||||
channels: channels
|
||||
}
|
||||
recipients_and_channels.push data
|
||||
next
|
||||
end
|
||||
next unless data['criteria']['no']
|
||||
data = {
|
||||
user: user,
|
||||
channels: channels
|
||||
}
|
||||
recipients_and_channels.push data
|
||||
next
|
||||
}
|
||||
|
||||
# send notifications
|
||||
recipient_list = ''
|
||||
recipients.each do |user|
|
||||
recipients_and_channels.each do |item|
|
||||
user = item[:user]
|
||||
channels = item[:channels]
|
||||
|
||||
# ignore user who changed it by him self via web
|
||||
if @via_web
|
||||
|
@ -62,32 +115,35 @@ class Observer::Ticket::Notification::BackgroundJob
|
|||
# ignore inactive users
|
||||
next if !user.active
|
||||
|
||||
# create online notification
|
||||
seen = ticket.online_notification_seen_state(user.id)
|
||||
OnlineNotification.add(
|
||||
type: @p[:type],
|
||||
object: 'Ticket',
|
||||
o_id: ticket.id,
|
||||
seen: seen,
|
||||
created_by_id: ticket.updated_by_id || 1,
|
||||
user_id: user.id,
|
||||
)
|
||||
|
||||
# create email notification
|
||||
next if !user.email || user.email == ''
|
||||
|
||||
# add recipient_list
|
||||
if recipient_list != ''
|
||||
recipient_list += ','
|
||||
end
|
||||
recipient_list += user.email.to_s
|
||||
|
||||
# ignore if no changes has been done
|
||||
changes = human_changes(user, ticket)
|
||||
if @p[:type] == 'update' && !article && ( !changes || changes.empty? )
|
||||
next if @p[:type] == 'update' && !article && ( !changes || changes.empty? )
|
||||
|
||||
# create online notification
|
||||
used_channels = []
|
||||
if channels['online']
|
||||
used_channels.push 'online'
|
||||
seen = ticket.online_notification_seen_state(user.id)
|
||||
OnlineNotification.add(
|
||||
type: @p[:type],
|
||||
object: 'Ticket',
|
||||
o_id: ticket.id,
|
||||
seen: seen,
|
||||
created_by_id: ticket.updated_by_id || 1,
|
||||
user_id: user.id,
|
||||
)
|
||||
Rails.logger.info "send ticket online notifiaction to agent (#{@p[:type]}/#{ticket.id}/#{user.email})"
|
||||
end
|
||||
|
||||
# ignore email channel notificaiton and empty emails
|
||||
if !channels['email'] && (!user.email || user.email == '')
|
||||
add_recipient_list(recipient_list, user, channels)
|
||||
next
|
||||
end
|
||||
|
||||
used_channels.push 'email'
|
||||
recipient_list = add_recipient_list(recipient_list, user, used_channels)
|
||||
|
||||
# get user based notification template
|
||||
# if create, send create message / block update messages
|
||||
if @p[:type] == 'create'
|
||||
|
@ -113,10 +169,9 @@ class Observer::Ticket::Notification::BackgroundJob
|
|||
}
|
||||
|
||||
# rebuild subject
|
||||
notification[:subject] = ticket.subject_build( notification[:subject] )
|
||||
notification[:subject] = ticket.subject_build(notification[:subject])
|
||||
|
||||
# send notification
|
||||
Rails.logger.info "send ticket notifiaction to agent (#{@p[:type]}/#{ticket.id}/#{user.email})"
|
||||
Rails.logger.info "send ticket email notifiaction to agent (#{@p[:type]}/#{ticket.id}/#{user.email})"
|
||||
|
||||
NotificationFactory.send(
|
||||
recipient: user,
|
||||
|
@ -138,6 +193,14 @@ class Observer::Ticket::Notification::BackgroundJob
|
|||
)
|
||||
end
|
||||
|
||||
def add_recipient_list(recipient_list, user, channels)
|
||||
return recipient_list if channels.empty?
|
||||
if recipient_list != ''
|
||||
recipient_list += ','
|
||||
end
|
||||
recipient_list += "#{user.email}(#{channels.join(',')})"
|
||||
end
|
||||
|
||||
def human_changes(user, record)
|
||||
|
||||
return {} if !@p[:changes]
|
||||
|
|
|
@ -84,7 +84,11 @@ returns
|
|||
=end
|
||||
|
||||
def agent_of_group
|
||||
Group.find( group_id ).users.where( active: true ).joins(:roles).where( 'roles.name' => Z_ROLENAME_AGENT, 'roles.active' => true ).uniq()
|
||||
Group.find(group_id)
|
||||
.users.where(active: true)
|
||||
.joins(:roles)
|
||||
.where('roles.name' => Z_ROLENAME_AGENT, 'roles.active' => true)
|
||||
.uniq()
|
||||
end
|
||||
|
||||
=begin
|
||||
|
|
|
@ -29,15 +29,15 @@ class User < ApplicationModel
|
|||
include User::Assets
|
||||
extend User::Search
|
||||
|
||||
before_create :check_name, :check_email, :check_login, :check_password
|
||||
before_update :check_password, :check_email, :check_login
|
||||
before_create :check_name, :check_email, :check_login, :check_password, :check_preferences_default
|
||||
before_update :check_password, :check_email, :check_login, :check_preferences_default
|
||||
after_create :avatar_for_email_check
|
||||
after_update :avatar_for_email_check
|
||||
after_destroy :avatar_destroy
|
||||
notify_clients_support
|
||||
|
||||
has_and_belongs_to_many :groups, after_add: :cache_update, after_remove: :cache_update
|
||||
has_and_belongs_to_many :roles, after_add: :cache_update, after_remove: :cache_update
|
||||
has_and_belongs_to_many :roles, after_add: [:cache_update, :check_notifications], after_remove: :cache_update
|
||||
has_and_belongs_to_many :organizations, after_add: :cache_update, after_remove: :cache_update
|
||||
has_many :tokens, after_add: :cache_update, after_remove: :cache_update
|
||||
has_many :authorizations, after_add: :cache_update, after_remove: :cache_update
|
||||
|
@ -451,7 +451,7 @@ returns
|
|||
|
||||
list of active users in role
|
||||
|
||||
result = User.of_role('Agent')
|
||||
result = User.of_role('Agent', group_ids)
|
||||
|
||||
returns
|
||||
|
||||
|
@ -459,9 +459,15 @@ returns
|
|||
|
||||
=end
|
||||
|
||||
def self.of_role(role)
|
||||
def self.of_role(role, group_ids = nil)
|
||||
roles_ids = Role.where(active: true, name: role).map(&:id)
|
||||
User.where(active: true).joins(:users_roles).where('roles_users.role_id IN (?)', roles_ids)
|
||||
if !group_ids
|
||||
return User.where(active: true).joins(:users_roles).where('roles_users.role_id IN (?)', roles_ids)
|
||||
end
|
||||
User.where(active: true)
|
||||
.joins(:users_roles)
|
||||
.joins(:users_groups)
|
||||
.where('roles_users.role_id IN (?) AND users_groups.group_ids IN (?)', roles_ids, group_ids)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -584,6 +590,13 @@ returns
|
|||
Avatar.remove('User', id)
|
||||
end
|
||||
|
||||
def check_preferences_default
|
||||
return if !@preferences_default
|
||||
return if @preferences_default.empty?
|
||||
preferences_tmp = @preferences_default.merge(preferences)
|
||||
self.preferences = preferences_tmp
|
||||
end
|
||||
|
||||
def check_password
|
||||
|
||||
# set old password again if not given
|
||||
|
@ -605,4 +618,18 @@ returns
|
|||
crypted = Digest::SHA2.hexdigest(password)
|
||||
self.password = "{sha2}#{crypted}"
|
||||
end
|
||||
|
||||
def check_notifications(o)
|
||||
default = Rails.configuration.preferences_default_by_role
|
||||
return if !default
|
||||
default.deep_stringify_keys!
|
||||
return if !default[o.name]
|
||||
if !@preferences_default
|
||||
@preferences_default = {}
|
||||
end
|
||||
default[o.name].each {|key, value|
|
||||
next if @preferences_default[key]
|
||||
@preferences_default[key] = value
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -50,5 +50,58 @@ module Zammad
|
|||
# define cache store
|
||||
config.cache_store = :file_store, "tmp/cache_file_store_#{Rails.env}"
|
||||
|
||||
# default preferences by role
|
||||
config.preferences_default_by_role = {
|
||||
Agent: {
|
||||
notification_config: {
|
||||
matrix: {
|
||||
create: {
|
||||
criteria: {
|
||||
owned_by_me: true,
|
||||
owned_by_nobody: true,
|
||||
no: false,
|
||||
},
|
||||
channel: {
|
||||
email: true,
|
||||
online: true,
|
||||
}
|
||||
},
|
||||
update: {
|
||||
criteria: {
|
||||
owned_by_me: true,
|
||||
owned_by_nobody: true,
|
||||
no: false,
|
||||
},
|
||||
channel: {
|
||||
email: true,
|
||||
online: true,
|
||||
}
|
||||
},
|
||||
reminder_reached: {
|
||||
criteria: {
|
||||
owned_by_me: true,
|
||||
owned_by_nobody: true,
|
||||
no: false,
|
||||
},
|
||||
channel: {
|
||||
email: true,
|
||||
online: true,
|
||||
}
|
||||
},
|
||||
escalation: {
|
||||
criteria: {
|
||||
owned_by_me: true,
|
||||
owned_by_nobody: true,
|
||||
no: false,
|
||||
},
|
||||
channel: {
|
||||
email: true,
|
||||
online: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -383,6 +383,369 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
|||
|
||||
end
|
||||
|
||||
test 'ticket notification - z preferences tests' do
|
||||
|
||||
agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
|
||||
agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
|
||||
agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = false
|
||||
agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
|
||||
agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
|
||||
agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = false
|
||||
agent1.save
|
||||
|
||||
agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = false
|
||||
agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
|
||||
agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
|
||||
agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = false
|
||||
agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
|
||||
agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
|
||||
agent2.save
|
||||
|
||||
# create ticket in group
|
||||
ticket1 = Ticket.create(
|
||||
title: 'some notification test - z preferences tests 1',
|
||||
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,
|
||||
)
|
||||
|
||||
# execute ticket events
|
||||
Rails.configuration.webserver_is_active = false
|
||||
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)
|
||||
|
||||
# update ticket attributes
|
||||
ticket1.title = "#{ticket1.title} - #2"
|
||||
ticket1.priority = Ticket::Priority.lookup(name: '3 high')
|
||||
ticket1.save
|
||||
|
||||
# execute ticket events
|
||||
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(2, notification_check(ticket1, agent2), ticket1.id)
|
||||
|
||||
# create ticket in group
|
||||
ticket2 = Ticket.create(
|
||||
title: 'some notification test - z preferences tests 2',
|
||||
group: Group.lookup(name: 'Users'),
|
||||
customer: customer,
|
||||
owner: agent1,
|
||||
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: ticket2.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,
|
||||
)
|
||||
|
||||
# execute ticket events
|
||||
Observer::Ticket::Notification.transaction
|
||||
#puts Delayed::Job.all.inspect
|
||||
Delayed::Worker.new.work_off
|
||||
|
||||
# verify notifications to agent1 + agent2
|
||||
assert_equal(1, notification_check(ticket2, agent1), ticket2.id)
|
||||
assert_equal(1, notification_check(ticket2, agent2), ticket2.id)
|
||||
|
||||
# update ticket attributes
|
||||
ticket2.title = "#{ticket2.title} - #2"
|
||||
ticket2.priority = Ticket::Priority.lookup(name: '3 high')
|
||||
ticket2.save
|
||||
|
||||
# execute ticket events
|
||||
Observer::Ticket::Notification.transaction
|
||||
#puts Delayed::Job.all.inspect
|
||||
Delayed::Worker.new.work_off
|
||||
|
||||
# verify notifications to agent1 + agent2
|
||||
assert_equal(2, notification_check(ticket2, agent1), ticket2.id)
|
||||
assert_equal(2, notification_check(ticket2, agent2), ticket2.id)
|
||||
|
||||
# create ticket in group
|
||||
ticket3 = Ticket.create(
|
||||
title: 'some notification test - z preferences tests 3',
|
||||
group: Group.lookup(name: 'Users'),
|
||||
customer: customer,
|
||||
owner: agent2,
|
||||
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: ticket3.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,
|
||||
)
|
||||
|
||||
# execute ticket events
|
||||
Observer::Ticket::Notification.transaction
|
||||
#puts Delayed::Job.all.inspect
|
||||
Delayed::Worker.new.work_off
|
||||
|
||||
# verify notifications to agent1 + agent2
|
||||
assert_equal(0, notification_check(ticket3, agent1), ticket3.id)
|
||||
assert_equal(1, notification_check(ticket3, agent2), ticket3.id)
|
||||
|
||||
# update ticket attributes
|
||||
ticket3.title = "#{ticket3.title} - #2"
|
||||
ticket3.priority = Ticket::Priority.lookup(name: '3 high')
|
||||
ticket3.save
|
||||
|
||||
# execute ticket events
|
||||
Observer::Ticket::Notification.transaction
|
||||
#puts Delayed::Job.all.inspect
|
||||
Delayed::Worker.new.work_off
|
||||
|
||||
# verify notifications to agent1 + agent2
|
||||
assert_equal(0, notification_check(ticket3, agent1), ticket3.id)
|
||||
assert_equal(2, notification_check(ticket3, agent2), ticket3.id)
|
||||
|
||||
agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
|
||||
agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
|
||||
agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
|
||||
agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
|
||||
agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
|
||||
agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
|
||||
agent1.preferences['notification_config']['group_ids'] = [Group.lookup(name: 'Users').id.to_s]
|
||||
agent1.save
|
||||
|
||||
agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = false
|
||||
agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
|
||||
agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
|
||||
agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = false
|
||||
agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
|
||||
agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
|
||||
agent1.preferences['notification_config']['group_ids'] = ['-']
|
||||
agent2.save
|
||||
|
||||
# create ticket in group
|
||||
ticket4 = Ticket.create(
|
||||
title: 'some notification test - z preferences tests 4',
|
||||
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: ticket4.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,
|
||||
)
|
||||
|
||||
# execute ticket events
|
||||
Rails.configuration.webserver_is_active = false
|
||||
Observer::Ticket::Notification.transaction
|
||||
#puts Delayed::Job.all.inspect
|
||||
Delayed::Worker.new.work_off
|
||||
|
||||
# verify notifications to agent1 + agent2
|
||||
assert_equal(1, notification_check(ticket4, agent1), ticket4.id)
|
||||
assert_equal(1, notification_check(ticket4, agent2), ticket4.id)
|
||||
|
||||
# update ticket attributes
|
||||
ticket4.title = "#{ticket4.title} - #2"
|
||||
ticket4.priority = Ticket::Priority.lookup(name: '3 high')
|
||||
ticket4.save
|
||||
|
||||
# execute ticket events
|
||||
Observer::Ticket::Notification.transaction
|
||||
#puts Delayed::Job.all.inspect
|
||||
Delayed::Worker.new.work_off
|
||||
|
||||
# verify notifications to agent1 + agent2
|
||||
assert_equal(2, notification_check(ticket4, agent1), ticket4.id)
|
||||
assert_equal(2, notification_check(ticket4, agent2), ticket4.id)
|
||||
|
||||
agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
|
||||
agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
|
||||
agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
|
||||
agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
|
||||
agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
|
||||
agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
|
||||
agent1.preferences['notification_config']['group_ids'] = [Group.lookup(name: 'Users').id.to_s]
|
||||
agent1.save
|
||||
|
||||
agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = false
|
||||
agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
|
||||
agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
|
||||
agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = false
|
||||
agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
|
||||
agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
|
||||
agent2.preferences['notification_config']['group_ids'] = [99]
|
||||
agent2.save
|
||||
|
||||
# create ticket in group
|
||||
ticket5 = Ticket.create(
|
||||
title: 'some notification test - z preferences tests 5',
|
||||
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: ticket5.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,
|
||||
)
|
||||
|
||||
# execute ticket events
|
||||
Rails.configuration.webserver_is_active = false
|
||||
Observer::Ticket::Notification.transaction
|
||||
#puts Delayed::Job.all.inspect
|
||||
Delayed::Worker.new.work_off
|
||||
|
||||
# verify notifications to agent1 + agent2
|
||||
assert_equal(1, notification_check(ticket5, agent1), ticket5.id)
|
||||
assert_equal(0, notification_check(ticket5, agent2), ticket5.id)
|
||||
|
||||
# update ticket attributes
|
||||
ticket5.title = "#{ticket5.title} - #2"
|
||||
ticket5.priority = Ticket::Priority.lookup(name: '3 high')
|
||||
ticket5.save
|
||||
|
||||
# execute ticket events
|
||||
Observer::Ticket::Notification.transaction
|
||||
#puts Delayed::Job.all.inspect
|
||||
Delayed::Worker.new.work_off
|
||||
|
||||
# verify notifications to agent1 + agent2
|
||||
assert_equal(2, notification_check(ticket5, agent1), ticket5.id)
|
||||
assert_equal(0, notification_check(ticket5, agent2), ticket5.id)
|
||||
|
||||
agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
|
||||
agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
|
||||
agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
|
||||
agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
|
||||
agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
|
||||
agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
|
||||
agent1.preferences['notification_config']['group_ids'] = [999]
|
||||
agent1.save
|
||||
|
||||
agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
|
||||
agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
|
||||
agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
|
||||
agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
|
||||
agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
|
||||
agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
|
||||
agent2.preferences['notification_config']['group_ids'] = [999]
|
||||
agent2.save
|
||||
|
||||
# create ticket in group
|
||||
ticket6 = Ticket.create(
|
||||
title: 'some notification test - z preferences tests 6',
|
||||
group: Group.lookup(name: 'Users'),
|
||||
customer: customer,
|
||||
owner: agent1,
|
||||
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: ticket6.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,
|
||||
)
|
||||
|
||||
# execute ticket events
|
||||
Rails.configuration.webserver_is_active = false
|
||||
Observer::Ticket::Notification.transaction
|
||||
#puts Delayed::Job.all.inspect
|
||||
Delayed::Worker.new.work_off
|
||||
|
||||
# verify notifications to agent1 + agent2
|
||||
assert_equal(1, notification_check(ticket6, agent1), ticket6.id)
|
||||
assert_equal(0, notification_check(ticket6, agent2), ticket6.id)
|
||||
|
||||
# update ticket attributes
|
||||
ticket6.title = "#{ticket6.title} - #2"
|
||||
ticket6.priority = Ticket::Priority.lookup(name: '3 high')
|
||||
ticket6.save
|
||||
|
||||
# execute ticket events
|
||||
Observer::Ticket::Notification.transaction
|
||||
#puts Delayed::Job.all.inspect
|
||||
Delayed::Worker.new.work_off
|
||||
|
||||
# verify notifications to agent1 + agent2
|
||||
assert_equal(2, notification_check(ticket6, agent1), ticket6.id)
|
||||
assert_equal(0, notification_check(ticket6, agent2), ticket6.id)
|
||||
|
||||
end
|
||||
|
||||
test 'ticket notification events' do
|
||||
|
||||
# create ticket in group
|
||||
|
|
|
@ -287,4 +287,61 @@ class UserTest < ActiveSupport::TestCase
|
|||
user.destroy
|
||||
}
|
||||
end
|
||||
|
||||
test 'user default preferences' do
|
||||
groups = Group.where(name: 'Users')
|
||||
roles = Role.where(name: 'Agent')
|
||||
agent1 = User.create_or_update(
|
||||
login: 'agent-default-preferences1@example.com',
|
||||
firstname: 'Preferences',
|
||||
lastname: 'Agent1',
|
||||
email: 'agent-default-preferences1@example.com',
|
||||
password: 'agentpw',
|
||||
active: true,
|
||||
roles: roles,
|
||||
groups: groups,
|
||||
preferences: {
|
||||
locale: 'de-de',
|
||||
},
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
assert(agent1.preferences)
|
||||
assert(agent1.preferences['locale'])
|
||||
assert_equal(agent1.preferences['locale'], 'de-de')
|
||||
assert(agent1.preferences['notification_config'])
|
||||
assert(agent1.preferences['notification_config']['matrix'])
|
||||
assert(agent1.preferences['notification_config']['matrix']['create'])
|
||||
assert(agent1.preferences['notification_config']['matrix']['update'])
|
||||
|
||||
roles = Role.where(name: 'Customer')
|
||||
customer1 = User.create_or_update(
|
||||
login: 'customer-default-preferences1@example.com',
|
||||
firstname: 'Preferences',
|
||||
lastname: 'Customer1',
|
||||
email: 'customer-default-preferences1@example.com',
|
||||
password: 'customerpw',
|
||||
active: true,
|
||||
roles: roles,
|
||||
preferences: {
|
||||
locale: 'de-de',
|
||||
},
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
assert(customer1.preferences)
|
||||
assert(customer1.preferences['locale'])
|
||||
assert_equal(customer1.preferences['locale'], 'de-de')
|
||||
assert_not(customer1.preferences['notification_config'])
|
||||
|
||||
customer1.roles = Role.where(name: 'Agent')
|
||||
assert(customer1.preferences)
|
||||
assert(customer1.preferences['locale'])
|
||||
assert_equal(customer1.preferences['locale'], 'de-de')
|
||||
assert(customer1.preferences['notification_config'])
|
||||
assert(customer1.preferences['notification_config']['matrix']['create'])
|
||||
assert(customer1.preferences['notification_config']['matrix']['update'])
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue