assets.rb 1.4 KB

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