Prevent commenting on nonexistent posts (#2704).
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user