signature_detection.rb 1.6 KB

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