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.
v1.18.x
Baris Usakli 6 years ago
parent 5cd9e1bf86
commit 64679b37cc

@ -140,6 +140,7 @@ Categories.getModerators = function (cid, callback) {
Categories.getModeratorUids = function (cids, callback) { Categories.getModeratorUids = function (cids, callback) {
var sets; var sets;
var uniqGroups;
async.waterfall([ async.waterfall([
function (next) { function (next) {
var groupNames = cids.reduce(function (memo, cid) { var groupNames = cids.reduce(function (memo, cid) {
@ -162,11 +163,13 @@ Categories.getModeratorUids = function (cids, callback) {
return memo; return memo;
}, { groupNames: [], uids: [] }); }, { groupNames: [], uids: [] });
groups.getMembersOfGroups(sets.groupNames, next); uniqGroups = _.uniq(_.flatten(sets.groupNames));
groups.getMembersOfGroups(uniqGroups, next);
}, },
function (groupUids, next) { function (groupUids, next) {
var map = _.zipObject(uniqGroups, groupUids);
const moderatorUids = cids.map(function (cid, index) { 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); 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) { after(function (done) {
async.series([ async.series([
async.apply(groups.leave, 'cid:1:privileges:groups:moderate', 'testGroup'), 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, 'testGroup'),
async.apply(groups.destroy, 'testGroup2'),
], done); ], done);
}); });
}); });

Loading…
Cancel
Save