assets.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class Overview
  3. module Assets
  4. =begin
  5. get all assets / related models for this overview
  6. overview = Overview.find(123)
  7. result = overview.assets(assets_if_exists)
  8. returns
  9. result = {
  10. :overviews => {
  11. 123 => overview_model_123,
  12. 1234 => overview_model_1234,
  13. }
  14. }
  15. =end
  16. def assets(data)
  17. app_model_overview = Overview.to_app_model
  18. app_model_user = User.to_app_model
  19. if !data[ app_model_overview ]
  20. data[ app_model_overview ] = {}
  21. end
  22. if !data[ app_model_user ]
  23. data[ app_model_user ] = {}
  24. end
  25. if !data[ app_model_overview ][ id ]
  26. data[ app_model_overview ][ id ] = attributes_with_association_ids
  27. user_ids&.each do |local_user_id|
  28. next if data[ app_model_user ][ local_user_id ]
  29. user = User.lookup(id: local_user_id)
  30. next if !user
  31. data = user.assets(data)
  32. end
  33. data = assets_of_selector('condition', data)
  34. end
  35. %w[created_by_id updated_by_id].each do |local_user_id|
  36. next if !self[ local_user_id ]
  37. next if 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
  45. end