2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2016-04-22 06:55:10 +00:00
|
|
|
class Transaction::SignatureDetection
|
|
|
|
|
|
|
|
=begin
|
|
|
|
{
|
|
|
|
object: 'Ticket',
|
|
|
|
type: 'update',
|
|
|
|
object_id: 123,
|
2016-08-20 19:29:22 +00:00
|
|
|
interface_handle: 'application_server', # application_server|websocket|scheduler
|
2016-04-22 06:55:10 +00:00
|
|
|
changes: {
|
|
|
|
'attribute1' => [before, now],
|
|
|
|
'attribute2' => [before, now],
|
2016-07-16 21:43:08 +00:00
|
|
|
},
|
|
|
|
created_at: Time.zone.now,
|
2016-04-27 07:31:11 +00:00
|
|
|
user_id: 123,
|
2016-04-22 06:55:10 +00:00
|
|
|
},
|
|
|
|
=end
|
|
|
|
|
|
|
|
def initialize(item, params = {})
|
|
|
|
@item = item
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def perform
|
|
|
|
|
|
|
|
# return if we run import mode
|
|
|
|
return if Setting.get('import_mode')
|
|
|
|
|
|
|
|
return if @item[:type] != 'create'
|
|
|
|
return if @item[:object] != 'Ticket'
|
|
|
|
|
|
|
|
ticket = Ticket.lookup(id: @item[:object_id])
|
|
|
|
return if !ticket
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2016-04-22 06:55:10 +00:00
|
|
|
article = ticket.articles.first
|
|
|
|
return if !article
|
|
|
|
|
|
|
|
# if sender is not customer, do not change anything
|
|
|
|
sender = Ticket::Article::Sender.lookup(id: article.sender_id)
|
|
|
|
return if !sender
|
|
|
|
return if sender['name'] != 'Customer'
|
|
|
|
|
|
|
|
# set email attributes
|
|
|
|
type = Ticket::Article::Type.lookup(id: article.type_id)
|
|
|
|
return if type['name'] != 'email'
|
|
|
|
|
2016-06-28 20:49:38 +00:00
|
|
|
# update current signature of user id
|
2018-04-26 08:55:53 +00:00
|
|
|
::SignatureDetection.rebuild_user(article.created_by_id)
|
2016-04-22 06:55:10 +00:00
|
|
|
|
|
|
|
# user
|
|
|
|
user = User.lookup(id: article.created_by_id)
|
|
|
|
return if !user
|
|
|
|
return if !user.preferences
|
|
|
|
return if !user.preferences[:signature_detection]
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-04-26 08:55:53 +00:00
|
|
|
line = ::SignatureDetection.find_signature_line_by_article(
|
2016-06-30 09:53:13 +00:00
|
|
|
user,
|
|
|
|
article
|
2016-06-28 20:49:38 +00:00
|
|
|
)
|
2016-06-30 11:37:13 +00:00
|
|
|
article.preferences[:signature_detection] = line
|
2016-04-22 06:55:10 +00:00
|
|
|
article.save
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|