1
0
mirror of https://github.com/bitwarden/directory-connector synced 2025-12-10 05:13:17 +00:00

Error on duplicate emails (#136)

* Allow main debugging in development builds

* Early fail on attempting to sync multiple users with the same email

* Truncate duplicate list if greater than 3

* Revert "Allow main debugging in development builds"

This reverts commit 3b804dd959.
This commit is contained in:
Matt Gibson
2021-06-24 15:35:12 -04:00
committed by GitHub
parent dfcb450a8a
commit 6e7e09064f
2 changed files with 34 additions and 0 deletions

View File

@@ -441,6 +441,19 @@
"sync": {
"message": "Sync"
},
"duplicateEmails": {
"message": "Emails must be unique. Multiple entries pulled with the following emails:",
"desription": "Error message displayed when duplicate email addresses are synced. Followed by a list of duplicate emails."
},
"andMore": {
"message": "and $NUMBER$ more...",
"placeholders": {
"NUMBER": {
"content": "$1",
"example": "10"
}
}
},
"ldapEncrypted": {
"message": "This server uses an encrypted connection"
},

View File

@@ -55,6 +55,14 @@ export class SyncService {
this.flattenUsersToGroups(groups, groups);
}
const duplicateEmails = this.findDuplicateUserEmails(users);
if (duplicateEmails.length > 0) {
const emailsMessage = duplicateEmails.length < 4 ?
duplicateEmails.join('\n') :
duplicateEmails.slice(0, 3).join('\n') + '\n' + this.i18nService.t('andMore', `${duplicateEmails.length - 3}`);
throw new Error(this.i18nService.t('duplicateEmails') + '\n' + emailsMessage);
}
if (test || (!syncConfig.overwriteExisting &&
(groups == null || groups.length === 0) && (users == null || users.length === 0))) {
if (!test) {
@@ -108,6 +116,19 @@ export class SyncService {
}
}
private findDuplicateUserEmails(users: UserEntry[]) {
const duplicatedEmails = new Array<string>();
users.reduce((agg, user) => {
if (agg.includes(user.email) && !duplicatedEmails.includes(user.email)) {
duplicatedEmails.push(user.email);
} else {
agg.push(user.email);
}
return agg;
}, new Array<string>());
return duplicatedEmails;
}
private filterUnsupportedUsers(users: UserEntry[]): UserEntry[] {
return users == null ? null : users.filter(u => u.email?.length <= 256);
}