fix isModeratorOfAnyCategory

returns true/false now instead of an array
new method getModeratedCids returns an array of moderated cids
v1.18.x
barisusakli 8 years ago
parent 36be79fcb2
commit b32d7b86e8

@ -8,17 +8,17 @@ var adminFlagsController = require('./admin/flags');
var modsController = {};
modsController.flagged = function (req, res, next) {
async.parallel([
async.apply(user.isAdminOrGlobalMod, req.uid),
async.apply(user.isModeratorOfAnyCategory, req.uid)
], function (err, results) {
if (err || !(results[0] || results[1])) {
async.parallel({
isAdminOrGlobalMod: async.apply(user.isAdminOrGlobalMod, req.uid),
moderatedCids: async.apply(user.getModeratedCids, req.uid)
}, function (err, results) {
if (err || !(results.isAdminOrGlobalMod || !!results.moderatedCids.length)) {
return next(err);
}
if (!results[0] && results[1]) {
res.locals.cids = results[1];
}
if (!results.isAdminOrGlobalMod && results.moderatedCids.length) {
res.locals.cids = results.moderatedCids;
}
adminFlagsController.get(req, res, next);
});

@ -235,19 +235,8 @@ var meta = require('./meta');
};
User.isModeratorOfAnyCategory = function (uid, callback) {
// Checks all active categories and determines whether passed-in uid is a mod of any of them
db.getSortedSetRange('categories:cid', 0, -1, function (err, cids) {
async.filter(cids, function (cid, next) {
User.isModerator(uid, cid, function (err, isMod) {
if (err) {
// do nothing because async doesn't support errors in filter yet
}
next(!!isMod);
});
}, function (result) {
callback(err, result);
});
User.getModeratedCids(uid, function (err, cids) {
callback(err, Array.isArray(cids) ? !!cids.length : false);
});
};
@ -328,6 +317,25 @@ var meta = require('./meta');
], callback);
};
User.getModeratedCids = function (uid, callback) {
var cids;
async.waterfall([
function (next) {
db.getSortedSetRange('categories:cid', 0, -1, next);
},
function (_cids, next) {
cids = _cids;
User.isModerator(uid, cids, next);
},
function (isMods, next) {
cids = cids.filter(function (cid, index) {
return cid && isMods[index];
});
next(null, cids);
}
], callback);
};
User.addInterstitials = function (callback) {
plugins.registerHook('core', {
hook: 'filter:register.interstitial',

Loading…
Cancel
Save