summaryrefslogtreecommitdiff
path: root/app/services/users
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-10-05 16:41:32 +0200
committerRémy Coutable <remy@rymai.me>2017-04-14 15:20:55 +0200
commit2951a8543ef97ceb1bcaca5f5140d822729c950b (patch)
treeff02540e813cd93e8df8a438c9b22cdacc96982e /app/services/users
parentb61199ce0ccdfcd11a338778ce300cd15e5f2a43 (diff)
downloadgitlab-ce-2951a8543ef97ceb1bcaca5f5140d822729c950b.tar.gz
Add user activity service and spec. Also added relevant - NOT offline - migration
It uses a user activity table instead of a column in users. Tested with mySQL and postgreSQL
Diffstat (limited to 'app/services/users')
-rw-r--r--app/services/users/activity_service.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/app/services/users/activity_service.rb b/app/services/users/activity_service.rb
new file mode 100644
index 00000000000..b81f947cd01
--- /dev/null
+++ b/app/services/users/activity_service.rb
@@ -0,0 +1,26 @@
+module Users
+ class ActivityService
+ def initialize(author, activity)
+ @author = author.respond_to?(:user) ? author.user : author
+ @activity = activity
+ end
+
+ def execute
+ return unless @author && @author.is_a?(User)
+
+ record_activity
+ end
+
+ private
+
+ def record_activity
+ user_activity.touch
+
+ Rails.logger.debug("Recorded activity: #{@activity} for User ID: #{@author.id} (username: #{@author.username}")
+ end
+
+ def user_activity
+ UserActivity.find_or_initialize_by(user: @author)
+ end
+ end
+end