diff --git a/app/assets/javascripts/app/lib/app_init/session.coffee b/app/assets/javascripts/app/lib/app_init/session.coffee index 87bf31d2d..deed33ade 100644 --- a/app/assets/javascripts/app/lib/app_init/session.coffee +++ b/app/assets/javascripts/app/lib/app_init/session.coffee @@ -5,15 +5,17 @@ class App.Session _instance ?= new _sessionSingleton _instance.clear() + # Do NOT modify the return value of this method! + # It is a direct reference to a value in the App.User.irecords object. @get: (key) -> if _instance == undefined _instance ?= new _sessionSingleton _instance.get(key) - @set: (user) -> + @set: (user_id) -> if _instance == undefined _instance ?= new _sessionSingleton - _instance.set(user) + _instance.set(user_id) class _sessionSingleton extends Spine.Module @include App.LogInclude @@ -25,10 +27,9 @@ class _sessionSingleton extends Spine.Module @user = undefined get: (key) -> - return if !@user if key - return @user[key] + return @user?[key] @user - set: (user) -> - @user = user + set: (user_id) -> + @user = App.User.findNative(user_id) diff --git a/app/assets/javascripts/app/lib/app_post/auth.coffee b/app/assets/javascripts/app/lib/app_post/auth.coffee index b77dda363..5bc41409c 100644 --- a/app/assets/javascripts/app/lib/app_post/auth.coffee +++ b/app/assets/javascripts/app/lib/app_post/auth.coffee @@ -123,8 +123,7 @@ class App.Auth App.Collection.loadAssets(data.assets) # store user data - sessionUser = App.User.fullLocal(data.session.id) - App.Session.set(sessionUser) + App.Session.set(data.session.id) # trigger auth ok with new session data App.Event.trigger('auth', data.session) diff --git a/app/views/tests/session.html.erb b/app/views/tests/session.html.erb new file mode 100644 index 000000000..14b83ecec --- /dev/null +++ b/app/views/tests/session.html.erb @@ -0,0 +1,16 @@ + + + + + + + + + +
+ diff --git a/config/routes/test.rb b/config/routes/test.rb index 1c906fdfa..f0a80eadf 100644 --- a/config/routes/test.rb +++ b/config/routes/test.rb @@ -1,6 +1,7 @@ Zammad::Application.routes.draw do match '/tests_core', to: 'tests#core', via: :get + match '/tests_session', to: 'tests#session', via: :get match '/tests_ui', to: 'tests#ui', via: :get match '/tests_model', to: 'tests#model', via: :get match '/tests_model_binding', to: 'tests#model_binding', via: :get diff --git a/public/assets/tests/session.js b/public/assets/tests/session.js new file mode 100644 index 000000000..e31eff281 --- /dev/null +++ b/public/assets/tests/session.js @@ -0,0 +1,72 @@ +window.onload = function() { + +test('test current user behaviour by updating session user via assets', function() { + + // load user + App.User.refresh([{ + "login": "hh@example.com", + "firstname": "Harald", + "lastname": "Habebe", + "email": "hh@example.com", + "role_ids": [ 1, 2, 4 ], + "group_ids": [ 1 ], + "active": true, + "updated_at": "2017-02-09T09:17:04.770Z", + "address": "", + "vip": false, + "custom_key": undefined, + "asdf": "", + "id": 6 + }]); + + // set session user + App.Session.set(6) + + // verify attributes + equal(App.Session.get('id'), 6) + equal(App.Session.get('login'), 'hh@example.com') + equal(App.Session.get('vip'), false) + equal(App.Session.get('custom_key'), undefined) + equal(App.Session.get().id, 6) + equal(App.Session.get().login, 'hh@example.com') + equal(App.Session.get().custom_key, undefined) + equal(App.Session.get().not_existing, undefined) + + // update session user via assets + App.User.refresh([{ + "login": "hh_new@example.com", + "firstname": "Harald", + "lastname": "Habebe", + "email": "hh_new@example.com", + "role_ids": [ 1, 2, 4 ], + "group_ids": [ 1 ], + "active": true, + "updated_at": "2017-02-09T09:17:04.770Z", + "address": "", + "vip": false, + "custom_key": undefined, + "asdf": "", + "id": 6 + }]); + + // verify attributes + equal(App.Session.get('id'), 6) + equal(App.Session.get('login'), 'hh_new@example.com') + equal(App.Session.get('vip'), false) + equal(App.Session.get('custom_key'), undefined) + equal(App.Session.get().id, 6) + equal(App.Session.get().login, 'hh_new@example.com') + equal(App.Session.get().custom_key, undefined) + equal(App.Session.get().not_existing, undefined) + + // clear session + App.Session.init() + equal(App.Session.get(), undefined) + equal(App.Session.get('id'), undefined) + equal(App.Session.get('login'), undefined) + equal(App.Session.get('vip'), undefined) + equal(App.Session.get('custom_key'), undefined) + +}); + +} \ No newline at end of file diff --git a/public/assets/tests/ticket_selector.js b/public/assets/tests/ticket_selector.js index 9254ce4ad..edf4de3f4 100644 --- a/public/assets/tests/ticket_selector.js +++ b/public/assets/tests/ticket_selector.js @@ -141,7 +141,7 @@ window.onload = function() { "id": 8 }; - var sessionData = { + App.User.refresh([{ "login": "hh@zammad.com", "firstname": "Harald", "lastname": "Habebe", @@ -175,7 +175,9 @@ window.onload = function() { "anrede": "", "asdf": "", "id": 6 - }; + }]); + + var sessionData = App.User.find(6); /* * ------------------------------------------------------------------------ @@ -232,7 +234,7 @@ window.onload = function() { }; var testPreConditionUser = function (key, specificValue, ticket, session) { - App.Session.set(sessionData); + App.Session.set(6); setting = { "condition": { @@ -324,7 +326,7 @@ window.onload = function() { }; var testPreConditionOrganization = function (key, specificValue, ticket, session) { - App.Session.set(sessionData); + App.Session.set(6); setting = { "condition": { @@ -416,7 +418,7 @@ window.onload = function() { }; var testPreConditionTags = function (key, ticket) { - App.Session.set(sessionData); + App.Session.set(6); setting = { "condition": { @@ -701,7 +703,7 @@ window.onload = function() { ticket = new App.Ticket(); ticket.load(ticketData); - App.Session.set(sessionData); + App.Session.set(6); testPreConditionUser('ticket.customer_id', '6', ticket, sessionData); }); @@ -724,7 +726,7 @@ window.onload = function() { ticket = new App.Ticket(); ticket.load(ticketData); - App.Session.set(sessionData); + App.Session.set(6); testPreConditionUser('ticket.owner_id', '6', ticket, sessionData); }); @@ -889,7 +891,7 @@ window.onload = function() { ticket = new App.Ticket(); ticket.load(ticketData); - App.Session.set(sessionData); + App.Session.set(6); testPreConditionUser('ticket.created_by_id', '6', ticket, sessionData); }); @@ -912,7 +914,7 @@ window.onload = function() { ticket = new App.Ticket(); ticket.load(ticketData); - App.Session.set(sessionData); + App.Session.set(6); testPreConditionUser('ticket.updated_by_id', '6', ticket, sessionData); }); @@ -1105,4 +1107,4 @@ window.onload = function() { testContains('organization.domain', 'cool', ticket); }); -} \ No newline at end of file +} diff --git a/test/browser/aab_unit_test.rb b/test/browser/aab_unit_test.rb index 1dc714455..4ab1fbfc5 100644 --- a/test/browser/aab_unit_test.rb +++ b/test/browser/aab_unit_test.rb @@ -18,7 +18,20 @@ class AAbUnitTest < TestCase def test_ui @browser = browser_instance + location(url: browser_url + '/tests_session') + sleep 5 + watch_for( + css: '.result', + value: 'Tests completed', + timeout: 8, + ) + match( + css: '.result .failed', + value: '0', + ) + location(url: browser_url + '/tests_ui') + sleep 5 watch_for( css: '.result', value: 'Tests completed',