From 7c694139ec14a750e770a53bbf8463166a3cc9e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 30 Nov 2015 19:08:35 +0100 Subject: [PATCH] trust staged accounts when validating posts --- lib/validators/post_validator.rb | 6 ++-- .../validators/post_validator_spec.rb | 32 +++++++++++++++---- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/lib/validators/post_validator.rb b/lib/validators/post_validator.rb index 29dcb9a9e8a..797af3f1af1 100644 --- a/lib/validators/post_validator.rb +++ b/lib/validators/post_validator.rb @@ -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) diff --git a/spec/components/validators/post_validator_spec.rb b/spec/components/validators/post_validator_spec.rb index 064da5c7099..97f2d92640f 100644 --- a/spec/components/validators/post_validator_spec.rb +++ b/spec/components/validators/post_validator_spec.rb @@ -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