Merge branch 'develop' into interface

Conflicts:
	app/models/observer/ticket/notification.rb
	lib/sessions/backend/recent_viewed.rb
This commit is contained in:
Martin Edenhofer 2014-08-26 09:59:59 +02:00
commit 4790878678
5 changed files with 124 additions and 119 deletions

View file

@ -173,94 +173,13 @@ class Observer::Ticket::Notification < ActiveRecord::Observer
def self.send_notify(data, ticket, article, type)
# find recipients
recipients = []
# group of agents to work on
if data[:recipient] == 'group'
recipients = ticket.agent_of_group()
# owner
elsif data[:recipient] == 'owner'
if ticket.owner_id != 1
recipients.push ticket.owner
end
# customer
elsif data[:recipient] == 'customer'
if ticket.customer_id != 1
# temporarily disabled
# recipients.push ticket.customer
end
# owner or group of agents to work on
elsif data[:recipient] == 'to_work_on'
if ticket.owner_id != 1
recipients.push ticket.owner
else
recipients = ticket.agent_of_group()
end
end
# send notifications
recipient_list = ''
notification_subject = ''
recipients.each do |user|
OnlineNotification.add(
:type => type,
:object => 'Ticket',
:o_id => ticket.id,
:seen => false,
:created_by_id => UserInfo.current_user_id || 1,
:user_id => user.id,
)
next if !user.email || user.email == ''
# add recipient_list
if recipient_list != ''
recipient_list += ','
end
recipient_list += user.email.to_s
# prepare subject & body
notification = {}
[:subject, :body].each { |key|
notification[key.to_sym] = NotificationFactory.build(
:locale => user.locale,
:string => data[key.to_sym],
:objects => {
:ticket => ticket,
:article => article,
:recipient => user,
# send background job
params = {
:ticket_id => ticket.id,
:article_id => article.id,
:data => data,
}
)
}
notification_subject = notification[:subject]
# rebuild subject
notification[:subject] = ticket.subject_build( notification[:subject] )
# send notification
NotificationFactory.send(
:recipient => user,
:subject => notification[:subject],
:body => notification[:body]
)
end
# add history record
if recipient_list != ''
History.add(
:o_id => ticket.id,
:history_type => 'notification',
:history_object => 'Ticket',
:value_from => notification_subject,
:value_to => recipient_list,
:created_by_id => article.created_by_id || 1
)
end
Delayed::Job.enqueue( Observer::Ticket::Notification::BackgroundJob.new( params ) )
end
def after_create(record)

View file

@ -0,0 +1,101 @@
class Observer::Ticket::Notification::BackgroundJob
def initialize(params)
@ticket_id = params[:ticket_id]
@article_id = params[:article_id]
@data = params[:data]
end
def perform
ticket = Ticket.find(@ticket_id)
article = Ticket::Article.find(@article_id)
data = @data
# find recipients
recipients = []
# group of agents to work on
if data[:recipient] == 'group'
recipients = ticket.agent_of_group()
# owner
elsif data[:recipient] == 'owner'
if ticket.owner_id != 1
recipients.push ticket.owner
end
# customer
elsif data[:recipient] == 'customer'
if ticket.customer_id != 1
# temporarily disabled
# recipients.push ticket.customer
end
# owner or group of agents to work on
elsif data[:recipient] == 'to_work_on'
if ticket.owner_id != 1
recipients.push ticket.owner
else
recipients = ticket.agent_of_group()
end
end
# send notifications
recipient_list = ''
notification_subject = ''
recipients.each do |user|
OnlineNotification.add(
:type => type,
:object => 'Ticket',
:o_id => ticket.id,
:seen => false,
:created_by_id => UserInfo.current_user_id || 1,
:user_id => user.id,
)
next if !user.email || user.email == ''
# add recipient_list
if recipient_list != ''
recipient_list += ','
end
recipient_list += user.email.to_s
# prepare subject & body
notification = {}
[:subject, :body].each { |key|
notification[key.to_sym] = NotificationFactory.build(
:locale => user.locale,
:string => data[key.to_sym],
:objects => {
:ticket => ticket,
:article => article,
:recipient => user,
}
)
}
notification_subject = notification[:subject]
# rebuild subject
notification[:subject] = ticket.subject_build( notification[:subject] )
# send notification
NotificationFactory.send(
:recipient => user,
:subject => notification[:subject],
:body => notification[:body]
)
end
# add history record
if recipient_list != ''
History.add(
:o_id => ticket.id,
:history_type => 'notification',
:history_object => 'Ticket',
:value_from => notification_subject,
:value_to => recipient_list,
:created_by_id => article.created_by_id || 1
)
end
end
end

View file

@ -3,6 +3,10 @@
class RecentView < ApplicationModel
belongs_to :object_lookup, :class_name => 'ObjectLookup'
after_create :notify_clients
after_update :notify_clients
after_destroy :notify_clients
def self.log( object, o_id, user )
# lookups
@ -53,6 +57,18 @@ class RecentView < ApplicationModel
:assets => assets,
}
end
def notify_clients
data = RecentView.list_fulldata( User.find(self.created_by_id), 10 )
Sessions.send_to(
self.created_by_id,
{
:event => 'update_recent_viewed',
:data => data,
}
)
end
class Object < ApplicationModel
end
end

View file

@ -15,7 +15,6 @@ class Sessions::Client
'Sessions::Backend::Collections',
'Sessions::Backend::Rss',
'Sessions::Backend::ActivityStream',
'Sessions::Backend::RecentViewed',
'Sessions::Backend::TicketCreate',
]

View file

@ -257,36 +257,6 @@ class SessionBasicTest < ActiveSupport::TestCase
assert( result1, "check as - recall 3" )
end
test 'b recent_viewed' do
user = User.lookup(:id => 1)
ticket = Ticket.all.last
RecentView.log( ticket.class.to_s, ticket.id, user )
recent_viewed_client1 = Sessions::Backend::RecentViewed.new(user, false, '123-1')
# get as stream
result1 = recent_viewed_client1.push
assert( result1, "check recent_viewed" )
sleep 1
# next check should be empty
result1 = recent_viewed_client1.push
assert( !result1, "check recent_viewed - recall" )
# next check should be empty
sleep 20
result1 = recent_viewed_client1.push
assert( !result1, "check recent_viewed - recall 2" )
RecentView.log( ticket.class.to_s, ticket.id, user )
sleep 20
# get as stream
result1 = recent_viewed_client1.push
assert( result1, "check recent_viewed - recall 3" )
end
test 'b ticket_create' do
UserInfo.current_user_id = 1