From 980c2fa30197eca1a609342a75eb66b7068269d1 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sat, 1 May 2010 17:03:18 +0100 Subject: [PATCH] Suspend users if their spam score gets too high Use an observer to watch all diary and user updates and, if the user is not confirmed, chek their spam score and suspend then if it has got too high. --- app/models/spam_observer.rb | 15 +++++++++++++++ config/application.yml | 2 ++ config/environment.rb | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 app/models/spam_observer.rb diff --git a/app/models/spam_observer.rb b/app/models/spam_observer.rb new file mode 100644 index 000000000..21561f671 --- /dev/null +++ b/app/models/spam_observer.rb @@ -0,0 +1,15 @@ +class SpamObserver < ActiveRecord::Observer + observe User, DiaryEntry, DiaryComment + + def after_save(record) + case + when record.is_a?(User): user = record + when record.is_a?(DiaryEntry): user = record.user + when record.is_a?(DiaryComment): user = record.user + end + + if user.status == "active" and user.spam_score > APP_CONFIG['spam_threshold'] + user.update_attributes(:status => "suspended") + end + end +end diff --git a/config/application.yml b/config/application.yml index 363cc6398..c0622df75 100644 --- a/config/application.yml +++ b/config/application.yml @@ -22,6 +22,8 @@ standard_settings: &standard_settings # Quova authentication details #quova_username: "" #quova_password: "" + # Spam threshold + spam_theshold: 50 development: <<: *standard_settings diff --git a/config/environment.rb b/config/environment.rb index 018e97451..d8f9b2fc8 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -100,7 +100,7 @@ Rails::Initializer.run do |config| config.active_record.schema_format = :sql # Activate observers that should always be running - # config.active_record.observers = :cacher, :garbage_collector + config.active_record.observers = :spam_observer # Make Active Record use UTC-base instead of local time config.active_record.default_timezone = :utc -- 2.43.2