Node.js based forum software built for the modern web
feat: added new admin option newbiePostEditDuration (#7737)
Julian Lam8a6a58ee4383
diff --git a/install/data/defaults.json b/install/data/defaults.jsonindex ab0a5f1c93..3c9221aa1a 100644--- a/install/data/defaults.json+++ b/install/data/defaults.json@@ -11,6 +11,7 @@"initialPostDelay": 10,"newbiePostDelay": 120,"postEditDuration": 0,+ "newbiePostEditDuration": 3600000,"postDeleteDuration": 0,"enablePostHistory": 1,"postCacheSize": 10485760,diff --git a/public/language/en-GB/admin/settings/post.json b/public/language/en-GB/admin/settings/post.jsonindex 528f02d835..7fc74a4d6b 100644--- a/public/language/en-GB/admin/settings/post.json+++ b/public/language/en-GB/admin/settings/post.json@@ -11,15 +11,15 @@"restrictions-new": "New User Restrictions","restrictions.post-queue": "Enable post queue","restrictions-new.post-queue": "Enable new user restrictions",- "restrictions.post-queue-help": "Enabling post queue will put the posts of new users in a queue for approval.",- "restrictions-new.post-queue-help": "Enabling new user restrictions will set restrictions on posts created by new users.",- "restrictions.seconds-between": "Seconds between posts",+ "restrictions.post-queue-help": "Enabling post queue will put the posts of new users in a queue for approval",+ "restrictions-new.post-queue-help": "Enabling new user restrictions will set restrictions on posts created by new users",+ "restrictions.seconds-between": "Number of seconds between posts","restrictions.seconds-between-new": "Seconds between posts for new users","restrictions.rep-threshold": "Reputation threshold before these restrictions are lifted",- "restrictions.seconds-defore-new": "Seconds before new user can post",- "restrictions.seconds-edit-after": "Number of seconds a post remains editable. (0 disabled)",- "restrictions.seconds-delete-after": "Number of seconds a post remains deletable. (0 disabled)",- "restrictions.replies-no-delete": "Number of replies after users are disallowed to delete their own topics. (0 disabled)",+ "restrictions.seconds-before-new": "Seconds before a new user can make their first post",+ "restrictions.seconds-edit-after": "Number of seconds a post remains editable (set to 0 to disable)",+ "restrictions.seconds-delete-after": "Number of seconds a post remains deletable (set to 0 to disable)",+ "restrictions.replies-no-delete": "Number of replies after users are disallowed to delete their own topics (set to 0 to disable)","restrictions.min-title-length": "Minimum Title Length","restrictions.max-title-length": "Maximum Title Length","restrictions.min-post-length": "Minimum Post Length",diff --git a/src/privileges/posts.js b/src/privileges/posts.jsindex 55c1e57b7a..1af55abac3 100644--- a/src/privileges/posts.js+++ b/src/privileges/posts.js@@ -155,6 +155,7 @@ module.exports = function (privileges) {owner: async.apply(posts.isOwner, pid, uid),edit: async.apply(privileges.posts.can, 'posts:edit', pid, uid),postData: async.apply(posts.getPostFields, pid, ['tid', 'timestamp', 'deleted', 'deleterUid']),+ userData: async.apply(user.getUserFields, uid, ['reputation']),}, next);},function (_results, next) {@@ -167,6 +168,10 @@ module.exports = function (privileges) {if (!results.isMod && meta.config.postEditDuration && (Date.now() - results.postData.timestamp > meta.config.postEditDuration * 1000)) {return callback(null, { flag: false, message: '[[error:post-edit-duration-expired, ' + meta.config.postEditDuration + ']]' });}+ if (!results.isMod && meta.config.newbiePostEditDuration > 0 && meta.config.newbiePostDelayThreshold > _results.userData.reputation && Date.now() - _results.postData.timestamp > meta.config.newbiePostEditDuration * 1000) {+ return callback(null, { flag: false, message: '[[error:post-edit-duration-expired, ' + meta.config.newbiePostEditDuration + ']]' });+ }+topics.isLocked(results.postData.tid, next);},function (isLocked, next) {diff --git a/src/views/admin/settings/post.tpl b/src/views/admin/settings/post.tplindex 97d8ed6499..24060b1391 100644--- a/src/views/admin/settings/post.tpl+++ b/src/views/admin/settings/post.tpl@@ -90,36 +90,44 @@<div class="col-sm-2 col-xs-12 settings-header">[[admin/settings/post:restrictions-new]]</div><div class="col-sm-10 col-xs-12"><form>+ <div class="form-group">+ <label for="newbiePostDelayThreshold">[[admin/settings/post:restrictions.rep-threshold]]</label>+ <input id="newbiePostDelayThreshold" type="text" class="form-control" value="3" data-field="newbiePostDelayThreshold">+ </div><div class="row">- <div class="col-xs-6">+ <div class="col-sm-6">+ <div class="form-group">+ <div class="checkbox">+ <label class="mdl-switch mdl-js-switch mdl-js-ripple-effect">+ <input class="mdl-switch__input" type="checkbox" data-field="postQueue">+ <span class="mdl-switch__label"><strong>[[admin/settings/post:restrictions.post-queue]]</strong></span>+ </label>+ </div>+ <p class="help-block">+ [[admin/settings/post:restrictions.post-queue-help]]+ </p>+ </div>+ </div>+ <div class="col-sm-6"><div class="form-group"><label for="newbiePostDelay">[[admin/settings/post:restrictions.seconds-between-new]]</label><input id="newbiePostDelay" type="text" class="form-control" value="120" data-field="newbiePostDelay"></div></div>- <div class="col-xs-6">+ </div>+ <div class="row">+ <div class="col-sm-6"><div class="form-group">- <label for="initialPostDelay">[[admin/settings/post:restrictions.seconds-defore-new]]</label>- <input id="initialPostDelay" type="text" class="form-control" value="10" data-field="initialPostDelay">-+ <label for="initialPostDelay">[[admin/settings/post:restrictions.seconds-before-new]]</label>+ <input id="initialPostDelay" type="text" class="form-control" value="10" data-field="initialPostDelay"></div></div>- </div>- <div class="form-group">- <div class="checkbox">- <label class="mdl-switch mdl-js-switch mdl-js-ripple-effect">- <input class="mdl-switch__input" type="checkbox" data-field="postQueue">- <span class="mdl-switch__label"><strong>[[admin/settings/post:restrictions.post-queue]]</strong></span>- </label>+ <div class="col-sm-6">+ <div class="form-group">+ <label for="newbiePostEditDuration">[[admin/settings/post:restrictions.seconds-edit-after]]</label>+ <input id="newbiePostEditDuration" type="text" class="form-control" value="120" data-field="newbiePostEditDuration">+ </div></div>- <p class="help-block">- [[admin/settings/post:restrictions.post-queue-help]]- </p>- </div>-- <div class="form-group">- <label for="newbiePostDelayThreshold">[[admin/settings/post:restrictions.rep-threshold]]</label>- <input id="newbiePostDelayThreshold" type="text" class="form-control" value="3" data-field="newbiePostDelayThreshold"></div></form></div>diff --git a/test/posts.js b/test/posts.jsindex de2aa50bd3..a975bc771a 100644--- a/test/posts.js+++ b/test/posts.js@@ -452,6 +452,17 @@ describe('Post\'s', function () {});});+ it('should disallow post editing for new users if post was made past the threshold for editing', function (done) {+ meta.config.newbiePostEditDuration = 1;+ setTimeout(function () {+ socketPosts.edit({ uid: voterUid }, { pid: pid, content: 'edited post content again', title: 'edited title again', tags: ['edited-twice'] }, function (err, data) {+ assert.equal(err.message, '[[error:post-edit-duration-expired, 1]]');+ meta.config.newbiePostEditDuration = 3600000;+ done();+ });+ }, 1000);+ });+it('should edit a deleted post', function (done) {socketPosts.delete({ uid: voterUid }, { pid: pid, tid: tid }, function (err) {assert.ifError(err);