session_helper.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. module SessionHelper
  2. def self.default_collections(user)
  3. # auto population collections, store all here
  4. default_collection = {}
  5. assets = {}
  6. # load collections to deliver from external files
  7. dir = File.expand_path('../../', __FILE__)
  8. files = Dir.glob( "#{dir}/app/controllers/sessions/collection_*.rb" )
  9. files.each { |file|
  10. load file
  11. (default_collection, assets ) = ExtraCollection.session( default_collection, assets, user )
  12. }
  13. [default_collection, assets]
  14. end
  15. def self.models(user = nil)
  16. models = {}
  17. objects = ObjectManager.list_objects
  18. objects.each {|object|
  19. attributes = ObjectManager::Attribute.by_object(object, user)
  20. models[object] = attributes
  21. }
  22. models
  23. end
  24. def self.cleanup_expired
  25. # delete temp. sessions
  26. ActiveRecord::SessionStore::Session.where('persistent IS NULL AND updated_at < ?', Time.zone.now - 2.hours ).delete_all
  27. # web sessions older the x days
  28. ActiveRecord::SessionStore::Session.where('updated_at < ?', Time.zone.now - 90.days ).delete_all
  29. end
  30. def self.get(id)
  31. ActiveRecord::SessionStore::Session.find_by( id: id )
  32. end
  33. def self.list(limit = 10_000)
  34. ActiveRecord::SessionStore::Session.order('updated_at DESC').limit(limit)
  35. end
  36. def self.destroy(id)
  37. session = ActiveRecord::SessionStore::Session.find_by( id: id )
  38. return if !session
  39. session.destroy
  40. end
  41. end