Moved to helper methods.
This commit is contained in:
parent
b9a18e90db
commit
ce60f5b71d
2 changed files with 27 additions and 9 deletions
|
@ -68,7 +68,7 @@ class SessionsController < ApplicationController
|
||||||
|
|
||||||
# check logon session
|
# check logon session
|
||||||
if params['logon_session']
|
if params['logon_session']
|
||||||
session = ActiveRecord::SessionStore::Session.where( :session_id => params['logon_session'] ).first
|
session = SessionHelper::get( params['logon_session'] )
|
||||||
if session
|
if session
|
||||||
user_id = session.data[:user_id]
|
user_id = session.data[:user_id]
|
||||||
end
|
end
|
||||||
|
@ -193,10 +193,9 @@ class SessionsController < ApplicationController
|
||||||
|
|
||||||
def list
|
def list
|
||||||
return if deny_if_not_role('Admin')
|
return if deny_if_not_role('Admin')
|
||||||
sessions = ActiveRecord::SessionStore::Session.order('updated_at DESC').limit(10000)
|
|
||||||
assets = {}
|
assets = {}
|
||||||
sessions_clean = []
|
sessions_clean = []
|
||||||
sessions.each {|session|
|
SessionHelper.list.each {|session|
|
||||||
next if !session.data['user_id']
|
next if !session.data['user_id']
|
||||||
sessions_clean.push session
|
sessions_clean.push session
|
||||||
if session.data['user_id']
|
if session.data['user_id']
|
||||||
|
@ -211,17 +210,13 @@ class SessionsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_old
|
def delete_old
|
||||||
ActiveRecord::SessionStore::Session.where('request_type = ? AND updated_at < ?', 1, Time.now - 90.days ).delete_all
|
SessionHelper::cleanup_expired
|
||||||
ActiveRecord::SessionStore::Session.where('request_type = ? AND updated_at < ?', 2, Time.now - 2.days ).delete_all
|
|
||||||
render :json => {}
|
render :json => {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete
|
def delete
|
||||||
return if deny_if_not_role('Admin')
|
return if deny_if_not_role('Admin')
|
||||||
session = ActiveRecord::SessionStore::Session.where( :id => params[:id] ).first
|
SessionHelper::destroy( params[:id] )
|
||||||
if session
|
|
||||||
session.destroy
|
|
||||||
end
|
|
||||||
render :json => {}
|
render :json => {}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,4 +29,27 @@ module SessionHelper
|
||||||
|
|
||||||
return push_collections
|
return push_collections
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.cleanup_expired
|
||||||
|
|
||||||
|
# web sessions
|
||||||
|
ActiveRecord::SessionStore::Session.where('request_type = ? AND updated_at < ?', 1, Time.now - 90.days ).delete_all
|
||||||
|
|
||||||
|
# http basic auth calls
|
||||||
|
ActiveRecord::SessionStore::Session.where('request_type = ? AND updated_at < ?', 2, Time.now - 2.days ).delete_all
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.get(id)
|
||||||
|
ActiveRecord::SessionStore::Session.where( :id => id ).first
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.list(limit = 10000)
|
||||||
|
ActiveRecord::SessionStore::Session.order('updated_at DESC').limit(limit)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.destroy(id)
|
||||||
|
session = ActiveRecord::SessionStore::Session.where( :id => id ).first
|
||||||
|
return if !session
|
||||||
|
session.destroy
|
||||||
|
end
|
||||||
end
|
end
|
Loading…
Reference in a new issue