session_helper.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. for file in files
  10. load file
  11. (default_collection, assets ) = ExtraCollection.session( default_collection, assets, user )
  12. end
  13. return default_collection, assets
  14. end
  15. def self.models(user = nil)
  16. models = {}
  17. objects = ObjectManager.listObjects
  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. # web sessions
  26. ActiveRecord::SessionStore::Session.where('request_type = ? AND updated_at < ?', 1, Time.now - 90.days ).delete_all
  27. # http basic auth calls
  28. ActiveRecord::SessionStore::Session.where('request_type = ? AND updated_at < ?', 2, Time.now - 2.days ).delete_all
  29. end
  30. def self.get(id)
  31. ActiveRecord::SessionStore::Session.where( :id => id ).first
  32. end
  33. def self.list(limit = 10000)
  34. ActiveRecord::SessionStore::Session.order('updated_at DESC').limit(limit)
  35. end
  36. def self.destroy(id)
  37. session = ActiveRecord::SessionStore::Session.where( :id => id ).first
  38. return if !session
  39. session.destroy
  40. end
  41. end