Moved to helper methods.

This commit is contained in:
Martin Edenhofer 2013-12-08 17:01:54 +01:00
parent b9a18e90db
commit ce60f5b71d
2 changed files with 27 additions and 9 deletions

View file

@ -68,7 +68,7 @@ class SessionsController < ApplicationController
# check 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
user_id = session.data[:user_id]
end
@ -193,10 +193,9 @@ class SessionsController < ApplicationController
def list
return if deny_if_not_role('Admin')
sessions = ActiveRecord::SessionStore::Session.order('updated_at DESC').limit(10000)
assets = {}
sessions_clean = []
sessions.each {|session|
SessionHelper.list.each {|session|
next if !session.data['user_id']
sessions_clean.push session
if session.data['user_id']
@ -211,17 +210,13 @@ class SessionsController < ApplicationController
end
def delete_old
ActiveRecord::SessionStore::Session.where('request_type = ? AND updated_at < ?', 1, Time.now - 90.days ).delete_all
ActiveRecord::SessionStore::Session.where('request_type = ? AND updated_at < ?', 2, Time.now - 2.days ).delete_all
SessionHelper::cleanup_expired
render :json => {}
end
def delete
return if deny_if_not_role('Admin')
session = ActiveRecord::SessionStore::Session.where( :id => params[:id] ).first
if session
session.destroy
end
SessionHelper::destroy( params[:id] )
render :json => {}
end
end

View file

@ -29,4 +29,27 @@ module SessionHelper
return push_collections
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