removed privileges.posts.get from addPostData

privilege data is already available higher up
v1.18.x
barisusakli 9 years ago
parent 40e26d3b9d
commit 2d01fe78d0

@ -3,9 +3,8 @@
var topicsController = {}, var topicsController = {},
async = require('async'), async = require('async'),
S = require('string'), S = require('string'),
validator = require('validator'),
nconf = require('nconf'), nconf = require('nconf'),
qs = require('querystring'),
user = require('../user'), user = require('../user'),
meta = require('../meta'), meta = require('../meta'),
topics = require('../topics'), topics = require('../topics'),
@ -124,6 +123,8 @@ topicsController.get = function(req, res, callback) {
topicData.pageCount = pageCount; topicData.pageCount = pageCount;
topicData.currentPage = page; topicData.currentPage = page;
topics.modifyByPrivilege(topicData.posts, results.privileges);
plugins.fireHook('filter:controllers.topic.get', topicData, next); plugins.fireHook('filter:controllers.topic.get', topicData, next);
}); });
}, },

@ -59,6 +59,8 @@ function generateForTopic(req, res, next) {
return next(); return next();
} }
topics.modifyByPrivilege(topicData.posts, userPrivileges);
var description = topicData.posts.length ? topicData.posts[0].content : ''; var description = topicData.posts.length ? topicData.posts[0].content : '';
var image_url = topicData.posts.length ? topicData.posts[0].picture : ''; var image_url = topicData.posts.length ? topicData.posts[0].picture : '';
var author = topicData.posts.length ? topicData.posts[0].username : ''; var author = topicData.posts.length ? topicData.posts[0].username : '';

@ -15,12 +15,12 @@ module.exports = function(SocketTopics) {
} }
async.parallel({ async.parallel({
settings: function(next) {
user.getSettings(socket.uid, next);
},
privileges: function(next) { privileges: function(next) {
privileges.topics.get(data.tid, socket.uid, next); privileges.topics.get(data.tid, socket.uid, next);
}, },
settings: function(next) {
user.getSettings(socket.uid, next);
},
topic: function(next) { topic: function(next) {
topics.getTopicFields(data.tid, ['postcount', 'deleted'], next); topics.getTopicFields(data.tid, ['postcount', 'deleted'], next);
} }
@ -78,12 +78,15 @@ module.exports = function(SocketTopics) {
'downvote:disabled': function(next) { 'downvote:disabled': function(next) {
next(null, parseInt(meta.config['downvote:disabled'], 10) === 1); next(null, parseInt(meta.config['downvote:disabled'], 10) === 1);
} }
}, function(err, results) { }, function(err, topicData) {
if (results.mainPost) { if (err) {
results.posts = [results.mainPost].concat(results.posts); return callback(err);
} }
if (topicData.mainPost) {
callback(err, results); topicData.posts = [topicData.mainPost].concat(topicData.posts);
}
topics.modifyByPrivilege(topicData.posts, results.privileges);
callback(null, topicData);
}); });
}); });
}; };

@ -10,7 +10,6 @@ var async = require('async'),
user = require('../user'), user = require('../user'),
favourites = require('../favourites'), favourites = require('../favourites'),
posts = require('../posts'), posts = require('../posts'),
privileges = require('../privileges'),
meta = require('../meta'); meta = require('../meta');
module.exports = function(Topics) { module.exports = function(Topics) {
@ -109,9 +108,6 @@ module.exports = function(Topics) {
next(null, editorData); next(null, editorData);
}); });
}, },
privileges: function(next) {
privileges.posts.get(pids, uid, next);
},
parents: function(next) { parents: function(next) {
Topics.addParentPosts(postData, next); Topics.addParentPosts(postData, next);
} }
@ -129,14 +125,8 @@ module.exports = function(Topics) {
postObj.upvoted = results.voteData.upvotes[i]; postObj.upvoted = results.voteData.upvotes[i];
postObj.downvoted = results.voteData.downvotes[i]; postObj.downvoted = results.voteData.downvotes[i];
postObj.votes = postObj.votes || 0; postObj.votes = postObj.votes || 0;
postObj.display_moderator_tools = results.privileges[i].editable;
postObj.display_move_tools = results.privileges[i].move && postObj.index !== 0;
postObj.selfPost = !!parseInt(uid, 10) && parseInt(uid, 10) === parseInt(postObj.uid, 10); postObj.selfPost = !!parseInt(uid, 10) && parseInt(uid, 10) === parseInt(postObj.uid, 10);
if (postObj.deleted && !results.privileges[i].view_deleted) {
postObj.content = '[[topic:post_is_deleted]]';
}
// Username override for guests, if enabled // Username override for guests, if enabled
if (parseInt(meta.config.allowGuestHandles, 10) === 1 && parseInt(postObj.uid, 10) === 0 && postObj.handle) { if (parseInt(meta.config.allowGuestHandles, 10) === 1 && parseInt(postObj.uid, 10) === 0 && postObj.handle) {
postObj.user.username = validator.escape(postObj.handle); postObj.user.username = validator.escape(postObj.handle);
@ -148,6 +138,18 @@ module.exports = function(Topics) {
}); });
}; };
Topics.modifyByPrivilege = function(postData, topicPrivileges) {
postData.forEach(function(post) {
if (post) {
post.display_moderator_tools = topicPrivileges.isAdminOrMod || post.selfPost;
post.display_move_tools = topicPrivileges.isAdminOrMod && post.index !== 0;
if (post.deleted && !(topicPrivileges.isAdminOrMod || post.selfPost)) {
post.content = '[[topic:post_is_deleted]]';
}
}
});
};
Topics.addParentPosts = function(postData, callback) { Topics.addParentPosts = function(postData, callback) {
var parentPids = postData.map(function(postObj) { var parentPids = postData.map(function(postObj) {
return postObj && postObj.hasOwnProperty('toPid') ? parseInt(postObj.toPid, 10) : null; return postObj && postObj.hasOwnProperty('toPid') ? parseInt(postObj.toPid, 10) : null;

Loading…
Cancel
Save