]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/user.rb
Replace the spam observer with simple after_save callbacks
[rails.git] / app / models / user.rb
index 2e312119f8d13e669e7b941890b65932d18ca837..6677d3b98372585e2a8ffacc1b5b6aa722fe17ca 100644 (file)
@@ -12,6 +12,8 @@ class User < ActiveRecord::Base
   has_many :tokens, :class_name => "UserToken"
   has_many :preferences, :class_name => "UserPreference"
   has_many :changesets, :order => 'created_at DESC'
+  has_many :note_comments, :foreign_key => :author_id
+  has_many :notes, :through => :note_comments
 
   has_many :client_applications
   has_many :oauth_tokens, :class_name => "OauthToken", :order => "authorized_at desc", :include => [:client_application]
@@ -50,6 +52,7 @@ class User < ActiveRecord::Base
 
   after_initialize :set_defaults
   before_save :encrypt_password
+  after_save :spam_check
 
   has_attached_file :image,
     :default_url => "/assets/:class/:attachment/:style.png",
@@ -214,6 +217,14 @@ class User < ActiveRecord::Base
     return score.to_i
   end
 
+  ##
+  # perform a spam check on a user
+  def spam_check
+    if status == "active" and spam_score > SPAM_THRESHOLD
+      update_column(:status, "suspended")
+    end
+  end
+
   ##
   # return an oauth access token for a specified application
   def access_token(application_key)