X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/b2a8df0bd73f1031dcf4684e084897a28b117345..5e7abf67fbda21735d12660a537a96e39bb87107:/app/models/user.rb diff --git a/app/models/user.rb b/app/models/user.rb index 7a8414ec0..c063b7c34 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -73,6 +73,11 @@ class User < ActiveRecord::Base has_many :roles, :class_name => "UserRole" + has_many :issues, :class_name => "Issue", :foreign_key => :reported_user_id + has_many :issue_comments + + has_many :reports + scope :visible, -> { where(:status => %w[pending active confirmed]) } scope :active, -> { where(:status => %w[active confirmed]) } scope :identifiable, -> { where(:data_public => true) } @@ -261,8 +266,8 @@ class User < ActiveRecord::Base def spam_score changeset_score = changesets.size * 50 trace_score = traces.size * 50 - diary_entry_score = diary_entries.inject(0) { |acc, elem| acc + elem.body.spam_score } - diary_comment_score = diary_comments.inject(0) { |acc, elem| acc + elem.body.spam_score } + diary_entry_score = diary_entries.visible.inject(0) { |acc, elem| acc + elem.body.spam_score } + diary_comment_score = diary_comments.visible.inject(0) { |acc, elem| acc + elem.body.spam_score } score = description.spam_score / 4.0 score += diary_entries.where("created_at > ?", 1.day.ago).count * 10 @@ -277,9 +282,7 @@ class User < ActiveRecord::Base ## # perform a spam check on a user def spam_check - if status == "active" && spam_score > SPAM_THRESHOLD - update(:status => "suspended") - end + update(:status => "suspended") if status == "active" && spam_score > SPAM_THRESHOLD end ##