signature_detection.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Transaction::SignatureDetection
  3. =begin
  4. {
  5. object: 'Ticket',
  6. type: 'update',
  7. object_id: 123,
  8. interface_handle: 'application_server', # application_server|websocket|scheduler
  9. changes: {
  10. 'attribute1' => [before, now],
  11. 'attribute2' => [before, now],
  12. },
  13. created_at: Time.zone.now,
  14. user_id: 123,
  15. },
  16. =end
  17. def initialize(item, params = {})
  18. @item = item
  19. @params = params
  20. end
  21. def perform
  22. # return if we run import mode
  23. return if Setting.get('import_mode')
  24. return if @item[:type] != 'create'
  25. return if @item[:object] != 'Ticket'
  26. ticket = Ticket.lookup(id: @item[:object_id])
  27. return if !ticket
  28. article = ticket.articles.first
  29. return if !article
  30. # if sender is not customer, do not change anything
  31. sender = Ticket::Article::Sender.lookup(id: article.sender_id)
  32. return if !sender
  33. return if sender['name'] != 'Customer'
  34. # set email attributes
  35. type = Ticket::Article::Type.lookup(id: article.type_id)
  36. return if type['name'] != 'email'
  37. # update current signature of user id
  38. ::SignatureDetection.rebuild_user(article.created_by_id)
  39. # user
  40. user = User.lookup(id: article.created_by_id)
  41. return if !user
  42. return if !user.preferences
  43. return if !user.preferences[:signature_detection]
  44. line = ::SignatureDetection.find_signature_line_by_article(
  45. user,
  46. article
  47. )
  48. article.preferences[:signature_detection] = line
  49. article.save
  50. end
  51. end