From: Tom Hughes Date: Mon, 26 Feb 2018 22:35:06 +0000 (+0000) Subject: Exclude hidden diary entries and comments from spam scoring X-Git-Tag: live~3142 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/81241b30835fe090ebc9f511d1954a5c511c94ca?ds=sidebyside Exclude hidden diary entries and comments from spam scoring --- diff --git a/app/models/diary_comment.rb b/app/models/diary_comment.rb index 8a99c7b2c..63eae3f21 100644 --- a/app/models/diary_comment.rb +++ b/app/models/diary_comment.rb @@ -26,6 +26,8 @@ class DiaryComment < ActiveRecord::Base belongs_to :user belongs_to :diary_entry + scope :visible, -> { where(:visible => true) } + validates :body, :presence => true validates :diary_entry, :user, :associated => true diff --git a/app/models/user.rb b/app/models/user.rb index 9eeb98290..1cd8c6d89 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -261,8 +261,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