From 866c31587e140074906cdd74e682066532aad0f4 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 29 Jun 2018 19:04:39 +0200 Subject: [PATCH] Fixed bug: Outdated data is used for Websocket session data gathering and is send to the frontend in some cases. --- lib/sessions/backend/activity_stream.rb | 2 ++ lib/sessions/backend/base.rb | 2 ++ lib/sessions/backend/collections.rb | 9 +++++++++ lib/sessions/backend/collections/base.rb | 2 ++ lib/sessions/client.rb | 17 +++++++++++++---- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/sessions/backend/activity_stream.rb b/lib/sessions/backend/activity_stream.rb index 950773f75..4ec3e5abf 100644 --- a/lib/sessions/backend/activity_stream.rb +++ b/lib/sessions/backend/activity_stream.rb @@ -1,5 +1,7 @@ class Sessions::Backend::ActivityStream + attr_writer :user + def initialize(user, asset_lookup, client = nil, client_id = nil, ttl = 25) @user = user @client = client diff --git a/lib/sessions/backend/base.rb b/lib/sessions/backend/base.rb index bd85471e4..e7e8f9eaf 100644 --- a/lib/sessions/backend/base.rb +++ b/lib/sessions/backend/base.rb @@ -1,5 +1,7 @@ class Sessions::Backend::Base + attr_writer :user + def initialize(user, asset_lookup, client, client_id, ttl = 10) @user = user @client = client diff --git a/lib/sessions/backend/collections.rb b/lib/sessions/backend/collections.rb index c74812a15..1f87923ec 100644 --- a/lib/sessions/backend/collections.rb +++ b/lib/sessions/backend/collections.rb @@ -22,6 +22,15 @@ class Sessions::Backend::Collections < Sessions::Backend::Base results end + def user=(user) + @user = user + + # update stored user in backends, too + @backends.each do |backend| + backend.user = user + end + end + def backend # auto population collections diff --git a/lib/sessions/backend/collections/base.rb b/lib/sessions/backend/collections/base.rb index c05da5383..1ca5e1bab 100644 --- a/lib/sessions/backend/collections/base.rb +++ b/lib/sessions/backend/collections/base.rb @@ -1,6 +1,8 @@ class Sessions::Backend::Collections::Base < Sessions::Backend::Base class << self; attr_accessor :model, :permissions end + attr_writer :user + def initialize(user, asset_lookup, client, client_id, ttl) @user = user @client = client diff --git a/lib/sessions/client.rb b/lib/sessions/client.rb index 0529b346d..4a111abe5 100644 --- a/lib/sessions/client.rb +++ b/lib/sessions/client.rb @@ -17,10 +17,11 @@ class Sessions::Client 'Sessions::Backend::TicketCreate', ] - asset_lookup = {} - backend_pool = [] - user_id_last_run = nil - loop_count = 0 + asset_lookup = {} + backend_pool = [] + user_id_last_run = nil + user_updated_at_last_run = nil + loop_count = 0 loop do # check if session still exists @@ -50,6 +51,14 @@ class Sessions::Client item = backend.constantize.new(user, asset_lookup, self, @client_id) backend_pool.push item end + # update user if required + elsif user_updated_at_last_run != user.updated_at + user_updated_at_last_run = user.updated_at + + log "---client - updating user #{user.id} - #{user_updated_at_last_run}" + backend_pool.each do |backend| + backend.user = user + end end loop_count += 1