assets.rb 998 B

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