assets.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://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. app_model_user = User.to_app_model
  20. if !data[ app_model_overview ]
  21. data[ app_model_overview ] = {}
  22. end
  23. if !data[ app_model_user ]
  24. data[ app_model_user ] = {}
  25. end
  26. if !data[ app_model_overview ][ id ]
  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. end
  36. %w[created_by_id updated_by_id].each do |local_user_id|
  37. next if !self[ local_user_id ]
  38. next if data[ app_model_user ][ self[ local_user_id ] ]
  39. user = User.lookup(id: self[ local_user_id ])
  40. next if !user
  41. data = user.assets(data)
  42. end
  43. data
  44. end
  45. end
  46. end