Merge pull request #3256 from yariplus/mintags

Add minimum tags per topic setting.
v1.18.x
Barış Soner Uşaklı 10 years ago
commit 6bd131815f

@ -58,6 +58,9 @@
"too-many-posts-newbie": "As a new user, you can only post once every %1 second(s) until you have earned %2 reputation - please wait before posting again",
"tag-too-short": "Please enter a longer tag. Tags should contain at least %1 character(s)",
"tag-too-long": "Please enter a shorter tag. Tags can't be longer than %1 character(s)",
"not-enough-tags": "Not enough tags. Topics must have at least %1 tag(s)",
"too-many-tags": "Too many tags. Topics can't have more than %1 tag(s)",
"file-too-big": "Maximum allowed file size is %1 kB - please upload a smaller file",
"cant-vote-self-post": "You cannot vote for your own post",

@ -55,7 +55,8 @@ apiController.getConfig = function(req, res, next) {
config.disableChat = parseInt(meta.config.disableChat, 10) === 1;
config.maxReconnectionAttempts = meta.config.maxReconnectionAttempts || 5;
config.reconnectionDelay = meta.config.reconnectionDelay || 1500;
config.tagsPerTopic = meta.config.tagsPerTopic || 5;
config.minimumTagsPerTopic = meta.config.minimumTagsPerTopic || 0;
config.maximumTagsPerTopic = meta.config.maximumTagsPerTopic || 5;
config.minimumTagLength = meta.config.minimumTagLength || 3;
config.maximumTagLength = meta.config.maximumTagLength || 15;
config.topicsPerPage = meta.config.topicsPerPage || 20;

@ -284,6 +284,8 @@ SocketPosts.edit = function(socket, data, callback) {
return callback(new Error('[[error:title-too-short, ' + meta.config.minimumTitleLength + ']]'));
} else if (data.title && data.title.length > parseInt(meta.config.maximumTitleLength, 10)) {
return callback(new Error('[[error:title-too-long, ' + meta.config.maximumTitleLength + ']]'));
} else if (data.tags && data.tags.length < parseInt(meta.config.minimumTagsPerTopic, 10)) {
return callback(new Error('[[error:not-enough-tags, ' + meta.config.minimumTagsPerTopic + ']]'));
} else if (!data.content || data.content.length < parseInt(meta.config.minimumPostLength, 10)) {
return callback(new Error('[[error:content-too-short, ' + meta.config.minimumPostLength + ']]'));
} else if (data.content.length > parseInt(meta.config.maximumPostLength, 10)) {

@ -96,6 +96,9 @@ module.exports = function(Topics) {
function(next) {
checkTitleLength(title, next);
},
function(next) {
checkTagsLength(data.tags, next);
},
function(next) {
checkContentLength(data.content, next);
},
@ -290,6 +293,15 @@ module.exports = function(Topics) {
callback();
}
function checkTagsLength(tags, callback) {
if (!tags || tags.length < parseInt(meta.config.minimumTagsPerTopic, 10)) {
return callback(new Error('[[error:not-enough-tags, ' + meta.config.minimumTagsPerTopic + ']]'));
} else if (tags.length > parseInt(meta.config.maximumTagsPerTopic, 10)) {
return callback(new Error('[[error:too-many-tags, ' + meta.config.maximumTagsPerTopic + ']]'));
}
callback();
}
function checkContentLength(content, callback) {
if (!content || content.length < parseInt(meta.config.miminumPostLength, 10)) {
return callback(new Error('[[error:content-too-short, ' + meta.config.minimumPostLength + ']]'));

@ -23,7 +23,7 @@ module.exports = function(Topics) {
return callback(err);
}
tags = data.tags.slice(0, meta.config.tagsPerTopic || 5);
tags = data.tags.slice(0, meta.config.maximumTagsPerTopic || 5);
async.each(tags, function(tag, next) {
tag = Topics.cleanUpTag(tag);

@ -10,8 +10,12 @@
</label>
</div>
<div class="form-group">
<label for="tagsPerTopics">Tags per Topic</label>
<input id="tagsPerTopics" type="text" class="form-control" value="5" data-field="tagsPerTopic">
<label for="minimumTagsPerTopics">Minimum Tags per Topic</label>
<input id="minimumTagsPerTopics" type="text" class="form-control" value="0" data-field="minimumTagsPerTopic">
</div>
<div class="form-group">
<label for="maximumTagsPerTopics">Maximum Tags per Topic</label>
<input id="maximumTagsPerTopics" type="text" class="form-control" value="5" data-field="maximumTagsPerTopic">
</div>
<div class="form-group">
<label for="minimumTagLength">Minimum Tag Length</label>

Loading…
Cancel
Save