mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-05 03:51:26 +01:00
closes #4499
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
winston = require('winston'),
|
||||
validator = require('validator'),
|
||||
_ = require('underscore'),
|
||||
var async = require('async');
|
||||
var winston = require('winston');
|
||||
var validator = require('validator');
|
||||
var _ = require('underscore');
|
||||
|
||||
db = require('../database'),
|
||||
posts = require('../posts'),
|
||||
topics = require('../topics'),
|
||||
privileges = require('../privileges');
|
||||
var db = require('../database');
|
||||
var posts = require('../posts');
|
||||
var topics = require('../topics');
|
||||
var privileges = require('../privileges');
|
||||
|
||||
module.exports = function(Categories) {
|
||||
|
||||
Categories.getRecentReplies = function(cid, uid, count, callback) {
|
||||
if (!parseInt(count, 10)) {
|
||||
return callback(null, []);
|
||||
|
||||
@@ -349,7 +349,9 @@ var utils = require('../public/src/utils');
|
||||
|
||||
Groups.getLatestMemberPosts = function(groupName, max, uid, callback) {
|
||||
async.waterfall([
|
||||
async.apply(Groups.getMembers, groupName, 0, -1),
|
||||
function(next) {
|
||||
Groups.getMembers(groupName, 0, -1, next);
|
||||
},
|
||||
function(uids, next) {
|
||||
if (!Array.isArray(uids) || !uids.length) {
|
||||
return callback(null, []);
|
||||
|
||||
16
src/posts.js
16
src/posts.js
@@ -1,14 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
_ = require('underscore'),
|
||||
var async = require('async');
|
||||
var _ = require('underscore');
|
||||
|
||||
db = require('./database'),
|
||||
utils = require('../public/src/utils'),
|
||||
user = require('./user'),
|
||||
topics = require('./topics'),
|
||||
privileges = require('./privileges'),
|
||||
plugins = require('./plugins');
|
||||
var db = require('./database');
|
||||
var utils = require('../public/src/utils');
|
||||
var user = require('./user');
|
||||
var topics = require('./topics');
|
||||
var privileges = require('./privileges');
|
||||
var plugins = require('./plugins');
|
||||
|
||||
(function(Posts) {
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
topics = require('../topics');
|
||||
var async = require('async');
|
||||
var topics = require('../topics');
|
||||
|
||||
module.exports = function(Posts) {
|
||||
|
||||
@@ -13,7 +13,7 @@ module.exports = function(Posts) {
|
||||
},
|
||||
function(tid, next) {
|
||||
topics.getTopicField(tid, 'cid', next);
|
||||
}
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
validator = require('validator'),
|
||||
S = require('string'),
|
||||
var async = require('async');
|
||||
var validator = require('validator');
|
||||
var S = require('string');
|
||||
|
||||
db = require('../database'),
|
||||
user = require('../user'),
|
||||
plugins = require('../plugins'),
|
||||
categories = require('../categories'),
|
||||
utils = require('../../public/src/utils');
|
||||
var db = require('../database');
|
||||
var user = require('../user');
|
||||
var plugins = require('../plugins');
|
||||
var categories = require('../categories');
|
||||
var utils = require('../../public/src/utils');
|
||||
|
||||
|
||||
module.exports = function(Posts) {
|
||||
@@ -30,9 +30,7 @@ module.exports = function(Posts) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
posts = posts.filter(function(p) {
|
||||
return !!p && parseInt(p.deleted, 10) !== 1;
|
||||
});
|
||||
posts = posts.filter(Boolean);
|
||||
|
||||
var uids = [], topicKeys = [];
|
||||
for(var i=0; i<posts.length; ++i) {
|
||||
@@ -66,10 +64,11 @@ module.exports = function(Posts) {
|
||||
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].isMainPost = posts[i].index - 1 === 0;
|
||||
posts[i].deleted = parseInt(posts[i].deleted, 10) === 1;
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -251,6 +251,21 @@ module.exports = function(privileges) {
|
||||
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({
|
||||
categories: function(next) {
|
||||
categories.getCategoriesFields(cids, ['disabled'], next);
|
||||
@@ -264,18 +279,7 @@ module.exports = function(privileges) {
|
||||
isAdmin: function(next) {
|
||||
user.isAdministrator(uid, next);
|
||||
}
|
||||
}, 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));
|
||||
});
|
||||
}, callback);
|
||||
};
|
||||
|
||||
privileges.categories.filterUids = function(privilege, cid, uids, callback) {
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
@@ -87,11 +122,11 @@ module.exports = function(privileges) {
|
||||
privilege: privilege,
|
||||
uid: uid,
|
||||
pids: pids
|
||||
}, function(err, data) {
|
||||
callback(err, data ? data.pids : null);
|
||||
}, function(err, data) {
|
||||
next(err, data ? data.pids : null);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
privileges.posts.canEdit = function(pid, uid, callback) {
|
||||
|
||||
@@ -70,56 +70,44 @@ module.exports = function(privileges) {
|
||||
if (!Array.isArray(tids) || !tids.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
var cids;
|
||||
var topicsData;
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
topics.getTopicsFields(tids, ['tid', 'cid', 'deleted'], next);
|
||||
},
|
||||
function(topicsData, next) {
|
||||
var cids = topicsData.map(function(topic) {
|
||||
function(_topicsData, next) {
|
||||
topicsData = _topicsData;
|
||||
cids = topicsData.map(function(topic) {
|
||||
return topic.cid;
|
||||
}).filter(function(cid, index, array) {
|
||||
return cid && array.indexOf(cid) === index;
|
||||
});
|
||||
|
||||
async.parallel({
|
||||
categories: function(next) {
|
||||
categories.getCategoriesFields(cids, ['disabled'], 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]);
|
||||
});
|
||||
privileges.categories.getBase(privilege, cids, uid, next);
|
||||
},
|
||||
function(results, next) {
|
||||
|
||||
tids = topicsData.filter(function(topic) {
|
||||
return cids.indexOf(topic.cid) !== -1 &&
|
||||
(parseInt(topic.deleted, 10) !== 1 || results.isAdmin || isModOf[topic.cid]);
|
||||
}).map(function(topic) {
|
||||
return topic.tid;
|
||||
});
|
||||
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]);
|
||||
});
|
||||
|
||||
plugins.fireHook('filter:privileges.topics.filter', {
|
||||
privilege: privilege,
|
||||
uid: uid,
|
||||
tids: tids
|
||||
}, function(err, data) {
|
||||
next(err, data ? data.tids : null);
|
||||
});
|
||||
tids = topicsData.filter(function(topic) {
|
||||
return cids.indexOf(topic.cid) !== -1 &&
|
||||
(parseInt(topic.deleted, 10) !== 1 || results.isAdmin || isModOf[topic.cid]);
|
||||
}).map(function(topic) {
|
||||
return topic.tid;
|
||||
});
|
||||
|
||||
plugins.fireHook('filter:privileges.topics.filter', {
|
||||
privilege: privilege,
|
||||
uid: uid,
|
||||
tids: tids
|
||||
}, function(err, data) {
|
||||
next(err, data ? data.tids : null);
|
||||
});
|
||||
}
|
||||
], callback);
|
||||
|
||||
@@ -118,8 +118,8 @@ function loadMorePosts(set, uid, data, callback) {
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
var start = Math.max(0, parseInt(data.after, 10)),
|
||||
stop = start + 9;
|
||||
var start = Math.max(0, parseInt(data.after, 10));
|
||||
var stop = start + 9;
|
||||
|
||||
posts.getPostSummariesFromSet(set, uid, start, stop, callback);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user