From 352bae8c3ef2aca41de4aacb85d5e036a1d2bace Mon Sep 17 00:00:00 2001 From: ThibG Date: Fri, 11 May 2018 13:20:58 +0200 Subject: [PATCH] Update session activation time (fixes #5605) (#7408) --- app/controllers/application_controller.rb | 1 + .../concerns/session_tracking_concern.rb | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 app/controllers/concerns/session_tracking_concern.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5885264470..5b22f17c63 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -9,6 +9,7 @@ class ApplicationController < ActionController::Base include Localized include UserTrackingConcern + include SessionTrackingConcern helper_method :current_account helper_method :current_session diff --git a/app/controllers/concerns/session_tracking_concern.rb b/app/controllers/concerns/session_tracking_concern.rb new file mode 100644 index 0000000000..45361b0190 --- /dev/null +++ b/app/controllers/concerns/session_tracking_concern.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module SessionTrackingConcern + extend ActiveSupport::Concern + + UPDATE_SIGN_IN_HOURS = 24 + + included do + before_action :set_session_activity + end + + private + + def set_session_activity + return unless session_needs_update? + current_session.touch + end + + def session_needs_update? + !current_session.nil? && current_session.updated_at < UPDATE_SIGN_IN_HOURS.hours.ago + end +end