mirror of
https://github.com/bitwarden/directory-connector
synced 2025-12-15 15:53:41 +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:
@@ -441,6 +441,19 @@
|
|||||||
"sync": {
|
"sync": {
|
||||||
"message": "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": {
|
"ldapEncrypted": {
|
||||||
"message": "This server uses an encrypted connection"
|
"message": "This server uses an encrypted connection"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -55,6 +55,14 @@ export class SyncService {
|
|||||||
this.flattenUsersToGroups(groups, groups);
|
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 &&
|
if (test || (!syncConfig.overwriteExisting &&
|
||||||
(groups == null || groups.length === 0) && (users == null || users.length === 0))) {
|
(groups == null || groups.length === 0) && (users == null || users.length === 0))) {
|
||||||
if (!test) {
|
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[] {
|
private filterUnsupportedUsers(users: UserEntry[]): UserEntry[] {
|
||||||
return users == null ? null : users.filter(u => u.email?.length <= 256);
|
return users == null ? null : users.filter(u => u.email?.length <= 256);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user