diff --git a/src/groups.js b/src/groups.js index f1bd0085ab..8d678cc517 100644 --- a/src/groups.js +++ b/src/groups.js @@ -78,10 +78,12 @@ return callback(err); } + // User counts results.base.count = numUsers || results.users.length; results.base.members = results.users; results.base.memberCount = numUsers || results.users.length; + results.base.slug = utils.slugify(results.base.name); results.base.deleted = !!parseInt(results.base.deleted, 10); results.base.hidden = !!parseInt(results.base.hidden, 10); results.base.system = !!parseInt(results.base.system, 10); @@ -131,7 +133,20 @@ }; Groups.exists = function(name, callback) { - db.isSetMember('groups', name, callback); + name = utils.slugify(name); + db.getSetMembers('groups', function(err, groupNames) { + if (err) { + return callback(err); + } + + var matches = groupNames.map(function(groupName) { + return utils.slugify(groupName); + }).filter(function(groupName) { + return groupName === name; + }); + + callback(null, matches.length > 0 ? true : false); + }); }; Groups.create = function(name, description, callback) { diff --git a/tests/groups.js b/tests/groups.js index d7f56d4437..6a877a33e6 100644 --- a/tests/groups.js +++ b/tests/groups.js @@ -167,11 +167,12 @@ describe('Groups', function() { }); }); - it('should also check slugified name for existence', function(done) { + it('should properly resolve a non-slugified group to slugs', function(done) { Groups.exists('Test();', function(err, exists) { if (err) return done(err); assert.strictEqual(exists, true); + done(); }); }); });