]> git.openstreetmap.org Git - rails.git/blob - app/models/spam_observer.rb
Suspend users if their spam score gets too high
[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): user = record
7     when record.is_a?(DiaryEntry): user = record.user
8     when record.is_a?(DiaryComment): user = record.user
9     end
10
11     if user.status == "active" and user.spam_score > APP_CONFIG['spam_threshold']
12       user.update_attributes(:status => "suspended")
13     end
14   end
15 end