2012-10-23 19:12:00 +00:00
|
|
|
module SessionHelper
|
2015-11-30 10:50:02 +00:00
|
|
|
def self.default_collections(user, assets = {})
|
2012-10-23 19:12:00 +00:00
|
|
|
|
|
|
|
# auto population collections, store all here
|
|
|
|
default_collection = {}
|
|
|
|
|
|
|
|
# load collections to deliver from external files
|
|
|
|
dir = File.expand_path('../../', __FILE__)
|
2016-05-12 09:26:11 +00:00
|
|
|
files = Dir.glob( "#{dir}/app/controllers/sessions/collection_*.rb")
|
2015-05-05 10:17:52 +00:00
|
|
|
files.each { |file|
|
2012-10-23 19:12:00 +00:00
|
|
|
load file
|
2016-05-12 09:26:11 +00:00
|
|
|
(default_collection, assets) = ExtraCollection.session(default_collection, assets, user)
|
2015-05-05 10:17:52 +00:00
|
|
|
}
|
2012-10-23 19:12:00 +00:00
|
|
|
|
2015-04-30 17:20:27 +00:00
|
|
|
[default_collection, assets]
|
2012-10-23 19:12:00 +00:00
|
|
|
end
|
2013-12-08 16:01:54 +00:00
|
|
|
|
2014-09-09 23:42:20 +00:00
|
|
|
def self.models(user = nil)
|
|
|
|
models = {}
|
2015-05-05 10:51:19 +00:00
|
|
|
objects = ObjectManager.list_objects
|
2014-09-09 23:42:20 +00:00
|
|
|
objects.each {|object|
|
|
|
|
attributes = ObjectManager::Attribute.by_object(object, user)
|
|
|
|
models[object] = attributes
|
|
|
|
}
|
|
|
|
models
|
|
|
|
end
|
|
|
|
|
2013-12-08 16:01:54 +00:00
|
|
|
def self.cleanup_expired
|
|
|
|
|
2015-06-23 12:17:04 +00:00
|
|
|
# delete temp. sessions
|
2016-05-12 09:26:11 +00:00
|
|
|
ActiveRecord::SessionStore::Session.where('persistent IS NULL AND updated_at < ?', Time.zone.now - 2.hours).delete_all
|
2015-06-23 12:17:04 +00:00
|
|
|
|
2015-09-08 07:55:47 +00:00
|
|
|
# web sessions not updated the last x days
|
2016-05-12 09:26:11 +00:00
|
|
|
ActiveRecord::SessionStore::Session.where('updated_at < ?', Time.zone.now - 60.days).delete_all
|
2013-12-08 16:01:54 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.get(id)
|
2016-05-12 09:26:11 +00:00
|
|
|
ActiveRecord::SessionStore::Session.find_by(id: id)
|
2013-12-08 16:01:54 +00:00
|
|
|
end
|
|
|
|
|
2015-04-27 13:43:34 +00:00
|
|
|
def self.list(limit = 10_000)
|
2013-12-08 16:01:54 +00:00
|
|
|
ActiveRecord::SessionStore::Session.order('updated_at DESC').limit(limit)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.destroy(id)
|
2016-05-12 09:26:11 +00:00
|
|
|
session = ActiveRecord::SessionStore::Session.find_by(id: id)
|
2013-12-08 16:01:54 +00:00
|
|
|
return if !session
|
|
|
|
session.destroy
|
|
|
|
end
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|