diff --git a/app/assets/javascripts/discourse/models/composer.js b/app/assets/javascripts/discourse/models/composer.js index 163e26aac32..0882b212424 100644 --- a/app/assets/javascripts/discourse/models/composer.js +++ b/app/assets/javascripts/discourse/models/composer.js @@ -135,10 +135,10 @@ Discourse.Composer = Discourse.Model.extend({ @property titleLengthValid **/ titleLengthValid: function() { - if (Discourse.User.currentProp('admin') && this.get('titleLength') > 0) return true; + if (Discourse.User.currentProp('admin') && this.get('post.static_doc') && this.get('titleLength') > 0) return true; if (this.get('titleLength') < this.get('minimumTitleLength')) return false; return (this.get('titleLength') <= Discourse.SiteSettings.max_topic_title_length); - }.property('minimumTitleLength', 'titleLength'), + }.property('minimumTitleLength', 'titleLength', 'post.static_doc'), // The text for the save button saveText: function() { diff --git a/app/serializers/post_serializer.rb b/app/serializers/post_serializer.rb index bff9c3fa650..08001b7c1ed 100644 --- a/app/serializers/post_serializer.rb +++ b/app/serializers/post_serializer.rb @@ -49,7 +49,8 @@ class PostSerializer < BasicPostSerializer :edit_reason, :can_view_edit_history, :wiki, - :user_custom_fields + :user_custom_fields, + :static_doc def moderator? !!(object.user && object.user.moderator?) @@ -231,6 +232,14 @@ class PostSerializer < BasicPostSerializer custom_fields && custom_fields[object.user_id] end + def static_doc + true + end + + def include_static_doc? + object.post_number == 1 && Discourse.static_doc_topic_ids.include?(object.topic_id) + end + private def post_actions diff --git a/lib/validators/post_validator.rb b/lib/validators/post_validator.rb index 81f9f264bf1..da32daee89c 100644 --- a/lib/validators/post_validator.rb +++ b/lib/validators/post_validator.rb @@ -3,7 +3,7 @@ module Validators; end class Validators::PostValidator < ActiveModel::Validator def validate(record) presence(record) - unless record.acting_user.try(:admin?) + unless Discourse.static_doc_topic_ids.include?(record.topic_id) && record.acting_user.try(:admin?) stripped_length(record) raw_quality(record) max_posts_validator(record) diff --git a/spec/components/validators/post_validator_spec.rb b/spec/components/validators/post_validator_spec.rb index 57e06555ddb..4ecf1ba02df 100644 --- a/spec/components/validators/post_validator_spec.rb +++ b/spec/components/validators/post_validator_spec.rb @@ -86,21 +86,24 @@ describe Validators::PostValidator do end end - context "acting_user is an admin" do + context "post is for a static page and acting_user is an admin" do before do - post.acting_user = Fabricate(:admin) + @tos_post = build(:post) + @tos_post.acting_user = Fabricate(:admin) + SiteSetting.stubs(:tos_topic_id).returns(@tos_post.topic_id) end it "skips most validations" do - validator.expects(:stripped_length).never - validator.expects(:raw_quality).never - validator.expects(:max_posts_validator).never - validator.expects(:max_mention_validator).never - validator.expects(:max_images_validator).never - validator.expects(:max_attachments_validator).never - validator.expects(:max_links_validator).never - validator.expects(:unique_post_validator).never - validator.validate(post) + v = Validators::PostValidator.new({}) + v.expects(:stripped_length).never + v.expects(:raw_quality).never + v.expects(:max_posts_validator).never + v.expects(:max_mention_validator).never + v.expects(:max_images_validator).never + v.expects(:max_attachments_validator).never + v.expects(:max_links_validator).never + v.expects(:unique_post_validator).never + v.validate(@tos_post) end end diff --git a/test/javascripts/models/composer_test.js b/test/javascripts/models/composer_test.js index 7d271ef1b0b..cd2e431ce24 100644 --- a/test/javascripts/models/composer_test.js +++ b/test/javascripts/models/composer_test.js @@ -243,19 +243,24 @@ test('open with a quote', function() { module("Discourse.Composer as admin", { setup: function() { + Discourse.SiteSettings.min_topic_title_length = 5; + Discourse.SiteSettings.max_topic_title_length = 10; sandbox.stub(Discourse.User, 'currentProp').withArgs('admin').returns(true); }, teardown: function() { + Discourse.SiteSettings.min_topic_title_length = 15; + Discourse.SiteSettings.max_topic_title_length = 255; Discourse.User.currentProp.restore(); } }); -test("Title length for regular topics as admin", function() { - Discourse.SiteSettings.min_topic_title_length = 5; - Discourse.SiteSettings.max_topic_title_length = 10; +test("Title length for static page topics as admin", function() { var composer = Discourse.Composer.create(); + var post = Discourse.Post.create({id: 123, post_number: 2, static_doc: true}); + composer.setProperties({post: post, action: Discourse.Composer.EDIT }); + composer.set('title', 'asdf'); ok(composer.get('titleLengthValid'), "admins can use short titles");