signature_detection.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Copyright (C) 2012-2014 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. via_web: true,
  10. changes: {
  11. 'attribute1' => [before, now],
  12. 'attribute2' => [before, now],
  13. }
  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. article.preferences[:signature_detection] = SignatureDetection.find_signature_line_by_article(
  45. user,
  46. article
  47. )
  48. article.save
  49. end
  50. end