groups.list added start stop

v1.18.x
Barış Soner Uşaklı 10 years ago
parent a065a73637
commit 8117b4459a

@ -381,12 +381,7 @@ adminController.extend.rewards = function(req, res, next) {
}; };
adminController.groups.get = function(req, res, next) { adminController.groups.get = function(req, res, next) {
groups.list({ groups.list(req.uid, 0, -1, function(err, groups) {
expand: true,
truncateUserList: true,
isAdmin: true,
showSystemGroups: true
}, function(err, groups) {
if (err) { if (err) {
return next(err); return next(err);
} }

@ -9,11 +9,7 @@ var async = require('async'),
groupsController = {}; groupsController = {};
groupsController.list = function(req, res, next) { groupsController.list = function(req, res, next) {
groups.list({ groups.list(req.uid, 0, -1, function(err, groups) {
truncateUserList: true,
expand: true,
uid: req.uid
}, function(err, groups) {
if (err) { if (err) {
return next(err); return next(err);
} }

@ -80,8 +80,8 @@ var async = require('async'),
return ephemeralGroups; return ephemeralGroups;
}; };
Groups.list = function(options, callback) { Groups.list = function(uid, start, stop, callback) {
db.getSortedSetRevRange('groups:createtime', 0, -1, function (err, groupNames) { db.getSortedSetRevRange('groups:createtime', start, stop, function (err, groupNames) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
@ -91,16 +91,25 @@ var async = require('async'),
}); });
async.parallel({ async.parallel({
groups: async.apply(async.map, groupNames, function (groupName, next) { groups: function(next) {
Groups.get(groupName, options, next); Groups.getGroupsData(groupNames, next);
}), },
isAdmin: function(next) { members: function(next) {
if (!options.uid || parseInt(options.uid, 10) === 0) { return next(null, false); } Groups.getMemberUsers(groupNames, 0, 3, next);
user.isAdministrator(parseInt(options.uid, 10), next);
} }
}, function (err, data) { }, function (err, data) {
options.isAdmin = options.isAdmin || data.isAdmin; if (err) {
callback(err, internals.filterGroups(data.groups, options)); 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.hidden = !!parseInt(results.base.hidden, 10);
results.base.system = !!parseInt(results.base.system, 10); results.base.system = !!parseInt(results.base.system, 10);
results.base.private = results.base.private ? !!parseInt(results.base.private, 10) : true; results.base.private = results.base.private ? !!parseInt(results.base.private, 10) : true;
results.base.deletable = !results.base.system;
results.base.truncated = truncated; results.base.truncated = truncated;
results.base.isMember = results.isMember; results.base.isMember = results.isMember;
results.base.isPending = results.isPending; results.base.isPending = results.isPending;
@ -413,7 +421,8 @@ var async = require('async'),
group.labelColor = group.labelColor || '#000000'; group.labelColor = group.labelColor || '#000000';
group.createtimeISO = utils.toISOString(group.createtime); group.createtimeISO = utils.toISOString(group.createtime);
group.hidden = parseInt(group.hidden, 10) === 1; 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']) { if (!group['cover:url']) {
group['cover:url'] = nconf.get('relative_path') + '/images/cover-default.png'; group['cover:url'] = nconf.get('relative_path') + '/images/cover-default.png';
group['cover:position'] = '50% 50%'; group['cover:position'] = '50% 50%';

@ -181,6 +181,18 @@ module.exports = function(Groups) {
db.getSortedSetRevRange('group:' + groupName + ':members', start, stop, callback); 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) { Groups.getMembersOfGroups = function(groupNames, callback) {
db.getSortedSetsMembers(groupNames.map(function(name) { db.getSortedSetsMembers(groupNames.map(function(name) {
return 'group:' + name + ':members'; return 'group:' + name + ':members';

@ -18,9 +18,9 @@
<div class="btn-group"> <div class="btn-group">
<button class="btn btn-default" data-action="members">Edit</button> <button class="btn btn-default" data-action="members">Edit</button>
<!-- IF groups.deletable --> <!-- IF !groups.system -->
<button class="btn btn-danger" data-action="delete">Delete Group</button> <button class="btn btn-danger" data-action="delete">Delete Group</button>
<!-- ENDIF groups.deletable --> <!-- ENDIF !groups.system -->
</div> </div>
</div> </div>
<div class="col-lg-4"> <div class="col-lg-4">

Loading…
Cancel
Save