mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 07:11:34 +08:00
trust staged accounts when validating posts
This commit is contained in:
@ -17,8 +17,8 @@ class Validators::PostValidator < ActiveModel::Validator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def presence(post)
|
def presence(post)
|
||||||
|
|
||||||
post.errors.add(:raw, :blank, options) if post.raw.blank?
|
post.errors.add(:raw, :blank, options) if post.raw.blank?
|
||||||
|
|
||||||
unless options[:skip_topic]
|
unless options[:skip_topic]
|
||||||
post.errors.add(:topic_id, :blank, options) if post.topic_id.blank?
|
post.errors.add(:topic_id, :blank, options) if post.topic_id.blank?
|
||||||
end
|
end
|
||||||
@ -32,7 +32,7 @@ class Validators::PostValidator < ActiveModel::Validator
|
|||||||
range = if post.topic.try(:private_message?)
|
range = if post.topic.try(:private_message?)
|
||||||
# private message
|
# private message
|
||||||
SiteSetting.private_message_post_length
|
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
|
# creating/editing first post
|
||||||
SiteSetting.first_post_length
|
SiteSetting.first_post_length
|
||||||
else
|
else
|
||||||
@ -95,7 +95,7 @@ class Validators::PostValidator < ActiveModel::Validator
|
|||||||
private
|
private
|
||||||
|
|
||||||
def acting_user_is_trusted?(post)
|
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
|
end
|
||||||
|
|
||||||
def add_error_if_count_exceeded(post, not_allowed_translation_key, limit_translation_key, current_count, max_count)
|
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'
|
require_dependency 'validators/post_validator'
|
||||||
|
|
||||||
describe Validators::PostValidator do
|
describe Validators::PostValidator do
|
||||||
let :post do
|
let(:post) { build(:post) }
|
||||||
build(:post)
|
let(:validator) { Validators::PostValidator.new({}) }
|
||||||
end
|
|
||||||
|
|
||||||
let :validator do
|
|
||||||
Validators::PostValidator.new({})
|
|
||||||
end
|
|
||||||
|
|
||||||
context "stripped_length" do
|
context "stripped_length" do
|
||||||
it "adds an error for short raw" do
|
it "adds an error for short raw" do
|
||||||
@ -107,4 +102,27 @@ describe Validators::PostValidator do
|
|||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
Reference in New Issue
Block a user