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

Created ActivitiesFilterService to maintain the code in one place

parent ccfff5e8
No related branches found
No related tags found
No related merge requests found
module Trackable module Trackable
extend ActiveSupport::Concern extend ActiveSupport::Concern
include PublicActivity::Model include PublicActivity::Model
include ActivitiesFilterService
included do included do
tracked owner: proc { |controller, model| model.try(:user) || model.try(:owner) || controller.try(:current_user) } tracked owner: proc { |controller, model| model.try(:user) || model.try(:owner) || controller.try(:current_user) }
...@@ -8,25 +9,4 @@ module Trackable ...@@ -8,25 +9,4 @@ module Trackable
tracked privacy: proc { |_controller, model| model.try(:privacy) || "public" } tracked privacy: proc { |_controller, model| model.try(:privacy) || "public" }
end 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 end
...@@ -41,6 +41,7 @@ class User < ApplicationRecord ...@@ -41,6 +41,7 @@ class User < ApplicationRecord
include Complainable include Complainable
include Publisher include Publisher
include PublicActivity::Common include PublicActivity::Common
include ActivitiesFilterService
after_create -> { new_activity("create") } after_create -> { new_activity("create") }
after_update -> { new_activity("update") } after_update -> { new_activity("update") }
...@@ -177,29 +178,6 @@ class User < ApplicationRecord ...@@ -177,29 +178,6 @@ class User < ApplicationRecord
# ~~~~ end followable actions ~~~~ # # ~~~~ 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 def default_role
roles << Role.teacher roles << Role.teacher
end end
......
class ActivityPolicy < ApplicationPolicy class ActivityPolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
include ActivitiesFilterService
attr_reader :user, :scope attr_reader :user, :scope
def initialize(user, scope) def initialize(user, scope)
...@@ -8,24 +9,9 @@ class ActivityPolicy < ApplicationPolicy ...@@ -8,24 +9,9 @@ class ActivityPolicy < ApplicationPolicy
end end
def resolve 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 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 end
def index? def index?
......
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
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