Fix #4125: Detect forum and comment spam.

This commit is contained in:
evazion
2019-08-23 22:07:04 -05:00
parent 06ff249530
commit a9b0362fc7
5 changed files with 107 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ class Comment < ApplicationRecord
include Mentionable
validate :validate_creator_is_not_limited, :on => :create
validate :validate_comment_is_not_spam, on: :create
validates_presence_of :body, :message => "has no content"
belongs_to :post
belongs_to_creator
@@ -124,6 +125,10 @@ class Comment < ApplicationRecord
end
end
def validate_comment_is_not_spam
errors[:base] << "Failed to create comment" if SpamDetector.new(self).spam?
end
def update_last_commented_at_on_create
Post.where(:id => post_id).update_all(:last_commented_at => created_at)
if Comment.where("post_id = ?", post_id).count <= Danbooru.config.comment_threshold && !do_not_bump_post?

View File

@@ -15,6 +15,7 @@ class ForumPost < ApplicationRecord
after_destroy :update_topic_updated_at_on_destroy
validates_presence_of :body
validate :validate_topic_is_unlocked
validate :validate_post_is_not_spam, on: :create
validate :topic_is_not_restricted, :on => :create
before_destroy :validate_topic_is_unlocked
after_save :delete_topic_if_original_post
@@ -133,6 +134,10 @@ class ForumPost < ApplicationRecord
votes.where(creator_id: user.id, score: score).exists?
end
def validate_post_is_not_spam
errors[:base] << "Failed to create forum post" if SpamDetector.new(self, user_ip: CurrentUser.ip_addr).spam?
end
def validate_topic_is_unlocked
return if CurrentUser.is_moderator?
return if topic.nil?