mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-12 17:05:51 +01:00
fix moderators
This commit is contained in:
@@ -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.getCategories(cids, uid, function(err, categories) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
categories = categories.filter(function(category) {
|
categories = categories.filter(function(category) {
|
||||||
return !category.disabled;
|
return !category.disabled;
|
||||||
});
|
});
|
||||||
|
next(null, categories);
|
||||||
callback(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, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user