2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
2013-06-12 15:59:58 +00:00
|
|
|
|
2021-03-01 08:18:40 +00:00
|
|
|
# Schedules a backgrond communication job for new email articles.
|
|
|
|
module Ticket::Article::EnqueueCommunicateEmailJob
|
|
|
|
extend ActiveSupport::Concern
|
2012-12-24 13:55:43 +00:00
|
|
|
|
2021-03-01 08:18:40 +00:00
|
|
|
included do
|
|
|
|
after_create :ticket_article_enqueue_communicate_email_job
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def ticket_article_enqueue_communicate_email_job
|
2012-12-24 13:55:43 +00:00
|
|
|
|
|
|
|
# return if we run import mode
|
2018-10-16 08:45:15 +00:00
|
|
|
return true if Setting.get('import_mode')
|
2012-12-24 13:55:43 +00:00
|
|
|
|
2016-08-20 19:29:22 +00:00
|
|
|
# only do send email if article got created via application_server (e. g. not
|
|
|
|
# if article and sender type is set via *.postmaster)
|
2018-10-16 08:45:15 +00:00
|
|
|
return true if ApplicationHandleInfo.postmaster?
|
2016-08-20 19:29:22 +00:00
|
|
|
|
|
|
|
# if sender is customer, do not communicate
|
2021-03-01 08:18:40 +00:00
|
|
|
return true if !sender_id
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2021-03-01 08:18:40 +00:00
|
|
|
sender = Ticket::Article::Sender.lookup(id: sender_id)
|
2018-10-16 08:45:15 +00:00
|
|
|
return true if sender.nil?
|
|
|
|
return true if sender.name == 'Customer'
|
2012-12-24 13:55:43 +00:00
|
|
|
|
|
|
|
# only apply on emails
|
2021-03-01 08:18:40 +00:00
|
|
|
return true if !type_id
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2021-03-01 08:18:40 +00:00
|
|
|
type = Ticket::Article::Type.lookup(id: type_id)
|
2018-10-16 08:45:15 +00:00
|
|
|
return true if type.nil?
|
|
|
|
return true if type.name != 'email'
|
2012-12-24 13:55:43 +00:00
|
|
|
|
2014-02-03 18:36:59 +00:00
|
|
|
# send background job
|
2021-03-01 08:18:40 +00:00
|
|
|
TicketArticleCommunicateEmailJob.perform_later(id)
|
2014-02-03 18:34:32 +00:00
|
|
|
end
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|