Fix #4125: Detect forum and comment spam.
This commit is contained in:
@@ -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?
|
||||
|
||||
Reference in New Issue
Block a user