only use unique cids in isModerator

v1.18.x
barisusakli 10 years ago
parent 07a5aeaf15
commit 29d90bc67d

@ -179,7 +179,7 @@ var async = require('async'),
Topics.getTopicsData(tids, function(err, topics) { Topics.getTopicsData(tids, function(err, topics) {
function mapFilter(array, field) { function mapFilter(array, field) {
return array.map(function(topic) { return array.map(function(topic) {
return topic && topic[field]; return topic && topic[field].toString();
}).filter(function(value, index, array) { }).filter(function(value, index, array) {
return utils.isNumber(value) && array.indexOf(value) === index; return utils.isNumber(value) && array.indexOf(value) === index;
}); });

@ -394,10 +394,28 @@ var async = require('async'),
User.isModerator = function(uid, cid, callback) { User.isModerator = function(uid, cid, callback) {
if (Array.isArray(cid)) { 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'; 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 { } else {
if (Array.isArray(uid)) { if (Array.isArray(uid)) {
groups.isMembers(uid, 'cid:' + cid + ':privileges:mods', callback); groups.isMembers(uid, 'cid:' + cid + ':privileges:mods', callback);

Loading…
Cancel
Save