diff --git a/app/controllers/sessions/collection_base.rb b/app/controllers/sessions/collection_base.rb index 04efc5b8c..cb594407f 100644 --- a/app/controllers/sessions/collection_base.rb +++ b/app/controllers/sessions/collection_base.rb @@ -10,6 +10,9 @@ module ExtraCollection assets = item.assets(assets) } + collections[ OnlineNotification.to_app_model ] = OnlineNotification.list(user, 20) + assets = ApplicationModel.assets_of_object_list(collections[ OnlineNotification.to_app_model ], assets) + collections[ Role.to_app_model ] = [] Role.all.each {|item| assets = item.assets(assets) @@ -32,6 +35,7 @@ module ExtraCollection } end end + [collections, assets] end module_function :session end diff --git a/app/controllers/sessions/collection_network.rb b/app/controllers/sessions/collection_network.rb index 466801d86..0ae9c1156 100644 --- a/app/controllers/sessions/collection_network.rb +++ b/app/controllers/sessions/collection_network.rb @@ -7,7 +7,7 @@ module ExtraCollection collections[ Network::Category.to_app_model ] = Network::Category.all collections[ Network::Category::Type.to_app_model ] = Network::Category::Type.all collections[ Network::Privacy.to_app_model ] = Network::Privacy.all - + [collections, assets] end module_function :session diff --git a/app/controllers/sessions/collection_ticket.rb b/app/controllers/sessions/collection_ticket.rb index b040711f9..3b23d3c9f 100644 --- a/app/controllers/sessions/collection_ticket.rb +++ b/app/controllers/sessions/collection_ticket.rb @@ -38,6 +38,7 @@ module ExtraCollection assets = item.assets(assets) } end + [collections, assets] end module_function :session end \ No newline at end of file diff --git a/app/models/application_model.rb b/app/models/application_model.rb index 6fd36e31e..4c699a15a 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -840,6 +840,42 @@ return object and assets } end +=begin + +get assets of object list + + list = [ + { + object => 'Ticket', + o_id => 1, + }, + { + object => 'User', + o_id => 121, + }, + ] + + assets = Model.assets_of_object_list(list, assets) + +=end + + def self.assets_of_object_list(list, assets = {}) + list.each {|item| + require item['object'].to_filename + record = Kernel.const_get( item['object'] ).find( item['o_id'] ) + assets = record.assets(assets) + if item['created_by_id'] + user = User.find( item['created_by_id'] ) + assets = user.assets(assets) + end + if item['updated_by_id'] + user = User.find( item['updated_by_id'] ) + assets = user.assets(assets) + end + } + assets + end + private def attachments_buffer diff --git a/app/models/recent_view.rb b/app/models/recent_view.rb index f0b4f8d77..470aff291 100644 --- a/app/models/recent_view.rb +++ b/app/models/recent_view.rb @@ -45,17 +45,9 @@ class RecentView < ApplicationModel def self.list_fulldata( user, limit = 10 ) recent_viewed = self.list( user, limit ) - # get related users - assets = {} - ticket_ids = [] - recent_viewed.each {|item| + # get related object + assets = ApplicationModel.assets_of_object_list(recent_viewed) - # get related objects - require item['object'].to_filename - record = Kernel.const_get( item['object'] ).find( item['o_id'] ) - assets = record.assets(assets) - - } return { :recent_viewed => recent_viewed, :assets => assets, diff --git a/app/models/user.rb b/app/models/user.rb index d4948764d..08d0621bf 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -132,12 +132,8 @@ returns return activity_stream if !fulldata # get related objects - assets = {} - activity_stream.each {|item| - require item['object'].to_filename - record = Kernel.const_get( item['object'] ).find( item['o_id'] ) - assets = record.assets(assets) - } + assets = ApplicationModel.assets_of_object_list(activity_stream) + return { :activity_stream => activity_stream, :assets => assets, diff --git a/lib/session_helper.rb b/lib/session_helper.rb index d9c16c298..51deb8120 100644 --- a/lib/session_helper.rb +++ b/lib/session_helper.rb @@ -10,7 +10,7 @@ module SessionHelper files = Dir.glob( "#{dir}/app/controllers/sessions/collection_*.rb" ) for file in files load file - ExtraCollection.session( default_collection, assets, user ) + (default_collection, assets ) = ExtraCollection.session( default_collection, assets, user ) end return default_collection, assets