Prevent commenting on nonexistent posts (#2704).

This commit is contained in:
evazion
2016-10-06 09:12:23 +00:00
parent 8c8f4a6a8f
commit cb1e1d3a94
3 changed files with 17 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
class Comment < ActiveRecord::Base
include Mentionable
validate :validate_post_exists, :on => :create
validate :validate_creator_is_not_limited, :on => :create
validates_format_of :body, :with => /\S/, :message => 'has no content'
belongs_to :post
@@ -148,6 +149,10 @@ class Comment < ActiveRecord::Base
User.id_to_name(updater_id)
end
def validate_post_exists
errors.add(:post, "must exist") unless Post.exists?(post_id)
end
def validate_creator_is_not_limited
if creator.is_comment_limited? && !do_not_bump_post?
errors.add(:base, "You can only post #{Danbooru.config.member_comment_limit} comments per hour")