Node.js based forum software built for the modern web
Merge branch 'fix-some-code-lint' of https://github.com/HeeL/NodeBB into HeeL-fix-some-code-lint
Julian Lamead4de6c6f1e
diff --cc src/controllers/admin/flags.jsindex 4334aef0c3,a0ead7e807..f4d83bbfaf--- a/src/controllers/admin/flags.js+++ b/src/controllers/admin/flags.js@@@ -20,16 -20,18 +20,16 @@@ flagsController.get = function (req, revar page = parseInt(req.query.page, 10) || 1;async.parallel({- categories: function(next) {+ categories: function (next) {categories.buildForSelect(req.uid, next);},- flagData: function(next) {+ flagData: function (next) {- getFlagData(req, next);+ getFlagData(req, res, next);},- analytics: function(next) {+ analytics: function (next) {analytics.getDailyStatsForSet('analytics:flags', Date.now(), 30, next);},- assignees: function (next) {- user.getAdminsandGlobalMods(next);- }+ assignees: async.apply(user.getAdminsandGlobalModsandModerators)}, function (err, results) {if (err) {return next(err);@@@ -43,16 -45,9 +43,16 @@@};});+ // If res.locals.cids is populated, then slim down the categories list+ if (res.locals.cids) {+ results.categories = results.categories.filter(function(category) {+ return res.locals.cids.indexOf(String(category.cid)) !== -1;+ });+ }+var pageCount = Math.max(1, Math.ceil(results.flagData.count / itemsPerPage));- results.categories.forEach(function(category) {+ results.categories.forEach(function (category) {category.selected = parseInt(category.cid, 10) === parseInt(cid, 10);});diff --cc src/controllers/globalmods.jsindex a5628f5a4d,b45c6ffbf4..7e4fd1ffec--- a/src/controllers/globalmods.js+++ b/src/controllers/globalmods.js@@@ -5,8 -6,18 +5,8 @@@ var adminBlacklistController = require(var globalModsController = {};- globalModsController.ipBlacklist = function(req, res, next) {- user.isAdminOrGlobalMod(req.uid, function(err, isAdminOrGlobalMod) {-globalModsController.flagged = function (req, res, next) {- user.isAdminOrGlobalMod(req.uid, function (err, isAdminOrGlobalMod) {- if (err || !isAdminOrGlobalMod) {- return next(err);- }-- adminFlagsController.get(req, res, next);- });-};-+ globalModsController.ipBlacklist = function (req, res, next) {+ user.isAdminOrGlobalMod(req.uid, function (err, isAdminOrGlobalMod) {if (err || !isAdminOrGlobalMod) {return next(err);}diff --cc src/middleware/header.jsindex e1997ddab9,124bcacee7..2741a599f8--- a/src/middleware/header.js+++ b/src/middleware/header.js@@@ -61,19 -61,16 +61,19 @@@ module.exports = function (middleware)templateValues.configJSON = JSON.stringify(res.locals.config);async.parallel({- scripts: function(next) {+ scripts: function (next) {plugins.fireHook('filter:scripts.get', [], next);},- isAdmin: function(next) {+ isAdmin: function (next) {user.isAdministrator(req.uid, next);},- isGlobalMod: function(next) {+ isGlobalMod: function (next) {user.isGlobalModerator(req.uid, next);},- isModerator: function(next) {++ isModerator: function (next) {+ user.isModeratorOfAnyCategory(req.uid, next);+ },- user: function(next) {+ user: function (next) {var userData = {uid: 0,username: '[[global:guest]]',diff --cc src/posts/category.jsindex 64d3615805,28444ce2a7..85a9414715--- a/src/posts/category.js+++ b/src/posts/category.js@@@ -57,29 -56,14 +57,29 @@@ module.exports = function (Posts)if (!cid) {return callback(null, pids);}- db.isSortedSetMembers('cid:' + cid + ':pids', pids, function (err, isMembers) {- if (err) {- return callback(err);- }- pids = pids.filter(function (pid, index) {- return pid && isMembers[index];++ if (!Array.isArray(cid) || cid.length === 1) {+ // Single cid- db.isSortedSetMembers('cid:' + parseInt(cid, 10) + ':pids', pids, function(err, isMembers) {++ db.isSortedSetMembers('cid:' + parseInt(cid, 10) + ':pids', pids, function (err, isMembers) {+ if (err) {+ return callback(err);+ }- pids = pids.filter(function(pid, index) {++ pids = pids.filter(function (pid, index) {+ return pid && isMembers[index];+ });+ callback(null, pids);});- callback(null, pids);- });+ } else {+ // Multiple cids+ async.map(cid, function(cid, next) {+ Posts.filterPidsByCid(pids, cid, next);+ }, function(err, pidsArr) {+ if (err) {+ return callback(err);+ }++ callback(null, _.union.apply(_, pidsArr));+ });+ }};};diff --cc src/posts/summary.jsindex 31a82b340f,11ccb24381..270d9d480b--- a/src/posts/summary.js+++ b/src/posts/summary.js@@@ -45,11 -45,14 +45,11 @@@ module.exports = function (Posts)}});async.parallel({- users: function(next) {+ users: function (next) {user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture'], next);},- topicsAndCategories: function(next) {+ topicsAndCategories: function (next) {getTopicAndCategories(topicKeys, next);- },- indices: function (next) {- Posts.getPostIndices(posts, uid, next);}}, next);},@@@ -58,7 -61,13 +58,7 @@@results.topics = toObject('tid', results.topicsAndCategories.topics);results.categories = toObject('cid', results.topicsAndCategories.categories);- posts.forEach(function(post) {- posts.forEach(function (post, i) {- post.index = utils.isNumber(results.indices[i]) ? parseInt(results.indices[i], 10) + 1 : 1;- post.isMainPost = post.index - 1 === 0;- post.deleted = parseInt(post.deleted, 10) === 1;- post.upvotes = parseInt(post.upvotes, 10) || 0;- post.downvotes = parseInt(post.downvotes, 10) || 0;- post.votes = post.upvotes - post.downvotes;++ posts.forEach(function (post) {// If the post author isn't represented in the retrieved users' data, then it means they were deleted, assume guest.if (!results.users.hasOwnProperty(post.uid)) {post.uid = 0;@@@ -113,7 -117,7 +113,7 @@@}function getTopicAndCategories(topicKeys, callback) {- db.getObjectsFields(topicKeys, ['uid', 'tid', 'title', 'cid', 'slug', 'deleted', 'postcount', 'mainPid'], function(err, topics) {- db.getObjectsFields(topicKeys, ['uid', 'tid', 'title', 'cid', 'slug', 'deleted', 'postcount'], function (err, topics) {++ db.getObjectsFields(topicKeys, ['uid', 'tid', 'title', 'cid', 'slug', 'deleted', 'postcount', 'mainPid'], function (err, topics) {if (err) {return callback(err);}diff --cc src/user.jsindex 1c7b2f772a,95e422d7a3..077b67ad22--- a/src/user.js+++ b/src/user.js@@@ -234,20 -233,7 +234,20 @@@ var meta = require('./meta')privileges.users.isModerator(uid, cid, 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) {+ next(!!isMod);+ });+ }, function(result) {+ callback(err, result);+ });+ });+ };+- User.isAdministrator = function(uid, callback) {+ User.isAdministrator = function (uid, callback) {privileges.users.isAdministrator(uid, callback);};@@@ -291,43 -277,10 +291,43 @@@});};+ 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) {+ if (err) {+ return callback(err);+ }++ User.getUsersData(_.union.apply(_, results), callback);+ });+ };++ User.getModeratorUids = function(callback) {+ async.waterfall([+ async.apply(db.getSortedSetRange, 'categories:cid', 0, -1),+ function(cids, next) {+ var groupNames = cids.map(function(cid) {+ return 'cid:' + cid + ':privileges:mods';+ });++ groups.getMembersOfGroups(groupNames, function(err, memberSets) {+ if (err) {+ return next(err);+ }++ next(null, _.union.apply(_, memberSets));+ });+ }+ ], callback);+ };+- User.addInterstitials = function(callback) {+ User.addInterstitials = function (callback) {plugins.registerHook('core', {hook: 'filter:register.interstitial',- method: function(data, callback) {+ method: function (data, callback) {if (meta.config.termsOfUse && !data.userData.acceptTos) {data.interstitials.push({template: 'partials/acceptTos',