mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 06:25:50 +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:
@@ -132,11 +132,11 @@ var async = require('async'),
|
||||
return callback(null, returnTopics);
|
||||
}
|
||||
|
||||
async.filter(tids, function(tid, next) {
|
||||
privileges.topics.can('read', tid, uid, function(err, canRead) {
|
||||
next(!err && canRead);
|
||||
});
|
||||
}, function(tids) {
|
||||
privileges.topics.filter('read', tids, uid, function(err, tids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
Topics.getTopicsByTids(tids, uid, function(err, topicData) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
@@ -185,6 +185,9 @@ var async = require('async'),
|
||||
}
|
||||
|
||||
function isTopicVisible(topicData, topicInfo) {
|
||||
if (parseInt(topicInfo.categoryData.disabled, 10) === 1) {
|
||||
return false;
|
||||
}
|
||||
var deleted = parseInt(topicData.deleted, 10) !== 0;
|
||||
return !deleted || (deleted && topicInfo.privileges.view_deleted) || parseInt(topicData.uid, 10) === parseInt(uid, 10);
|
||||
}
|
||||
@@ -206,7 +209,7 @@ var async = require('async'),
|
||||
if (categoryCache[topicData.cid]) {
|
||||
return next(null, categoryCache[topicData.cid]);
|
||||
}
|
||||
categories.getCategoryFields(topicData.cid, ['name', 'slug', 'icon', 'bgColor', 'color'], next);
|
||||
categories.getCategoryFields(topicData.cid, ['name', 'slug', 'icon', 'bgColor', 'color', 'disabled'], next);
|
||||
},
|
||||
user: function(next) {
|
||||
if (userCache[topicData.uid]) {
|
||||
|
||||
Reference in New Issue
Block a user