v1.18.x
Barış Soner Uşaklı 4 years ago
commit 700ef1af97

@ -29,6 +29,8 @@ get:
type: string type: string
sort_lastonline: sort_lastonline:
type: boolean type: boolean
userCount:
type: number
showInviteButton: showInviteButton:
type: boolean type: boolean
inviteOnly: inviteOnly:

@ -241,7 +241,7 @@ async function render(req, res, data) {
filterBy.forEach(function (filter) { filterBy.forEach(function (filter) {
data['filterBy_' + validator.escape(String(filter))] = true; data['filterBy_' + validator.escape(String(filter))] = true;
}); });
data.userCount = await db.getObjectField('global', 'userCount'); data.userCount = parseInt(await db.getObjectField('global', 'userCount'), 10);
if (data.adminInviteOnly) { if (data.adminInviteOnly) {
data.showInviteButton = await privileges.users.isAdministrator(req.uid); data.showInviteButton = await privileges.users.isAdministrator(req.uid);
} else { } else {

@ -17,8 +17,10 @@ describe('Admin Controllers', function () {
var tid; var tid;
var cid; var cid;
var pid; var pid;
let regularPid;
var adminUid; var adminUid;
var regularUid; var regularUid;
let regular2Uid;
var moderatorUid; var moderatorUid;
var jar; var jar;
@ -36,24 +38,30 @@ describe('Admin Controllers', function () {
regularUid: function (next) { regularUid: function (next) {
user.create({ username: 'regular' }, next); user.create({ username: 'regular' }, next);
}, },
regular2Uid: function (next) {
user.create({ username: 'regular2' }, next);
},
moderatorUid: function (next) { moderatorUid: function (next) {
user.create({ username: 'moderator', password: 'modmod' }, next); user.create({ username: 'moderator', password: 'modmod' }, next);
}, },
}, function (err, results) { }, async function (err, results) {
if (err) { if (err) {
return done(err); return done(err);
} }
adminUid = results.adminUid; adminUid = results.adminUid;
regularUid = results.regularUid; regularUid = results.regularUid;
regular2Uid = results.regular2Uid;
moderatorUid = results.moderatorUid; moderatorUid = results.moderatorUid;
cid = results.category.cid; cid = results.category.cid;
topics.post({ uid: adminUid, title: 'test topic title', content: 'test topic content', cid: results.category.cid }, function (err, result) { const adminPost = await topics.post({ uid: adminUid, title: 'test topic title', content: 'test topic content', cid: results.category.cid });
assert.ifError(err); assert.ifError(err);
tid = result.topicData.tid; tid = adminPost.topicData.tid;
pid = result.postData.pid; pid = adminPost.postData.pid;
done();
}); const regularPost = await topics.post({ uid: regular2Uid, title: 'regular user\'s test topic title', content: 'test topic content', cid: results.category.cid });
regularPid = regularPost.postData.pid;
done();
}); });
}); });
@ -587,12 +595,22 @@ describe('Admin Controllers', function () {
}); });
}); });
it('should error when you attempt to flag a privileged user\'s post', async () => {
var socketFlags = require('../src/socket.io/flags');
var oldValue = meta.config['min:rep:flag'];
try {
await socketFlags.create({ uid: regularUid }, { id: pid, type: 'post', reason: 'spam' });
} catch (err) {
assert.strictEqual(err.message, '[[error:cant-flag-privileged]]');
}
});
it('should error with not enough reputation to flag', function (done) { it('should error with not enough reputation to flag', function (done) {
var socketFlags = require('../src/socket.io/flags'); var socketFlags = require('../src/socket.io/flags');
var oldValue = meta.config['min:rep:flag']; var oldValue = meta.config['min:rep:flag'];
meta.config['min:rep:flag'] = 1000; meta.config['min:rep:flag'] = 1000;
socketFlags.create({ uid: regularUid }, { id: pid, type: 'post', reason: 'spam' }, function (err) { socketFlags.create({ uid: regularUid }, { id: regularPid, type: 'post', reason: 'spam' }, function (err) {
assert.equal(err.message, '[[error:not-enough-reputation-to-flag]]'); assert.strictEqual(err.message, '[[error:not-enough-reputation-to-flag]]');
meta.config['min:rep:flag'] = oldValue; meta.config['min:rep:flag'] = oldValue;
done(); done();
}); });
@ -602,7 +620,7 @@ describe('Admin Controllers', function () {
var socketFlags = require('../src/socket.io/flags'); var socketFlags = require('../src/socket.io/flags');
var oldValue = meta.config['min:rep:flag']; var oldValue = meta.config['min:rep:flag'];
meta.config['min:rep:flag'] = 0; meta.config['min:rep:flag'] = 0;
socketFlags.create({ uid: regularUid }, { id: pid, type: 'post', reason: 'spam' }, function (err, flagId) { socketFlags.create({ uid: regularUid }, { id: regularPid, type: 'post', reason: 'spam' }, function (err, flagId) {
meta.config['min:rep:flag'] = oldValue; meta.config['min:rep:flag'] = oldValue;
assert.ifError(err); assert.ifError(err);
request(nconf.get('url') + '/api/flags/' + flagId, { jar: moderatorJar, json: true }, function (err, res, body) { request(nconf.get('url') + '/api/flags/' + flagId, { jar: moderatorJar, json: true }, function (err, res, body) {
@ -610,7 +628,7 @@ describe('Admin Controllers', function () {
assert(body); assert(body);
assert(body.reports); assert(body.reports);
assert(Array.isArray(body.reports)); assert(Array.isArray(body.reports));
assert.equal(body.reports[0].reporter.username, 'regular'); assert.strictEqual(body.reports[0].reporter.username, 'regular');
done(); done();
}); });
}); });

Loading…
Cancel
Save