enqueue_communicate_twitter_job.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. # Schedules a backgrond communication job for new twitter articles.
  3. module Ticket::Article::EnqueueCommunicateTwitterJob
  4. extend ActiveSupport::Concern
  5. included do
  6. after_create :ticket_article_enqueue_communicate_twitter_job
  7. end
  8. private
  9. def ticket_article_enqueue_communicate_twitter_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 tweets
  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.match?(%r{\Atwitter}i)
  25. raise Exceptions::UnprocessableEntity, 'twitter to: parameter is missing' if to.blank? && type['name'] == 'twitter direct-message'
  26. CommunicateTwitterJob.perform_later(id)
  27. end
  28. end