diff --git a/public/src/modules/composer.js b/public/src/modules/composer.js index 1e32892617..4bcdffff5d 100644 --- a/public/src/modules/composer.js +++ b/public/src/modules/composer.js @@ -497,6 +497,8 @@ define('composer', [ return composerAlert(post_uuid, '[[error:title-too-long, ' + config.maximumTitleLength + ']]'); } else if (checkTitle && !utils.slugify(titleEl.val()).length) { return composerAlert(post_uuid, '[[error:invalid-title]]'); + } else if (checkTitle && tags.getTags(post_uuid) && tags.getTags(post_uuid).length < parseInt(config.minimumTagsPerTopic, 10)) { + return composerAlert(post_uuid, '[[error:not-enough-tags]]'); } else if (bodyEl.val().length < parseInt(config.minimumPostLength, 10)) { return composerAlert(post_uuid, '[[error:content-too-short, ' + config.minimumPostLength + ']]'); } else if (bodyEl.val().length > parseInt(config.maximumPostLength, 10)) { diff --git a/public/src/modules/composer/tags.js b/public/src/modules/composer/tags.js index 8e516e83b8..ab2d9effb4 100644 --- a/public/src/modules/composer/tags.js +++ b/public/src/modules/composer/tags.js @@ -13,6 +13,7 @@ define('composer/tags', function() { } tagEl.tagsinput({ + minTags: config.minimumTagsPerTopic, maxTags: config.tagsPerTopic, maxChars: config.maximumTagLength, confirmKeys: [13, 44], diff --git a/src/controllers/api.js b/src/controllers/api.js index 9e024f92e9..20b0b1978f 100644 --- a/src/controllers/api.js +++ b/src/controllers/api.js @@ -55,6 +55,7 @@ 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.minimumTagsPerTopic = meta.config.minimumTagsPerTopic || 0; config.tagsPerTopic = meta.config.tagsPerTopic || 5; config.minimumTagLength = meta.config.minimumTagLength || 3; config.maximumTagLength = meta.config.maximumTagLength || 15; diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js index 7d37379807..0a2f97dd0c 100644 --- a/src/socket.io/posts.js +++ b/src/socket.io/posts.js @@ -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.title && 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)) { diff --git a/src/topics/create.js b/src/topics/create.js index af90a3a0c8..5d0ca7b34f 100644 --- a/src/topics/create.js +++ b/src/topics/create.js @@ -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,13 @@ 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 + ']]')); + } + 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 + ']]')); diff --git a/src/views/admin/settings/tags.tpl b/src/views/admin/settings/tags.tpl index b54e6295f3..65f3b22d06 100644 --- a/src/views/admin/settings/tags.tpl +++ b/src/views/admin/settings/tags.tpl @@ -10,7 +10,11 @@