This commit is contained in:
Baris Usakli
2017-08-02 13:03:34 -04:00
parent 5fc6fe1c80
commit de55c8e431
7 changed files with 88 additions and 48 deletions

View File

@@ -1,6 +1,7 @@
'use strict';
var async = require('async');
var validator = require('validator');
var db = require('../../database');
var groups = require('../../groups');
@@ -16,12 +17,9 @@ groupsController.list = function (req, res, next) {
async.waterfall([
function (next) {
db.getSortedSetRange('groups:createtime', 0, -1, next);
getGroupNames(next);
},
function (groupNames, next) {
groupNames = groupNames.filter(function (name) {
return name.indexOf(':privileges:') === -1 && name !== 'registered-users';
});
pageCount = Math.ceil(groupNames.length / groupsPerPage);
var start = (page - 1) * groupsPerPage;
@@ -44,20 +42,48 @@ groupsController.get = function (req, res, callback) {
var groupName = req.params.name;
async.waterfall([
function (next) {
groups.exists(groupName, next);
async.parallel({
groupNames: function (next) {
getGroupNames(next);
},
group: function (next) {
groups.get(groupName, { uid: req.uid, truncateUserList: true, userListCount: 20 }, next);
},
}, next);
},
function (exists, next) {
if (!exists) {
function (result) {
if (!result.group) {
return callback();
}
groups.get(groupName, { uid: req.uid, truncateUserList: true, userListCount: 20 }, next);
},
function (group) {
group.isOwner = true;
result.group.isOwner = true;
result.groupNames = result.groupNames.map(function (name) {
return {
encodedName: encodeURIComponent(name),
displayName: validator.escape(String(name)),
selected: name === groupName,
};
});
res.render('admin/manage/group', {
group: group,
group: result.group,
groupNames: result.groupNames,
allowPrivateGroups: parseInt(meta.config.allowPrivateGroups, 10) === 1,
});
},
], callback);
};
function getGroupNames(callback) {
async.waterfall([
function (next) {
db.getSortedSetRange('groups:createtime', 0, -1, next);
},
function (groupNames, next) {
groupNames = groupNames.filter(function (name) {
return name !== 'registered-users' && !groups.isPrivilegeGroup(name);
});
next(null, groupNames);
},
], callback);
}