2016-10-19 03:11:36 +00:00
|
|
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
2013-06-12 15:59:58 +00:00
|
|
|
|
2012-12-24 13:55:43 +00:00
|
|
|
class Observer::Ticket::Article::FillupFromGeneral < ActiveRecord::Observer
|
|
|
|
observe 'ticket::_article'
|
|
|
|
|
|
|
|
def before_create(record)
|
|
|
|
|
|
|
|
# return if we run import mode
|
2017-06-16 22:53:20 +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 fill of from 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
|
|
|
|
2016-08-31 16:17:08 +00:00
|
|
|
# set from on all article types excluding email|twitter status|twitter direct-message|facebook feed post|facebook feed comment
|
2018-02-12 08:35:54 +00:00
|
|
|
return true if record.type_id.blank?
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2016-08-24 18:29:56 +00:00
|
|
|
type = Ticket::Article::Type.lookup(id: record.type_id)
|
2015-04-30 15:25:04 +00:00
|
|
|
|
2016-08-31 16:17:08 +00:00
|
|
|
# from will be set by channel backend
|
2018-10-16 08:45:15 +00:00
|
|
|
return true if type.nil?
|
|
|
|
return true if type.name == 'email'
|
|
|
|
return true if type.name == 'twitter status'
|
|
|
|
return true if type.name == 'twitter direct-message'
|
|
|
|
return true if type.name == 'facebook feed post'
|
|
|
|
return true if type.name == 'facebook feed comment'
|
|
|
|
return true if type.name == 'sms'
|
2016-08-31 16:17:08 +00:00
|
|
|
|
2018-02-12 08:35:54 +00:00
|
|
|
user_id = record.created_by_id
|
|
|
|
|
|
|
|
if record.origin_by_id.present?
|
|
|
|
|
|
|
|
# in case the customer is using origin_by_id, force it to current session user
|
|
|
|
# and set sender to Customer
|
|
|
|
if !record.created_by.permissions?('ticket.agent')
|
|
|
|
record.origin_by_id = record.created_by_id
|
|
|
|
record.sender_id = Ticket::Article::Sender.lookup(name: 'Customer').id
|
|
|
|
end
|
|
|
|
|
2020-09-11 07:25:47 +00:00
|
|
|
# in case origin_by is different than created_by, set sender to Customer
|
|
|
|
# Customer in context of this conversation, not as a permission
|
|
|
|
if record.origin_by != record.created_by_id
|
2018-02-12 08:35:54 +00:00
|
|
|
record.sender_id = Ticket::Article::Sender.lookup(name: 'Customer').id
|
|
|
|
user_id = record.origin_by_id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true if user_id.blank?
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-02-12 08:35:54 +00:00
|
|
|
user = User.find(user_id)
|
|
|
|
if type.name == 'web' || type.name == 'phone'
|
2016-10-06 17:01:28 +00:00
|
|
|
record.from = "#{user.firstname} #{user.lastname} <#{user.email}>"
|
|
|
|
return
|
|
|
|
end
|
2015-04-30 15:25:04 +00:00
|
|
|
record.from = "#{user.firstname} #{user.lastname}"
|
2012-12-24 13:55:43 +00:00
|
|
|
end
|
2013-06-12 15:59:58 +00:00
|
|
|
end
|