diff --git a/src/controllers/admin.js b/src/controllers/admin.js index 65112ad229..9847d2d800 100644 --- a/src/controllers/admin.js +++ b/src/controllers/admin.js @@ -381,12 +381,7 @@ adminController.extend.rewards = function(req, res, next) { }; adminController.groups.get = function(req, res, next) { - groups.list({ - expand: true, - truncateUserList: true, - isAdmin: true, - showSystemGroups: true - }, function(err, groups) { + groups.list(req.uid, 0, -1, function(err, groups) { if (err) { return next(err); } diff --git a/src/controllers/groups.js b/src/controllers/groups.js index e3bdd500a6..01474aba64 100644 --- a/src/controllers/groups.js +++ b/src/controllers/groups.js @@ -9,11 +9,7 @@ var async = require('async'), groupsController = {}; groupsController.list = function(req, res, next) { - groups.list({ - truncateUserList: true, - expand: true, - uid: req.uid - }, function(err, groups) { + groups.list(req.uid, 0, -1, function(err, groups) { if (err) { return next(err); } diff --git a/src/groups.js b/src/groups.js index 17d39c413b..a36b6ae27b 100644 --- a/src/groups.js +++ b/src/groups.js @@ -80,8 +80,8 @@ var async = require('async'), return ephemeralGroups; }; - Groups.list = function(options, callback) { - db.getSortedSetRevRange('groups:createtime', 0, -1, function (err, groupNames) { + Groups.list = function(uid, start, stop, callback) { + db.getSortedSetRevRange('groups:createtime', start, stop, function (err, groupNames) { if (err) { return callback(err); } @@ -91,16 +91,25 @@ var async = require('async'), }); async.parallel({ - groups: async.apply(async.map, groupNames, function (groupName, next) { - Groups.get(groupName, options, next); - }), - isAdmin: function(next) { - if (!options.uid || parseInt(options.uid, 10) === 0) { return next(null, false); } - user.isAdministrator(parseInt(options.uid, 10), next); + groups: function(next) { + Groups.getGroupsData(groupNames, next); + }, + members: function(next) { + Groups.getMemberUsers(groupNames, 0, 3, next); } }, function (err, data) { - options.isAdmin = options.isAdmin || data.isAdmin; - callback(err, internals.filterGroups(data.groups, options)); + if (err) { + return callback(err); + } + data.groups.forEach(function(group, index) { + if (!group) { + return; + } + group.members = data.members[index] || []; + group.truncated = group.memberCount > data.members.length; + }); + + callback(null, data.groups); }); }); }; @@ -260,7 +269,6 @@ var async = require('async'), results.base.hidden = !!parseInt(results.base.hidden, 10); results.base.system = !!parseInt(results.base.system, 10); results.base.private = results.base.private ? !!parseInt(results.base.private, 10) : true; - results.base.deletable = !results.base.system; results.base.truncated = truncated; results.base.isMember = results.isMember; results.base.isPending = results.isPending; @@ -413,7 +421,8 @@ var async = require('async'), group.labelColor = group.labelColor || '#000000'; group.createtimeISO = utils.toISOString(group.createtime); group.hidden = parseInt(group.hidden, 10) === 1; - + group.system = parseInt(group.system, 10) === 1; + group.private = parseInt(group.private, 10) === 1; if (!group['cover:url']) { group['cover:url'] = nconf.get('relative_path') + '/images/cover-default.png'; group['cover:position'] = '50% 50%'; diff --git a/src/groups/membership.js b/src/groups/membership.js index 152029d6b1..451985e275 100644 --- a/src/groups/membership.js +++ b/src/groups/membership.js @@ -181,6 +181,18 @@ module.exports = function(Groups) { db.getSortedSetRevRange('group:' + groupName + ':members', start, stop, callback); }; + Groups.getMemberUsers = function(groupNames, start, stop, callback) { + async.map(groupNames, function(groupName, next) { + Groups.getMembers(groupName, start, stop, function(err, uids) { + if (err) { + return next(err); + } + + user.getMultipleUserFields(uids, ['uid', 'username', 'picture', 'userslug'], next); + }); + }, callback); + }; + Groups.getMembersOfGroups = function(groupNames, callback) { db.getSortedSetsMembers(groupNames.map(function(name) { return 'group:' + name + ':members'; diff --git a/src/views/admin/manage/groups.tpl b/src/views/admin/manage/groups.tpl index 26fe157dac..7dd0bfe5f5 100644 --- a/src/views/admin/manage/groups.tpl +++ b/src/views/admin/manage/groups.tpl @@ -2,7 +2,7 @@