v1.18.x
barisusakli 9 years ago
parent cb1920d45a
commit 5e5e46e95f

@ -1,17 +1,18 @@
'use strict'; 'use strict';
var async = require('async'), var async = require('async');
winston = require('winston'), var winston = require('winston');
validator = require('validator'), var validator = require('validator');
_ = require('underscore'), var _ = require('underscore');
db = require('../database'), var db = require('../database');
posts = require('../posts'), var posts = require('../posts');
topics = require('../topics'), var topics = require('../topics');
privileges = require('../privileges'); var privileges = require('../privileges');
module.exports = function(Categories) { module.exports = function(Categories) {
Categories.getRecentReplies = function(cid, uid, count, callback) { Categories.getRecentReplies = function(cid, uid, count, callback) {
if (!parseInt(count, 10)) { if (!parseInt(count, 10)) {
return callback(null, []); return callback(null, []);

@ -349,7 +349,9 @@ var utils = require('../public/src/utils');
Groups.getLatestMemberPosts = function(groupName, max, uid, callback) { Groups.getLatestMemberPosts = function(groupName, max, uid, callback) {
async.waterfall([ async.waterfall([
async.apply(Groups.getMembers, groupName, 0, -1), function(next) {
Groups.getMembers(groupName, 0, -1, next);
},
function(uids, next) { function(uids, next) {
if (!Array.isArray(uids) || !uids.length) { if (!Array.isArray(uids) || !uids.length) {
return callback(null, []); return callback(null, []);

@ -1,14 +1,14 @@
'use strict'; 'use strict';
var async = require('async'), var async = require('async');
_ = require('underscore'), var _ = require('underscore');
db = require('./database'), var db = require('./database');
utils = require('../public/src/utils'), var utils = require('../public/src/utils');
user = require('./user'), var user = require('./user');
topics = require('./topics'), var topics = require('./topics');
privileges = require('./privileges'), var privileges = require('./privileges');
plugins = require('./plugins'); var plugins = require('./plugins');
(function(Posts) { (function(Posts) {

@ -1,8 +1,8 @@
'use strict'; 'use strict';
var async = require('async'), var async = require('async');
topics = require('../topics'); var topics = require('../topics');
module.exports = function(Posts) { module.exports = function(Posts) {
@ -13,7 +13,7 @@ module.exports = function(Posts) {
}, },
function(tid, next) { function(tid, next) {
topics.getTopicField(tid, 'cid', next); topics.getTopicField(tid, 'cid', next);
} }
], callback); ], callback);
}; };

@ -1,15 +1,15 @@
'use strict'; 'use strict';
var async = require('async'), var async = require('async');
validator = require('validator'), var validator = require('validator');
S = require('string'), var S = require('string');
db = require('../database'), var db = require('../database');
user = require('../user'), var user = require('../user');
plugins = require('../plugins'), var plugins = require('../plugins');
categories = require('../categories'), var categories = require('../categories');
utils = require('../../public/src/utils'); var utils = require('../../public/src/utils');
module.exports = function(Posts) { module.exports = function(Posts) {
@ -30,9 +30,7 @@ module.exports = function(Posts) {
return callback(err); return callback(err);
} }
posts = posts.filter(function(p) { posts = posts.filter(Boolean);
return !!p && parseInt(p.deleted, 10) !== 1;
});
var uids = [], topicKeys = []; var uids = [], topicKeys = [];
for(var i=0; i<posts.length; ++i) { for(var i=0; i<posts.length; ++i) {
@ -66,10 +64,11 @@ module.exports = function(Posts) {
for (var i=0; i<posts.length; ++i) { for (var i=0; i<posts.length; ++i) {
posts[i].index = utils.isNumber(results.indices[i]) ? parseInt(results.indices[i], 10) + 1 : 1; posts[i].index = utils.isNumber(results.indices[i]) ? parseInt(results.indices[i], 10) + 1 : 1;
posts[i].isMainPost = posts[i].index - 1 === 0; posts[i].isMainPost = posts[i].index - 1 === 0;
posts[i].deleted = parseInt(posts[i].deleted, 10) === 1;
} }
posts = posts.filter(function(post) { posts = posts.filter(function(post) {
return results.topics[post.tid] && parseInt(results.topics[post.tid].deleted, 10) !== 1; return results.topics[post.tid];
}); });
async.map(posts, function(post, next) { async.map(posts, function(post, next) {

@ -251,6 +251,21 @@ module.exports = function(privileges) {
return array.indexOf(cid) === index; return array.indexOf(cid) === index;
}); });
privileges.categories.getBase(privilege, cids, uid, function(err, results) {
if (err) {
return callback(err);
}
cids = cids.filter(function(cid, index) {
return !results.categories[index].disabled &&
(results.allowedTo[index] || results.isAdmin || results.isModerators[index]);
});
callback(null, cids.filter(Boolean));
});
};
privileges.categories.getBase = function(privilege, cids, uid, callback) {
async.parallel({ async.parallel({
categories: function(next) { categories: function(next) {
categories.getCategoriesFields(cids, ['disabled'], next); categories.getCategoriesFields(cids, ['disabled'], next);
@ -264,18 +279,7 @@ module.exports = function(privileges) {
isAdmin: function(next) { isAdmin: function(next) {
user.isAdministrator(uid, next); user.isAdministrator(uid, next);
} }
}, function(err, results) { }, callback);
if (err) {
return callback(err);
}
cids = cids.filter(function(cid, index) {
return !results.categories[index].disabled &&
(results.allowedTo[index] || results.isAdmin || results.isModerators[index]);
});
callback(null, cids.filter(Boolean));
});
}; };
privileges.categories.filterUids = function(privilege, cid, uids, callback) { privileges.categories.filterUids = function(privilege, cid, uids, callback) {

@ -63,22 +63,57 @@ module.exports = function(privileges) {
if (!Array.isArray(pids) || !pids.length) { if (!Array.isArray(pids) || !pids.length) {
return callback(null, []); return callback(null, []);
} }
posts.getCidsByPids(pids, function(err, cids) { var cids;
if (err) { var postData;
return callback(err); var tids;
} var tidToTopic = {};
pids = pids.map(function(pid, index) { async.waterfall([
return {pid: pid, cid: cids[index]}; 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) { topicData.forEach(function(topic, index) {
if (err) { if (topic) {
return callback(err); tidToTopic[tids[index]] = topic;
} }
});
pids = pids.filter(function(post) { cids = postData.map(function(post, index) {
return cids.indexOf(post.cid) !== -1; 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) { }).map(function(post) {
return post.pid; return post.pid;
}); });
@ -87,11 +122,11 @@ module.exports = function(privileges) {
privilege: privilege, privilege: privilege,
uid: uid, uid: uid,
pids: pids pids: pids
}, function(err, data) { }, function(err, data) {
callback(err, data ? data.pids : null); next(err, data ? data.pids : null);
}); });
}); }
}); ], callback);
}; };
privileges.posts.canEdit = function(pid, uid, callback) { privileges.posts.canEdit = function(pid, uid, callback) {

@ -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);

@ -118,8 +118,8 @@ function loadMorePosts(set, uid, data, callback) {
return callback(new Error('[[error:invalid-data]]')); return callback(new Error('[[error:invalid-data]]'));
} }
var start = Math.max(0, parseInt(data.after, 10)), var start = Math.max(0, parseInt(data.after, 10));
stop = start + 9; var stop = start + 9;
posts.getPostSummariesFromSet(set, uid, start, stop, callback); posts.getPostSummariesFromSet(set, uid, start, stop, callback);
} }

Loading…
Cancel
Save