FIX: don't let admins skip post validations, unless it's faq, tos, or privacy
This commit is contained in:
parent
46a88e0c70
commit
443caaa8f7
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
Loading…
Reference in New Issue