From 8a6a58ee4383c9b0f3b344f5343adb759b0addfb Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 4 Jul 2019 13:28:36 -0400 Subject: [PATCH] feat: added new admin option newbiePostEditDuration (#7737) * feat: added new admin option newbiePostEditDuration Also: - Grammar-checked a couple language strings - Moved a couple form inputs around in new user restrictions - Added a test for the new option - fix: 'defore' typo --- install/data/defaults.json | 1 + .../language/en-GB/admin/settings/post.json | 14 +++--- src/privileges/posts.js | 5 ++ src/views/admin/settings/post.tpl | 48 +++++++++++-------- test/posts.js | 11 +++++ 5 files changed, 52 insertions(+), 27 deletions(-) diff --git a/install/data/defaults.json b/install/data/defaults.json index 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.json index 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.js index 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.tpl index 97d8ed6499..24060b1391 100644 --- a/src/views/admin/settings/post.tpl +++ b/src/views/admin/settings/post.tpl @@ -90,36 +90,44 @@
[[admin/settings/post:restrictions-new]]
+
+ + +
-
+
+
+
+ +
+

+ [[admin/settings/post:restrictions.post-queue-help]] +

+
+
+
-
+
+
+
- - - + +
-
-
-
- +
+
+ + +
-

- [[admin/settings/post:restrictions.post-queue-help]] -

-
- -
- -
diff --git a/test/posts.js b/test/posts.js index 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);