FIX: admins bypass some post validations. This allows them to edit legal docs even if those docs are longer than max post length, for example.

This commit is contained in:
Neil Lalonde
2014-07-28 16:40:06 -04:00
parent 81ff121fe8
commit e1be478ef4
4 changed files with 67 additions and 9 deletions

View File

@ -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");
});