assets.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class RecentView
  3. module Assets
  4. extend ActiveSupport::Concern
  5. =begin
  6. get all assets / related models for this recent view item
  7. recent_view = RecentView.find(123)
  8. result = recent_view.assets(assets_if_exists)
  9. returns
  10. result = {
  11. :RecentView => {
  12. 123 => recent_view_model_123,
  13. 1234 => recent_view_model_1234,
  14. }
  15. }
  16. =end
  17. def assets(data)
  18. app_model = self.class.to_app_model
  19. if !data[ app_model ]
  20. data[ app_model ] = {}
  21. end
  22. return data if data[ app_model ][ id ]
  23. local_attributes = attributes_with_association_ids
  24. local_attributes['object'] = ObjectLookup.by_id(local_attributes['recent_view_object_id'])
  25. # set temp. current attributes to assets pool to prevent
  26. # loops, will be updated with lookup attributes later
  27. data[ app_model ][ id ] = local_attributes
  28. ApplicationModel.assets_of_object_list([local_attributes], data)
  29. return data if !self['created_by_id']
  30. app_model_user = User.to_app_model
  31. %w[created_by_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. data
  39. end
  40. end
  41. end