From: Tom Hughes Date: Sat, 1 May 2010 16:03:18 +0000 (+0100) Subject: Suspend users if their spam score gets too high X-Git-Tag: live~6421^2~17 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/980c2fa30197eca1a609342a75eb66b7068269d1?hp=5a54630b572d222b0abea05f3e19e1b1951f0aee 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. --- 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