Fixed race condition: Running AJAX requests after logout was performed cause side effects.
This commit is contained in:
parent
a70153106a
commit
a9239997ef
3 changed files with 41 additions and 19 deletions
|
@ -45,6 +45,20 @@ class App.Auth
|
||||||
|
|
||||||
@logout: ->
|
@logout: ->
|
||||||
App.Log.debug 'Auth', 'logout'
|
App.Log.debug 'Auth', 'logout'
|
||||||
|
|
||||||
|
# abort all AJAX requests
|
||||||
|
# performed from the App context
|
||||||
|
App.Ajax.abortAll()
|
||||||
|
|
||||||
|
# add task to Spine.AJAX queue
|
||||||
|
# which will finish all queued requests
|
||||||
|
# and perform the logout afterwards
|
||||||
|
performLogut = =>
|
||||||
|
|
||||||
|
# clear all following AJAX
|
||||||
|
# tasks left in the queue
|
||||||
|
Spine.Ajax.clearQueue()
|
||||||
|
|
||||||
App.Ajax.request(
|
App.Ajax.request(
|
||||||
id: 'logout'
|
id: 'logout'
|
||||||
type: 'DELETE'
|
type: 'DELETE'
|
||||||
|
@ -57,6 +71,7 @@ class App.Auth
|
||||||
error: (xhr, statusText, error) =>
|
error: (xhr, statusText, error) =>
|
||||||
@_loginError()
|
@_loginError()
|
||||||
)
|
)
|
||||||
|
Spine.Ajax.queue(performLogut)
|
||||||
|
|
||||||
@_login: (data, type) ->
|
@_login: (data, type) ->
|
||||||
App.Log.debug 'Auth', '_login:success', data
|
App.Log.debug 'Auth', '_login:success', data
|
||||||
|
@ -137,9 +152,14 @@ class App.Auth
|
||||||
@_logout: (rerender = true) ->
|
@_logout: (rerender = true) ->
|
||||||
App.Log.debug 'Auth', '_logout'
|
App.Log.debug 'Auth', '_logout'
|
||||||
|
|
||||||
App.Ajax.abortAll()
|
|
||||||
App.TaskManager.reset()
|
App.TaskManager.reset()
|
||||||
App.Session.init()
|
App.Session.init()
|
||||||
|
App.Ajax.abortAll()
|
||||||
|
|
||||||
|
# clear all in-memory data of all App.Model's
|
||||||
|
for model_key, model_object of App
|
||||||
|
if _.isFunction(model_object.clearInMemory)
|
||||||
|
model_object.clearInMemory()
|
||||||
|
|
||||||
App.Event.trigger('auth')
|
App.Event.trigger('auth')
|
||||||
App.Event.trigger('auth:logout')
|
App.Event.trigger('auth:logout')
|
||||||
|
@ -148,11 +168,6 @@ class App.Auth
|
||||||
App.Event.trigger('ui:rerender')
|
App.Event.trigger('ui:rerender')
|
||||||
App.Event.trigger('clearStore')
|
App.Event.trigger('clearStore')
|
||||||
|
|
||||||
# clear all in-memory data of all App.Model's
|
|
||||||
for model_key, model_object of App
|
|
||||||
if _.isFunction(model_object.clearInMemory)
|
|
||||||
model_object.clearInMemory()
|
|
||||||
|
|
||||||
@_loginError: ->
|
@_loginError: ->
|
||||||
App.Log.debug 'Auth', '_loginError:error'
|
App.Log.debug 'Auth', '_loginError:error'
|
||||||
|
|
||||||
|
|
|
@ -393,7 +393,7 @@ set new attributes of model (remove already available attributes)
|
||||||
->
|
->
|
||||||
clear: true
|
clear: true
|
||||||
)
|
)
|
||||||
App.Delay.set(callback, 200, "full-#{@className}")
|
App.Delay.set(callback, 200, "fullcollection-#{@className}", "model-#{@className}")
|
||||||
|
|
||||||
"Collection::Subscribe::#{@className}"
|
"Collection::Subscribe::#{@className}"
|
||||||
)
|
)
|
||||||
|
@ -506,7 +506,7 @@ set new attributes of model (remove already available attributes)
|
||||||
if !genericObject || new Date(item.updated_at) > new Date(genericObject.updated_at)
|
if !genericObject || new Date(item.updated_at) > new Date(genericObject.updated_at)
|
||||||
App.Log.debug('Model', "request #{@className}.find(#{item.id}) from server")
|
App.Log.debug('Model', "request #{@className}.find(#{item.id}) from server")
|
||||||
@full(item.id, false, true)
|
@full(item.id, false, true)
|
||||||
App.Delay.set(callback, 600, item.id, "full-#{@className}-#{item.id}")
|
App.Delay.set(callback, 600, "full-#{item.id}", "model-#{@className}")
|
||||||
"Item::Subscribe::#{@className}"
|
"Item::Subscribe::#{@className}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -520,7 +520,7 @@ set new attributes of model (remove already available attributes)
|
||||||
App.Log.debug('Model', "server delete on #{@className}.find(#{item.id}) #{item.updated_at}")
|
App.Log.debug('Model', "server delete on #{@className}.find(#{item.id}) #{item.updated_at}")
|
||||||
callback = ->
|
callback = ->
|
||||||
genericObject.trigger('destroy', genericObject)
|
genericObject.trigger('destroy', genericObject)
|
||||||
App.Delay.set(callback, 500, item.id, "delete-#{@className}-#{item.id}")
|
App.Delay.set(callback, 500, "delete-#{item.id}", "model-#{@className}")
|
||||||
"Item::SubscribeDelete::#{@className}"
|
"Item::SubscribeDelete::#{@className}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -833,6 +833,8 @@ set new attributes of model (remove already available attributes)
|
||||||
)
|
)
|
||||||
|
|
||||||
@clearInMemory: ->
|
@clearInMemory: ->
|
||||||
|
App.Delay.clearLevel("model-#{@className}")
|
||||||
|
|
||||||
# reset callbacks to session based functions
|
# reset callbacks to session based functions
|
||||||
@resetCallbacks()
|
@resetCallbacks()
|
||||||
|
|
||||||
|
|
|
@ -152,5 +152,10 @@ class AgentTicketTimeAccountingTest < TestCase
|
||||||
css: '.content.active .js-timeAccountingSetting',
|
css: '.content.active .js-timeAccountingSetting',
|
||||||
type: 'off',
|
type: 'off',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# make sure "off" AJAX request gets completed
|
||||||
|
# otherwise following tests might fail because
|
||||||
|
# off still active timeaccounting
|
||||||
|
logout()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue