From 29d90bc67d872f53bcd52ad5394388ee91c72268 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 9 Oct 2014 19:53:10 -0400 Subject: [PATCH] only use unique cids in isModerator --- src/topics.js | 2 +- src/user.js | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/topics.js b/src/topics.js index 26a68d7402..3cb6538804 100644 --- a/src/topics.js +++ b/src/topics.js @@ -179,7 +179,7 @@ var async = require('async'), Topics.getTopicsData(tids, function(err, topics) { function mapFilter(array, field) { return array.map(function(topic) { - return topic && topic[field]; + return topic && topic[field].toString(); }).filter(function(value, index, array) { return utils.isNumber(value) && array.indexOf(value) === index; }); diff --git a/src/user.js b/src/user.js index 62259f90ee..5121384dbf 100644 --- a/src/user.js +++ b/src/user.js @@ -394,10 +394,28 @@ var async = require('async'), User.isModerator = function(uid, cid, callback) { if (Array.isArray(cid)) { - var groupNames = cid.map(function(cid) { + var uniqueCids = cid.filter(function(cid, index, array) { + return array.indexOf(cid) === index; + }); + + var groupNames = uniqueCids.map(function(cid) { return 'cid:' + cid + ':privileges:mods'; }); - groups.isMemberOfGroups(uid, groupNames, callback); + + groups.isMemberOfGroups(uid, groupNames, function(err, isMembers) { + if (err) { + return callback(err); + } + + var map = {}; + uniqueCids.forEach(function(cid, index) { + map[cid] = isMembers[index]; + }); + + callback(null, cid.map(function(cid) { + return map[cid]; + })); + }); } else { if (Array.isArray(uid)) { groups.isMembers(uid, 'cid:' + cid + ':privileges:mods', callback);