From 5ae40a02ecabc74233cf1f11b88eef831d010cf4 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Fri, 18 Mar 2016 12:37:21 -0400 Subject: [PATCH] (fix) respect the LDAP attributes mapping in the list view --- SoObjects/Contacts/SOGoContactSourceFolder.m | 18 ++++++++++++++---- SoObjects/SOGo/LDAPSource.h | 2 ++ SoObjects/SOGo/LDAPSource.m | 8 ++++---- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/SoObjects/Contacts/SOGoContactSourceFolder.m b/SoObjects/Contacts/SOGoContactSourceFolder.m index bf4f30bd8..2cfe833d0 100644 --- a/SoObjects/Contacts/SOGoContactSourceFolder.m +++ b/SoObjects/Contacts/SOGoContactSourceFolder.m @@ -41,6 +41,7 @@ #import #import +#import #import #import #import @@ -257,7 +258,9 @@ } [newRecord setObject: data forKey: @"c_mail"]; - data = [oldRecord objectForKey: @"nsaimid"]; + data = [oldRecord objectForKey: @"mozillanickname"]; + if (![data length]) + data = [oldRecord objectForKey: @"nsaimid"]; if (![data length]) data = [oldRecord objectForKey: @"nscpaimscreenname"]; if (![data length]) @@ -313,15 +316,22 @@ - (NSArray *) _flattenedRecords: (NSArray *) records { + NSMutableDictionary *oldRecord; NSMutableArray *newRecords; NSEnumerator *oldRecords; - NSDictionary *oldRecord; + NSDictionary *o; newRecords = [NSMutableArray arrayWithCapacity: [records count]]; oldRecords = [records objectEnumerator]; - while ((oldRecord = [oldRecords nextObject])) - [newRecords addObject: [self _flattenedRecord: oldRecord]]; + while ((o = [oldRecords nextObject])) + { + oldRecord = [NSMutableDictionary dictionary]; + [oldRecord addEntriesFromDictionary: o]; + if ([source isKindOfClass: [LDAPSource class]]) + [(LDAPSource *)source applyContactMappingToResult: oldRecord]; + [newRecords addObject: [self _flattenedRecord: oldRecord]]; + } return newRecords; } diff --git a/SoObjects/SOGo/LDAPSource.h b/SoObjects/SOGo/LDAPSource.h index 9081196be..105e596e7 100644 --- a/SoObjects/SOGo/LDAPSource.h +++ b/SoObjects/SOGo/LDAPSource.h @@ -125,6 +125,8 @@ andMultipleBookingsField: (NSString *) newMultipleBookingsField; - (NGLdapEntry *) lookupGroupEntryByEmail: (NSString *) theEmail inDomain: (NSString *) domain; +- (void) applyContactMappingToResult: (NSMutableDictionary *) ldifRecord; + @end #endif /* LDAPSOURCE_H */ diff --git a/SoObjects/SOGo/LDAPSource.m b/SoObjects/SOGo/LDAPSource.m index 2fa8f3773..63cd8c976 100644 --- a/SoObjects/SOGo/LDAPSource.m +++ b/SoObjects/SOGo/LDAPSource.m @@ -972,7 +972,7 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses } /* conversion LDAP -> SOGo inetOrgPerson entry */ -- (void) _applyContactMappingToResult: (NSMutableDictionary *) ldifRecord +- (void) applyContactMappingToResult: (NSMutableDictionary *) ldifRecord { NSArray *sourceFields; NSArray *keys; @@ -1172,7 +1172,7 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses intoLDIFRecord: (NSMutableDictionary *) ldifRecord]; if (contactMapping) - [self _applyContactMappingToResult: ldifRecord]; + [self applyContactMappingToResult: ldifRecord]; return ldifRecord; } @@ -1496,7 +1496,7 @@ _convertRecordToLDAPAttributes (LDAPSourceSchema *schema, NSDictionary *ldifReco [ldifRecord setObject: aId forKey: @"cn"]; } - [self _applyContactMappingToOutput: ldifRecord]; + [self applyContactMappingToOutput: ldifRecord]; /* since the id might have changed due to the mapping above, we reload the record ID */ @@ -1604,7 +1604,7 @@ _makeLDAPChanges (NGLdapConnection *ldapConnection, ldapConnection = [self _ldapConnection]; ldifRecord = [roLdifRecord mutableCopy]; [ldifRecord autorelease]; - [self _applyContactMappingToOutput: ldifRecord]; + [self applyContactMappingToOutput: ldifRecord]; attributes = _convertRecordToLDAPAttributes (schema, ldifRecord); changes = _makeLDAPChanges (ldapConnection, dn, attributes);