Node.js based forum software built for the modern web
fix: #7647, fix getModeratorUids
Baris Usakli64679b37cc9b
diff --git a/src/categories/index.js b/src/categories/index.jsindex b201e8e204..cbc99e3c79 100644--- a/src/categories/index.js+++ b/src/categories/index.js@@ -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);},diff --git a/test/categories.js b/test/categories.jsindex 30e5c30842..644ce6adb1 100644--- a/test/categories.js+++ b/test/categories.js@@ -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);});});