diff --git a/app/models/concerns/trackable.rb b/app/models/concerns/trackable.rb index 4a6712ced336438e3f7bc7a1a752315b5ea5fd08..a8da93f4f48c87701517dfcfef7be35c2164abd5 100644 --- a/app/models/concerns/trackable.rb +++ b/app/models/concerns/trackable.rb @@ -1,6 +1,7 @@ module Trackable extend ActiveSupport::Concern include PublicActivity::Model + include ActivitiesFilterService included do tracked owner: proc { |controller, model| model.try(:user) || model.try(:owner) || controller.try(:current_user) } @@ -8,25 +9,4 @@ module Trackable tracked privacy: proc { |_controller, model| model.try(:privacy) || "public" } end - - def activities_filtered - p "--------------------- LOLOLOLOLLOLO" - @activities.where.not(key: activities_filter) - end - - def activities_filter - [ 'complaint.update', 'complaint.destroy', - 'complaint_reason.create', 'complaint_reason.update', 'complaint_reason.destroy', - 'institution.create', 'institution.update', 'institution.destroy', - 'review.update', 'review.destroy', - 'rate.create', 'rate.update', 'rate.destroy', - 'follow.create', 'follow.update', 'follow.destroy', - 'share.create', 'share.update', 'share.destroy', - 'view.create', 'view.update', 'view.destroy', - 'tagging.create', 'tagging.update', 'tagging.destroy', - 'bookmark.create', 'bookmark.update', 'bookmark.destroy', - 'download.update', 'download.destroy', - 'like.update' - ] - end end diff --git a/app/models/user.rb b/app/models/user.rb index b71382e635243ec2852131d3d88a54b7dce645a1..03aa1154bc8e6c52b4a74cf90185941954364e28 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -41,6 +41,7 @@ class User < ApplicationRecord include Complainable include Publisher include PublicActivity::Common + include ActivitiesFilterService after_create -> { new_activity("create") } after_update -> { new_activity("update") } @@ -177,29 +178,6 @@ class User < ApplicationRecord # ~~~~ end followable actions ~~~~ # - def activities_filtered - p "--------------------- LOLOLOLOLLOLO" - self.activities.where.not(key: activities_filter) - end - - private - - def activities_filter - [ 'complaint.update', 'complaint.destroy', - 'complaint_reason.create', 'complaint_reason.update', 'complaint_reason.destroy', - 'institution.create', 'institution.update', 'institution.destroy', - 'review.update', 'review.destroy', - 'rate.create', 'rate.update', 'rate.destroy', - 'follow.create', 'follow.update', 'follow.destroy', - 'share.create', 'share.update', 'share.destroy', - 'view.create', 'view.update', 'view.destroy', - 'tagging.create', 'tagging.update', 'tagging.destroy', - 'bookmark.create', 'bookmark.update', 'bookmark.destroy', - 'download.update', 'download.destroy', - 'like.update' - ] - end - def default_role roles << Role.teacher end diff --git a/app/policies/activity_policy.rb b/app/policies/activity_policy.rb index 77abe14d5b3a21a0bba4f71f244b3a3b9dcfd4d9..ee15995f6a871c2fc9c314388af3c9f5fd6fa74d 100644 --- a/app/policies/activity_policy.rb +++ b/app/policies/activity_policy.rb @@ -1,5 +1,6 @@ class ActivityPolicy < ApplicationPolicy class Scope < Scope + include ActivitiesFilterService attr_reader :user, :scope def initialize(user, scope) @@ -8,24 +9,9 @@ class ActivityPolicy < ApplicationPolicy end def resolve - scope.includes(:owner,:recipient).where("privacy = 'public'").where.not(key: except).order('created_at DESC').all + scope.includes(:owner,:recipient).where("privacy = 'public'").where.not(key: activities_filter).order('created_at DESC').all end - def except - [ 'complaint.update', 'complaint.destroy', - 'complaint_reason.create', 'complaint_reason.update', 'complaint_reason.destroy', - 'institution.create', 'institution.update', 'institution.destroy', - 'review.update', 'review.destroy', - 'rate.create', 'rate.update', 'rate.destroy', - 'follow.create', 'follow.update', 'follow.destroy', - 'share.create', 'share.update', 'share.destroy', - 'view.create', 'view.update', 'view.destroy', - 'tagging.create', 'tagging.update', 'tagging.destroy', - 'bookmark.create', 'bookmark.update', 'bookmark.destroy', - 'download.update', 'download.destroy', - 'like.update' - ] - end end def index? diff --git a/app/services/activities_filter_service.rb b/app/services/activities_filter_service.rb new file mode 100644 index 0000000000000000000000000000000000000000..c4e763ff12865bbcd4879a2501dbbb22c75920b0 --- /dev/null +++ b/app/services/activities_filter_service.rb @@ -0,0 +1,22 @@ +module ActivitiesFilterService + + def activities_filtered + self.activities.where.not(key: activities_filter) + end + + def activities_filter + [ 'complaint.update', 'complaint.destroy', + 'complaint_reason.create', 'complaint_reason.update', 'complaint_reason.destroy', + 'institution.create', 'institution.update', 'institution.destroy', + 'review.update', 'review.destroy', + 'rate.create', 'rate.update', 'rate.destroy', + 'follow.create', 'follow.update', 'follow.destroy', + 'share.create', 'share.update', 'share.destroy', + 'view.create', 'view.update', 'view.destroy', + 'tagging.create', 'tagging.update', 'tagging.destroy', + 'bookmark.create', 'bookmark.update', 'bookmark.destroy', + 'download.update', 'download.destroy', + 'like.update' + ] + end +end