Skip to content
Snippets Groups Projects
Commit 81f42813 authored by Israel Barreto Sant'Anna's avatar Israel Barreto Sant'Anna
Browse files

Added activities to user on create and update

parent 31b10223
No related branches found
No related tags found
No related merge requests found
...@@ -40,6 +40,10 @@ class User < ApplicationRecord ...@@ -40,6 +40,10 @@ class User < ApplicationRecord
include Tagger include Tagger
include Complainable include Complainable
include Publisher include Publisher
include PublicActivity::Common
after_create -> { new_activity("create") }
after_update -> { new_activity("update") }
# Include default devise modules. Others available are: # Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable # :confirmable, :lockable, :timeoutable and :omniauthable
...@@ -193,4 +197,14 @@ class User < ApplicationRecord ...@@ -193,4 +197,14 @@ class User < ApplicationRecord
password: Devise.friendly_token[0, 20] password: Devise.friendly_token[0, 20]
) )
end end
def new_activity(type)
should_create = true
if type == "update"
ignore = ["tokens", "sign_in_count", "current_sign_in_at", "last_sign_in_at", "updated_at"]
filtered = changed.reject { |x| ignore.include?(x) }
should_create = !filtered.empty?
end
self.create_activity key: 'user.'+type, trackable: self, owner: self, recipient: self, privacy: "public" if should_create
end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment