Changeset - 6b57aabf9556
[Not reviewed]
0 1 0
Branko Majic (branko) - 9 years ago 2015-03-08 11:22:24
branko@majic.rs
MAR-1: Fixed the handling of state addattributes in ldap_entry module to be more optimal (which also fixes some issues with cn=config additions related to inability to remove some attribute values).
1 file changed with 11 insertions and 6 deletions:
0 comments (0 inline, 0 general)
roles/ldap_server/library/ldap_entry.py
Show inline comments
 
@@ -228,17 +228,22 @@ class LDAPEntry(object):
 
        attribute_list = self.attributes.keys()
 

	
 
        current_attributes = self.connection.search_s(self.dn, ldap.SCOPE_BASE, attrlist=attribute_list)[0][1]
 
        new_attributes = deepcopy(self.attributes)
 

	
 
        # This dictionary will contain all new attributes (or attribute values)
 
        # that should be added to the entry. We can't rely on modifyModlist
 
        # unfortunately, since if the values already exists, it will try to
 
        # remove and re-add them.
 
        new_attributes = {}
 

	
 
        # If attribute is already present, only add the difference between
 
        # requested and current values.
 
        for attribute, values in current_attributes.iteritems():
 
            if attribute in new_attributes:
 
                new_attributes[attribute].extend(values)
 
                new_attributes[attribute] = list(set(new_attributes[attribute]))
 
            if attribute in self.attributes:
 
                new_attributes[attribute] = [ item for item in self.attributes[attribute] if item not in values ]
 
            else:
 
                new_attributes[attribute] = values
 

	
 
        modification_list = ldap.modlist.modifyModlist(current_attributes,
 
                                                       new_attributes)
 
        modification_list = ldap.modlist.modifyModlist({}, new_attributes)
 

	
 
        if not modification_list:
 
            return False
0 comments (0 inline, 0 general)