FIX: Validate the raw content of posts before enqueuing them

This commit is contained in:
Robin Ward
2016-09-12 12:26:49 -04:00
parent 06eb256d0a
commit 2c9a47dda5
2 changed files with 49 additions and 28 deletions

View File

@ -80,6 +80,15 @@ class NewPostManager
def self.default_handler(manager)
if user_needs_approval?(manager)
validator = Validators::PostValidator.new
post = Post.new(raw: manager.args[:raw])
validator.validate(post)
if post.errors[:raw].present?
result = NewPostResult.new(:created_post, false)
result.errors[:base] = post.errors[:raw]
return result
end
# Can the user create the post in the first place?
if manager.args[:topic_id]
topic = Topic.unscoped.where(id: manager.args[:topic_id]).first