mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 18:16:17 +01:00
fix topics.loadMore so it checks read permission
This commit is contained in:
@@ -342,20 +342,31 @@ SocketTopics.loadMore = function(socket, data, callback) {
|
|||||||
return callback(new Error('[[error:invalid-data]]'));
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
user.getSettings(socket.uid, function(err, settings) {
|
async.parallel({
|
||||||
if(err) {
|
settings: function(next) {
|
||||||
|
user.getSettings(socket.uid, next);
|
||||||
|
},
|
||||||
|
privileges: function(next) {
|
||||||
|
privileges.topics.get(data.tid, socket.uid, next);
|
||||||
|
}
|
||||||
|
}, function(err, results) {
|
||||||
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!results.privileges.read) {
|
||||||
|
return callback(new Error('[[error:no-privileges]]'));
|
||||||
|
}
|
||||||
|
|
||||||
var start = Math.max(parseInt(data.after, 10) - 1, 0),
|
var start = Math.max(parseInt(data.after, 10) - 1, 0),
|
||||||
end = start + settings.postsPerPage - 1;
|
end = start + results.settings.postsPerPage - 1;
|
||||||
|
|
||||||
var set = 'tid:' + data.tid + ':posts',
|
var set = 'tid:' + data.tid + ':posts',
|
||||||
reverse = false;
|
reverse = false;
|
||||||
|
|
||||||
if (settings.topicPostSort === 'newest_to_oldest') {
|
if (results.settings.topicPostSort === 'newest_to_oldest') {
|
||||||
reverse = true;
|
reverse = true;
|
||||||
} else if (settings.topicPostSort === 'most_votes') {
|
} else if (results.settings.topicPostSort === 'most_votes') {
|
||||||
reverse = true;
|
reverse = true;
|
||||||
set = 'tid:' + data.tid + ':posts:votes';
|
set = 'tid:' + data.tid + ':posts:votes';
|
||||||
}
|
}
|
||||||
@@ -365,7 +376,7 @@ SocketTopics.loadMore = function(socket, data, callback) {
|
|||||||
topics.getTopicPosts(data.tid, set, start, end, socket.uid, reverse, next);
|
topics.getTopicPosts(data.tid, set, start, end, socket.uid, reverse, next);
|
||||||
},
|
},
|
||||||
privileges: function(next) {
|
privileges: function(next) {
|
||||||
privileges.topics.get(data.tid, socket.uid, next);
|
next(null, results.privileges);
|
||||||
},
|
},
|
||||||
'reputation:disabled': function(next) {
|
'reputation:disabled': function(next) {
|
||||||
next(null, parseInt(meta.config['reputation:disabled'], 10) === 1);
|
next(null, parseInt(meta.config['reputation:disabled'], 10) === 1);
|
||||||
|
|||||||
@@ -413,8 +413,12 @@ var async = require('async'),
|
|||||||
};
|
};
|
||||||
|
|
||||||
Topics.isOwner = function(tid, uid, callback) {
|
Topics.isOwner = function(tid, uid, callback) {
|
||||||
|
uid = parseInt(uid, 10);
|
||||||
|
if (uid === 0) {
|
||||||
|
return callback(null, false);
|
||||||
|
}
|
||||||
Topics.getTopicField(tid, 'uid', function(err, author) {
|
Topics.getTopicField(tid, 'uid', function(err, author) {
|
||||||
callback(err, parseInt(author, 10) === parseInt(uid, 10));
|
callback(err, parseInt(author, 10) === uid);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user