diff --git a/src/externalldap.js b/src/externalldap.js index 0f146034c..b76f43b4b 100644 --- a/src/externalldap.js +++ b/src/externalldap.js @@ -330,12 +330,9 @@ function sync(progressCallback, callback) { progressCallback({ percent, message: `Syncing... ${user.username}` }); users.getByUsername(user.username, function (error, result) { - if (error && error.reason !== BoxError.NOT_FOUND) { - debug(`Could not find user with username ${user.username}: ${error.message}`); - return iteratorCallback(); - } + if (error && error.reason !== BoxError.NOT_FOUND) return iteratorCallback(error); - if (error) { + if (!result) { debug(`[adding user] username=${user.username} email=${user.email} displayName=${user.displayName}`); users.create(user.username, null /* password */, user.email, user.displayName, { source: 'ldap' }, auditSource.EXTERNAL_LDAP_TASK, function (error) { @@ -379,17 +376,17 @@ function sync(progressCallback, callback) { 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 { + if (!result) { debug(`[adding group] groupname=${groupName}`); groups.create(groupName, 'ldap', function (error) { if (error) console.error('Failed to create group', groupName, error); iteratorCallback(); }); + } else { + debug(`[up-to-date group] groupname=${groupName}`); + + iteratorCallback(); } }); }, function (error) {