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..a8da93f4f48c87701517dfcfef7be35c2164abd5 100644 --- a/app/models/concerns/trackable.rb +++ b/app/models/concerns/trackable.rb @@ -1,10 +1,12 @@ 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) } tracked recipient: proc { |_controller, model| model.try(:recipient) || model } tracked privacy: proc { |_controller, model| model.try(:privacy) || "public" } + end end diff --git a/app/models/user.rb b/app/models/user.rb index 471b39b82e5eeaba1fac6aa768fa90dfa3bf794b..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,8 +178,6 @@ class User < ApplicationRecord # ~~~~ end followable actions ~~~~ # - private - def default_role roles << Role.teacher end diff --git a/app/policies/activity_policy.rb b/app/policies/activity_policy.rb index cf550a904aefffe22da19d376b9afa393f382511..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,8 +9,9 @@ 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: activities_filter).order('created_at DESC').all 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