diff --git a/app/assets/javascripts/discourse/models/composer.js b/app/assets/javascripts/discourse/models/composer.js index cc0b90119b7..163e26aac32 100644 --- a/app/assets/javascripts/discourse/models/composer.js +++ b/app/assets/javascripts/discourse/models/composer.js @@ -135,6 +135,7 @@ Discourse.Composer = Discourse.Model.extend({ @property titleLengthValid **/ titleLengthValid: function() { + if (Discourse.User.currentProp('admin') && 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'), diff --git a/lib/validators/post_validator.rb b/lib/validators/post_validator.rb index 2baf7992d84..81f9f264bf1 100644 --- a/lib/validators/post_validator.rb +++ b/lib/validators/post_validator.rb @@ -3,14 +3,16 @@ module Validators; end class Validators::PostValidator < ActiveModel::Validator def validate(record) presence(record) - stripped_length(record) - raw_quality(record) - max_posts_validator(record) - max_mention_validator(record) - max_images_validator(record) - max_attachments_validator(record) - max_links_validator(record) - unique_post_validator(record) + unless record.acting_user.try(:admin?) + stripped_length(record) + raw_quality(record) + max_posts_validator(record) + max_mention_validator(record) + max_images_validator(record) + max_attachments_validator(record) + max_links_validator(record) + unique_post_validator(record) + end end def presence(post) diff --git a/spec/components/validators/post_validator_spec.rb b/spec/components/validators/post_validator_spec.rb index 28484400f9f..57e06555ddb 100644 --- a/spec/components/validators/post_validator_spec.rb +++ b/spec/components/validators/post_validator_spec.rb @@ -86,4 +86,22 @@ describe Validators::PostValidator do end end + context "acting_user is an admin" do + before do + post.acting_user = Fabricate(:admin) + 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) + end + end + end diff --git a/test/javascripts/models/composer_test.js b/test/javascripts/models/composer_test.js index f9b219cff79..f9bb57baece 100644 --- a/test/javascripts/models/composer_test.js +++ b/test/javascripts/models/composer_test.js @@ -1,4 +1,12 @@ -module("Discourse.Composer"); +module("Discourse.Composer", { + setup: function() { + sinon.stub(Discourse.User, 'currentProp').withArgs('admin').returns(false); + }, + + teardown: function() { + Discourse.User.currentProp.restore(); + } +}); test('replyLength', function() { var replyLength = function(val, expectedLength) { @@ -231,3 +239,32 @@ test('open with a quote', function() { equal(new_composer().get('originalText'), quote, "originalText is the quote" ); equal(new_composer().get('replyDirty'), false, "replyDirty is initally false with a quote" ); }); + + +module("Discourse.Composer as admin", { + setup: function() { + sinon.stub(Discourse.User, 'currentProp').withArgs('admin').returns(true); + }, + + teardown: function() { + 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; + var composer = Discourse.Composer.create(); + + composer.set('title', 'asdf'); + ok(composer.get('titleLengthValid'), "admins can use short titles"); + + composer.set('title', 'this is a long title'); + ok(composer.get('titleLengthValid'), "admins can use long titles"); + + composer.set('title', 'just right'); + ok(composer.get('titleLengthValid'), "in the range is okay"); + + composer.set('title', ''); + ok(!composer.get('titleLengthValid'), "admins must set title to at least 1 character"); +}); \ No newline at end of file