LdapClient.get_changes(): properly handle attributes with empty value
This commit is contained in:
parent
ebd73812bc
commit
72877dd13e
1 changed files with 6 additions and 4 deletions
|
@ -782,21 +782,23 @@ class LdapClient:
|
||||||
protected_attrs = [a.lower() for a in protected_attrs or []]
|
protected_attrs = [a.lower() for a in protected_attrs or []]
|
||||||
protected_attrs.append("dn")
|
protected_attrs.append("dn")
|
||||||
# New/updated attributes
|
# New/updated attributes
|
||||||
for attr in attrs:
|
for attr, values in attrs.items():
|
||||||
if protected_attrs and attr.lower() in protected_attrs:
|
if protected_attrs and attr.lower() in protected_attrs:
|
||||||
continue
|
continue
|
||||||
if attr in ldap_obj and ldap_obj[attr]:
|
if attr in ldap_obj and ldap_obj[attr]:
|
||||||
if sorted(ldap_obj[attr]) == sorted(attrs[attr]):
|
if sorted(ldap_obj[attr]) == sorted(values):
|
||||||
continue
|
continue
|
||||||
old[attr] = self.encode(ldap_obj[attr])
|
old[attr] = self.encode(ldap_obj[attr])
|
||||||
new[attr] = self.encode(attrs[attr])
|
elif not values:
|
||||||
|
continue
|
||||||
|
new[attr] = self.encode(values)
|
||||||
|
|
||||||
# Deleted attributes
|
# Deleted attributes
|
||||||
for attr in ldap_obj:
|
for attr in ldap_obj:
|
||||||
if (
|
if (
|
||||||
(not protected_attrs or attr.lower() not in protected_attrs)
|
(not protected_attrs or attr.lower() not in protected_attrs)
|
||||||
and ldap_obj[attr]
|
and ldap_obj[attr]
|
||||||
and attr not in attrs
|
and not attrs.get(attr)
|
||||||
):
|
):
|
||||||
old[attr] = self.encode(ldap_obj[attr])
|
old[attr] = self.encode(ldap_obj[attr])
|
||||||
if old == new:
|
if old == new:
|
||||||
|
|
Loading…
Reference in a new issue