trabajo-afectivo/app/models/observer/ticket/article/communicate_twitter.rb

35 lines
1.1 KiB
Ruby
Raw Normal View History

2016-10-19 03:11:36 +00:00
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
class Observer::Ticket::Article::CommunicateTwitter < ActiveRecord::Observer
observe 'ticket::_article'
def after_create(record)
# return if we run import mode
return true if Setting.get('import_mode')
# only do send email if article got created via application_server (e. g. not
# if article and sender type is set via *.postmaster)
return true if ApplicationHandleInfo.postmaster?
# if sender is customer, do not communicate
return true if !record.sender_id
2015-12-14 09:23:14 +00:00
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
return true if sender.nil?
return true if sender.name == 'Customer'
# only apply on tweets
return true if !record.type_id
2015-12-14 09:23:14 +00:00
type = Ticket::Article::Type.lookup(id: record.type_id)
return true if type.nil?
return true if !type.name.match?(/\Atwitter/i)
2015-12-14 09:23:14 +00:00
raise Exceptions::UnprocessableEntity, 'twitter to: parameter is missing' if record.to.blank? && type['name'] == 'twitter direct-message'
CommunicateTwitterJob.perform_later(record.id)
end
2015-12-14 09:23:14 +00:00
end