better check for group exist, groups with different cases can no longer be created, #2588

v1.18.x
Julian Lam 10 years ago
parent 1e57c5d001
commit eb5b8ccec3

@ -88,6 +88,24 @@ module.exports = function(redisClient, module) {
});
};
module.isObjectFields = function(key, fields, callback) {
var multi = redisClient.multi();
for (var i=0; i<fields.length; ++i) {
multi.hexists(key, fields[i]);
}
multi.exec(function(err, results) {
if (err) {
return callback(err);
}
for (var i=0; i<results.length; ++i) {
results[i] = results[i] === 1;
}
callback(null, results);
});
};
module.deleteObjectField = function(key, field, callback) {
redisClient.hdel(key, field, function(err, res) {
callback(err);

@ -147,7 +147,7 @@ var async = require('async'),
return next(err);
}
if (options.expand) {
if (options.expand && uids.length) {
async.map(uids, user.getUserData, next);
} else {
next(err, uids);
@ -405,9 +405,29 @@ var async = require('async'),
Groups.exists = function(name, callback) {
if (Array.isArray(name)) {
db.isSetMembers('groups', name, callback);
var slugs = name.map(function(groupName) {
return utils.slugify(groupName);
});
async.parallel([
async.apply(db.isObjectFields, 'groupslug:groupname', slugs),
async.apply(db.isSetMembers, 'groups', name)
], function(err, results) {
if (err) {
return callback(err);
}
callback(null, results.map(function(pair) {
return pair[0] || pair[1];
}));
});
} else {
db.isSetMember('groups', name, callback);
var slug = utils.slugify(name);
async.parallel([
async.apply(db.isObjectField, 'groupslug:groupname', slug),
async.apply(db.isSetMember, 'groups', name)
], function(err, results) {
callback(err, !err ? (results[0] || results[1]) : null);
});
}
};

Loading…
Cancel
Save