Merge pull request #3284 from techAPJ/patch-1
FEATURE: new site setting min_first_post_length
This commit is contained in:
commit
5084e2bdf1
|
@ -40,6 +40,8 @@ const Composer = Discourse.Model.extend({
|
||||||
return this.get('creatingPrivateMessage') || this.get('topic.archetype') === 'private_message';
|
return this.get('creatingPrivateMessage') || this.get('topic.archetype') === 'private_message';
|
||||||
}.property('creatingPrivateMessage', 'topic'),
|
}.property('creatingPrivateMessage', 'topic'),
|
||||||
|
|
||||||
|
topicFirstPost: Em.computed.or('creatingTopic', 'editingFirstPost'),
|
||||||
|
|
||||||
editingPost: Em.computed.equal('action', EDIT),
|
editingPost: Em.computed.equal('action', EDIT),
|
||||||
replyingToTopic: Em.computed.equal('action', REPLY),
|
replyingToTopic: Em.computed.equal('action', REPLY),
|
||||||
|
|
||||||
|
@ -215,10 +217,13 @@ const Composer = Discourse.Model.extend({
|
||||||
minimumPostLength: function() {
|
minimumPostLength: function() {
|
||||||
if( this.get('privateMessage') ) {
|
if( this.get('privateMessage') ) {
|
||||||
return Discourse.SiteSettings.min_private_message_post_length;
|
return Discourse.SiteSettings.min_private_message_post_length;
|
||||||
|
} else if (this.get('topicFirstPost')) {
|
||||||
|
// first post (topic body)
|
||||||
|
return Discourse.SiteSettings.min_first_post_length;
|
||||||
} else {
|
} else {
|
||||||
return Discourse.SiteSettings.min_post_length;
|
return Discourse.SiteSettings.min_post_length;
|
||||||
}
|
}
|
||||||
}.property('privateMessage'),
|
}.property('privateMessage', 'topicFirstPost'),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Computes the length of the title minus non-significant whitespaces
|
Computes the length of the title minus non-significant whitespaces
|
||||||
|
|
|
@ -48,6 +48,10 @@ class SiteSetting < ActiveRecord::Base
|
||||||
min_post_length..max_post_length
|
min_post_length..max_post_length
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.first_post_length
|
||||||
|
min_first_post_length..max_post_length
|
||||||
|
end
|
||||||
|
|
||||||
def self.private_message_post_length
|
def self.private_message_post_length
|
||||||
min_private_message_post_length..max_post_length
|
min_private_message_post_length..max_post_length
|
||||||
end
|
end
|
||||||
|
|
|
@ -733,6 +733,7 @@ en:
|
||||||
default_locale: "The default language of this Discourse instance (ISO 639-1 Code)"
|
default_locale: "The default language of this Discourse instance (ISO 639-1 Code)"
|
||||||
allow_user_locale: "Allow users to choose their own language interface preference"
|
allow_user_locale: "Allow users to choose their own language interface preference"
|
||||||
min_post_length: "Minimum allowed post length in characters"
|
min_post_length: "Minimum allowed post length in characters"
|
||||||
|
min_first_post_length: "Minimum allowed first post (topic body) length in characters"
|
||||||
min_private_message_post_length: "Minimum allowed post length in characters for private messages"
|
min_private_message_post_length: "Minimum allowed post length in characters for private messages"
|
||||||
max_post_length: "Maximum allowed post length in characters"
|
max_post_length: "Maximum allowed post length in characters"
|
||||||
min_topic_title_length: "Minimum allowed topic title length in characters"
|
min_topic_title_length: "Minimum allowed topic title length in characters"
|
||||||
|
|
|
@ -310,6 +310,12 @@ posting:
|
||||||
default:
|
default:
|
||||||
test: 5
|
test: 5
|
||||||
default: 20
|
default: 20
|
||||||
|
min_first_post_length:
|
||||||
|
client: true
|
||||||
|
min: 1
|
||||||
|
default:
|
||||||
|
test: 5
|
||||||
|
default: 20
|
||||||
min_private_message_post_length:
|
min_private_message_post_length:
|
||||||
client: true
|
client: true
|
||||||
min: 1
|
min: 1
|
||||||
|
|
|
@ -25,7 +25,17 @@ class Validators::PostValidator < ActiveModel::Validator
|
||||||
end
|
end
|
||||||
|
|
||||||
def stripped_length(post)
|
def stripped_length(post)
|
||||||
range = post.topic.try(:private_message?) ? SiteSetting.private_message_post_length : SiteSetting.post_length
|
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) )
|
||||||
|
# creating/editing first post
|
||||||
|
SiteSetting.first_post_length
|
||||||
|
else
|
||||||
|
# regular post
|
||||||
|
SiteSetting.post_length
|
||||||
|
end
|
||||||
|
|
||||||
Validators::StrippedLengthValidator.validate(post, :raw, post.raw, range)
|
Validators::StrippedLengthValidator.validate(post, :raw, post.raw, range)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -99,6 +99,7 @@ class ImportScripts::Base
|
||||||
email_domains_blacklist: '',
|
email_domains_blacklist: '',
|
||||||
min_topic_title_length: 1,
|
min_topic_title_length: 1,
|
||||||
min_post_length: 1,
|
min_post_length: 1,
|
||||||
|
min_first_post_length: 1,
|
||||||
min_private_message_post_length: 1,
|
min_private_message_post_length: 1,
|
||||||
min_private_message_title_length: 1,
|
min_private_message_title_length: 1,
|
||||||
allow_duplicate_topic_titles: true,
|
allow_duplicate_topic_titles: true,
|
||||||
|
|
|
@ -35,6 +35,12 @@ describe SiteSetting do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'first_post_length' do
|
||||||
|
it 'returns a range of min/max first post length' do
|
||||||
|
expect(SiteSetting.first_post_length).to eq(SiteSetting.defaults[:min_first_post_length]..SiteSetting.defaults[:max_post_length])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'private_message_title_length' do
|
describe 'private_message_title_length' do
|
||||||
it 'returns a range of min/max pm topic title length' do
|
it 'returns a range of min/max pm topic title length' do
|
||||||
expect(SiteSetting.private_message_title_length).to eq(SiteSetting.defaults[:min_private_message_title_length]..SiteSetting.defaults[:max_topic_title_length])
|
expect(SiteSetting.private_message_title_length).to eq(SiteSetting.defaults[:min_private_message_title_length]..SiteSetting.defaults[:max_topic_title_length])
|
||||||
|
|
|
@ -22,13 +22,15 @@ test('replyLength', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('missingReplyCharacters', function() {
|
test('missingReplyCharacters', function() {
|
||||||
var missingReplyCharacters = function(val, isPM, expected, message) {
|
Discourse.SiteSettings.min_first_post_length = 40;
|
||||||
var composer = Discourse.Composer.create({ reply: val, creatingPrivateMessage: isPM });
|
var missingReplyCharacters = function(val, isPM, isFirstPost, expected, message) {
|
||||||
|
var composer = Discourse.Composer.create({ reply: val, creatingPrivateMessage: isPM, creatingTopic: isFirstPost });
|
||||||
equal(composer.get('missingReplyCharacters'), expected, message);
|
equal(composer.get('missingReplyCharacters'), expected, message);
|
||||||
};
|
};
|
||||||
|
|
||||||
missingReplyCharacters('hi', false, Discourse.SiteSettings.min_post_length - 2, 'too short public post');
|
missingReplyCharacters('hi', false, false, Discourse.SiteSettings.min_post_length - 2, 'too short public post');
|
||||||
missingReplyCharacters('hi', true, Discourse.SiteSettings.min_private_message_post_length - 2, 'too short private message');
|
missingReplyCharacters('hi', false, true, Discourse.SiteSettings.min_first_post_length - 2, 'too short first post');
|
||||||
|
missingReplyCharacters('hi', true, false, Discourse.SiteSettings.min_private_message_post_length - 2, 'too short private message');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('missingTitleCharacters', function() {
|
test('missingTitleCharacters', function() {
|
||||||
|
|
Loading…
Reference in New Issue