Introduced config.interface_handle to find out via which interface the source code got executed.
This commit is contained in:
parent
e2eef259b4
commit
4628299d20
27 changed files with 126 additions and 54 deletions
|
@ -15,7 +15,7 @@ class ApplicationController < ActionController::Base
|
||||||
:model_index_render
|
:model_index_render
|
||||||
|
|
||||||
skip_before_action :verify_authenticity_token
|
skip_before_action :verify_authenticity_token
|
||||||
before_action :set_user, :session_update, :user_device_check, :cors_preflight_check
|
before_action :set_interface_handle, :set_user, :session_update, :user_device_check, :cors_preflight_check
|
||||||
after_action :trigger_events, :http_log, :set_access_control_headers
|
after_action :trigger_events, :http_log, :set_access_control_headers
|
||||||
|
|
||||||
rescue_from StandardError, with: :server_error
|
rescue_from StandardError, with: :server_error
|
||||||
|
@ -58,6 +58,10 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def set_interface_handle
|
||||||
|
ApplicationHandleInfo.current = 'application_server'
|
||||||
|
end
|
||||||
|
|
||||||
# execute events
|
# execute events
|
||||||
def trigger_events
|
def trigger_events
|
||||||
Observer::Transaction.commit
|
Observer::Transaction.commit
|
||||||
|
|
|
@ -390,6 +390,8 @@ retrns
|
||||||
end
|
end
|
||||||
|
|
||||||
def _process(channel, msg)
|
def _process(channel, msg)
|
||||||
|
|
||||||
|
# parse email
|
||||||
mail = parse(msg)
|
mail = parse(msg)
|
||||||
|
|
||||||
# run postmaster pre filter
|
# run postmaster pre filter
|
||||||
|
@ -410,7 +412,14 @@ retrns
|
||||||
}
|
}
|
||||||
|
|
||||||
# check ignore header
|
# check ignore header
|
||||||
return true if mail[ 'x-zammad-ignore'.to_sym ] == 'true' || mail[ 'x-zammad-ignore'.to_sym ] == true
|
if mail[ 'x-zammad-ignore'.to_sym ] == 'true' || mail[ 'x-zammad-ignore'.to_sym ] == true
|
||||||
|
Rails.logger.info "ignored email with msgid '#{mail[:message_id]}' from '#{mail[:from]}' because of x-zammad-ignore header"
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
# set interface handle
|
||||||
|
original_interface_handle = ApplicationHandleInfo.current
|
||||||
|
ApplicationHandleInfo.current = "#{original_interface_handle}.postmaster"
|
||||||
|
|
||||||
ticket = nil
|
ticket = nil
|
||||||
article = nil
|
article = nil
|
||||||
|
@ -497,11 +506,9 @@ retrns
|
||||||
set_attributes_by_x_headers(ticket, 'ticket', mail)
|
set_attributes_by_x_headers(ticket, 'ticket', mail)
|
||||||
|
|
||||||
# create ticket
|
# create ticket
|
||||||
ticket.save
|
ticket.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
# import mail
|
|
||||||
|
|
||||||
# set attributes
|
# set attributes
|
||||||
article = Ticket::Article.new(
|
article = Ticket::Article.new(
|
||||||
ticket_id: ticket.id,
|
ticket_id: ticket.id,
|
||||||
|
@ -521,7 +528,7 @@ retrns
|
||||||
set_attributes_by_x_headers(article, 'article', mail)
|
set_attributes_by_x_headers(article, 'article', mail)
|
||||||
|
|
||||||
# create article
|
# create article
|
||||||
article.save
|
article.save!
|
||||||
|
|
||||||
# store mail plain
|
# store mail plain
|
||||||
Store.add(
|
Store.add(
|
||||||
|
@ -546,6 +553,8 @@ retrns
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
ApplicationHandleInfo.current = original_interface_handle
|
||||||
|
|
||||||
# execute object transaction
|
# execute object transaction
|
||||||
Observer::Transaction.commit
|
Observer::Transaction.commit
|
||||||
|
|
||||||
|
@ -617,8 +626,8 @@ retrns
|
||||||
item_object[key] = mail[ header.to_sym ]
|
item_object[key] = mail[ header.to_sym ]
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# workaround to parse subjects with 2 different encodings correctly (e. g. quoted-printable see test/fixtures/mail9.box)
|
# workaround to parse subjects with 2 different encodings correctly (e. g. quoted-printable see test/fixtures/mail9.box)
|
||||||
|
|
|
@ -8,7 +8,7 @@ module Channel::Filter::Database
|
||||||
# process postmaster filter
|
# process postmaster filter
|
||||||
filters = PostmasterFilter.where( active: true, channel: 'email' ).order(:name, :created_at)
|
filters = PostmasterFilter.where( active: true, channel: 'email' ).order(:name, :created_at)
|
||||||
filters.each { |filter|
|
filters.each { |filter|
|
||||||
Rails.logger.info " proccess filter #{filter.name} ..."
|
Rails.logger.info " process filter #{filter.name} ..."
|
||||||
all_matches_ok = true
|
all_matches_ok = true
|
||||||
min_one_rule_exists = false
|
min_one_rule_exists = false
|
||||||
filter[:match].each { |key, meta|
|
filter[:match].each { |key, meta|
|
||||||
|
|
|
@ -8,7 +8,11 @@ class Observer::Ticket::Article::CommunicateEmail < ActiveRecord::Observer
|
||||||
# return if we run import mode
|
# return if we run import mode
|
||||||
return if Setting.get('import_mode')
|
return if Setting.get('import_mode')
|
||||||
|
|
||||||
# if sender is customer, do not communication
|
# only do send email if article got created via application_server (e. g. not
|
||||||
|
# if article and sender type is set via *.postmaster)
|
||||||
|
return if ApplicationHandleInfo.current.split('.')[1] == 'postmaster'
|
||||||
|
|
||||||
|
# if sender is customer, do not communicate
|
||||||
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
|
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
|
||||||
return 1 if sender.nil?
|
return 1 if sender.nil?
|
||||||
return 1 if sender['name'] == 'Customer'
|
return 1 if sender['name'] == 'Customer'
|
||||||
|
|
|
@ -66,7 +66,7 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob
|
||||||
record.preferences['delivery_status_message'] = nil
|
record.preferences['delivery_status_message'] = nil
|
||||||
record.preferences['delivery_status'] = 'success'
|
record.preferences['delivery_status'] = 'success'
|
||||||
record.preferences['delivery_status_date'] = Time.zone.now
|
record.preferences['delivery_status_date'] = Time.zone.now
|
||||||
record.save
|
record.save!
|
||||||
|
|
||||||
# store mail plain
|
# store mail plain
|
||||||
Store.add(
|
Store.add(
|
||||||
|
@ -91,6 +91,8 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob
|
||||||
recipient_list += record[key]
|
recipient_list += record[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rails.logger.info "Send email to: '#{recipient_list}' (from #{record.from})"
|
||||||
|
|
||||||
return if recipient_list == ''
|
return if recipient_list == ''
|
||||||
|
|
||||||
History.add(
|
History.add(
|
||||||
|
|
|
@ -10,7 +10,11 @@ class Observer::Ticket::Article::CommunicateFacebook < ActiveRecord::Observer
|
||||||
# return if we run import mode
|
# return if we run import mode
|
||||||
return if Setting.get('import_mode')
|
return if Setting.get('import_mode')
|
||||||
|
|
||||||
# if sender is customer, do not communication
|
# only do send email if article got created via application_server (e. g. not
|
||||||
|
# if article and sender type is set via *.postmaster)
|
||||||
|
return if ApplicationHandleInfo.current.split('.')[1] == 'postmaster'
|
||||||
|
|
||||||
|
# if sender is customer, do not communicate
|
||||||
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
|
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
|
||||||
return 1 if sender.nil?
|
return 1 if sender.nil?
|
||||||
return 1 if sender['name'] == 'Customer'
|
return 1 if sender['name'] == 'Customer'
|
||||||
|
|
|
@ -59,7 +59,11 @@ class Observer::Ticket::Article::CommunicateFacebook::BackgroundJob
|
||||||
article.preferences['delivery_status'] = 'success'
|
article.preferences['delivery_status'] = 'success'
|
||||||
article.preferences['delivery_status_date'] = Time.zone.now
|
article.preferences['delivery_status_date'] = Time.zone.now
|
||||||
|
|
||||||
article.save
|
article.save!
|
||||||
|
|
||||||
|
Rails.logger.info "Send facebook to: '#{article.to}' (from #{article.from})"
|
||||||
|
|
||||||
|
article
|
||||||
end
|
end
|
||||||
|
|
||||||
def log_error(local_record, message)
|
def log_error(local_record, message)
|
||||||
|
|
|
@ -8,7 +8,11 @@ class Observer::Ticket::Article::CommunicateTwitter < ActiveRecord::Observer
|
||||||
# return if we run import mode
|
# return if we run import mode
|
||||||
return if Setting.get('import_mode')
|
return if Setting.get('import_mode')
|
||||||
|
|
||||||
# if sender is customer, do not communication
|
# only do send email if article got created via application_server (e. g. not
|
||||||
|
# if article and sender type is set via *.postmaster)
|
||||||
|
return if ApplicationHandleInfo.current.split('.')[1] == 'postmaster'
|
||||||
|
|
||||||
|
# if sender is customer, do not communicate
|
||||||
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
|
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
|
||||||
return if sender.nil?
|
return if sender.nil?
|
||||||
return if sender['name'] == 'Customer'
|
return if sender['name'] == 'Customer'
|
||||||
|
|
|
@ -68,8 +68,11 @@ class Observer::Ticket::Article::CommunicateTwitter::BackgroundJob
|
||||||
article.preferences['delivery_status_date'] = Time.zone.now
|
article.preferences['delivery_status_date'] = Time.zone.now
|
||||||
|
|
||||||
article.message_id = tweet.id.to_s
|
article.message_id = tweet.id.to_s
|
||||||
article.save
|
article.save!
|
||||||
|
|
||||||
|
Rails.logger.info "Send twitter (#{tweet.class}) to: '#{article.to}' (from #{article.from})"
|
||||||
|
|
||||||
|
article
|
||||||
end
|
end
|
||||||
|
|
||||||
def log_error(local_record, message)
|
def log_error(local_record, message)
|
||||||
|
|
|
@ -8,6 +8,10 @@ class Observer::Ticket::Article::FillupFromEmail < ActiveRecord::Observer
|
||||||
# return if we run import mode
|
# return if we run import mode
|
||||||
return if Setting.get('import_mode')
|
return if Setting.get('import_mode')
|
||||||
|
|
||||||
|
# only do fill of email from if article got created via application_server (e. g. not
|
||||||
|
# if article and sender type is set via *.postmaster)
|
||||||
|
return if ApplicationHandleInfo.current.split('.')[1] == 'postmaster'
|
||||||
|
|
||||||
# if sender is customer, do not change anything
|
# if sender is customer, do not change anything
|
||||||
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
|
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
|
||||||
return if sender.nil?
|
return if sender.nil?
|
||||||
|
|
|
@ -8,6 +8,10 @@ class Observer::Ticket::Article::FillupFromGeneral < ActiveRecord::Observer
|
||||||
# return if we run import mode
|
# return if we run import mode
|
||||||
return if Setting.get('import_mode')
|
return if Setting.get('import_mode')
|
||||||
|
|
||||||
|
# only do fill of from if article got created via application_server (e. g. not
|
||||||
|
# if article and sender type is set via *.postmaster)
|
||||||
|
return if ApplicationHandleInfo.current.split('.')[1] == 'postmaster'
|
||||||
|
|
||||||
# if sender is customer, do not change anything
|
# if sender is customer, do not change anything
|
||||||
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
|
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
|
||||||
return if sender.nil?
|
return if sender.nil?
|
||||||
|
|
|
@ -5,11 +5,10 @@ class Observer::Transaction < ActiveRecord::Observer
|
||||||
|
|
||||||
def self.commit(params = {})
|
def self.commit(params = {})
|
||||||
|
|
||||||
# add attribute if execution is via web
|
# add attribute of interface handle (e. g. to send (no) notifications if a agent
|
||||||
params[:via_web] = false
|
# is creating a ticket via application_server, but send it if it's created via
|
||||||
if ENV['RACK_ENV'] || Rails.configuration.webserver_is_active
|
# postmaster)
|
||||||
params[:via_web] = true
|
params[:interface_handle] = ApplicationHandleInfo.current
|
||||||
end
|
|
||||||
|
|
||||||
# execute object transactions
|
# execute object transactions
|
||||||
Observer::Transaction.perform(params)
|
Observer::Transaction.perform(params)
|
||||||
|
|
|
@ -47,6 +47,7 @@ class Scheduler < ApplicationModel
|
||||||
def self.start_job(job)
|
def self.start_job(job)
|
||||||
|
|
||||||
Thread.new {
|
Thread.new {
|
||||||
|
ApplicationHandleInfo.current = 'scheduler'
|
||||||
|
|
||||||
logger.info "Started job thread for '#{job.name}' (#{job.method})..."
|
logger.info "Started job thread for '#{job.name}' (#{job.method})..."
|
||||||
|
|
||||||
|
@ -118,8 +119,12 @@ class Scheduler < ApplicationModel
|
||||||
|
|
||||||
# used for tests
|
# used for tests
|
||||||
if foreground
|
if foreground
|
||||||
|
original_interface_handle = ApplicationHandleInfo.current
|
||||||
|
ApplicationHandleInfo.current = 'scheduler'
|
||||||
|
|
||||||
original_user_id = UserInfo.current_user_id
|
original_user_id = UserInfo.current_user_id
|
||||||
UserInfo.current_user_id = nil
|
UserInfo.current_user_id = nil
|
||||||
|
|
||||||
loop do
|
loop do
|
||||||
success, failure = Delayed::Worker.new.work_off
|
success, failure = Delayed::Worker.new.work_off
|
||||||
if failure.nonzero?
|
if failure.nonzero?
|
||||||
|
@ -128,6 +133,7 @@ class Scheduler < ApplicationModel
|
||||||
break if success.zero?
|
break if success.zero?
|
||||||
end
|
end
|
||||||
UserInfo.current_user_id = original_user_id
|
UserInfo.current_user_id = original_user_id
|
||||||
|
ApplicationHandleInfo.current = original_interface_handle
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -139,6 +145,7 @@ class Scheduler < ApplicationModel
|
||||||
logger.info "Starting worker thread #{Delayed::Job}"
|
logger.info "Starting worker thread #{Delayed::Job}"
|
||||||
|
|
||||||
loop do
|
loop do
|
||||||
|
ApplicationHandleInfo.current = 'scheduler'
|
||||||
result = nil
|
result = nil
|
||||||
|
|
||||||
realtime = Benchmark.realtime do
|
realtime = Benchmark.realtime do
|
||||||
|
|
|
@ -8,7 +8,7 @@ class Transaction::BackgroundJob
|
||||||
object: 'Ticket',
|
object: 'Ticket',
|
||||||
type: 'update',
|
type: 'update',
|
||||||
ticket_id: 123,
|
ticket_id: 123,
|
||||||
via_web: true,
|
interface_handle: 'application_server', # application_server|websocket|scheduler
|
||||||
changes: {
|
changes: {
|
||||||
'attribute1' => [before,now],
|
'attribute1' => [before,now],
|
||||||
'attribute2' => [before,now],
|
'attribute2' => [before,now],
|
||||||
|
|
|
@ -8,7 +8,7 @@ class Transaction::CtiCallerIdDetection
|
||||||
object: 'Ticket',
|
object: 'Ticket',
|
||||||
type: 'create',
|
type: 'create',
|
||||||
object_id: 123,
|
object_id: 123,
|
||||||
via_web: true,
|
interface_handle: 'application_server', # application_server|websocket|scheduler
|
||||||
user_id: 123,
|
user_id: 123,
|
||||||
created_at: Time.zone.now,
|
created_at: Time.zone.now,
|
||||||
},
|
},
|
||||||
|
@ -16,7 +16,7 @@ class Transaction::CtiCallerIdDetection
|
||||||
object: 'User',
|
object: 'User',
|
||||||
type: 'update',
|
type: 'update',
|
||||||
object_id: 123,
|
object_id: 123,
|
||||||
via_web: true,
|
interface_handle: 'application_server', # application_server|websocket|scheduler
|
||||||
changes: {
|
changes: {
|
||||||
'attribute1' => [before, now],
|
'attribute1' => [before, now],
|
||||||
'attribute2' => [before, now],
|
'attribute2' => [before, now],
|
||||||
|
|
|
@ -7,7 +7,7 @@ class Transaction::Karma
|
||||||
object: 'Ticket',
|
object: 'Ticket',
|
||||||
type: 'update',
|
type: 'update',
|
||||||
object_id: 123,
|
object_id: 123,
|
||||||
via_web: true,
|
interface_handle: 'application_server', # application_server|websocket|scheduler
|
||||||
changes: {
|
changes: {
|
||||||
'attribute1' => [before, now],
|
'attribute1' => [before, now],
|
||||||
'attribute2' => [before, now],
|
'attribute2' => [before, now],
|
||||||
|
|
|
@ -7,7 +7,7 @@ class Transaction::Notification
|
||||||
object: 'Ticket',
|
object: 'Ticket',
|
||||||
type: 'update',
|
type: 'update',
|
||||||
object_id: 123,
|
object_id: 123,
|
||||||
via_web: true,
|
interface_handle: 'application_server', # application_server|websocket|scheduler
|
||||||
changes: {
|
changes: {
|
||||||
'attribute1' => [before, now],
|
'attribute1' => [before, now],
|
||||||
'attribute2' => [before, now],
|
'attribute2' => [before, now],
|
||||||
|
@ -95,7 +95,7 @@ class Transaction::Notification
|
||||||
channels = item[:channels]
|
channels = item[:channels]
|
||||||
|
|
||||||
# ignore user who changed it by him self via web
|
# ignore user who changed it by him self via web
|
||||||
if @params[:via_web]
|
if @params[:interface_handle] == 'application_server'
|
||||||
next if article && article.updated_by_id == user.id
|
next if article && article.updated_by_id == user.id
|
||||||
next if !article && @item[:user_id] == user.id
|
next if !article && @item[:user_id] == user.id
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,7 @@ class Transaction::SignatureDetection
|
||||||
object: 'Ticket',
|
object: 'Ticket',
|
||||||
type: 'update',
|
type: 'update',
|
||||||
object_id: 123,
|
object_id: 123,
|
||||||
via_web: true,
|
interface_handle: 'application_server', # application_server|websocket|scheduler
|
||||||
changes: {
|
changes: {
|
||||||
'attribute1' => [before, now],
|
'attribute1' => [before, now],
|
||||||
'attribute2' => [before, now],
|
'attribute2' => [before, now],
|
||||||
|
|
|
@ -1,30 +1,25 @@
|
||||||
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
class Transaction::Slack
|
class Transaction::Slack
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
backend = Transaction::Slack.new(
|
backend = Transaction::Slack.new(
|
||||||
object: 'Ticket',
|
|
||||||
type: 'create',
|
|
||||||
object_id: 1,
|
|
||||||
user_id: 123,
|
|
||||||
created_at: Time.zone.now,
|
|
||||||
)
|
|
||||||
backend.perform
|
|
||||||
|
|
||||||
{
|
|
||||||
object: 'Ticket',
|
object: 'Ticket',
|
||||||
type: 'update',
|
type: 'update',
|
||||||
object_id: 123,
|
object_id: 123,
|
||||||
via_web: true,
|
interface_handle: 'application_server', # application_server|websocket|scheduler
|
||||||
changes: {
|
changes: {
|
||||||
'attribute1' => [before, now],
|
'attribute1' => [before, now],
|
||||||
'attribute2' => [before, now],
|
'attribute2' => [before, now],
|
||||||
},
|
},
|
||||||
created_at: Time.zone.now,
|
created_at: Time.zone.now,
|
||||||
user_id: 123,
|
user_id: 123,
|
||||||
},
|
)
|
||||||
|
backend.perform
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def initialize(item, params = {})
|
def initialize(item, params = {})
|
||||||
@item = item
|
@item = item
|
||||||
@params = params
|
@params = params
|
||||||
|
|
|
@ -7,7 +7,7 @@ class Transaction::Trigger
|
||||||
object: 'Ticket',
|
object: 'Ticket',
|
||||||
type: 'update',
|
type: 'update',
|
||||||
object_id: 123,
|
object_id: 123,
|
||||||
via_web: true,
|
interface_handle: 'application_server', # application_server|websocket|scheduler
|
||||||
changes: {
|
changes: {
|
||||||
'attribute1' => [before, now],
|
'attribute1' => [before, now],
|
||||||
'attribute2' => [before, now],
|
'attribute2' => [before, now],
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
|
|
||||||
Rails.configuration.webserver_is_active = false
|
|
9
lib/application_handle_info.rb
Normal file
9
lib/application_handle_info.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
module ApplicationHandleInfo
|
||||||
|
def self.current
|
||||||
|
Thread.current[:application_handle] || 'unknown'
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.current=(name)
|
||||||
|
Thread.current[:application_handle] = name
|
||||||
|
end
|
||||||
|
end
|
|
@ -59,7 +59,7 @@ create/update/delete index
|
||||||
)
|
)
|
||||||
Rails.logger.info "# #{response.code}"
|
Rails.logger.info "# #{response.code}"
|
||||||
return true if response.success?
|
return true if response.success?
|
||||||
raise "Unable to proccess PUT at #{url}\n#{response.inspect}"
|
raise "Unable to process PUT at #{url}\n#{response.inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
@ -91,7 +91,7 @@ add new object to search index
|
||||||
)
|
)
|
||||||
Rails.logger.info "# #{response.code}"
|
Rails.logger.info "# #{response.code}"
|
||||||
return true if response.success?
|
return true if response.success?
|
||||||
raise "Unable to proccess POST at #{url} (size: #{data.to_json.bytesize / 1024 / 1024}M)\n#{response.inspect}"
|
raise "Unable to process POST at #{url} (size: #{data.to_json.bytesize / 1024 / 1024}M)\n#{response.inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
@ -321,7 +321,7 @@ get count of tickets and tickets which match on selector
|
||||||
|
|
||||||
Rails.logger.info "# #{response.code}"
|
Rails.logger.info "# #{response.code}"
|
||||||
if !response.success?
|
if !response.success?
|
||||||
raise "Unable to proccess POST at #{url}\n#{response.inspect}"
|
raise "Unable to process POST at #{url}\n#{response.inspect}"
|
||||||
end
|
end
|
||||||
Rails.logger.debug response.data.to_json
|
Rails.logger.debug response.data.to_json
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,7 @@ if ARGV[0] == 'start' && @options[:d]
|
||||||
end
|
end
|
||||||
|
|
||||||
@clients = {}
|
@clients = {}
|
||||||
|
Rails.configuration.interface = 'websocket'
|
||||||
EventMachine.run {
|
EventMachine.run {
|
||||||
EventMachine::WebSocket.start( host: @options[:b], port: @options[:p], secure: @options[:s], tls_options: tls_options ) do |ws|
|
EventMachine::WebSocket.start( host: @options[:b], port: @options[:p], secure: @options[:s], tls_options: tls_options ) do |ws|
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,9 @@ class ActiveSupport::TestCase
|
||||||
# set current user
|
# set current user
|
||||||
UserInfo.current_user_id = nil
|
UserInfo.current_user_id = nil
|
||||||
|
|
||||||
|
# set interface handle
|
||||||
|
ApplicationHandleInfo.current = 'unknown'
|
||||||
|
|
||||||
Rails.logger.info '++++NEW++++TEST++++'
|
Rails.logger.info '++++NEW++++TEST++++'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -64,4 +67,22 @@ class ActiveSupport::TestCase
|
||||||
count
|
count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def email_count(recipient)
|
||||||
|
|
||||||
|
# read config file and count & recipients
|
||||||
|
file = "#{Rails.root}/log/#{Rails.env}.log"
|
||||||
|
lines = []
|
||||||
|
IO.foreach(file) do |line|
|
||||||
|
lines.push line
|
||||||
|
end
|
||||||
|
count = 0
|
||||||
|
lines.reverse.each { |line|
|
||||||
|
break if line =~ /\+\+\+\+NEW\+\+\+\+TEST\+\+\+\+/
|
||||||
|
next if line !~ /Send email to:/
|
||||||
|
next if line !~ /to:\s'#{recipient}'/
|
||||||
|
count += 1
|
||||||
|
}
|
||||||
|
count
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -42,7 +42,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
test 'ticket notification' do
|
test 'ticket notification' do
|
||||||
|
|
||||||
Rails.configuration.webserver_is_active = true
|
ApplicationHandleInfo.current = 'application_server'
|
||||||
|
|
||||||
# case #1
|
# case #1
|
||||||
ticket1 = Ticket.create(
|
ticket1 = Ticket.create(
|
||||||
|
@ -381,7 +381,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
)
|
)
|
||||||
assert( ticket1, 'ticket created' )
|
assert(ticket1, 'ticket created')
|
||||||
article_inbound = Ticket::Article.create(
|
article_inbound = Ticket::Article.create(
|
||||||
ticket_id: ticket1.id,
|
ticket_id: ticket1.id,
|
||||||
from: 'some_sender@example.com',
|
from: 'some_sender@example.com',
|
||||||
|
|
|
@ -109,6 +109,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
test 'ticket notification - to all agents / to explicit agents' do
|
test 'ticket notification - to all agents / to explicit agents' do
|
||||||
|
|
||||||
# create ticket in group
|
# create ticket in group
|
||||||
|
ApplicationHandleInfo.current = 'scheduler.postmaster'
|
||||||
ticket1 = Ticket.create(
|
ticket1 = Ticket.create(
|
||||||
title: 'some notification test 1',
|
title: 'some notification test 1',
|
||||||
group: Group.lookup(name: 'TicketNotificationTest'),
|
group: Group.lookup(name: 'TicketNotificationTest'),
|
||||||
|
@ -134,7 +135,6 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
assert(ticket1)
|
assert(ticket1)
|
||||||
|
|
||||||
# execute object transaction
|
# execute object transaction
|
||||||
Rails.configuration.webserver_is_active = nil
|
|
||||||
Observer::Transaction.commit
|
Observer::Transaction.commit
|
||||||
Scheduler.worker(true)
|
Scheduler.worker(true)
|
||||||
|
|
||||||
|
@ -143,6 +143,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, agent2, 'email'), ticket1.id)
|
assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, agent2, 'email'), ticket1.id)
|
||||||
|
|
||||||
# create ticket in group
|
# create ticket in group
|
||||||
|
ApplicationHandleInfo.current = 'application_server'
|
||||||
ticket1 = Ticket.create(
|
ticket1 = Ticket.create(
|
||||||
title: 'some notification test 2',
|
title: 'some notification test 2',
|
||||||
group: Group.lookup(name: 'TicketNotificationTest'),
|
group: Group.lookup(name: 'TicketNotificationTest'),
|
||||||
|
@ -168,7 +169,6 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
assert(ticket1)
|
assert(ticket1)
|
||||||
|
|
||||||
# execute object transaction
|
# execute object transaction
|
||||||
Rails.configuration.webserver_is_active = true
|
|
||||||
Observer::Transaction.commit
|
Observer::Transaction.commit
|
||||||
Scheduler.worker(true)
|
Scheduler.worker(true)
|
||||||
|
|
||||||
|
@ -180,6 +180,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
test 'ticket notification - simple' do
|
test 'ticket notification - simple' do
|
||||||
|
|
||||||
# create ticket in group
|
# create ticket in group
|
||||||
|
ApplicationHandleInfo.current = 'application_server'
|
||||||
ticket1 = Ticket.create(
|
ticket1 = Ticket.create(
|
||||||
title: 'some notification test 3',
|
title: 'some notification test 3',
|
||||||
group: Group.lookup(name: 'TicketNotificationTest'),
|
group: Group.lookup(name: 'TicketNotificationTest'),
|
||||||
|
@ -205,7 +206,6 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
assert(ticket1, 'ticket created - ticket notification simple')
|
assert(ticket1, 'ticket created - ticket notification simple')
|
||||||
|
|
||||||
# execute object transaction
|
# execute object transaction
|
||||||
Rails.configuration.webserver_is_active = true
|
|
||||||
Observer::Transaction.commit
|
Observer::Transaction.commit
|
||||||
Scheduler.worker(true)
|
Scheduler.worker(true)
|
||||||
|
|
||||||
|
@ -474,6 +474,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
agent2.save
|
agent2.save
|
||||||
|
|
||||||
# create ticket in group
|
# create ticket in group
|
||||||
|
ApplicationHandleInfo.current = 'scheduler.postmaster'
|
||||||
ticket1 = Ticket.create(
|
ticket1 = Ticket.create(
|
||||||
title: 'some notification test - z preferences tests 1',
|
title: 'some notification test - z preferences tests 1',
|
||||||
group: Group.lookup(name: 'TicketNotificationTest'),
|
group: Group.lookup(name: 'TicketNotificationTest'),
|
||||||
|
@ -498,7 +499,6 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
)
|
)
|
||||||
|
|
||||||
# execute object transaction
|
# execute object transaction
|
||||||
Rails.configuration.webserver_is_active = false
|
|
||||||
Observer::Transaction.commit
|
Observer::Transaction.commit
|
||||||
Scheduler.worker(true)
|
Scheduler.worker(true)
|
||||||
|
|
||||||
|
@ -630,6 +630,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
agent2.save
|
agent2.save
|
||||||
|
|
||||||
# create ticket in group
|
# create ticket in group
|
||||||
|
ApplicationHandleInfo.current = 'scheduler.postmaster'
|
||||||
ticket4 = Ticket.create(
|
ticket4 = Ticket.create(
|
||||||
title: 'some notification test - z preferences tests 4',
|
title: 'some notification test - z preferences tests 4',
|
||||||
group: Group.lookup(name: 'TicketNotificationTest'),
|
group: Group.lookup(name: 'TicketNotificationTest'),
|
||||||
|
@ -654,7 +655,6 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
)
|
)
|
||||||
|
|
||||||
# execute object transaction
|
# execute object transaction
|
||||||
Rails.configuration.webserver_is_active = false
|
|
||||||
Observer::Transaction.commit
|
Observer::Transaction.commit
|
||||||
Scheduler.worker(true)
|
Scheduler.worker(true)
|
||||||
|
|
||||||
|
@ -694,6 +694,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
agent2.save
|
agent2.save
|
||||||
|
|
||||||
# create ticket in group
|
# create ticket in group
|
||||||
|
ApplicationHandleInfo.current = 'scheduler.postmaster'
|
||||||
ticket5 = Ticket.create(
|
ticket5 = Ticket.create(
|
||||||
title: 'some notification test - z preferences tests 5',
|
title: 'some notification test - z preferences tests 5',
|
||||||
group: Group.lookup(name: 'TicketNotificationTest'),
|
group: Group.lookup(name: 'TicketNotificationTest'),
|
||||||
|
@ -718,7 +719,6 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
)
|
)
|
||||||
|
|
||||||
# execute object transaction
|
# execute object transaction
|
||||||
Rails.configuration.webserver_is_active = false
|
|
||||||
Observer::Transaction.commit
|
Observer::Transaction.commit
|
||||||
Scheduler.worker(true)
|
Scheduler.worker(true)
|
||||||
|
|
||||||
|
@ -758,6 +758,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
agent2.save
|
agent2.save
|
||||||
|
|
||||||
# create ticket in group
|
# create ticket in group
|
||||||
|
ApplicationHandleInfo.current = 'scheduler.postmaster'
|
||||||
ticket6 = Ticket.create(
|
ticket6 = Ticket.create(
|
||||||
title: 'some notification test - z preferences tests 6',
|
title: 'some notification test - z preferences tests 6',
|
||||||
group: Group.lookup(name: 'TicketNotificationTest'),
|
group: Group.lookup(name: 'TicketNotificationTest'),
|
||||||
|
@ -783,7 +784,6 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
)
|
)
|
||||||
|
|
||||||
# execute object transaction
|
# execute object transaction
|
||||||
Rails.configuration.webserver_is_active = false
|
|
||||||
Observer::Transaction.commit
|
Observer::Transaction.commit
|
||||||
Scheduler.worker(true)
|
Scheduler.worker(true)
|
||||||
|
|
||||||
|
@ -835,6 +835,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
agent2.save
|
agent2.save
|
||||||
|
|
||||||
# create ticket in group
|
# create ticket in group
|
||||||
|
ApplicationHandleInfo.current = 'scheduler.postmaster'
|
||||||
ticket7 = Ticket.create(
|
ticket7 = Ticket.create(
|
||||||
title: 'some notification test - z preferences tests 7',
|
title: 'some notification test - z preferences tests 7',
|
||||||
group: Group.lookup(name: 'TicketNotificationTest'),
|
group: Group.lookup(name: 'TicketNotificationTest'),
|
||||||
|
@ -860,7 +861,6 @@ class TicketNotificationTest < ActiveSupport::TestCase
|
||||||
)
|
)
|
||||||
|
|
||||||
# execute object transaction
|
# execute object transaction
|
||||||
Rails.configuration.webserver_is_active = false
|
|
||||||
Observer::Transaction.commit
|
Observer::Transaction.commit
|
||||||
Scheduler.worker(true)
|
Scheduler.worker(true)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue