]> git.openstreetmap.org Git - rails.git/blob - app/models/spam_observer.rb
Turn on mass assignment protection
[rails.git] / app / models / spam_observer.rb
1 class SpamObserver < ActiveRecord::Observer
2   observe User, DiaryEntry, DiaryComment
3
4   def after_save(record)
5     case
6     when record.is_a?(User) then user = record
7     when record.is_a?(DiaryEntry) then user = record.user
8     when record.is_a?(DiaryComment) then user = record.user
9     end
10
11     if user.status == "active" and user.spam_score > SPAM_THRESHOLD
12       user.update_attributes(:status => "suspended")
13     end
14   end
15 end