diff --git a/app/controllers/v1/activities_controller.rb b/app/controllers/v1/activities_controller.rb index 4d2b7cca1fd972fdc403d1b7a17d8bf017106784..e8de993b7653abc24f5f0ba1c050d3867af60236 100644 --- a/app/controllers/v1/activities_controller.rb +++ b/app/controllers/v1/activities_controller.rb @@ -18,13 +18,13 @@ class V1::ActivitiesController < ApplicationController # Only followers can see user activities def user_activities raise ::Pundit::NotAuthorizedError unless ::ActivityPolicy.new(current_user, resource_model).user_activities? - activities = paginate resource_model.activities + activities = paginate resource_model.activities_filtered render json: activities end def me authorize :activity, :index? - activities = paginate current_user.activities + activities = paginate current_user.activities_filtered render json: activities end end diff --git a/app/controllers/v1/feed_controller.rb b/app/controllers/v1/feed_controller.rb index 3a1d894494aa40c2ee300b2eecd9ffc4d1aba55a..cd1aeb110f26b4f7787d676647ac57d7cacb8f28 100644 --- a/app/controllers/v1/feed_controller.rb +++ b/app/controllers/v1/feed_controller.rb @@ -15,7 +15,7 @@ class V1::FeedController < ApplicationController def activities_followed activities = [] current_user.watching.each do |watching| - activities.push(*watching.activities.to_a) + activities.push(*watching.activities_filtered.to_a) end activities end diff --git a/app/models/concerns/trackable.rb b/app/models/concerns/trackable.rb index f3ee59309230bf71a785b12a15410acff3058363..4a6712ced336438e3f7bc7a1a752315b5ea5fd08 100644 --- a/app/models/concerns/trackable.rb +++ b/app/models/concerns/trackable.rb @@ -6,5 +6,27 @@ module Trackable tracked owner: proc { |controller, model| model.try(:user) || model.try(:owner) || controller.try(:current_user) } tracked recipient: proc { |_controller, model| model.try(:recipient) || model } 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 471b39b82e5eeaba1fac6aa768fa90dfa3bf794b..b71382e635243ec2852131d3d88a54b7dce645a1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -177,8 +177,29 @@ 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 cf550a904aefffe22da19d376b9afa393f382511..77abe14d5b3a21a0bba4f71f244b3a3b9dcfd4d9 100644 --- a/app/policies/activity_policy.rb +++ b/app/policies/activity_policy.rb @@ -8,7 +8,23 @@ class ActivityPolicy < ApplicationPolicy end def resolve - scope.includes(:owner,:recipient).where("privacy = 'public'").order('created_at DESC').all + scope.includes(:owner,:recipient).where("privacy = 'public'").where.not(key: except).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