diff --git a/ChangeLog b/ChangeLog index d055aafb5..eaf5fd943 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2009-11-29 Wolfgang Sourdeau + * SoObjects/SOGo/SOGoUserManager.m + (-authenticationSourceIDsInDomain:): now takes a domain argument. + Contrarily to contact sources, specifying a domain will cause the + generic sources to be ignored. + (-fetchUsersMatching:inDomain:): now takes a domain argument. + * SoObjects/SOGo/LDAPSource.m (-initFromUDSource:inDomain): removed handing of "domain attribute", since the underlying mechanism causes complex code for an unrealistic case. diff --git a/SoObjects/SOGo/LDAPSource.h b/SoObjects/SOGo/LDAPSource.h index 2cd3bdb13..796f17d0a 100644 --- a/SoObjects/SOGo/LDAPSource.h +++ b/SoObjects/SOGo/LDAPSource.h @@ -56,7 +56,6 @@ NSString *domain; NSString *contactInfoAttribute; - NSString *domainAttribute; NSDictionary *modulesConstraints; diff --git a/SoObjects/SOGo/SOGoUserFolder.m b/SoObjects/SOGo/SOGoUserFolder.m index ce178bd59..6033c782b 100644 --- a/SoObjects/SOGo/SOGoUserFolder.m +++ b/SoObjects/SOGo/SOGoUserFolder.m @@ -207,21 +207,24 @@ - (NSDictionary *) foldersOfType: (NSString *) type matchingUID: (NSString *) uid { - NSArray *contacts, *folders; + NSArray *users, *folders; + NSString *domain; NSEnumerator *enumerator; - NSDictionary *contact; + NSDictionary *user; NSMutableDictionary *results; results = [NSMutableDictionary dictionary]; - contacts = [[SOGoUserManager sharedUserManager] fetchUsersMatching: uid]; - enumerator = [contacts objectEnumerator]; - while ((contact = [enumerator nextObject])) + domain = [[SOGoUser userWithLogin: owner] domain]; + users = [[SOGoUserManager sharedUserManager] fetchUsersMatching: uid + inDomain: domain]; + enumerator = [users objectEnumerator]; + while ((user = [enumerator nextObject])) { - uid = [contact objectForKey: @"c_uid"]; + uid = [user objectForKey: @"c_uid"]; folders = [self foldersOfType: type - forUID: [contact objectForKey: @"c_uid"]]; - [results setObject: folders forKey: contact]; + forUID: [user objectForKey: @"c_uid"]]; + [results setObject: folders forKey: user]; } return results; @@ -312,15 +315,16 @@ - (NSArray *) _searchDavOwners: (NSString *) davOwnerMatch { NSArray *users, *owners; - NSString *ownerMatch; + NSString *ownerMatch, *domain; SOGoUserManager *um; owners = [NSMutableArray array]; if (davOwnerMatch) { ownerMatch = [self _userFromDAVuser: davOwnerMatch]; + domain = [[SOGoUser userWithLogin: owner] domain]; um = [SOGoUserManager sharedUserManager]; - users = [[um fetchUsersMatching: ownerMatch] + users = [[um fetchUsersMatching: ownerMatch inDomain: domain] sortedArrayUsingSelector: @selector (caseInsensitiveDisplayNameCompare:)]; owners = [users objectsForKey: @"c_uid" notFoundMarker: nil]; } @@ -379,7 +383,7 @@ SOGoUserManager *um; NSMutableString *fetch; NSDictionary *currentUser; - NSString *field, *login; + NSString *field, *login, *domain; NSArray *users; int i; @@ -389,9 +393,10 @@ login = [[context activeUser] login]; um = [SOGoUserManager sharedUserManager]; + domain = [[context activeUser] domain]; // We sort our array - this is pretty useful for the // SOGo Integrator extension, among other things. - users = [[um fetchUsersMatching: user] + users = [[um fetchUsersMatching: user inDomain: domain] sortedArrayUsingSelector: @selector (caseInsensitiveDisplayNameCompare:)]; for (i = 0; i < [users count]; i++) { diff --git a/SoObjects/SOGo/SOGoUserManager.h b/SoObjects/SOGo/SOGoUserManager.h index 44cd73a73..90784bded 100644 --- a/SoObjects/SOGo/SOGoUserManager.h +++ b/SoObjects/SOGo/SOGoUserManager.h @@ -45,7 +45,7 @@ + (id) sharedUserManager; - (NSArray *) sourceIDsInDomain: (NSString *) domain; -- (NSArray *) authenticationSourceIDs; +- (NSArray *) authenticationSourceIDsInDomain: (NSString *) domain; - (NSArray *) addressBookSourceIDsInDomain: (NSString *) domain; - (NSObject *) sourceWithID: (NSString *) sourceID; @@ -54,7 +54,8 @@ - (NSDictionary *) contactInfosForUserWithUIDorEmail: (NSString *) uid; - (NSArray *) fetchContactsMatching: (NSString *) match inDomain: (NSString *) domain; -- (NSArray *) fetchUsersMatching: (NSString *) filter; +- (NSArray *) fetchUsersMatching: (NSString *) filter + inDomain: (NSString *) domain; - (NSString *) getCNForUID: (NSString *) uid; - (NSString *) getEmailForUID: (NSString *) uid; diff --git a/SoObjects/SOGo/SOGoUserManager.m b/SoObjects/SOGo/SOGoUserManager.m index 586f3a566..be13f02c3 100644 --- a/SoObjects/SOGo/SOGoUserManager.m +++ b/SoObjects/SOGo/SOGoUserManager.m @@ -184,39 +184,13 @@ currentID = [keys objectAtIndex: count]; currentSource = [_sources objectForKey: currentID]; sourceDomain = [currentSource domain]; - if (!domain || [sourceDomain isEqualToString: domain]) + if (![sourceDomain length] || [sourceDomain isEqualToString: domain]) [sourceIDs addObject: currentID]; } return sourceIDs; } -- (NSArray *) _sourcesOfType: (NSString *) sourceType - inDomain: (NSString *) domain -{ - NSMutableArray *sourceIDs; - NSEnumerator *allIDs; - NSString *currentID; - NSNumber *typeValue; - NSDictionary *metadata; - - sourceIDs = [NSMutableArray array]; - allIDs = [[_sources allKeys] objectEnumerator]; - while ((currentID = [allIDs nextObject])) - { - metadata = [_sourcesMetadata objectForKey: currentID]; - if (!domain - || [[metadata objectForKey: @"domain"] isEqualToString: domain]) - { - typeValue = [metadata objectForKey: sourceType]; - if ([typeValue boolValue]) - [sourceIDs addObject: currentID]; - } - } - - return sourceIDs; -} - - (NSObject *) sourceWithID: (NSString *) sourceID { return [_sources objectForKey: sourceID]; @@ -227,14 +201,46 @@ return [_sourcesMetadata objectForKey: sourceID]; } -- (NSArray *) authenticationSourceIDs +- (NSArray *) authenticationSourceIDsInDomain: (NSString *) domain { - return [self _sourcesOfType: @"canAuthenticate" inDomain: nil]; + NSMutableArray *sourceIDs; + NSEnumerator *allIDs; + NSString *currentID, *sourceDomain; + NSDictionary *metadata; + + sourceIDs = [NSMutableArray array]; + allIDs = [[_sources allKeys] objectEnumerator]; + while ((currentID = [allIDs nextObject])) + { + sourceDomain = [[_sources objectForKey: currentID] domain]; + if (![domain length] || [domain isEqualToString: sourceDomain]) + { + metadata = [_sourcesMetadata objectForKey: currentID]; + if ([[metadata objectForKey: @"canAuthenticate"] boolValue]) + [sourceIDs addObject: currentID]; + } + } + + return sourceIDs; } - (NSArray *) addressBookSourceIDsInDomain: (NSString *) domain { - return [self _sourcesOfType: @"isAddressBook" inDomain: domain]; + NSMutableArray *sourceIDs; + NSEnumerator *allIDs; + NSString *currentID; + NSDictionary *metadata; + + sourceIDs = [NSMutableArray array]; + allIDs = [[self sourceIDsInDomain: domain] objectEnumerator]; + while ((currentID = [allIDs nextObject])) + { + metadata = [_sourcesMetadata objectForKey: currentID]; + if ([[metadata objectForKey: @"isAddressBook"] boolValue]) + [sourceIDs addObject: currentID]; + } + + return sourceIDs; } - (NSString *) displayNameForSourceWithID: (NSString *) sourceID @@ -310,10 +316,10 @@ NSEnumerator *authIDs; NSString *currentID; BOOL checkOK; - + checkOK = NO; - authIDs = [[self authenticationSourceIDs] objectEnumerator]; + authIDs = [[self authenticationSourceIDsInDomain: nil] objectEnumerator]; while (!checkOK && (currentID = [authIDs nextObject])) { ldapSource = [_sources objectForKey: currentID]; @@ -388,13 +394,14 @@ NSDictionary *userEntry; NSEnumerator *ldapSources; LDAPSource *currentSource; - NSString *sourceID, *cn, *c_uid, *c_imaphostname; + NSString *sourceID, *cn, *c_domain, *c_uid, *c_imaphostname; NSArray *c_emails; BOOL access; emails = [NSMutableArray array]; cn = nil; c_uid = nil; + c_domain = nil; c_imaphostname = nil; [currentUser setObject: [NSNumber numberWithBool: YES] @@ -402,7 +409,7 @@ [currentUser setObject: [NSNumber numberWithBool: YES] forKey: @"MailAccess"]; - ldapSources = [[self authenticationSourceIDs] + ldapSources = [[self authenticationSourceIDsInDomain: nil] objectEnumerator]; while ((sourceID = [ldapSources nextObject])) { @@ -414,6 +421,8 @@ cn = [userEntry objectForKey: @"c_cn"]; if (!c_uid) c_uid = [userEntry objectForKey: @"c_uid"]; + if (!c_domain) + c_domain = [userEntry objectForKey: @"c_domain"]; c_emails = [userEntry objectForKey: @"c_emails"]; if ([c_emails count]) [emails addObjectsFromArray: c_emails]; @@ -434,12 +443,15 @@ cn = @""; if (!c_uid) c_uid = @""; + if (!c_domain) + c_domain = @""; if (c_imaphostname) [currentUser setObject: c_imaphostname forKey: @"c_imaphostname"]; [currentUser setObject: emails forKey: @"emails"]; [currentUser setObject: cn forKey: @"cn"]; [currentUser setObject: c_uid forKey: @"c_uid"]; + [currentUser setObject: c_domain forKey: @"c_domain"]; // If our LDAP queries gave us nothing, we add at least one default // email address based on the default domain. @@ -598,8 +610,10 @@ } - (NSArray *) fetchUsersMatching: (NSString *) filter + inDomain: (NSString *) domain { - return [self _fetchEntriesInSources: [self authenticationSourceIDs] + return [self _fetchEntriesInSources: + [self authenticationSourceIDsInDomain: domain] matching: filter]; } diff --git a/SoObjects/SOGo/SQLSource.h b/SoObjects/SOGo/SQLSource.h index fd1c384e5..2a894c367 100644 --- a/SoObjects/SOGo/SQLSource.h +++ b/SoObjects/SOGo/SQLSource.h @@ -36,7 +36,6 @@ { NSString *_sourceID; NSString *_domain; - NSString *_domainAttribute; NSArray *_mailFields; NSString *_userPasswordAlgorithm; NSURL *_viewURL; diff --git a/Tools/SOGoToolBackup.m b/Tools/SOGoToolBackup.m index cabd1827f..ed40f64b4 100644 --- a/Tools/SOGoToolBackup.m +++ b/Tools/SOGoToolBackup.m @@ -128,7 +128,7 @@ max = [users count]; user = [users objectAtIndex: 0]; if (max == 1 && [user isEqualToString: @"ALL"]) - allUsers = [lm fetchUsersMatching: @"."]; + allUsers = [lm fetchUsersMatching: @"." inDomain: nil]; else { allUsers = [NSMutableArray array]; @@ -309,7 +309,7 @@ lm = [SOGoUserManager sharedUserManager]; done = NO; - ldapSources = [[lm authenticationSourceIDs] objectEnumerator]; + ldapSources = [[lm authenticationSourceIDsInDomain: nil] objectEnumerator]; while (!done && (sourceID = [ldapSources nextObject])) { currentSource = [lm sourceWithID: sourceID]; diff --git a/Tools/SOGoToolRestore.m b/Tools/SOGoToolRestore.m index a9a3198a6..1ed2dc26d 100644 --- a/Tools/SOGoToolRestore.m +++ b/Tools/SOGoToolRestore.m @@ -36,7 +36,9 @@ #import #import #import +#import #import +#import #import "SOGoToolRestore.h" diff --git a/UI/MainUI/SOGoUserHomePage.m b/UI/MainUI/SOGoUserHomePage.m index 28ca8767e..37a47d4dd 100644 --- a/UI/MainUI/SOGoUserHomePage.m +++ b/UI/MainUI/SOGoUserHomePage.m @@ -332,7 +332,8 @@ { domain = [[context activeUser] domain]; result - = [self _usersResponseForResults: [um fetchUsersMatching: contact]]; + = [self _usersResponseForResults: [um fetchUsersMatching: contact + inDomain: domain]]; } else result = [NSException exceptionWithHTTPStatus: 400