enqueue_communicate_email_job.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. # Schedules a backgrond communication job for new email articles.
  3. module Ticket::Article::EnqueueCommunicateEmailJob
  4. extend ActiveSupport::Concern
  5. included do
  6. after_create :ticket_article_enqueue_communicate_email_job
  7. end
  8. private
  9. def ticket_article_enqueue_communicate_email_job
  10. # return if we run import mode
  11. return true if Setting.get('import_mode')
  12. # only do send email if article got created via application_server (e. g. not
  13. # if article and sender type is set via *.postmaster)
  14. return true if ApplicationHandleInfo.postmaster?
  15. # if sender is customer, do not communicate
  16. return true if !sender_id
  17. sender = Ticket::Article::Sender.lookup(id: sender_id)
  18. return true if sender.nil?
  19. return true if sender.name == 'Customer'
  20. # only apply on emails
  21. return true if !type_id
  22. type = Ticket::Article::Type.lookup(id: type_id)
  23. return true if type.nil?
  24. return true if type.name != 'email'
  25. # send background job
  26. TicketArticleCommunicateEmailJob.perform_later(id)
  27. end
  28. end