forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession_helper.rb
64 lines (50 loc) · 1.62 KB
/
session_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
module SessionHelper
def self.json_hash(user)
collections, assets = default_collections(user)
{
session: user,
models: models(user),
collections: collections,
assets: assets,
}
end
def self.default_collections(user)
# auto population collections, store all here
default_collection = {}
assets = user.assets({})
# load collections to deliver from external files
dir = File.expand_path('..', __dir__)
files = Dir.glob( "#{dir}/app/controllers/sessions/collection_*.rb")
files.each do |file|
load file
(default_collection, assets) = ExtraCollection.session(default_collection, assets, user)
end
[default_collection, assets]
end
def self.models(user = nil)
models = {}
objects = ObjectManager.list_objects
objects.each do |object|
attributes = ObjectManager::Attribute.by_object(object, user)
models[object] = attributes
end
models
end
def self.cleanup_expired
# delete temp. sessions
ActiveRecord::SessionStore::Session.where('persistent IS NULL AND updated_at < ?', Time.zone.now - 2.hours).delete_all
# web sessions not updated the last x days
ActiveRecord::SessionStore::Session.where('updated_at < ?', Time.zone.now - 60.days).delete_all
end
def self.get(id)
ActiveRecord::SessionStore::Session.find_by(id: id)
end
def self.list(limit = 10_000)
ActiveRecord::SessionStore::Session.order(updated_at: :desc).limit(limit)
end
def self.destroy(id)
session = ActiveRecord::SessionStore::Session.find_by(id: id)
return if !session
session.destroy
end
end