]> git.openstreetmap.org Git - rails.git/commitdiff
Suspend users if their spam score gets too high
authorTom Hughes <tom@compton.nu>
Sat, 1 May 2010 16:03:18 +0000 (17:03 +0100)
committerTom Hughes <tom@compton.nu>
Thu, 6 May 2010 16:18:34 +0000 (17:18 +0100)
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 [new file with mode: 0644]
config/application.yml
config/environment.rb

diff --git a/app/models/spam_observer.rb b/app/models/spam_observer.rb
new file mode 100644 (file)
index 0000000..21561f6
--- /dev/null
@@ -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
index 363cc6398286467dcb907def552bc04d20f4d86d..c0622df75f1551fb0ddad837424f1e92a652555b 100644 (file)
@@ -22,6 +22,8 @@ standard_settings: &standard_settings
   # Quova authentication details
   #quova_username: ""
   #quova_password: ""
+  # Spam threshold
+  spam_theshold: 50
  
 development:
   <<: *standard_settings
index 018e97451501ceacab36f74ac7e5148e2f6cb449..d8f9b2fc85ca0503146b1c55ff390c86bf1003cc 100644 (file)
@@ -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