mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 04:25:55 +01:00
fix: #7647, fix getModeratorUids
sets.groupNames is an array that contains other arrays of groupnames so passing it to getMembersOfGroups returned wrong results when there were more than 1 element in it.
This commit is contained in:
@@ -140,6 +140,7 @@ Categories.getModerators = function (cid, callback) {
|
||||
|
||||
Categories.getModeratorUids = function (cids, callback) {
|
||||
var sets;
|
||||
var uniqGroups;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
var groupNames = cids.reduce(function (memo, cid) {
|
||||
@@ -162,11 +163,13 @@ Categories.getModeratorUids = function (cids, callback) {
|
||||
return memo;
|
||||
}, { groupNames: [], uids: [] });
|
||||
|
||||
groups.getMembersOfGroups(sets.groupNames, next);
|
||||
uniqGroups = _.uniq(_.flatten(sets.groupNames));
|
||||
groups.getMembersOfGroups(uniqGroups, next);
|
||||
},
|
||||
function (groupUids, next) {
|
||||
var map = _.zipObject(uniqGroups, groupUids);
|
||||
const moderatorUids = cids.map(function (cid, index) {
|
||||
return _.union(sets.uids[index].concat(groupUids[index]));
|
||||
return _.uniq(sets.uids[index].concat(_.flatten(sets.groupNames[index].map(g => map[g]))));
|
||||
});
|
||||
next(null, moderatorUids);
|
||||
},
|
||||
|
||||
@@ -856,10 +856,27 @@ describe('Categories', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not fail when there are multiple groups', function (done) {
|
||||
async.series([
|
||||
async.apply(groups.create, { name: 'testGroup2' }),
|
||||
async.apply(groups.join, 'cid:1:privileges:groups:moderate', 'testGroup2'),
|
||||
async.apply(groups.join, 'testGroup2', 1),
|
||||
function (next) {
|
||||
Categories.getModeratorUids([1, 2], function (err, uids) {
|
||||
assert.ifError(err);
|
||||
assert(uids[0].includes('1'));
|
||||
next();
|
||||
});
|
||||
},
|
||||
], done);
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
async.series([
|
||||
async.apply(groups.leave, 'cid:1:privileges:groups:moderate', 'testGroup'),
|
||||
async.apply(groups.leave, 'cid:1:privileges:groups:moderate', 'testGroup2'),
|
||||
async.apply(groups.destroy, 'testGroup'),
|
||||
async.apply(groups.destroy, 'testGroup2'),
|
||||
], done);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user