Create user groups for ldap groups
This commit is contained in:
+24
-4
@@ -20,6 +20,7 @@ var assert = require('assert'),
|
||||
BoxError = require('./boxerror.js'),
|
||||
constants = require('./constants.js'),
|
||||
debug = require('debug')('box:externalldap'),
|
||||
groups = require('./groups.js'),
|
||||
ldap = require('ldapjs'),
|
||||
settings = require('./settings.js'),
|
||||
tasks = require('./tasks.js'),
|
||||
@@ -368,10 +369,29 @@ function sync(progressCallback, callback) {
|
||||
|
||||
debug(`Found ${ldapGroups.length} groups`);
|
||||
|
||||
// we ignore all errors here and just log them for now
|
||||
async.eachSeries(ldapGroups, function (group, iteratorCallback) {
|
||||
console.log(group);
|
||||
iteratorCallback();
|
||||
// we ignore all non internal errors here and just log them for now
|
||||
async.eachSeries(ldapGroups, function (ldapGroup, iteratorCallback) {
|
||||
console.log(ldapGroup);
|
||||
|
||||
var groupName = ldapGroup[externalLdapConfig.groupnameField || 'cn'];
|
||||
if (!groupName) return iteratorCallback();
|
||||
|
||||
groups.getByName(groupName, function (error, result) {
|
||||
if (error && error.reason !== BoxError.NOT_FOUND) return iteratorCallback(error);
|
||||
|
||||
if (result) {
|
||||
debug(`[up-to-date group] groupname=${groupName}`);
|
||||
|
||||
iteratorCallback();
|
||||
} else {
|
||||
debug(`[adding group] groupname=${groupName}`);
|
||||
|
||||
groups.create(groupName, 'ldap', function (error) {
|
||||
if (error) console.error('Failed to create group', groupName, error);
|
||||
iteratorCallback();
|
||||
});
|
||||
}
|
||||
});
|
||||
}, function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user