collection_base.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. collections[ Locale.to_app_model ] = Locale.where( active: true )
  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, 30)
  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.role?(Z_ROLENAME_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