mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-19 22:21:32 +02:00
fixes #5776
This commit is contained in:
24
src/user.js
24
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));
|
||||
},
|
||||
|
||||
45
test/user.js
45
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 || {};
|
||||
|
||||
Reference in New Issue
Block a user