Skip to content

Commit

Permalink
permission fix for popular page
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Jul 31, 2014
1 parent aa4089e commit 7bfec99
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions src/topics/popular.js
Expand Up @@ -2,7 +2,8 @@
'use strict';

var async = require('async'),
db = require('./../database');
db = require('../database'),
privileges = require('../privileges');


module.exports = function(Topics) {
Expand All @@ -17,13 +18,31 @@ module.exports = function(Topics) {

var since = terms[term] || 'day';

Topics.getLatestTids(0, -1, since, function(err, tids) {
if (err) {
return callback(err);
}
async.waterfall([
function(next) {
Topics.getLatestTids(0, -1, since, next);
},
function(tids, next) {
getTopics(tids, uid, next);
},
function(topics, next) {
var tids = topics.map(function(topic) {
return topic.tid;
});

getTopics(tids, uid, callback);
});
privileges.topics.filter('read', tids, uid, function(err, tids) {
if (err) {
return next(err);
}

topics = topics.filter(function(topic) {
return tids.indexOf(topic.tid) !== -1;
});

next(null, topics);
});
}
], callback);
};

function getTopics(tids, uid, callback) {
Expand All @@ -32,6 +51,10 @@ module.exports = function(Topics) {
});

db.getObjectsFields(keys, ['tid', 'postcount'], function(err, topics) {
if (err) {
return callback(err);
}

topics.sort(function(a, b) {
return parseInt(b.postcount, 10) - parseInt(a.postcount, 10);
});
Expand Down

0 comments on commit 7bfec99

Please sign in to comment.