Skip to content

Node.js based forum software built for the modern web

fixes #5776

Julian Lam09621a3a3d3e
diff --git a/src/user.js b/src/user.js
index db8f9774ed..e5b270add8 100644
--- a/src/user.js
+++ b/src/user.js
@@ -277,12 +277,30 @@ User.getModeratorUids = function (callback) {
async.waterfall([
async.apply(db.getSortedSetRange, 'categories:cid', 0, -1),
function (cids, next) {
- var groupNames = cids.map(function (cid) {
- return 'cid:' + cid + ':privileges:moderate';
- });
+ var groupNames = cids.reduce(function (memo, cid) {
+ memo.push('cid:' + cid + ':privileges:moderate');
+ memo.push('cid:' + cid + ':privileges:groups:moderate');
+ return memo;
+ }, []);
groups.getMembersOfGroups(groupNames, next);
},
+ function (memberSets, next) {
+ // Every other set is actually a list of user groups, not uids, so convert those to members
+ var sets = memberSets.reduce(function (memo, set, idx) {
+ if (idx % 2) {
+ memo.working.push(set);
+ } else {
+ memo.regular.push(set);
+ }
+
+ return memo;
+ }, { working: [], regular: [] });
+
+ groups.getMembersOfGroups(sets.working, function (err, memberSets) {
+ next(null, sets.regular.concat(memberSets));
+ });
+ },
function (memberSets, next) {
next(null, _.union.apply(_, memberSets));
},
diff --git a/test/user.js b/test/user.js
index d7118e4a0b..4c6647c8fd 100644
--- a/test/user.js
+++ b/test/user.js
@@ -155,6 +155,51 @@ describe('User', function () {
});
});
+ describe('.getModeratorUids()', function () {
+ before(function (done) {
+ groups.join('cid:1:privileges:moderate', 1, done);
+ });
+
+ it('should retrieve all users with moderator bit in category privilege', function (done) {
+ User.getModeratorUids(function (err, uids) {
+ assert.ifError(err);
+ assert.strictEqual(1, uids.length);
+ assert.strictEqual(1, parseInt(uids[0]));
+ done();
+ });
+ });
+
+ after(function (done) {
+ groups.leave('cid:1:privileges:moderate', 1, done);
+ });
+ });
+
+ describe('.getModeratorUids()', function () {
+ before(function (done) {
+ async.series([
+ async.apply(groups.create, { name: 'testGroup' }),
+ async.apply(groups.join, 'cid:1:privileges:groups:moderate', 'testGroup'),
+ async.apply(groups.join, 'testGroup', 1),
+ ], done);
+ });
+
+ it('should retrieve all users with moderator bit in category privilege', function (done) {
+ User.getModeratorUids(function (err, uids) {
+ assert.ifError(err);
+ assert.strictEqual(1, uids.length);
+ assert.strictEqual(1, parseInt(uids[0]));
+ done();
+ });
+ });
+
+ after(function (done) {
+ async.series([
+ async.apply(groups.leave, 'cid:1:privileges:groups:moderate', 'testGroup'),
+ async.apply(groups.destroy, 'testGroup'),
+ ], done);
+ });
+ });
+
describe('.isReadyToPost()', function () {
it('should error when a user makes two posts in quick succession', function (done) {
Meta.config = Meta.config || {};