fix moderators

v1.18.x
barisusakli 10 years ago
parent 8294aec5e7
commit 420aa5e102

@ -84,22 +84,19 @@ var async = require('async'),
}; };
Categories.getPageCount = function(cid, uid, callback) { Categories.getPageCount = function(cid, uid, callback) {
Categories.getCategoryField(cid, 'topic_count', function(err, topicCount) { async.parallel({
topicCount: async.apply(Categories.getCategoryField, cid, 'topic_count'),
settings: async.apply(user.getSettings, uid)
}, function(err, results) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
if (parseInt(topicCount, 10) === 0) { if (!parseInt(results.topicCount, 10)) {
return callback(null, 1); return callback(null, 1);
} }
user.getSettings(uid, function(err, settings) { callback(null, Math.ceil(parseInt(results.topicCount, 10) / results.settings.topicsPerPage));
if (err) {
return callback(err);
}
callback(null, Math.ceil(parseInt(topicCount, 10) / settings.topicsPerPage));
});
}); });
}; };
@ -118,49 +115,32 @@ var async = require('async'),
}; };
Categories.getCategoriesByPrivilege = function(uid, privilege, callback) { Categories.getCategoriesByPrivilege = function(uid, privilege, callback) {
db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) { async.waterfall([
if (err) { function(next) {
return callback(err); db.getSortedSetRange('categories:cid', 0, -1, next);
} },
function(cids, next) {
if (!Array.isArray(cids) || !cids.length) { privileges.categories.filterCids(privilege, cids, uid, next);
return callback(null, []); },
} function(cids, next) {
Categories.getCategories(cids, uid, next);
privileges.categories.filterCids(privilege, cids, uid, function(err, cids) { },
if (err) { function(categories, next) {
return callback(err); categories = categories.filter(function(category) {
} return !category.disabled;
Categories.getCategories(cids, uid, function(err, categories) {
if (err) {
return callback(err);
}
categories = categories.filter(function(category) {
return !category.disabled;
});
callback(null, categories);
}); });
}); next(null, categories);
}); }
], callback);
}; };
Categories.getModerators = function(cid, callback) { Categories.getModerators = function(cid, callback) {
Groups.get('cid:' + cid + ':privileges:mods', {}, function(err, groupObj) { Groups.getMembers('cid:' + cid + ':privileges:mods', function(err, uids) {
if (err && err === 'group-not-found') { if (err || !Array.isArray(uids) || !uids.length) {
return callback(null, []);
}
if (err) {
return callback(err); return callback(err);
} }
if (!Array.isArray(groupObj) || !groupObj.members.length) { user.getMultipleUserFields(uids, ['uid', 'username', 'userslug', 'picture'], callback);
return callback(null, []);
}
user.getMultipleUserFields(groupObj.members, ['uid', 'username', 'userslug', 'picture'], callback);
}); });
}; };

@ -140,6 +140,10 @@ var async = require('async'),
}); });
}; };
Groups.getMembers = function(groupName, callback) {
db.getSetMembers('group:' + groupName + ':members', callback);
};
Groups.search = function(query, options, callback) { Groups.search = function(query, options, callback) {
if (!query) { if (!query) {
return callback(null, []); return callback(null, []);

@ -70,7 +70,7 @@ module.exports = function(privileges) {
}; };
privileges.categories.filterCids = function(privilege, cids, uid, callback) { privileges.categories.filterCids = function(privilege, cids, uid, callback) {
if (!cids.length) { if (!Array.isArray(cids) || !cids.length) {
return callback(null, []); return callback(null, []);
} }

Loading…
Cancel
Save