From 13e12ba3a5b84f285884159166374622a4f470fb Mon Sep 17 00:00:00 2001 From: yariplus Date: Tue, 23 Jun 2015 10:23:56 -0400 Subject: [PATCH 1/4] Add minimum tags per topic setting. --- public/src/modules/composer.js | 2 ++ public/src/modules/composer/tags.js | 1 + src/controllers/api.js | 1 + src/socket.io/posts.js | 2 ++ src/topics/create.js | 10 ++++++++++ src/views/admin/settings/tags.tpl | 6 +++++- 6 files changed, 21 insertions(+), 1 deletion(-) 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 @@
- + + +
+
+
From e112190bee3c91e501335df1d2c1eccaa1127be1 Mon Sep 17 00:00:00 2001 From: yariplus Date: Tue, 23 Jun 2015 13:25:26 -0400 Subject: [PATCH 2/4] Fix maximumTagsPerTopic --- public/src/modules/composer.js | 2 -- public/src/modules/composer/tags.js | 1 - src/controllers/api.js | 2 +- src/topics/create.js | 2 ++ src/topics/tags.js | 2 +- src/views/admin/settings/tags.tpl | 4 ++-- 6 files changed, 6 insertions(+), 7 deletions(-) diff --git a/public/src/modules/composer.js b/public/src/modules/composer.js index 4bcdffff5d..1e32892617 100644 --- a/public/src/modules/composer.js +++ b/public/src/modules/composer.js @@ -497,8 +497,6 @@ 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 ab2d9effb4..8e516e83b8 100644 --- a/public/src/modules/composer/tags.js +++ b/public/src/modules/composer/tags.js @@ -13,7 +13,6 @@ 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 20b0b1978f..5518addd45 100644 --- a/src/controllers/api.js +++ b/src/controllers/api.js @@ -56,7 +56,7 @@ apiController.getConfig = function(req, res, next) { 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.maximumTagsPerTopic = meta.config.maximumTagsPerTopic || 5; config.minimumTagLength = meta.config.minimumTagLength || 3; config.maximumTagLength = meta.config.maximumTagLength || 15; config.topicsPerPage = meta.config.topicsPerPage || 20; diff --git a/src/topics/create.js b/src/topics/create.js index 5d0ca7b34f..bfec57e491 100644 --- a/src/topics/create.js +++ b/src/topics/create.js @@ -296,6 +296,8 @@ module.exports = function(Topics) { 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(); } diff --git a/src/topics/tags.js b/src/topics/tags.js index f19738b315..dfbdf5ab03 100644 --- a/src/topics/tags.js +++ b/src/topics/tags.js @@ -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); diff --git a/src/views/admin/settings/tags.tpl b/src/views/admin/settings/tags.tpl index 65f3b22d06..857080ddcf 100644 --- a/src/views/admin/settings/tags.tpl +++ b/src/views/admin/settings/tags.tpl @@ -14,8 +14,8 @@
- - + +
From 546efbbd1ba6b8e7e761990e7e17bf6788a4d540 Mon Sep 17 00:00:00 2001 From: yariplus Date: Sat, 18 Jul 2015 02:21:34 -0400 Subject: [PATCH 3/4] Add translations for min and max tag errors. --- public/language/en_GB/error.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/public/language/en_GB/error.json b/public/language/en_GB/error.json index dc640fcecf..40955e7f3b 100644 --- a/public/language/en_GB/error.json +++ b/public/language/en_GB/error.json @@ -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", @@ -108,4 +111,4 @@ "parse-error": "Something went wrong while parsing server response", "wrong-login-type-email": "Please use your email to login", "wrong-login-type-username": "Please use your username to login" -} \ No newline at end of file +} From bd863e1ccb3137112be4e6c193fe39450c66e56a Mon Sep 17 00:00:00 2001 From: yariplus Date: Sat, 18 Jul 2015 02:24:33 -0400 Subject: [PATCH 4/4] Fix derp. --- public/language/en_GB/error.json | 4 ++-- src/socket.io/posts.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/public/language/en_GB/error.json b/public/language/en_GB/error.json index 40955e7f3b..6c492824a9 100644 --- a/public/language/en_GB/error.json +++ b/public/language/en_GB/error.json @@ -59,7 +59,7 @@ "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)", + "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", @@ -111,4 +111,4 @@ "parse-error": "Something went wrong while parsing server response", "wrong-login-type-email": "Please use your email to login", "wrong-login-type-username": "Please use your username to login" -} +} \ No newline at end of file diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js index 0a2f97dd0c..9c3736a9af 100644 --- a/src/socket.io/posts.js +++ b/src/socket.io/posts.js @@ -284,7 +284,7 @@ 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)) { + } 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 + ']]'));