assets.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Ticket::Article::Assets
  3. extend ActiveSupport::Concern
  4. =begin
  5. get all assets / related models for this article
  6. article = Ticket::Article.find(123)
  7. result = article.assets(assets_if_exists)
  8. returns
  9. result = {
  10. :users => {
  11. 123 => user_model_123,
  12. 1234 => user_model_1234,
  13. }
  14. :article => [ article_model1 ],
  15. }
  16. =end
  17. def assets(data)
  18. app_model_article = Ticket::Article.to_app_model
  19. if !data[ app_model_article ]
  20. data[ app_model_article ] = {}
  21. end
  22. return data if data[ app_model_article ][ id ]
  23. app_model_ticket = Ticket.to_app_model
  24. app_model_user = User.to_app_model
  25. if !data[ app_model_ticket ]
  26. data[ app_model_ticket ] = {}
  27. end
  28. if !data[ app_model_ticket ][ ticket_id ]
  29. ticket = Ticket.lookup(id: ticket_id)
  30. if ticket
  31. data = ticket.assets(data)
  32. end
  33. end
  34. data[ app_model_article ][ id ] = attributes_with_association_ids
  35. %w[created_by_id updated_by_id origin_by_id].each do |local_user_id|
  36. next if !self[ local_user_id ]
  37. next if data[ app_model_user ] && data[ app_model_user ][ self[ local_user_id ] ]
  38. user = User.lookup(id: self[ local_user_id ])
  39. next if !user
  40. data = user.assets(data)
  41. end
  42. data
  43. end
  44. end