mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-17 04:01:29 -05:00
trust staged accounts when validating posts
This commit is contained in:
parent
dd28a3c63a
commit
7c694139ec
2 changed files with 28 additions and 10 deletions
|
@ -17,8 +17,8 @@ class Validators::PostValidator < ActiveModel::Validator
|
|||
end
|
||||
|
||||
def presence(post)
|
||||
|
||||
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
|
||||
|
@ -32,7 +32,7 @@ class Validators::PostValidator < ActiveModel::Validator
|
|||
range = if post.topic.try(:private_message?)
|
||||
# private message
|
||||
SiteSetting.private_message_post_length
|
||||
elsif ( post.is_first_post? || (post.topic.present? && post.topic.posts_count == 0) )
|
||||
elsif post.is_first_post? || (post.topic.present? && post.topic.posts_count == 0)
|
||||
# creating/editing first post
|
||||
SiteSetting.first_post_length
|
||||
else
|
||||
|
@ -95,7 +95,7 @@ class Validators::PostValidator < ActiveModel::Validator
|
|||
private
|
||||
|
||||
def acting_user_is_trusted?(post)
|
||||
post.acting_user.present? && post.acting_user.has_trust_level?(TrustLevel[1])
|
||||
post.acting_user.present? && (post.acting_user.has_trust_level?(TrustLevel[1]) || post.acting_user.staged?)
|
||||
end
|
||||
|
||||
def add_error_if_count_exceeded(post, not_allowed_translation_key, limit_translation_key, current_count, max_count)
|
||||
|
|
|
@ -2,13 +2,8 @@ require 'spec_helper'
|
|||
require_dependency 'validators/post_validator'
|
||||
|
||||
describe Validators::PostValidator do
|
||||
let :post do
|
||||
build(:post)
|
||||
end
|
||||
|
||||
let :validator do
|
||||
Validators::PostValidator.new({})
|
||||
end
|
||||
let(:post) { build(:post) }
|
||||
let(:validator) { Validators::PostValidator.new({}) }
|
||||
|
||||
context "stripped_length" do
|
||||
it "adds an error for short raw" do
|
||||
|
@ -107,4 +102,27 @@ describe Validators::PostValidator do
|
|||
end
|
||||
end
|
||||
|
||||
context "staged user" do
|
||||
|
||||
it "trust staged users" do
|
||||
post.acting_user = build(:user, staged: true)
|
||||
|
||||
post.expects(:raw_mentions).returns(Array.new(SiteSetting.newuser_max_mentions_per_post + 1))
|
||||
validator.max_mention_validator(post)
|
||||
expect(post.errors.count).to eq(0)
|
||||
|
||||
post.expects(:image_count).never
|
||||
validator.max_images_validator(post)
|
||||
expect(post.errors.count).to eq(0)
|
||||
|
||||
post.expects(:attachment_count).never
|
||||
validator.max_attachments_validator(post)
|
||||
expect(post.errors.count).to eq(0)
|
||||
|
||||
post.expects(:link_count).never
|
||||
validator.max_links_validator(post)
|
||||
expect(post.errors.count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue