2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
2013-06-12 15:59:58 +00:00
|
|
|
|
2021-03-01 08:18:40 +00:00
|
|
|
# Adds certain (missing) meta data when creating articles.
|
|
|
|
# This module depends on AddsMetadataOriginById to run before it.
|
|
|
|
module Ticket::Article::AddsMetadataGeneral
|
|
|
|
extend ActiveSupport::Concern
|
2012-12-24 13:55:43 +00:00
|
|
|
|
2021-03-01 08:18:40 +00:00
|
|
|
included do
|
|
|
|
before_create :ticket_article_add_metadata_general
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def ticket_article_add_metadata_general
|
2012-12-24 13:55:43 +00:00
|
|
|
|
|
|
|
# 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
|
2021-03-01 08:18:40 +00:00
|
|
|
return true if type_id.blank?
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2021-03-01 08:18:40 +00:00
|
|
|
type = Ticket::Article::Type.lookup(id: 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
|
|
|
|
2021-03-01 08:18:40 +00:00
|
|
|
user_id = created_by_id
|
2018-02-12 08:35:54 +00:00
|
|
|
|
2021-03-01 08:18:40 +00:00
|
|
|
if origin_by_id.present?
|
2018-02-12 08:35:54 +00:00
|
|
|
|
|
|
|
# in case the customer is using origin_by_id, force it to current session user
|
|
|
|
# and set sender to Customer
|
2021-03-01 08:18:40 +00:00
|
|
|
if !created_by.permissions?('ticket.agent')
|
|
|
|
self.origin_by_id = created_by_id
|
|
|
|
self.sender_id = Ticket::Article::Sender.lookup(name: 'Customer').id
|
2018-02-12 08:35:54 +00:00
|
|
|
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
|
2021-03-01 08:18:40 +00:00
|
|
|
if origin_by != created_by_id
|
|
|
|
self.sender_id = Ticket::Article::Sender.lookup(name: 'Customer').id
|
|
|
|
user_id = origin_by_id
|
2018-02-12 08:35:54 +00:00
|
|
|
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'
|
2021-03-01 08:18:40 +00:00
|
|
|
self.from = "#{user.firstname} #{user.lastname} <#{user.email}>"
|
2016-10-06 17:01:28 +00:00
|
|
|
return
|
|
|
|
end
|
2021-03-01 08:18:40 +00:00
|
|
|
self.from = "#{user.firstname} #{user.lastname}"
|
2012-12-24 13:55:43 +00:00
|
|
|
end
|
2013-06-12 15:59:58 +00:00
|
|
|
end
|