refactored groups and categories, groups no longer explodes when

attempting to add members to a whitelist that doesn't exist, isEmpty
checks (new methods!) and such...
This commit is contained in:
Julian Lam
2013-11-27 20:07:04 -05:00
parent 0a06f1ac7d
commit 8b62041d28
4 changed files with 68 additions and 16 deletions

View File

@@ -105,6 +105,22 @@
});
};
Groups.isEmpty = function(gid, callback) {
RDB.scard('gid:' + gid + ':members', function(err, numMembers) {
callback(err, numMembers === 0);
});
};
Groups.isEmptyByGroupName = function(groupName, callback) {
Groups.getGidFromName(groupName, function(err, gid) {
if (err || !gid) {
callback(new Error('gid-not-found'));
} else {
Groups.isEmpty(gid, callback);
}
});
};
Groups.exists = function(name, callback) {
async.parallel({
exists: function(next) {
@@ -169,7 +185,9 @@
Groups.joinByGroupName = function(groupName, uid, callback) {
Groups.getGidFromName(groupName, function(err, gid) {
if (err || !gid) {
callback(new Error('gid-not-found'));
Groups.create(groupName, '', function(err, groupObj) {
Groups.join(groupObj.gid, uid, callback);
});
} else {
Groups.join(gid, uid, callback);
}