diff --git a/src/controllers/admin/flags.js b/src/controllers/admin/flags.js index f4d83bbfaf..1b31a95ff4 100644 --- a/src/controllers/admin/flags.js +++ b/src/controllers/admin/flags.js @@ -45,7 +45,7 @@ flagsController.get = function (req, res, next) { // If res.locals.cids is populated, then slim down the categories list if (res.locals.cids) { - results.categories = results.categories.filter(function(category) { + results.categories = results.categories.filter(function (category) { return res.locals.cids.indexOf(String(category.cid)) !== -1; }); } diff --git a/src/controllers/mods.js b/src/controllers/mods.js index e319c90086..5d2d904663 100644 --- a/src/controllers/mods.js +++ b/src/controllers/mods.js @@ -7,11 +7,11 @@ var adminFlagsController = require('./admin/flags'); var modsController = {}; -modsController.flagged = function(req, res, next) { +modsController.flagged = function (req, res, next) { async.parallel([ async.apply(user.isAdminOrGlobalMod, req.uid), async.apply(user.isModeratorOfAnyCategory, req.uid) - ], function(err, results) { + ], function (err, results) { if (err || !(results[0] || results[1])) { return next(err); } diff --git a/src/posts/category.js b/src/posts/category.js index 85a9414715..a1f3e8afbc 100644 --- a/src/posts/category.js +++ b/src/posts/category.js @@ -71,9 +71,9 @@ module.exports = function (Posts) { }); } else { // Multiple cids - async.map(cid, function(cid, next) { + async.map(cid, function (cid, next) { Posts.filterPidsByCid(pids, cid, next); - }, function(err, pidsArr) { + }, function (err, pidsArr) { if (err) { return callback(err); } diff --git a/src/socket.io/posts/flag.js b/src/socket.io/posts/flag.js index e11928c928..e34808990a 100644 --- a/src/socket.io/posts/flag.js +++ b/src/socket.io/posts/flag.js @@ -148,7 +148,7 @@ module.exports = function (SocketPosts) { async.parallel([ async.apply(user.isAdminOrGlobalMod, socket.uid), async.apply(user.isModeratorOfAnyCategory, socket.uid) - ], function(err, results) { + ], function (err, results) { next(err, results[0] || results[1]); }); }, diff --git a/src/user.js b/src/user.js index 077b67ad22..996d1abd0a 100644 --- a/src/user.js +++ b/src/user.js @@ -234,14 +234,18 @@ var meta = require('./meta'); privileges.users.isModerator(uid, cid, callback); }; - User.isModeratorOfAnyCategory = function(uid, callback) { + 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) { + 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) { + }, function (result) { callback(err, result); }); }); @@ -291,12 +295,12 @@ var meta = require('./meta'); }); }; - User.getAdminsandGlobalModsandModerators = function(callback) { + User.getAdminsandGlobalModsandModerators = function (callback) { async.parallel([ async.apply(groups.getMembers, 'administrators', 0, -1), async.apply(groups.getMembers, 'Global Moderators', 0, -1), async.apply(User.getModeratorUids) - ], function(err, results) { + ], function (err, results) { if (err) { return callback(err); } @@ -305,15 +309,15 @@ var meta = require('./meta'); }); }; - User.getModeratorUids = function(callback) { + User.getModeratorUids = function (callback) { async.waterfall([ async.apply(db.getSortedSetRange, 'categories:cid', 0, -1), - function(cids, next) { - var groupNames = cids.map(function(cid) { + function (cids, next) { + var groupNames = cids.map(function (cid) { return 'cid:' + cid + ':privileges:mods'; }); - groups.getMembersOfGroups(groupNames, function(err, memberSets) { + groups.getMembersOfGroups(groupNames, function (err, memberSets) { if (err) { return next(err); } diff --git a/test/translator.js b/test/translator.js index 968f9118ce..18debb8dc9 100644 --- a/test/translator.js +++ b/test/translator.js @@ -155,9 +155,9 @@ describe('new Translator(language)', function (){ }); }); - it('should translate [[pages:users/latest]] properly', function(done) { + it('should translate [[pages:users/latest]] properly', function (done) { var translator = new Translator('en_GB'); - translator.translate('[[pages:users/latest]]').then(function(translated) { + translator.translate('[[pages:users/latest]]').then(function (translated) { assert.strictEqual('[[pages:users/latest]]', 'Latest Users'); done(); });