assets.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class ActivityStream
  3. module Assets
  4. extend ActiveSupport::Concern
  5. =begin
  6. get all assets / related models for this activity stream item
  7. activity_stream = ActivityStream.find(123)
  8. result = activity_stream.assets(assets_if_exists)
  9. returns
  10. result = {
  11. :ActivityStream => {
  12. 123 => activity_stream_model_123,
  13. 1234 => activity_stream_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. if !data[ app_model ][ id ]
  23. local_attributes = attributes_with_association_ids
  24. local_attributes['object'] = ObjectLookup.by_id(local_attributes['activity_stream_object_id'])
  25. local_attributes['type'] = TypeLookup.by_id(local_attributes['activity_stream_type_id'])
  26. # set temp. current attributes to assets pool to prevent
  27. # loops, will be updated with lookup attributes later
  28. data[ app_model ][ id ] = local_attributes
  29. ApplicationModel.assets_of_object_list([local_attributes], data)
  30. end
  31. return data if !self['created_by_id']
  32. app_model_user = User.to_app_model
  33. %w[created_by_id].each do |local_user_id|
  34. next if !self[ local_user_id ]
  35. next if data[ app_model_user ] && data[ app_model_user ][ self[ local_user_id ] ]
  36. user = User.lookup(id: self[ local_user_id ])
  37. next if !user
  38. data = user.assets(data)
  39. end
  40. data
  41. end
  42. end
  43. end