Skip to content

Node.js based forum software built for the modern web

almost everything for #2335

Julian Lamb91d39a0d3f2
diff --git a/install/data/defaults.json b/install/data/defaults.json
index b81b1b8523..5507ad0822 100644
--- a/install/data/defaults.json
+++ b/install/data/defaults.json
@@ -15,6 +15,14 @@
"field": "initialPostDelay",
"value": 10
},
+ {
+ "field": "newbiePostDelay",
+ "value": 120
+ },
+ {
+ "field": "newbiePostDelayThreshold",
+ "value": 3
+ },
{
"field": "minimumPostLength",
"value": 8
diff --git a/public/language/en_GB/error.json b/public/language/en_GB/error.json
index 6f0c2653da..f0c4bc4d45 100644
--- a/public/language/en_GB/error.json
+++ b/public/language/en_GB/error.json
@@ -49,6 +49,7 @@
"title-too-long": "Please enter a shorter title. Titles can't be longer than %1 characters.",
"invalid-title": "Invalid title!",
"too-many-posts": "You can only post once every %1 seconds - please wait before posting again",
+ "too-many-posts-newbie": "As a new registrant, you can only post once every %1 seconds until you have earned %2 reputation - please wait before posting again",
"file-too-big": "Maximum allowed file size is %1 kbs - please upload a smaller file",
"cant-vote-self-post": "You cannot vote for your own post",
diff --git a/public/src/admin/admin.js b/public/src/admin/admin.js
index 77dbe50947..e9a061bc52 100644
--- a/public/src/admin/admin.js
+++ b/public/src/admin/admin.js
@@ -89,6 +89,15 @@ var admin = {};
socket.emit('admin.restart');
});
+ Mousetrap.bind('ctrl+shift+a d', function() {
+ var tid = ajaxify.variables.get('topic_id'),
+ cid = ajaxify.variables.get('category_id');
+
+ if (tid && cid) {
+ socket.emit('topics.delete', { tids: [tid], cid: cid });
+ }
+ });
+
Mousetrap.bind('/', function(e) {
$('#acp-search input').focus();
diff --git a/src/categories.js b/src/categories.js
index f91309b04c..1a87c0d3b9 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -50,13 +50,14 @@ var db = require('./database'),
imageClass: 'auto'
};
- db.setObject('category:' + cid, category, function(err) {
- if(err) {
+ async.series([
+ async.apply(db.setObject, 'category:' + cid, category),
+ async.apply(db.sortedSetAdd, 'categories:cid', data.order, cid)
+ ], function(err) {
+ if (err) {
return callback(err);
}
- db.sortedSetAdd('categories:cid', data.order, cid);
-
callback(null, category);
});
});
diff --git a/src/user.js b/src/user.js
index a4920e14da..74299cb8bf 100644
--- a/src/user.js
+++ b/src/user.js
@@ -148,7 +148,7 @@ var async = require('async'),
async.parallel({
userData: function(next) {
- User.getUserFields(uid, ['banned', 'lastposttime', 'joindate', 'email', 'email:confirmed'], next);
+ User.getUserFields(uid, ['banned', 'lastposttime', 'joindate', 'email', 'email:confirmed', 'reputation'], next);
},
exists: function(next) {
db.exists('user:' + uid, next);
@@ -185,9 +185,12 @@ var async = require('async'),
var lastposttime = userData.lastposttime || 0;
- if (now - parseInt(lastposttime, 10) < parseInt(meta.config.postDelay, 10) * 1000) {
+ if (parseInt(meta.config.newbiePostDelay, 10) > 0 && parseInt(meta.config.newbiePostDelayThreshold, 10) > parseInt(userData.reputation, 10) && now - parseInt(lastposttime, 10) < parseInt(meta.config.newbiePostDelay, 10) * 1000) {
+ return callback(new Error('[[error:too-many-posts-newbie, ' + meta.config.postDelay + ', ' + meta.config.newbiePostDelayThreshold + ']]'));
+ } else if (now - parseInt(lastposttime, 10) < parseInt(meta.config.postDelay, 10) * 1000) {
return callback(new Error('[[error:too-many-posts, ' + meta.config.postDelay + ']]'));
}
+
callback();
});
};
diff --git a/src/views/admin/settings/post.tpl b/src/views/admin/settings/post.tpl
index a451e701e2..af1b927fbe 100644
--- a/src/views/admin/settings/post.tpl
+++ b/src/views/admin/settings/post.tpl
@@ -13,11 +13,34 @@
</select>
</div>
- <strong>Seconds between Posts</strong><br /> <input type="text" class="form-control" value="10" data-field="postDelay"><br />
- <strong>Seconds before new user can post</strong><br /> <input type="text" class="form-control" value="10" data-field="initialPostDelay"><br />
- <strong>Minimum Title Length</strong><br /> <input type="text" class="form-control" value="3" data-field="minimumTitleLength"><br />
- <strong>Maximum Title Length</strong><br /> <input type="text" class="form-control" value="255" data-field="maximumTitleLength"><br />
- <strong>Minimum Post Length</strong><br /> <input type="text" class="form-control" value="8" data-field="minimumPostLength"><br />
+ <div class="form-group">
+ <label>Seconds between Posts</label>
+ <input type="number" class="form-control" value="10" data-field="postDelay">
+ </div>
+ <div class="form-group col-sm-6">
+ <label>Seconds between Posts for New Users</label>
+ <input type="number" class="form-control" value="120" data-field="newbiePostDelay">
+ </div>
+ <div class="form-group col-sm-6">
+ <label>Reputation threshold before this restriction is lifted</label>
+ <input type="number" class="form-control" value="3" data-field="newbiePostDelayThreshold">
+ </div>
+ <div class="form-group">
+ <label>Seconds before new user can post</label>
+ <input type="number" class="form-control" value="10" data-field="initialPostDelay">
+ </div>
+ <div class="form-group">
+ <label>Minimum Title Length</label>
+ <input type="number" class="form-control" value="3" data-field="minimumTitleLength">
+ </div>
+ <div class="form-group">
+ <label>Maximum Title Length</label>
+ <input type="number" class="form-control" value="255" data-field="maximumTitleLength">
+ </div>
+ <div class="form-group">
+ <label>Minimum Post Length</label>
+ <input type="number" class="form-control" value="8" data-field="minimumPostLength">
+ </div>
<div class="checkbox">
<label>
<input type="checkbox" data-field="disableSignatures"> <strong>Disable signatures</strong>
diff --git a/tests/messaging.js b/tests/messaging.js
index a5945de950..29d3e79418 100644
--- a/tests/messaging.js
+++ b/tests/messaging.js
@@ -23,6 +23,13 @@ describe("Messaging Library", function() {
});
describe(".canMessage()", function() {
+ it('should not error out', function(done) {
+ Messaging.canMessage(testUids[1], testUids[2], function(err, allowed) {
+ assert.ifError(err);
+ done();
+ });
+ });
+
it("should allow messages to be sent to an unrestricted user", function(done) {
Messaging.canMessage(testUids[1], testUids[2], function(err, allowed) {
assert.strictEqual(allowed, true, 'should be true, received ' + allowed);
diff --git a/tests/user.js b/tests/user.js
index 9f2eb73e17..24a752afdd 100644
--- a/tests/user.js
+++ b/tests/user.js
@@ -5,12 +5,29 @@ process.on('uncaughtException', function (err) {
});
var assert = require('assert'),
+ async = require('async'),
db = require('./mocks/databasemock');
-var User = require('../src/user');
+var User = require('../src/user'),
+ Topics = require('../src/topics'),
+ Categories = require('../src/categories'),
+ Meta = require('../src/meta');
describe('User', function() {
- var userData;
+ var userData,
+ testUid,
+ testCid;
+
+ before(function(done) {
+ Categories.create({
+ name: 'Test Category',
+ description: 'A test',
+ order: 1
+ }, function(err, categoryObj) {
+ testCid = categoryObj.cid;
+ done();
+ });
+ });
beforeEach(function(){
userData = {
@@ -22,11 +39,13 @@ describe('User', function() {
});
- describe('when created', function() {
+ describe('.create(), when created', function() {
it('should be created properly', function(done) {
User.create({username: userData.username, password: userData.password, email: userData.email}, function(error,userId){
assert.equal(error, null, 'was created with error');
assert.ok(userId);
+
+ testUid = userId;
done();
});
});
@@ -40,6 +59,79 @@ describe('User', function() {
});
});
+ describe('.isReadyToPost()', function() {
+ it('should error when a user makes two posts in quick succession', function(done) {
+ Meta.config = Meta.config || {};
+ Meta.config.postDelay = '10';
+
+ async.series([
+ async.apply(Topics.post, {
+ uid: testUid,
+ title: 'Topic 1',
+ content: 'lorem ipsum',
+ cid: testCid
+ }),
+ async.apply(Topics.post, {
+ uid: testUid,
+ title: 'Topic 2',
+ content: 'lorem ipsum',
+ cid: testCid
+ })
+ ], function(err) {
+ assert(err);
+ done();
+ });
+ });
+
+ it('should allow a post if the last post time is > 10 seconds', function(done) {
+ User.setUserField(testUid, 'lastposttime', +new Date()-(11*1000), function() {
+ Topics.post({
+ uid: testUid,
+ title: 'Topic 3',
+ content: 'lorem ipsum',
+ cid: testCid
+ }, function(err) {
+ assert.ifError(err);
+ done();
+ });
+ });
+ });
+
+ it('should error when a new user posts if the last post time is 10 < 30 seconds', function(done) {
+ Meta.config.newbiePostDelay = 30;
+ Meta.config.newbiePostDelayThreshold = 3;
+
+ User.setUserField(testUid, 'lastposttime', +new Date()-(20*1000), function() {
+ Topics.post({
+ uid: testUid,
+ title: 'Topic 4',
+ content: 'lorem ipsum',
+ cid: testCid
+ }, function(err) {
+ assert(err);
+ done();
+ });
+ });
+ });
+
+ it('should not error if a non-newbie user posts if the last post time is 10 < 30 seconds', function(done) {
+ User.setUserFields(testUid, {
+ lastposttime: +new Date()-(20*1000),
+ reputation: 10
+ }, function() {
+ Topics.post({
+ uid: testUid,
+ title: 'Topic 5',
+ content: 'lorem ipsum',
+ cid: testCid
+ }, function(err) {
+ assert.ifError(err);
+ done();
+ });
+ });
+ });
+ });
+
after(function() {
db.flushdb();
});