|
|
@ -70,56 +70,44 @@ module.exports = function(privileges) {
|
|
|
|
if (!Array.isArray(tids) || !tids.length) {
|
|
|
|
if (!Array.isArray(tids) || !tids.length) {
|
|
|
|
return callback(null, []);
|
|
|
|
return callback(null, []);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var cids;
|
|
|
|
|
|
|
|
var topicsData;
|
|
|
|
async.waterfall([
|
|
|
|
async.waterfall([
|
|
|
|
function(next) {
|
|
|
|
function(next) {
|
|
|
|
topics.getTopicsFields(tids, ['tid', 'cid', 'deleted'], next);
|
|
|
|
topics.getTopicsFields(tids, ['tid', 'cid', 'deleted'], next);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
function(topicsData, next) {
|
|
|
|
function(_topicsData, next) {
|
|
|
|
var cids = topicsData.map(function(topic) {
|
|
|
|
topicsData = _topicsData;
|
|
|
|
|
|
|
|
cids = topicsData.map(function(topic) {
|
|
|
|
return topic.cid;
|
|
|
|
return topic.cid;
|
|
|
|
}).filter(function(cid, index, array) {
|
|
|
|
}).filter(function(cid, index, array) {
|
|
|
|
return cid && array.indexOf(cid) === index;
|
|
|
|
return cid && array.indexOf(cid) === index;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
async.parallel({
|
|
|
|
privileges.categories.getBase(privilege, cids, uid, next);
|
|
|
|
categories: function(next) {
|
|
|
|
},
|
|
|
|
categories.getCategoriesFields(cids, ['disabled'], next);
|
|
|
|
function(results, next) {
|
|
|
|
},
|
|
|
|
|
|
|
|
allowedTo: function(next) {
|
|
|
|
|
|
|
|
helpers.isUserAllowedTo(privilege, uid, cids, next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
isModerators: function(next) {
|
|
|
|
|
|
|
|
user.isModerator(uid, cids, next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
isAdmin: function(next) {
|
|
|
|
|
|
|
|
user.isAdministrator(uid, next);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, function(err, results) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
return next(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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]);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tids = topicsData.filter(function(topic) {
|
|
|
|
var isModOf = {};
|
|
|
|
return cids.indexOf(topic.cid) !== -1 &&
|
|
|
|
cids = cids.filter(function(cid, index) {
|
|
|
|
(parseInt(topic.deleted, 10) !== 1 || results.isAdmin || isModOf[topic.cid]);
|
|
|
|
isModOf[cid] = results.isModerators[index];
|
|
|
|
}).map(function(topic) {
|
|
|
|
return !results.categories[index].disabled &&
|
|
|
|
return topic.tid;
|
|
|
|
(results.allowedTo[index] || results.isAdmin || results.isModerators[index]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
plugins.fireHook('filter:privileges.topics.filter', {
|
|
|
|
tids = topicsData.filter(function(topic) {
|
|
|
|
privilege: privilege,
|
|
|
|
return cids.indexOf(topic.cid) !== -1 &&
|
|
|
|
uid: uid,
|
|
|
|
(parseInt(topic.deleted, 10) !== 1 || results.isAdmin || isModOf[topic.cid]);
|
|
|
|
tids: tids
|
|
|
|
}).map(function(topic) {
|
|
|
|
}, function(err, data) {
|
|
|
|
return topic.tid;
|
|
|
|
next(err, data ? data.tids : null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
plugins.fireHook('filter:privileges.topics.filter', {
|
|
|
|
|
|
|
|
privilege: privilege,
|
|
|
|
|
|
|
|
uid: uid,
|
|
|
|
|
|
|
|
tids: tids
|
|
|
|
|
|
|
|
}, function(err, data) {
|
|
|
|
|
|
|
|
next(err, data ? data.tids : null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
], callback);
|
|
|
|
], callback);
|
|
|
|