collection_base.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. module ExtraCollection
  3. def session( collections, assets, user )
  4. # all base stuff
  5. assets = {}
  6. collections[ Taskbar.to_app_model ] = Taskbar.where( :user_id => user.id )
  7. collections[ Taskbar.to_app_model ].each {|item|
  8. assets = item.assets(assets)
  9. }
  10. collections[ OnlineNotification.to_app_model ] = OnlineNotification.list(user, 20)
  11. assets = ApplicationModel.assets_of_object_list(collections[ OnlineNotification.to_app_model ], assets)
  12. collections[ RecentView.to_app_model ] = RecentView.list(user, 10)
  13. assets = RecentView.assets_of_object_list(collections[ RecentView.to_app_model ], assets)
  14. collections[ Role.to_app_model ] = []
  15. Role.all.each {|item|
  16. assets = item.assets(assets)
  17. }
  18. collections[ Group.to_app_model ] = []
  19. Group.all.each {|item|
  20. assets = item.assets(assets)
  21. }
  22. if !user.is_role('Customer')
  23. collections[ Organization.to_app_model ] = []
  24. Organization.all.each {|item|
  25. assets = item.assets(assets)
  26. }
  27. else
  28. if user.organization_id
  29. collections[ Organization.to_app_model ] = []
  30. Organization.where( :id => user.organization_id ).each {|item|
  31. assets = item.assets(assets)
  32. }
  33. end
  34. end
  35. [collections, assets]
  36. end
  37. module_function :session
  38. end