Refactoring of App.Session class.

This commit is contained in:
Martin Edenhofer 2014-09-21 14:50:39 +02:00
parent 9ee8e5c0c1
commit 2028a564b1
17 changed files with 43 additions and 46 deletions

View file

@ -185,8 +185,8 @@ class App.Controller extends Spine.Controller
authenticate: ->
# return rtue if session exists
return true if @Session.get( 'id' )
# return true if session exists
return true if @Session.get()
# remember requested url
@Config.set( 'requested_url', window.location.hash )
@ -417,7 +417,7 @@ class App.Controller extends Spine.Controller
item.link = object.uiUrl()
item.title = object.displayName()
item.object_name = object.objectDisplayName()
item.cssIcon = object.iconActivity( @Session.all() )
item.cssIcon = object.iconActivity( @Session.get() )
item.created_by = App.User.retrieve( item.created_by_id )
items

View file

@ -5,7 +5,8 @@ App.Config.set( 'User', {
item = {}
item['name'] = App.Session.get( 'login' )
item['image'] = App.Session.get( 'imageUrl' )
item['avatar'] = App.User.fullLocal( App.Session.get('id') ).avatar()
if App.Session.get()
item['avatar'] = App.Session.get().avatar()
return item
target: '#current_user',
class: 'user'

View file

@ -40,7 +40,7 @@ class Index extends App.Controller
auth_providers.push provider
@html App.view('profile/linked_accounts')(
user: App.Session.all()
user: App.Session.get()
auth_providers: auth_providers
)

View file

@ -400,8 +400,8 @@ class App.TicketCreate extends App.Controller
ui.scrollTo()
# access to group
session = App.Session.all()
if session && session['group_ids'] && _.contains(session['group_ids'], @group_id)
group_ids = App.Session.get('group_ids')
if group_ids && _.contains( group_ids, @group_id )
ui.navigate "#ticket/zoom/#{@id}"
return

View file

@ -203,7 +203,7 @@ class Index extends App.ControllerContent
# create article
params['article'] = {
from: "#{ @Session.get('firstname') } #{ @Session.get('lastname') }"
from: "#{ @Session.get().displayName() }"
to: (group && group.name) || ''
subject: params.subject
body: params.body

View file

@ -6,7 +6,7 @@ class Index extends App.ControllerContent
super
# navigate to # if session if exists
if @Session.get( 'id' )
if @Session.get()
@navigate '#'
return

View file

@ -126,7 +126,7 @@ class App.Navigation extends App.Controller
# remember old search query
search = @el.find('#global-search').val()
user = App.Session.all()
user = App.Session.get()
@html App.view('navigation')(
user: user
search: search
@ -366,6 +366,10 @@ class App.Navigation extends App.Controller
if part[0] is 'RecendViewed'
delete NavBarRight[key]
if !@Session.get()
@Config.set( 'NavBarRight', NavBarRight )
return
# add new views
items = App.RecentView.search(sortBy: 'created_at', order: 'DESC' )
items = @prepareForObjectList(items)

View file

@ -19,7 +19,7 @@ class App.TaskbarWidget extends App.Controller
@bind 'auth:logout', => @render()
render: ->
return if _.isEmpty( @Session.all() )
return if !@Session.get()
tasks = App.TaskManager.all()
item_list = []

View file

@ -393,7 +393,7 @@ class Table extends App.ControllerContent
# validate article
if params['body']
article = new App.TicketArticle
params.from = @Session.get( 'firstname' ) + ' ' + @Session.get( 'lastname' )
params.from = @Session.get().displayName()
params.ticket_id = ticket.id
params.form_id = @form_id

View file

@ -62,7 +62,7 @@ class App.TicketZoom extends App.Controller
fetch: (ticket_id, force) ->
return if !@Session.all()
return if !@Session.get()
# get data
@ajax(
@ -80,7 +80,7 @@ class App.TicketZoom extends App.Controller
return if @ticketUpdatedAtLastCall is newTicketRaw.updated_at
# notify if ticket changed not by my self
if newTicketRaw.updated_by_id isnt @Session.all().id
if newTicketRaw.updated_by_id isnt @Session.get('id')
App.TaskManager.notify( @task_key )
# rerender edit box
@ -835,7 +835,7 @@ class Edit extends App.Controller
articleAttributes = App.TicketArticle.attributesGet( 'edit' )
if params['body'] || ( articleAttributes['body'] && articleAttributes['body']['null'] is false )
article = new App.TicketArticle
params.from = @Session.get( 'firstname' ) + ' ' + @Session.get( 'lastname' )
params.from = @Session.get().displayName()
params.ticket_id = ticket.id
params.form_id = @form_id

View file

@ -26,7 +26,7 @@ class Widget extends App.Controller
@start()
access: ->
return false if _.isEmpty( @Session.all() )
return false if !@Session.get()
return true if @isRole('Agent')
return true if @isRole('Admin')
return false

View file

@ -21,16 +21,14 @@ class App.OnlineNotificationWidget extends App.Controller
if @access()
@start()
@start()
@subscribeId = App.OnlineNotification.subscribe( @start )
@subscribeId = App.OnlineNotification.subscribe( @start )
release: =>
@stop()
App.OnlineNotification.unsubscribe( @subscribeId )
access: ->
return false if _.isEmpty( @Session.all() )
return false if !@Session.get()
return true if @isRole('Agent')
return true if @isRole('Admin')
return false

View file

@ -17,7 +17,7 @@ class Widget extends App.Controller
render: (user) ->
# if no switch to user is active
if !App.Config.get('switch_back_to_possible') || _.isEmpty( App.Session.all() )
if !App.Config.get('switch_back_to_possible') || !App.Session.get()
@el.html('')
$('#app').removeClass('switchBackToUserSpace')
return

View file

@ -10,15 +10,10 @@ class App.Session
_instance ?= new _sessionSingleton
_instance.get( key )
@set: ( key, value ) ->
@set: ( user ) ->
if _instance == undefined
_instance ?= new _sessionSingleton
_instance.set( key, value )
@all: ->
if _instance == undefined
_instance ?= new _sessionSingleton
_instance.all()
_instance.set( user )
class _sessionSingleton extends Spine.Module
@include App.LogInclude
@ -27,15 +22,13 @@ class _sessionSingleton extends Spine.Module
@clear()
clear: ->
@data = {}
@user = undefined
get: ( key ) ->
@log 'debug', key, @data[key]
@data[key]
return if !@user
if key
return @user[key]
@user
set: ( key, value ) ->
@log 'debug', 'set', key, value
@data[key] = value
all: ->
@data
set: ( user ) ->
@user = user

View file

@ -102,9 +102,8 @@ class App.Auth
App.Collection.loadAssets( data.assets )
# store user data
session = App.User.fullLocal(data.session.id)
for key, value of session
App.Session.set( key, value )
sessionUser = App.User.fullLocal(data.session.id)
App.Session.set( sessionUser )
# trigger auth ok with new session data
App.Event.trigger( 'auth', data.session )

View file

@ -114,7 +114,7 @@ class _webSocketSingleton extends App.Controller
# logon websocket
data =
action: 'login'
session: App.Session.all()
session: App.Session.get()
@send(data)
spool: =>

View file

@ -29,21 +29,23 @@ returns
=end
def self.create( client_id, session, meta )
data = {}
if session
data[:id] = session[:id]
end
path = @path + '/' + client_id.to_s
FileUtils.mkpath path
meta[:last_ping] = Time.new.to_i.to_s
File.open( path + '/session', 'wb' ) { |file|
data = {
:user => {
:id => session['id'],
},
:user => data,
:meta => meta,
}
file.write Marshal.dump(data)
}
# send update to browser
if session['id']
if session && session['id']
self.send( client_id, {
:event => 'ws:login',
:data => { :success => true },