|
|
|
@ -63,22 +63,57 @@ module.exports = function(privileges) {
|
|
|
|
|
if (!Array.isArray(pids) || !pids.length) {
|
|
|
|
|
return callback(null, []);
|
|
|
|
|
}
|
|
|
|
|
posts.getCidsByPids(pids, function(err, cids) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
var cids;
|
|
|
|
|
var postData;
|
|
|
|
|
var tids;
|
|
|
|
|
var tidToTopic = {};
|
|
|
|
|
|
|
|
|
|
pids = pids.map(function(pid, index) {
|
|
|
|
|
return {pid: pid, cid: cids[index]};
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
posts.getPostsFields(pids, ['uid', 'tid', 'deleted'], next);
|
|
|
|
|
},
|
|
|
|
|
function (_posts, next) {
|
|
|
|
|
postData = _posts;
|
|
|
|
|
tids = _posts.map(function(post) {
|
|
|
|
|
return post && post.tid;
|
|
|
|
|
}).filter(function(tid, index, array) {
|
|
|
|
|
return tid && array.indexOf(tid) === index;
|
|
|
|
|
});
|
|
|
|
|
topics.getTopicsFields(tids, ['deleted', 'cid'], next);
|
|
|
|
|
},
|
|
|
|
|
function (topicData, next) {
|
|
|
|
|
|
|
|
|
|
privileges.categories.filterCids(privilege, cids, uid, function(err, cids) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
topicData.forEach(function(topic, index) {
|
|
|
|
|
if (topic) {
|
|
|
|
|
tidToTopic[tids[index]] = topic;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
pids = pids.filter(function(post) {
|
|
|
|
|
return cids.indexOf(post.cid) !== -1;
|
|
|
|
|
cids = postData.map(function(post, index) {
|
|
|
|
|
if (post) {
|
|
|
|
|
post.pid = pids[index];
|
|
|
|
|
post.topic = tidToTopic[post.tid];
|
|
|
|
|
}
|
|
|
|
|
return tidToTopic[post.tid] && tidToTopic[post.tid].cid;
|
|
|
|
|
}).filter(function(cid, index, array) {
|
|
|
|
|
return cid && array.indexOf(cid) === index;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
privileges.categories.getBase(privilege, cids, uid, next);
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
|
|
|
|
|
var isModOf = {};
|
|
|
|
|
cids = cids.filter(function(cid, index) {
|
|
|
|
|
isModOf[cid] = results.isModerators[index];
|
|
|
|
|
return !results.categories[index].disabled &&
|
|
|
|
|
(results.allowedTo[index] || results.isAdmin || results.isModerators[index]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pids = postData.filter(function(post) {
|
|
|
|
|
return cids.indexOf(post.topic.cid) !== -1 &&
|
|
|
|
|
((parseInt(post.topic.deleted, 10) !== 1 && parseInt(post.deleted, 10) !== 1) || results.isAdmin || isModOf[post.cid]);
|
|
|
|
|
}).map(function(post) {
|
|
|
|
|
return post.pid;
|
|
|
|
|
});
|
|
|
|
@ -88,10 +123,10 @@ module.exports = function(privileges) {
|
|
|
|
|
uid: uid,
|
|
|
|
|
pids: pids
|
|
|
|
|
}, function(err, data) {
|
|
|
|
|
callback(err, data ? data.pids : null);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
next(err, data ? data.pids : null);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
privileges.posts.canEdit = function(pid, uid, callback) {
|
|
|
|
|