From d8df9ab3edeb8f858fb89cd935070e5db4a49e62 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Wed, 9 Apr 2014 14:11:03 -0400 Subject: [PATCH] reverting groups.js to 4701eb1cee1a35b7f059f4362773bd9d67b7370c --- src/groups.js | 66 +++++++++++---------------------------------------- 1 file changed, 14 insertions(+), 52 deletions(-) diff --git a/src/groups.js b/src/groups.js index 8d678cc517..c12deaacd1 100644 --- a/src/groups.js +++ b/src/groups.js @@ -4,23 +4,7 @@ var async = require('async'), winston = require('winston'), user = require('./user'), - db = require('./database'), - utils = require('../public/src/utils'), - - filterGroups = function(groups, options) { - // Remove system, hidden, or deleted groups from this list - if (groups && !options.showAllGroups) { - return groups.filter(function (group) { - if (group.deleted || (group.hidden && !group.system) || (!options.showSystemGroups && group.system)) { - return false; - } else { - return true; - } - }); - } else { - return groups; - } - }; + db = require('./database'); Groups.list = function(options, callback) { db.getSetMembers('groups', function (err, groupNames) { @@ -28,7 +12,18 @@ async.map(groupNames, function (groupName, next) { Groups.get(groupName, options, next); }, function (err, groups) { - callback(err, filterGroups(groups, options)); + // Remove system, hidden, or deleted groups from this list + if (!options.showAllGroups) { + groups = groups.filter(function (group) { + if (group.deleted || (group.hidden && !group.system) || (!options.showSystemGroups && group.system)) { + return false; + } else { + return true; + } + }); + } + + callback(err, groups); }); } else { callback(null, []); @@ -78,12 +73,10 @@ 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); @@ -94,24 +87,6 @@ }); }; - Groups.search = function(query, options, callback) { - if (query.length) { - db.getSetMembers('groups', function(err, groups) { - groups = groups.filter(function(groupName) { - return groupName.match(new RegExp(utils.escapeRegexChars(query), 'i')); - }); - - async.map(groups, function(groupName, next) { - Groups.get(groupName, options, next); - }, function(err, groups) { - callback(err, filterGroups(groups, options)); - }); - }); - } else { - callback(null, []); - } - }; - Groups.isMember = function(uid, groupName, callback) { db.isSetMember('group:' + groupName + ':members', uid, callback); }; @@ -133,20 +108,7 @@ }; Groups.exists = function(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); - }); + db.isSetMember('groups', name, callback); }; Groups.create = function(name, description, callback) {