diff --git a/public/openapi/read/admin/manage/users.yaml b/public/openapi/read/admin/manage/users.yaml index 713ccb9c7b..05c651b318 100644 --- a/public/openapi/read/admin/manage/users.yaml +++ b/public/openapi/read/admin/manage/users.yaml @@ -29,6 +29,8 @@ get: type: string sort_lastonline: type: boolean + userCount: + type: number showInviteButton: type: boolean inviteOnly: diff --git a/src/controllers/admin/users.js b/src/controllers/admin/users.js index 2e5cd2438a..438b0aae78 100644 --- a/src/controllers/admin/users.js +++ b/src/controllers/admin/users.js @@ -241,7 +241,7 @@ async function render(req, res, data) { filterBy.forEach(function (filter) { 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) { data.showInviteButton = await privileges.users.isAdministrator(req.uid); } else { diff --git a/test/controllers-admin.js b/test/controllers-admin.js index fe88abd456..09691f4766 100644 --- a/test/controllers-admin.js +++ b/test/controllers-admin.js @@ -17,8 +17,10 @@ describe('Admin Controllers', function () { var tid; var cid; var pid; + let regularPid; var adminUid; var regularUid; + let regular2Uid; var moderatorUid; var jar; @@ -36,24 +38,30 @@ describe('Admin Controllers', function () { regularUid: function (next) { user.create({ username: 'regular' }, next); }, + regular2Uid: function (next) { + user.create({ username: 'regular2' }, next); + }, moderatorUid: function (next) { user.create({ username: 'moderator', password: 'modmod' }, next); }, - }, function (err, results) { + }, async function (err, results) { if (err) { return done(err); } adminUid = results.adminUid; regularUid = results.regularUid; + regular2Uid = results.regular2Uid; moderatorUid = results.moderatorUid; cid = results.category.cid; - topics.post({ uid: adminUid, title: 'test topic title', content: 'test topic content', cid: results.category.cid }, function (err, result) { - assert.ifError(err); - tid = result.topicData.tid; - pid = result.postData.pid; - done(); - }); + const adminPost = await topics.post({ uid: adminUid, title: 'test topic title', content: 'test topic content', cid: results.category.cid }); + assert.ifError(err); + tid = adminPost.topicData.tid; + pid = adminPost.postData.pid; + + 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) { var socketFlags = require('../src/socket.io/flags'); var oldValue = meta.config['min:rep:flag']; meta.config['min:rep:flag'] = 1000; - socketFlags.create({ uid: regularUid }, { id: pid, type: 'post', reason: 'spam' }, function (err) { - assert.equal(err.message, '[[error:not-enough-reputation-to-flag]]'); + socketFlags.create({ uid: regularUid }, { id: regularPid, type: 'post', reason: 'spam' }, function (err) { + assert.strictEqual(err.message, '[[error:not-enough-reputation-to-flag]]'); meta.config['min:rep:flag'] = oldValue; done(); }); @@ -602,7 +620,7 @@ describe('Admin Controllers', function () { var socketFlags = require('../src/socket.io/flags'); var oldValue = meta.config['min:rep:flag']; 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; assert.ifError(err); 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.reports); assert(Array.isArray(body.reports)); - assert.equal(body.reports[0].reporter.username, 'regular'); + assert.strictEqual(body.reports[0].reporter.username, 'regular'); done(); }); });