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

Merge branch 'ignore_activities' into 'master'

Ignore activities

See merge request !409
parents c0fa1e75 4e3f39dc
No related branches found
No related tags found
No related merge requests found
...@@ -119,4 +119,8 @@ class Collection < ApplicationRecord ...@@ -119,4 +119,8 @@ class Collection < ApplicationRecord
def download_link def download_link
'/'+PackageService.link(self) '/'+PackageService.link(self)
end end
def ignore_changes
super + %w(score views_count downloads_count likes_count shares_count follows_count)
end
end end
module Trackable module Trackable
extend ActiveSupport::Concern extend ActiveSupport::Concern
include PublicActivity::Model include PublicActivity::Common
include ActivitiesFilterService include ActivitiesFilterService
included do included do
tracked owner: proc { |controller, model| model.try(:user) || model.try(:owner) || controller.try(:current_user) } after_create :new_create_activity
tracked recipient: proc { |_controller, model| model.try(:recipient) || model } after_destroy :new_destroy_activity
tracked privacy: proc { |_controller, model| model.try(:privacy) || "public" } after_update :new_update_activity
end
private
def new_update_activity
return nil if changed.blank?
return new_activity(:update) if ignore_changes == %w(updated_at)
filtered = changed.reject { |x| ignore_changes.include?(x) }
new_activity(:update) unless filtered.empty?
end
def new_create_activity
new_activity(:create)
end
def new_destroy_activity
new_activity(:destroy)
end
def new_activity(action)
create_activity(
action,
owner: activity_owner,
recipient: activity_recipient,
privacy: activity_privacy
)
end
def ignore_changes
%w(updated_at)
end
def activity_owner
proc { |controller, model| model.try(:user) || model.try(:owner) || controller.try(:current_user) }
end
def activity_recipient
proc { |_controller, model| model.try(:recipient) || model }
end
def activity_privacy
proc { |_controller, model| model.try(:privacy) || 'public' }
end end
end end
...@@ -61,7 +61,7 @@ class LearningObject < ApplicationRecord ...@@ -61,7 +61,7 @@ class LearningObject < ApplicationRecord
belongs_to :object_type belongs_to :object_type
belongs_to :attachment, class_name: 'LearningObject::Attachment' belongs_to :attachment, class_name: 'LearningObject::Attachment'
validates_presence_of :name, :publisher, :object_type, :language, :author, unless: :draft? validates :name, :publisher, :object_type, :language, :author, unless: :draft?, presence: true
validates :id_dspace, presence: true, uniqueness: true, unless: :published? validates :id_dspace, presence: true, uniqueness: true, unless: :published?
default_scope { includes(:object_type, :attachment, :attachments) } default_scope { includes(:object_type, :attachment, :attachments) }
...@@ -111,7 +111,7 @@ class LearningObject < ApplicationRecord ...@@ -111,7 +111,7 @@ class LearningObject < ApplicationRecord
# If a LO has more than one object, this gives the location of the main one # If a LO has more than one object, this gives the location of the main one
def default_attachment_location def default_attachment_location
object_type.try(:name) == ("Vídeo" || "Áudio") ? default_attachment.try(:retrieve_cache_link) : default_attachment.try(:retrieve_url) object_type.try(:name) == ('Vídeo' || 'Áudio') ? default_attachment.try(:retrieve_cache_link) : default_attachment.try(:retrieve_url)
end end
def default_thumbnail def default_thumbnail
...@@ -135,6 +135,10 @@ class LearningObject < ApplicationRecord ...@@ -135,6 +135,10 @@ class LearningObject < ApplicationRecord
default_attachment_location default_attachment_location
end end
def ignore_changes
super + %w(score views_count downloads_count likes_count shares_count)
end
## score methods ## score methods
def normalized_collected def normalized_collected
max = CollectionItem.where(collectionable_type: 'LearningObject').group(:collectionable_id).order('count_all DESC').count max = CollectionItem.where(collectionable_type: 'LearningObject').group(:collectionable_id).order('count_all DESC').count
......
...@@ -41,12 +41,9 @@ class User < ApplicationRecord ...@@ -41,12 +41,9 @@ class User < ApplicationRecord
include Tagger include Tagger
include Complainable include Complainable
include Publisher include Publisher
include PublicActivity::Common include Trackable
include ActivitiesFilterService include ActivitiesFilterService
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
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
...@@ -79,7 +76,7 @@ class User < ApplicationRecord ...@@ -79,7 +76,7 @@ class User < ApplicationRecord
has_attached_file :cover, styles: { medium: '800x300>', thumb: '160x60>' }, default_url: '' has_attached_file :cover, styles: { medium: '800x300>', thumb: '160x60>' }, default_url: ''
validates_attachment_content_type :cover, content_type: ['image/jpg', 'image/jpeg', 'image/png', 'image/gif'] validates_attachment_content_type :cover, content_type: ['image/jpg', 'image/jpeg', 'image/png', 'image/gif']
validates :terms_of_service, acceptance: true validates :terms_of_service, acceptance: true
searchkick language: 'brazilian', match: :word_start, searchable: [:name], callbacks: :async searchkick language: 'brazilian', match: :word_start, searchable: [:name], callbacks: :async
...@@ -207,13 +204,11 @@ class User < ApplicationRecord ...@@ -207,13 +204,11 @@ class User < ApplicationRecord
) )
end end
def new_activity(type) def activity_owner
should_create = true self
if type == "update" end
ignore = ["tokens", "sign_in_count", "current_sign_in_at", "last_sign_in_at", "updated_at"]
filtered = changed.reject { |x| ignore.include?(x) } def ignore_changes
should_create = !filtered.empty? super + %w(tokens sign_in_count current_sign_in_at last_sign_in_at current_sign_in_ip last_sign_in_ip score follows_count confirmation_token confirmed_at confirmation_sent_at)
end
self.create_activity key: 'user.'+type, trackable: self, owner: self, recipient: self, privacy: "public" if should_create
end 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