mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 20:16:04 +01:00
optimize privileges and assorted fixes.
* new methods privileges.categories.filter privileges.topics.filter privileges.posts.filter they take a list of ids and a privilege, and return the filtered list of ids, faster than doing async.filter and calling the db for each id. * remove event listeners on recent page before adding * group.exists works for both single group names and arrays * helpers.allowedTo works for both a single cid and an array of cids * moved filter:topic.post hook right before topic creation. * moved filter:topic.reply hook right before topic reply.
This commit is contained in:
@@ -198,19 +198,21 @@ var db = require('./database'),
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
Categories.getCategories(cids, uid, function(err, categories) {
|
||||
privileges.categories.filter('find', cids, uid, function(err, cids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
async.filter(categories, function (category, next) {
|
||||
if (category.disabled) {
|
||||
return next(false);
|
||||
|
||||
Categories.getCategories(cids, uid, function(err, categories) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
privileges.categories.can('find', category.cid, uid, function(err, findable) {
|
||||
next(!err && findable);
|
||||
|
||||
categories = categories.filter(function(category) {
|
||||
return !category.disabled;
|
||||
});
|
||||
}, function(visibleCategories) {
|
||||
callback(null, visibleCategories);
|
||||
|
||||
callback(null, categories);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -218,18 +220,15 @@ var db = require('./database'),
|
||||
|
||||
Categories.getModerators = function(cid, callback) {
|
||||
Groups.get('cid:' + cid + ':privileges:mods', {}, function(err, groupObj) {
|
||||
if (!err) {
|
||||
if (groupObj.members && groupObj.members.length) {
|
||||
user.getMultipleUserFields(groupObj.members, ['uid', 'username', 'userslug', 'picture'], function(err, moderators) {
|
||||
callback(err, moderators);
|
||||
});
|
||||
} else {
|
||||
callback(null, []);
|
||||
}
|
||||
} else {
|
||||
// Probably no mods
|
||||
callback(null, []);
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!Array.isArray(groupObj) || !groupObj.members.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
user.getMultipleUserFields(groupObj.members, ['uid', 'username', 'userslug', 'picture'], callback);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -309,11 +308,14 @@ var db = require('./database'),
|
||||
};
|
||||
|
||||
Categories.getCategories = function(cids, uid, callback) {
|
||||
|
||||
if (!Array.isArray(cids) || cids.length === 0) {
|
||||
if (!Array.isArray(cids)) {
|
||||
return callback(new Error('[[error:invalid-cid]]'));
|
||||
}
|
||||
|
||||
if (!cids.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
categories: function(next) {
|
||||
Categories.getCategoriesData(cids, next);
|
||||
|
||||
Reference in New Issue
Block a user