diff options
author | James Lopez <james@jameslopez.es> | 2016-10-05 16:41:32 +0200 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-04-14 15:20:55 +0200 |
commit | 2951a8543ef97ceb1bcaca5f5140d822729c950b (patch) | |
tree | ff02540e813cd93e8df8a438c9b22cdacc96982e /app/services/users | |
parent | b61199ce0ccdfcd11a338778ce300cd15e5f2a43 (diff) | |
download | gitlab-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.rb | 26 |
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 |