mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
almost everything for #2335
This commit is contained in:
@@ -15,6 +15,14 @@
|
|||||||
"field": "initialPostDelay",
|
"field": "initialPostDelay",
|
||||||
"value": 10
|
"value": 10
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"field": "newbiePostDelay",
|
||||||
|
"value": 120
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"field": "newbiePostDelayThreshold",
|
||||||
|
"value": 3
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"field": "minimumPostLength",
|
"field": "minimumPostLength",
|
||||||
"value": 8
|
"value": 8
|
||||||
|
|||||||
@@ -49,6 +49,7 @@
|
|||||||
"title-too-long": "Please enter a shorter title. Titles can't be longer than %1 characters.",
|
"title-too-long": "Please enter a shorter title. Titles can't be longer than %1 characters.",
|
||||||
"invalid-title": "Invalid title!",
|
"invalid-title": "Invalid title!",
|
||||||
"too-many-posts": "You can only post once every %1 seconds - please wait before posting again",
|
"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",
|
"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",
|
"cant-vote-self-post": "You cannot vote for your own post",
|
||||||
|
|||||||
@@ -89,6 +89,15 @@ var admin = {};
|
|||||||
socket.emit('admin.restart');
|
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) {
|
Mousetrap.bind('/', function(e) {
|
||||||
$('#acp-search input').focus();
|
$('#acp-search input').focus();
|
||||||
|
|
||||||
|
|||||||
@@ -50,13 +50,14 @@ var db = require('./database'),
|
|||||||
imageClass: 'auto'
|
imageClass: 'auto'
|
||||||
};
|
};
|
||||||
|
|
||||||
db.setObject('category:' + cid, category, function(err) {
|
async.series([
|
||||||
if(err) {
|
async.apply(db.setObject, 'category:' + cid, category),
|
||||||
|
async.apply(db.sortedSetAdd, 'categories:cid', data.order, cid)
|
||||||
|
], function(err) {
|
||||||
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
db.sortedSetAdd('categories:cid', data.order, cid);
|
|
||||||
|
|
||||||
callback(null, category);
|
callback(null, category);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ var async = require('async'),
|
|||||||
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
userData: function(next) {
|
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) {
|
exists: function(next) {
|
||||||
db.exists('user:' + uid, next);
|
db.exists('user:' + uid, next);
|
||||||
@@ -185,9 +185,12 @@ var async = require('async'),
|
|||||||
|
|
||||||
var lastposttime = userData.lastposttime || 0;
|
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 + ']]'));
|
return callback(new Error('[[error:too-many-posts, ' + meta.config.postDelay + ']]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,11 +13,34 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<strong>Seconds between Posts</strong><br /> <input type="text" class="form-control" value="10" data-field="postDelay"><br />
|
<div class="form-group">
|
||||||
<strong>Seconds before new user can post</strong><br /> <input type="text" class="form-control" value="10" data-field="initialPostDelay"><br />
|
<label>Seconds between Posts</label>
|
||||||
<strong>Minimum Title Length</strong><br /> <input type="text" class="form-control" value="3" data-field="minimumTitleLength"><br />
|
<input type="number" class="form-control" value="10" data-field="postDelay">
|
||||||
<strong>Maximum Title Length</strong><br /> <input type="text" class="form-control" value="255" data-field="maximumTitleLength"><br />
|
</div>
|
||||||
<strong>Minimum Post Length</strong><br /> <input type="text" class="form-control" value="8" data-field="minimumPostLength"><br />
|
<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">
|
<div class="checkbox">
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" data-field="disableSignatures"> <strong>Disable signatures</strong>
|
<input type="checkbox" data-field="disableSignatures"> <strong>Disable signatures</strong>
|
||||||
|
|||||||
@@ -23,6 +23,13 @@ describe("Messaging Library", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe(".canMessage()", 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) {
|
it("should allow messages to be sent to an unrestricted user", function(done) {
|
||||||
Messaging.canMessage(testUids[1], testUids[2], function(err, allowed) {
|
Messaging.canMessage(testUids[1], testUids[2], function(err, allowed) {
|
||||||
assert.strictEqual(allowed, true, 'should be true, received ' + allowed);
|
assert.strictEqual(allowed, true, 'should be true, received ' + allowed);
|
||||||
|
|||||||
@@ -5,12 +5,29 @@ process.on('uncaughtException', function (err) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var assert = require('assert'),
|
var assert = require('assert'),
|
||||||
|
async = require('async'),
|
||||||
db = require('./mocks/databasemock');
|
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() {
|
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(){
|
beforeEach(function(){
|
||||||
userData = {
|
userData = {
|
||||||
@@ -22,11 +39,13 @@ describe('User', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('when created', function() {
|
describe('.create(), when created', function() {
|
||||||
it('should be created properly', function(done) {
|
it('should be created properly', function(done) {
|
||||||
User.create({username: userData.username, password: userData.password, email: userData.email}, function(error,userId){
|
User.create({username: userData.username, password: userData.password, email: userData.email}, function(error,userId){
|
||||||
assert.equal(error, null, 'was created with error');
|
assert.equal(error, null, 'was created with error');
|
||||||
assert.ok(userId);
|
assert.ok(userId);
|
||||||
|
|
||||||
|
testUid = userId;
|
||||||
done();
|
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() {
|
after(function() {
|
||||||
db.flushdb();
|
db.flushdb();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user