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
v1.18.x
Julian Lam 6 years ago committed by GitHub
parent f3440ebfca
commit 8a6a58ee43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -11,6 +11,7 @@
"initialPostDelay": 10,
"newbiePostDelay": 120,
"postEditDuration": 0,
"newbiePostEditDuration": 3600000,
"postDeleteDuration": 0,
"enablePostHistory": 1,
"postCacheSize": 10485760,

@ -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",

@ -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) {

@ -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>

@ -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);

Loading…
Cancel
Save