Fixed issue #1280 - Invalidate cache when switching users.
This commit is contained in:
parent
248bc015e1
commit
5b8715184e
8 changed files with 158 additions and 21 deletions
|
@ -1170,6 +1170,7 @@ class App.ObserverController extends App.Controller
|
||||||
if @globalRerender
|
if @globalRerender
|
||||||
@bind('ui:rerender', =>
|
@bind('ui:rerender', =>
|
||||||
@lastAttributres = undefined
|
@lastAttributres = undefined
|
||||||
|
console.log('aaaa', @model, @template)
|
||||||
@maybeRender(App[@model].fullLocal(@object_id))
|
@maybeRender(App[@model].fullLocal(@object_id))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ class App._CollectionSingletonBase
|
||||||
@callbacks = {}
|
@callbacks = {}
|
||||||
@counter = 0
|
@counter = 0
|
||||||
@key = "collection-#{@event}"
|
@key = "collection-#{@event}"
|
||||||
|
|
||||||
# read from cache
|
# read from cache
|
||||||
cache = App.SessionStorage.get(@key)
|
cache = App.SessionStorage.get(@key)
|
||||||
if cache
|
if cache
|
||||||
|
@ -16,6 +17,9 @@ class App._CollectionSingletonBase
|
||||||
@set(data)
|
@set(data)
|
||||||
@callback(data)
|
@callback(data)
|
||||||
|
|
||||||
|
App.Event.bind 'auth:logout', (data) =>
|
||||||
|
@clear(data)
|
||||||
|
|
||||||
get: =>
|
get: =>
|
||||||
@collectionData
|
@collectionData
|
||||||
|
|
||||||
|
@ -79,3 +83,6 @@ class App._CollectionSingletonBase
|
||||||
delete @callbacks[counter]
|
delete @callbacks[counter]
|
||||||
App.QueueManager.add(@key, callback)
|
App.QueueManager.add(@key, callback)
|
||||||
App.QueueManager.run(@key)
|
App.QueueManager.run(@key)
|
||||||
|
|
||||||
|
clear: =>
|
||||||
|
@collectionData = undefined
|
||||||
|
|
|
@ -76,13 +76,7 @@ class App.Auth
|
||||||
App.Session.init()
|
App.Session.init()
|
||||||
|
|
||||||
# update model definition (needed for not authenticated areas like wizard)
|
# update model definition (needed for not authenticated areas like wizard)
|
||||||
if data.models
|
@_updateModelAttributes(data.models)
|
||||||
for model, attributes of data.models
|
|
||||||
if !App[model]
|
|
||||||
throw "No such model App.#{model}"
|
|
||||||
for attribute in attributes
|
|
||||||
App[model].attributes.push attribute.name
|
|
||||||
App[model].configure_attributes.push attribute
|
|
||||||
|
|
||||||
# set locale
|
# set locale
|
||||||
locale = window.navigator.userLanguage || window.navigator.language || 'en-us'
|
locale = window.navigator.userLanguage || window.navigator.language || 'en-us'
|
||||||
|
@ -100,13 +94,7 @@ class App.Auth
|
||||||
App.Event.trigger('clearStore')
|
App.Event.trigger('clearStore')
|
||||||
|
|
||||||
# update model definition
|
# update model definition
|
||||||
if data.models
|
@_updateModelAttributes(data.models)
|
||||||
for model, attributes of data.models
|
|
||||||
if !App[model]
|
|
||||||
throw "No such model App.#{model}"
|
|
||||||
for attribute in attributes
|
|
||||||
App[model].attributes.push attribute.name
|
|
||||||
App[model].configure_attributes.push attribute
|
|
||||||
|
|
||||||
# update config
|
# update config
|
||||||
for key, value of data.config
|
for key, value of data.config
|
||||||
|
@ -139,6 +127,14 @@ class App.Auth
|
||||||
App.Event.trigger('ui:rerender')
|
App.Event.trigger('ui:rerender')
|
||||||
App.TaskManager.tasksInitial()
|
App.TaskManager.tasksInitial()
|
||||||
|
|
||||||
|
@_updateModelAttributes: (models) ->
|
||||||
|
return if _.isEmpty(models)
|
||||||
|
|
||||||
|
for model, attributes of models
|
||||||
|
if App[model]
|
||||||
|
if _.isFunction(App[model].updateAttributes)
|
||||||
|
App[model].updateAttributes(attributes)
|
||||||
|
|
||||||
@_logout: (rerender = true) ->
|
@_logout: (rerender = true) ->
|
||||||
App.Log.debug 'Auth', '_logout'
|
App.Log.debug 'Auth', '_logout'
|
||||||
|
|
||||||
|
@ -153,6 +149,15 @@ 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.resetCallbacks)
|
||||||
|
model_object.resetCallbacks()
|
||||||
|
if _.isFunction(model_object.resetAttributes)
|
||||||
|
model_object.resetAttributes()
|
||||||
|
if _.isFunction(model_object.clearInMemory)
|
||||||
|
model_object.clearInMemory()
|
||||||
|
|
||||||
@_loginError: ->
|
@_loginError: ->
|
||||||
App.Log.debug 'Auth', '_loginError:error'
|
App.Log.debug 'Auth', '_loginError:error'
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,9 @@ class _Singleton
|
||||||
@overview[data.overview.view] = data
|
@overview[data.overview.view] = data
|
||||||
@callback(data.overview.view, data)
|
@callback(data.overview.view, data)
|
||||||
|
|
||||||
|
App.Event.bind 'auth:logout', (data) =>
|
||||||
|
@clear(data)
|
||||||
|
|
||||||
get: (view) ->
|
get: (view) ->
|
||||||
@overview[view]
|
@overview[view]
|
||||||
|
|
||||||
|
@ -76,6 +79,12 @@ class _Singleton
|
||||||
App.QueueManager.add('ticket_overviews', callback)
|
App.QueueManager.add('ticket_overviews', callback)
|
||||||
App.QueueManager.run('ticket_overviews')
|
App.QueueManager.run('ticket_overviews')
|
||||||
|
|
||||||
|
clear: =>
|
||||||
|
@overview = {}
|
||||||
|
@callbacks = {}
|
||||||
|
@fetchActive = {}
|
||||||
|
@counter = 0
|
||||||
|
|
||||||
class App.OverviewListCollection
|
class App.OverviewListCollection
|
||||||
_instance = new _Singleton
|
_instance = new _Singleton
|
||||||
|
|
||||||
|
|
|
@ -812,3 +812,29 @@ set new attributes of model (remove already available attributes)
|
||||||
item: item
|
item: item
|
||||||
processData: true
|
processData: true
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@clearInMemory: ->
|
||||||
|
return if !@className
|
||||||
|
|
||||||
|
# reset attributes to prevent cached forms on relogin
|
||||||
|
if !_.isEmpty(App[@className].org_configure_attributes)
|
||||||
|
App[@className].configure_attributes = App[@className].org_configure_attributes
|
||||||
|
|
||||||
|
# reset cached values of model
|
||||||
|
App[@className].deleteAll()
|
||||||
|
|
||||||
|
@updateAttributes: (attributes) ->
|
||||||
|
return if !@className
|
||||||
|
if _.isEmpty(@org_configure_attributes)
|
||||||
|
@org_configure_attributes = clone(@configure_attributes)
|
||||||
|
for attribute in attributes
|
||||||
|
@attributes.push attribute.name
|
||||||
|
@configure_attributes.push attribute
|
||||||
|
|
||||||
|
@resetAttributes: ->
|
||||||
|
return if _.isEmpty(@org_configure_attributes)
|
||||||
|
@configure_attributes = @org_configure_attributes
|
||||||
|
|
||||||
|
@resetCallbacks: ->
|
||||||
|
@SUBSCRIPTION_ITEM = {}
|
||||||
|
@SUBSCRIPTION_COLLECTION = {}
|
||||||
|
|
|
@ -60,6 +60,7 @@ if [ "$LEVEL" == '1' ]; then
|
||||||
# test/browser/taskbar_session_test.rb
|
# test/browser/taskbar_session_test.rb
|
||||||
# test/browser/taskbar_task_test.rb
|
# test/browser/taskbar_task_test.rb
|
||||||
# test/browser/translation_test.rb
|
# test/browser/translation_test.rb
|
||||||
|
rm test/browser/user_switch_cache_test.rb
|
||||||
|
|
||||||
elif [ "$LEVEL" == '2' ]; then
|
elif [ "$LEVEL" == '2' ]; then
|
||||||
echo "slicing level 2"
|
echo "slicing level 2"
|
||||||
|
@ -117,6 +118,7 @@ elif [ "$LEVEL" == '2' ]; then
|
||||||
rm test/browser/taskbar_session_test.rb
|
rm test/browser/taskbar_session_test.rb
|
||||||
rm test/browser/taskbar_task_test.rb
|
rm test/browser/taskbar_task_test.rb
|
||||||
rm test/browser/translation_test.rb
|
rm test/browser/translation_test.rb
|
||||||
|
#rm test/browser/user_switch_cache_test.rb
|
||||||
|
|
||||||
elif [ "$LEVEL" == '3' ]; then
|
elif [ "$LEVEL" == '3' ]; then
|
||||||
echo "slicing level 3"
|
echo "slicing level 3"
|
||||||
|
@ -174,6 +176,7 @@ elif [ "$LEVEL" == '3' ]; then
|
||||||
rm test/browser/taskbar_session_test.rb
|
rm test/browser/taskbar_session_test.rb
|
||||||
rm test/browser/taskbar_task_test.rb
|
rm test/browser/taskbar_task_test.rb
|
||||||
rm test/browser/translation_test.rb
|
rm test/browser/translation_test.rb
|
||||||
|
rm test/browser/user_switch_cache_test.rb
|
||||||
|
|
||||||
elif [ "$LEVEL" == '4' ]; then
|
elif [ "$LEVEL" == '4' ]; then
|
||||||
echo "slicing level 4"
|
echo "slicing level 4"
|
||||||
|
@ -231,6 +234,7 @@ elif [ "$LEVEL" == '4' ]; then
|
||||||
rm test/browser/taskbar_session_test.rb
|
rm test/browser/taskbar_session_test.rb
|
||||||
rm test/browser/taskbar_task_test.rb
|
rm test/browser/taskbar_task_test.rb
|
||||||
rm test/browser/translation_test.rb
|
rm test/browser/translation_test.rb
|
||||||
|
rm test/browser/user_switch_cache_test.rb
|
||||||
|
|
||||||
elif [ "$LEVEL" == '5' ]; then
|
elif [ "$LEVEL" == '5' ]; then
|
||||||
echo "slicing level 5"
|
echo "slicing level 5"
|
||||||
|
@ -287,6 +291,7 @@ elif [ "$LEVEL" == '5' ]; then
|
||||||
rm test/browser/taskbar_session_test.rb
|
rm test/browser/taskbar_session_test.rb
|
||||||
rm test/browser/taskbar_task_test.rb
|
rm test/browser/taskbar_task_test.rb
|
||||||
rm test/browser/translation_test.rb
|
rm test/browser/translation_test.rb
|
||||||
|
rm test/browser/user_switch_cache_test.rb
|
||||||
|
|
||||||
elif [ "$LEVEL" == '6' ]; then
|
elif [ "$LEVEL" == '6' ]; then
|
||||||
echo "slicing level 6"
|
echo "slicing level 6"
|
||||||
|
@ -346,6 +351,7 @@ elif [ "$LEVEL" == '6' ]; then
|
||||||
rm test/browser/taskbar_session_test.rb
|
rm test/browser/taskbar_session_test.rb
|
||||||
rm test/browser/taskbar_task_test.rb
|
rm test/browser/taskbar_task_test.rb
|
||||||
rm test/browser/translation_test.rb
|
rm test/browser/translation_test.rb
|
||||||
|
rm test/browser/user_switch_cache_test.rb
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "ERROR: Invalid level $LEVEL - 1, 2, 3, 4, 5 or 6 is available"
|
echo "ERROR: Invalid level $LEVEL - 1, 2, 3, 4, 5 or 6 is available"
|
||||||
|
|
83
test/browser/user_switch_cache_test.rb
Normal file
83
test/browser/user_switch_cache_test.rb
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
require 'browser_test_helper'
|
||||||
|
|
||||||
|
class UserSwitchCache < TestCase
|
||||||
|
def test_re_login
|
||||||
|
|
||||||
|
# login as agent and create one ticket
|
||||||
|
@browser = browser_instance
|
||||||
|
login(
|
||||||
|
username: 'agent1@example.com',
|
||||||
|
password: 'test',
|
||||||
|
url: browser_url,
|
||||||
|
)
|
||||||
|
tasks_close_all()
|
||||||
|
ticket1 = ticket_create(
|
||||||
|
data: {
|
||||||
|
customer: 'nico',
|
||||||
|
group: 'Users',
|
||||||
|
title: 'some subject 123äöü - reply test',
|
||||||
|
body: 'some body 123äöü - reply test',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
logout()
|
||||||
|
|
||||||
|
# login as customer and verify ticket create screen
|
||||||
|
login(
|
||||||
|
username: 'nicole.braun@zammad.org',
|
||||||
|
password: 'test',
|
||||||
|
url: browser_url,
|
||||||
|
)
|
||||||
|
click(css: 'a[href="#new"]')
|
||||||
|
click(css: 'a[href="#customer_ticket_new"]')
|
||||||
|
sleep 4
|
||||||
|
|
||||||
|
match(
|
||||||
|
css: '#content',
|
||||||
|
value: 'Priority',
|
||||||
|
should_not_match: true,
|
||||||
|
)
|
||||||
|
|
||||||
|
match(
|
||||||
|
css: '#content',
|
||||||
|
value: 'Owner',
|
||||||
|
should_not_match: true,
|
||||||
|
)
|
||||||
|
|
||||||
|
match(
|
||||||
|
css: '#content',
|
||||||
|
value: 'State',
|
||||||
|
)
|
||||||
|
|
||||||
|
logout()
|
||||||
|
|
||||||
|
# login again as customer and verify ticket create screen
|
||||||
|
login(
|
||||||
|
username: 'nicole.braun@zammad.org',
|
||||||
|
password: 'test',
|
||||||
|
url: browser_url,
|
||||||
|
)
|
||||||
|
click(css: 'a[href="#new"]')
|
||||||
|
click(css: 'a[href="#customer_ticket_new"]')
|
||||||
|
sleep 4
|
||||||
|
|
||||||
|
match(
|
||||||
|
css: '#content',
|
||||||
|
value: 'Priority',
|
||||||
|
should_not_match: true,
|
||||||
|
)
|
||||||
|
|
||||||
|
match(
|
||||||
|
css: '#content',
|
||||||
|
value: 'Owner',
|
||||||
|
should_not_match: true,
|
||||||
|
)
|
||||||
|
|
||||||
|
match(
|
||||||
|
css: '#content',
|
||||||
|
value: 'State',
|
||||||
|
)
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue