truncating user list in Groups ACP page, resolved #1132. Refactored system groups handling

v1.18.x
Julian Lam 11 years ago
parent 3c5fc72e20
commit 4239c376c8

@ -208,6 +208,9 @@ define(function() {
} }
}); });
}); });
// Tooltips
$('#groups-list .members li').tooltip();
}; };
return Groups; return Groups;

@ -150,20 +150,11 @@ adminController.themes.get = function(req, res, next) {
}; };
adminController.groups.get = function(req, res, next) { adminController.groups.get = function(req, res, next) {
async.parallel([
function(next) {
groups.list({ groups.list({
expand: true expand: true,
}, next); showSystemGroups: true,
}, truncateUserList: true
function(next) { }, function(err, groups) {
groups.listSystemGroups({
expand: true
}, next);
}
], function(err, groupData) {
var groups = groupData[0].concat(groupData[1]);
res.render('admin/groups', { res.render('admin/groups', {
groups: groups, groups: groups,
yourid: req.user.uid yourid: req.user.uid

@ -15,18 +15,18 @@
db.getObjectValues('group:gid', function (err, gids) { db.getObjectValues('group:gid', function (err, gids) {
if (gids.length > 0) { if (gids.length > 0) {
async.map(gids, function (gid, next) { async.map(gids, function (gid, next) {
Groups.get(gid, { Groups.get(gid, options, next);
expand: options.expand
}, next);
}, function (err, groups) { }, function (err, groups) {
// Remove deleted and hidden groups from this list // Remove system, hidden, or deleted groups from this list
callback(err, groups.filter(function (group) { groups = groups.filter(function (group) {
if (parseInt(group.deleted, 10) === 1 || parseInt(group.hidden, 10) === 1) { if (group.deleted || (group.hidden && !group.system) || (!options.showSystemGroups && group.system)) {
return false; return false;
} else { } else {
return true; return true;
} }
})); });
callback(err, groups);
}); });
} else { } else {
callback(null, []); callback(null, []);
@ -34,32 +34,30 @@
}); });
}; };
Groups.listSystemGroups = function(options, callback) {
var systemGroups = ['administrators', 'registered-users'],
humanNames = ['Administrators', 'Registered Users'];
async.map(systemGroups, function(groupName, next) {
Groups.getByGroupName(groupName, options, function(err, groupObj) {
groupObj.name = humanNames[systemGroups.indexOf(groupObj.name)];
next(err, groupObj);
});
}, callback);
};
Groups.get = function(gid, options, callback) { Groups.get = function(gid, options, callback) {
var truncated = false,
numUsers;
async.parallel({ async.parallel({
base: function (next) { base: function (next) {
db.getObject('gid:' + gid, next); db.getObject('gid:' + gid, next);
}, },
users: function (next) { users: function (next) {
db.getSetMembers('gid:' + gid + ':members', function (err, uids) { db.getSetMembers('gid:' + gid + ':members', function (err, uids) {
if (options.expand) {
if (err) { if (err) {
return next(err); return next(err);
} }
async.map(uids, user.getUserData, next); if (options.truncateUserList) {
if (uids.length > 4) {
numUsers = uids.length;
uids.length = 4;
truncated = true;
}
}
if (options.expand) {
async.map(uids, user.getUserData, next);
} else { } else {
next(err, uids); next(err, uids);
} }
@ -72,8 +70,13 @@
results.base.count = results.users.length; results.base.count = results.users.length;
results.base.members = results.users; results.base.members = results.users;
results.base.memberCount = numUsers || results.users.length;
results.base.deletable = results.base.hidden !== '1'; results.base.deleted = !!parseInt(results.base.deleted, 10);
results.base.hidden = !!parseInt(results.base.hidden, 10);
results.base.system = !!parseInt(results.base.system, 10);
results.base.deletable = !results.base.system;
results.base.truncated = truncated;
callback(err, results.base); callback(err, results.base);
}); });
@ -197,6 +200,10 @@
return callback(new Error('name-too-short')); return callback(new Error('name-too-short'));
} }
if (name === 'administrators' || name === 'registered-users') {
var system = true;
}
Groups.exists(name, function (err, exists) { Groups.exists(name, function (err, exists) {
if (!exists) { if (!exists) {
db.incrObjectField('global', 'nextGid', function (err, gid) { db.incrObjectField('global', 'nextGid', function (err, gid) {
@ -207,7 +214,8 @@
name: name, name: name,
description: description, description: description,
deleted: '0', deleted: '0',
hidden: '0' hidden: '0',
system: system ? '1' : '0'
}; };
db.setObject('gid:' + gid, groupData, function(err) { db.setObject('gid:' + gid, groupData, function(err) {

@ -266,20 +266,14 @@ SocketAdmin.categories.setGroupPrivilege = function(socket, data, callback) {
}; };
SocketAdmin.categories.groupsList = function(socket, cid, callback) { SocketAdmin.categories.groupsList = function(socket, cid, callback) {
async.parallel({ groups.list({
groups: function(next) { expand: false,
groups.list({expand:false}, next); showSystemGroups: true
}, }, function(err, data) {
system: function(next) {
groups.listSystemGroups({expand: false}, next);
}
}, function(err, results) {
if(err) { if(err) {
return callback(err); return callback(err);
} }
var data = results.groups.concat(results.system);
async.map(data, function(groupObj, next) { async.map(data, function(groupObj, next) {
CategoryTools.groupPrivileges(cid, groupObj.gid, function(err, privileges) { CategoryTools.groupPrivileges(cid, groupObj.gid, function(err, privileges) {
if(err) { if(err) {

Loading…
Cancel
Save