2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-07 12:02:53 +08:00

PostEnqueuer object to handle validation of enqueued posts

This commit is contained in:
Robin Ward 2015-03-26 16:57:50 -04:00
parent 8ba6a45cd7
commit a5ee45ccbe
14 changed files with 348 additions and 165 deletions

View file

@ -1,6 +1,7 @@
require_dependency 'validators/stripped_length_validator'
module Validators; end
class Validators::PostValidator < ActiveModel::Validator
def validate(record)
presence(record)
unless Discourse.static_doc_topic_ids.include?(record.topic_id) && record.acting_user.try(:admin?)
@ -16,9 +17,12 @@ class Validators::PostValidator < ActiveModel::Validator
end
def presence(post)
[:raw,:topic_id].each do |attr_name|
post.errors.add(attr_name, :blank, options) if post.send(attr_name).blank?
post.errors.add(:raw, :blank, options) if post.raw.blank?
unless options[:skip_topic]
post.errors.add(:topic_id, :blank, options) if post.topic_id.blank?
end
if post.new_record? and post.user_id.nil?
post.errors.add(:user_id, :blank, options)
end