mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
ldap import: avoid duplicated entries.
This commit is contained in:
+12
-10
@@ -202,18 +202,20 @@ def import_accounts_from_ldap(config):
|
||||
role = "DomainAdmins"
|
||||
break
|
||||
username = force_str(entry[config["ldap_import_username_attr"]][0])
|
||||
if role == "SimpleUsers":
|
||||
lpart, domain = split_mailbox(username)
|
||||
if domain is None:
|
||||
# Try to find associated email
|
||||
username = None
|
||||
for attr in ["mail", "userPrincipalName"]:
|
||||
if attr in entry:
|
||||
username = force_str(entry[attr][0])
|
||||
break
|
||||
if username is None:
|
||||
lpart, domain = split_mailbox(username)
|
||||
if domain is None:
|
||||
# Try to find associated email
|
||||
email = None
|
||||
for attr in ["mail", "userPrincipalName"]:
|
||||
if attr in entry:
|
||||
email = force_str(entry[attr][0])
|
||||
break
|
||||
if email is None:
|
||||
if grp == "SimpleUsers":
|
||||
print("Skipping {} because no email found".format(dn))
|
||||
continue
|
||||
else:
|
||||
username = email
|
||||
defaults = {
|
||||
"username": username.lower(),
|
||||
"is_local": False,
|
||||
|
||||
Reference in New Issue
Block a user