diff options
author | Rubén Dávila <ruben@gitlab.com> | 2019-02-05 09:55:31 -0500 |
---|---|---|
committer | Rubén Dávila <ruben@gitlab.com> | 2019-02-05 09:55:31 -0500 |
commit | 24226b9fe25ad98b279eae6b3ccd37749ba4d60d (patch) | |
tree | 29daa7422ca445c4c172d7c94509da96ff87bedc /app/controllers/concerns/record_user_last_activity.rb | |
parent | 4b07f22d93de1417ab7918ffd982e35526b50c6e (diff) | |
download | gitlab-ce-24226b9fe25ad98b279eae6b3ccd37749ba4d60d.tar.gz |
Update last_activity_on for Users on some main GET endpoints
In order to have an accurate date about the last activity of a User
we need to update the last_activity_on field when the User is visiting
some basic pages of GitLab like pages related to Dashboards, Projects,
Issues and Merge Requests
Diffstat (limited to 'app/controllers/concerns/record_user_last_activity.rb')
-rw-r--r-- | app/controllers/concerns/record_user_last_activity.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/app/controllers/concerns/record_user_last_activity.rb b/app/controllers/concerns/record_user_last_activity.rb new file mode 100644 index 00000000000..884c17b3f68 --- /dev/null +++ b/app/controllers/concerns/record_user_last_activity.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +# == RecordUserLastActivity +# +# Controller concern that updates the `last_activity_on` field of `users` +# for any authenticated GET request. The DB update will only happen once per day +# if the client supports cookies. +# +# In order to determine if you should include this concern or not, please check the +# description and discussion on this issue: https://gitlab.com/gitlab-org/gitlab-ce/issues/54947 +module RecordUserLastActivity + include CookiesHelper + extend ActiveSupport::Concern + + included do + before_action :set_user_last_activity + end + + def set_user_last_activity + return unless request.get? + return unless Feature.enabled?(:set_user_last_activity, default_enabled: true) + return if Gitlab::Database.read_only? + + if current_user && current_user.last_activity_on != Date.today + Users::ActivityService.new(current_user, "visited #{request.path}").execute + end + end +end |