mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 04:25:55 +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:
@@ -76,6 +76,31 @@ module.exports = function(privileges) {
|
||||
});
|
||||
};
|
||||
|
||||
privileges.posts.filter = function(privilege, pids, uid, callback) {
|
||||
posts.getCidsByPids(pids, function(err, cids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
pids = pids.map(function(pid, index) {
|
||||
return {pid: pid, cid: cids[index]};
|
||||
});
|
||||
|
||||
privileges.categories.filter(privilege, cids, uid, function(err, cids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
pids = pids.filter(function(post) {
|
||||
return cids.indexOf(post.cid) !== -1;
|
||||
}).map(function(post) {
|
||||
return post.pid;
|
||||
});
|
||||
callback(null, pids);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
privileges.posts.canEdit = function(pid, uid, callback) {
|
||||
helpers.some([
|
||||
function(next) {
|
||||
|
||||
Reference in New Issue
Block a user