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)
|
2017-11-23 08:09:44 +00:00
|
|
|
return 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
|
2017-06-16 22:53:20 +00:00
|
|
|
return true if !record.type_id
|
2016-08-24 18:29:56 +00:00
|
|
|
type = Ticket::Article::Type.lookup(id: record.type_id)
|
2017-06-16 22:53:20 +00:00
|
|
|
return true if type['name'] == 'email'
|
2015-04-30 15:25:04 +00:00
|
|
|
|
2016-08-31 16:17:08 +00:00
|
|
|
# from will be set by channel backend
|
2017-06-16 22:53:20 +00:00
|
|
|
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'
|
2016-08-31 16:17:08 +00:00
|
|
|
|
2017-06-16 22:53:20 +00:00
|
|
|
return true if !record.created_by_id
|
2016-10-06 17:01:28 +00:00
|
|
|
user = User.find(record.created_by_id)
|
|
|
|
if type.name == 'web'
|
|
|
|
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
|