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

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

@ -15,12 +15,12 @@ module.exports = function(SocketTopics) {
}
async.parallel({
settings: function(next) {
user.getSettings(socket.uid, next);
},
privileges: function(next) {
privileges.topics.get(data.tid, socket.uid, next);
},
settings: function(next) {
user.getSettings(socket.uid, next);
},
topic: function(next) {
topics.getTopicFields(data.tid, ['postcount', 'deleted'], next);
}
@ -78,12 +78,15 @@ module.exports = function(SocketTopics) {
'downvote:disabled': function(next) {
next(null, parseInt(meta.config['downvote:disabled'], 10) === 1);
}
}, function(err, results) {
if (results.mainPost) {
results.posts = [results.mainPost].concat(results.posts);
}, function(err, topicData) {
if (err) {
return callback(err);
}
callback(err, results);
if (topicData.mainPost) {
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'),
favourites = require('../favourites'),
posts = require('../posts'),
privileges = require('../privileges'),
meta = require('../meta');
module.exports = function(Topics) {
@ -109,9 +108,6 @@ module.exports = function(Topics) {
next(null, editorData);
});
},
privileges: function(next) {
privileges.posts.get(pids, uid, next);
},
parents: function(next) {
Topics.addParentPosts(postData, next);
}
@ -129,14 +125,8 @@ module.exports = function(Topics) {
postObj.upvoted = results.voteData.upvotes[i];
postObj.downvoted = results.voteData.downvotes[i];
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);
if (postObj.deleted && !results.privileges[i].view_deleted) {
postObj.content = '[[topic:post_is_deleted]]';
}
// Username override for guests, if enabled
if (parseInt(meta.config.allowGuestHandles, 10) === 1 && parseInt(postObj.uid, 10) === 0 && 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) {
var parentPids = postData.map(function(postObj) {
return postObj && postObj.hasOwnProperty('toPid') ? parseInt(postObj.toPid, 10) : null;

Loading…
Cancel
Save