From 5ae70beaeb1584845bc7dff54ddca5788dfeaa7f Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 27 Mar 2024 14:15:53 -0700 Subject: [PATCH] some anti-spam measures --- app/controllers/users_controller.rb | 1 + app/models/stream/share_comment.rb | 2 +- lib/tasks/daily.rake | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 996d6f37d..3d7ec93d3 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -98,6 +98,7 @@ def set_user @user = User.find_by(user_params) return redirect_to(root_path, notice: 'That user does not exist.') if @user.nil? return redirect_to(root_path, notice: 'That user has chosen to hide their profile.') if @user.private_profile? + return redirect_to(root_path, notice: 'That user has had their profile hidden.') if @user.thredded_user_detail.moderation_state == 'blocked' @accent_color = @user.favorite_page_type_color @accent_icon = @user.favorite_page_type_icon diff --git a/app/models/stream/share_comment.rb b/app/models/stream/share_comment.rb index 8f790e192..f379e705e 100644 --- a/app/models/stream/share_comment.rb +++ b/app/models/stream/share_comment.rb @@ -1,7 +1,7 @@ class ShareComment < ApplicationRecord acts_as_paranoid - belongs_to :user, optional: true + belongs_to :user, optional: true # now that we're auto-deleting this data, we can probably remove this constraint without db errors belongs_to :content_page_share def from_op?(share) diff --git a/lib/tasks/daily.rake b/lib/tasks/daily.rake index d43194b76..a8f5fbd6d 100644 --- a/lib/tasks/daily.rake +++ b/lib/tasks/daily.rake @@ -3,6 +3,12 @@ namespace :daily do task clear_thredded_spam: :environment do Thredded::Post.where(moderation_state: "blocked").destroy_all Thredded::Topic.where(moderation_state: "blocked").destroy_all + + blocked_user_ids = Thredded::UserDetail.where(moderation_state: "blocked").pluck(:user_id) + + # Destroy all stream comments from blocked users and nil users + ShareComment.where(user_id: blocked_user_ids).destroy_all + ShareComment.where(user_id: nil).destroy_all end desc "Run end-of-day-analytics reporter"