assets.rb 1.1 KB

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