From 7815b3403c90c041f350596cf8388dbf4e883dfb Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Sat, 11 Feb 2012 07:08:02 +0000 Subject: [PATCH] See ChangeLog. Monotone-Parent: d4394b4b92fdfda720d67698c9fbadc75787ad18 Monotone-Revision: e8c7d8a4465a1b9357c1d9f201dec2b93c5f3507 Monotone-Author: flachapelle@inverse.ca Monotone-Date: 2012-02-11T07:08:02 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 25 +++++++++ SoObjects/Contacts/SOGoContactFolder.h | 3 +- SoObjects/Contacts/SOGoContactGCSFolder.m | 5 ++ SoObjects/Contacts/SOGoContactSourceFolder.m | 4 +- SoObjects/Contacts/SOGoFolder+CardDAV.m | 8 ++- SoObjects/SOGo/LDAPSource.m | 5 +- SoObjects/SOGo/SOGoSource.h | 6 ++- SoObjects/SOGo/SOGoUser.m | 2 +- SoObjects/SOGo/SOGoUserManager.m | 19 ++++--- SoObjects/SOGo/SQLSource.h | 1 + SoObjects/SOGo/SQLSource.m | 56 +++++++++++++++----- Tools/SOGoSockDOperation.m | 3 +- UI/Contacts/UIxContactFoldersView.m | 10 ++-- UI/Contacts/UIxContactsListActions.m | 12 +++-- UI/MailerUI/UIxMailEditor.m | 3 +- 15 files changed, 124 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8e9fddb21..fb31d7483 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,9 +5,34 @@ 2012-02-22 Francis Lachapelle + * SoObjects/SOGo/SOGoUserManager.m + (-authenticationSourceIDsInDomain:): when looking for a specific + domain, also return sources that are not associated to a domain. + + * SoObjects/SOGo/SOGoSource.h + (-lookupContactEntryWithUIDorEmail:inDomain:): changed this method + of the protocol to specify a domain. + (-fetchContactsMatching:inDomain:): idem. + + * SoObjects/Contacts/SOGoContactFolder.h + (-lookupContactsWithFilter:onCriteria:sortBy:ordering:inDomain:): + changed this method of the protocol to specify a domain. + * UI/WebServerResources/UIxAclEditor.js (addUser): fixed case when both canSubscribeUsers and isPublicAccessEnabled are disabled. + * SoObjects/SOGo/SQLSource.m + (-_lookupContactEntry:considerEmail:inDomain:): if the configuration + parameter DomainFieldName is defined for the source, set the user + domain to the value of this field. + (-fetchContactsMatching:inDomain:): when the configuration parameter + DomainField is defined, limit the results to the entries matching + the specified domain. + + * SoObjects/SOGo/SOGoUserManager.m (-sourceIDsInDomain): if the + source is not associated to a domain, set it to the requested + domain. It will be used by sources with dynamic domain assignation. + 2012-02-22 Wolfgang Sourdeau * SoObjects/SOGo/SQLSource.m (_lookupContactEntry:considerEmail:): diff --git a/SoObjects/Contacts/SOGoContactFolder.h b/SoObjects/Contacts/SOGoContactFolder.h index 28e16be79..f523c3085 100644 --- a/SoObjects/Contacts/SOGoContactFolder.h +++ b/SoObjects/Contacts/SOGoContactFolder.h @@ -46,7 +46,8 @@ - (NSArray *) lookupContactsWithFilter: (NSString *) filter onCriteria: (NSString *) criteria sortBy: (NSString *) sortKey - ordering: (NSComparisonResult) sortOrdering; + ordering: (NSComparisonResult) sortOrdering + inDomain: (NSString *) domain; - (NSDictionary *) lookupContactWithName: (NSString *) aName; @end diff --git a/SoObjects/Contacts/SOGoContactGCSFolder.m b/SoObjects/Contacts/SOGoContactGCSFolder.m index c98e2ecd5..6b8b313dd 100644 --- a/SoObjects/Contacts/SOGoContactGCSFolder.m +++ b/SoObjects/Contacts/SOGoContactGCSFolder.m @@ -285,10 +285,15 @@ static NSArray *folderListingFields = nil; return record; } +/* + * GCS folder are personal folders and are not associated to a domain. + * The domain is therefore ignored. + */ - (NSArray *) lookupContactsWithFilter: (NSString *) filter onCriteria: (NSString *) criteria sortBy: (NSString *) sortKey ordering: (NSComparisonResult) sortOrdering + inDomain: (NSString *) domain { NSArray *dbRecords, *records; EOQualifier *qualifier; diff --git a/SoObjects/Contacts/SOGoContactSourceFolder.m b/SoObjects/Contacts/SOGoContactSourceFolder.m index cc906ce14..780bcd742 100644 --- a/SoObjects/Contacts/SOGoContactSourceFolder.m +++ b/SoObjects/Contacts/SOGoContactSourceFolder.m @@ -314,6 +314,7 @@ onCriteria: (NSString *) criteria sortBy: (NSString *) sortKey ordering: (NSComparisonResult) sortOrdering + inDomain: (NSString *) domain { NSArray *records, *result; EOSortOrdering *ordering; @@ -323,7 +324,8 @@ if (([filter length] > 0 && [criteria isEqualToString: @"name_or_address"]) || ![source listRequiresDot]) { - records = [source fetchContactsMatching: filter]; + records = [source fetchContactsMatching: filter + inDomain: domain]; [childRecords setObjects: records forKeys: [records objectsForKey: @"c_name" notFoundMarker: nil]]; diff --git a/SoObjects/Contacts/SOGoFolder+CardDAV.m b/SoObjects/Contacts/SOGoFolder+CardDAV.m index dfb761dfa..fed4c2105 100644 --- a/SoObjects/Contacts/SOGoFolder+CardDAV.m +++ b/SoObjects/Contacts/SOGoFolder+CardDAV.m @@ -25,6 +25,7 @@ #import #import +#import #import #import #import @@ -34,6 +35,7 @@ #import #import +#import #import #import "SOGoContactFolder.h" @@ -92,9 +94,10 @@ unsigned int count, max; NSDictionary *currentFilter, *contact; NSEnumerator *contacts; - NSString *baseURL; + NSString *baseURL, *domain; baseURL = [self baseURLInContext: localContext]; + domain = [[localContext activeUser] domain]; max = [filters count]; for (count = 0; count < max; count++) @@ -103,7 +106,8 @@ contacts = [[(id)self lookupContactsWithFilter: [[currentFilter allValues] lastObject] onCriteria: @"name_or_address" sortBy: @"c_givenname" - ordering: NSOrderedDescending] + ordering: NSOrderedDescending + inDomain: domain] objectEnumerator]; while ((contact = [contacts nextObject])) diff --git a/SoObjects/SOGo/LDAPSource.m b/SoObjects/SOGo/LDAPSource.m index e8e5b23ae..51db36374 100644 --- a/SoObjects/SOGo/LDAPSource.m +++ b/SoObjects/SOGo/LDAPSource.m @@ -499,9 +499,6 @@ andMultipleBookingsField: (NSString *) newMultipleBookingsField return ldapConnection; } -// -// -// - (NSString *) domain { return domain; @@ -1131,6 +1128,7 @@ andMultipleBookingsField: (NSString *) newMultipleBookingsField } - (NSArray *) fetchContactsMatching: (NSString *) match + inDomain: (NSString *) domain { NGLdapConnection *ldapConnection; NGLdapEntry *currentEntry; @@ -1217,6 +1215,7 @@ andMultipleBookingsField: (NSString *) newMultipleBookingsField } - (NSDictionary *) lookupContactEntryWithUIDorEmail: (NSString *) uid + inDomain: (NSString *) domain { NGLdapEntry *ldapEntry; EOQualifier *qualifier; diff --git a/SoObjects/SOGo/SOGoSource.h b/SoObjects/SOGo/SOGoSource.h index 3a500cd4a..ebf085200 100644 --- a/SoObjects/SOGo/SOGoSource.h +++ b/SoObjects/SOGo/SOGoSource.h @@ -57,10 +57,12 @@ perr: (SOGoPasswordPolicyError *) perr; - (NSDictionary *) lookupContactEntry: (NSString *) theID; -- (NSDictionary *) lookupContactEntryWithUIDorEmail: (NSString *) entryID; +- (NSDictionary *) lookupContactEntryWithUIDorEmail: (NSString *) entryID + inDomain: (NSString *) domain; - (NSArray *) allEntryIDs; -- (NSArray *) fetchContactsMatching: (NSString *) filter; +- (NSArray *) fetchContactsMatching: (NSString *) filter + inDomain: (NSString *) domain; - (void) setSourceID: (NSString *) newSourceID; - (NSString *) sourceID; diff --git a/SoObjects/SOGo/SOGoUser.m b/SoObjects/SOGo/SOGoUser.m index 721f857ad..fa2fe846a 100644 --- a/SoObjects/SOGo/SOGoUser.m +++ b/SoObjects/SOGo/SOGoUser.m @@ -400,7 +400,7 @@ _domainDefaults = [SOGoDomainDefaults defaultsForDomain: domain]; if (!_domainDefaults) { - [self errorWithFormat: @"domain '%@' does not exist!", domain]; + //[self errorWithFormat: @"domain '%@' does not exist!", domain]; _domainDefaults = [SOGoSystemDefaults sharedSystemDefaults]; } } diff --git a/SoObjects/SOGo/SOGoUserManager.m b/SoObjects/SOGo/SOGoUserManager.m index b857d7764..e84ca329a 100644 --- a/SoObjects/SOGo/SOGoUserManager.m +++ b/SoObjects/SOGo/SOGoUserManager.m @@ -268,7 +268,7 @@ while ((currentID = [allIDs nextObject])) { sourceDomain = [[_sources objectForKey: currentID] domain]; - if (![domain length] || [domain isEqualToString: sourceDomain]) + if (![domain length] || ![sourceDomain length] || [domain isEqualToString: sourceDomain]) { metadata = [_sourcesMetadata objectForKey: currentID]; if ([[metadata objectForKey: @"canAuthenticate"] boolValue]) @@ -609,7 +609,8 @@ while (!userEntry && (sourceID = [sogoSources nextObject])) { currentSource = [_sources objectForKey: sourceID]; - userEntry = [currentSource lookupContactEntryWithUIDorEmail: uid]; + userEntry = [currentSource lookupContactEntryWithUIDorEmail: uid + inDomain: domain]; if (userEntry) { [currentUser setObject: sourceID forKey: @"SOGoSource"]; @@ -876,6 +877,7 @@ - (NSArray *) _fetchEntriesInSources: (NSArray *) sourcesList matching: (NSString *) filter + inDomain: (NSString *) domain { NSMutableArray *contacts; NSEnumerator *sources; @@ -888,7 +890,8 @@ { currentSource = [_sources objectForKey: sourceID]; [contacts addObjectsFromArray: - [currentSource fetchContactsMatching: filter]]; + [currentSource fetchContactsMatching: filter + inDomain: domain]]; } return [self _compactAndCompleteContacts: [contacts objectEnumerator]]; @@ -899,15 +902,17 @@ { return [self _fetchEntriesInSources: [self addressBookSourceIDsInDomain: domain] - matching: filter]; + matching: filter + inDomain: domain]; } - (NSArray *) fetchUsersMatching: (NSString *) filter inDomain: (NSString *) domain { - return [self _fetchEntriesInSources: - [self authenticationSourceIDsInDomain: domain] - matching: filter]; + return [self + _fetchEntriesInSources: [self authenticationSourceIDsInDomain: domain] + matching: filter + inDomain: domain]; } - (NSString *) getLoginForDN: (NSString *) theDN diff --git a/SoObjects/SOGo/SQLSource.h b/SoObjects/SOGo/SQLSource.h index 38d35c930..8e254c8f1 100644 --- a/SoObjects/SOGo/SQLSource.h +++ b/SoObjects/SOGo/SQLSource.h @@ -37,6 +37,7 @@ { NSString *_sourceID; NSString *_domain; + NSString *_domainField; NSString *_authenticationFilter; NSArray *_loginFields; NSArray *_mailFields; diff --git a/SoObjects/SOGo/SQLSource.m b/SoObjects/SOGo/SQLSource.m index ec1801231..5ccc833ac 100644 --- a/SoObjects/SOGo/SQLSource.m +++ b/SoObjects/SOGo/SQLSource.m @@ -1,6 +1,6 @@ /* SQLSource.h - this file is part of SOGo * - * Copyright (C) 2009-2011 Inverse inc. + * Copyright (C) 2009-2012 Inverse inc. * * Authors: Ludovic Marcotte * Francis Lachapelle @@ -59,7 +59,7 @@ * { * id = zot; * type = sql; - * viewURL = "http://sogo:sogo@127.0.0.1:5432/sogo/sogo_view"; + * viewURL = "mysql://sogo:sogo@127.0.0.1:5432/sogo/sogo_view"; * canAuthenticate = YES; * isAddressBook = YES; * userPasswordAlgorithm = md5; @@ -81,6 +81,7 @@ if ((self = [super init])) { _sourceID = nil; + _domainField = nil; _authenticationFilter = nil; _loginFields = nil; _mailFields = nil; @@ -104,6 +105,7 @@ [_viewURL release]; [_kindField release]; [_multipleBookingsField release]; + [_domainField release]; [_imapHostField release]; [super dealloc]; @@ -123,6 +125,7 @@ ASSIGN(_imapHostField, [udSource objectForKey: @"IMAPHostFieldName"]); ASSIGN(_kindField, [udSource objectForKey: @"KindFieldName"]); ASSIGN(_multipleBookingsField, [udSource objectForKey: @"MultipleBookingsFieldName"]); + ASSIGN(_domainField, [udSource objectForKey: @"DomainFieldName"]); if (!_userPasswordAlgorithm) _userPasswordAlgorithm = @"none"; @@ -380,12 +383,13 @@ - (NSDictionary *) _lookupContactEntry: (NSString *) theID considerEmail: (BOOL) b + inDomain: (NSString *) domain { NSMutableDictionary *response; NSMutableArray *qualifiers; NSArray *fieldNames; EOAdaptorChannel *channel; - EOQualifier *loginQualifier, *qualifier; + EOQualifier *loginQualifier, *domainQualifier, *qualifier; GCSChannelManager *cm; NSMutableString *sql; NSString *value, *field; @@ -424,6 +428,15 @@ } } + domainQualifier = nil; + if (_domainField && domain) + { + domainQualifier = [[EOKeyValueQualifier alloc] initWithKey: _domainField + operatorSelector: EOQualifierOperatorEqual + value: domain]; + [domainQualifier autorelease]; + } + if (b) { // Always compare againts the mail field @@ -456,6 +469,8 @@ @" WHERE ", [_viewURL gcsTableName]]; qualifier = [[EOOrQualifier alloc] initWithQualifierArray: qualifiers]; + if (domainQualifier) + qualifier = [[EOAndQualifier alloc] initWithQualifiers: domainQualifier, qualifier, nil]; [qualifier _gcsAppendToString: sql]; ex = [channel evaluateExpressionX: sql]; @@ -484,9 +499,12 @@ [response setObject: [NSNumber numberWithBool: YES] forKey: @"MailAccess"]; // We set the domain, if any + value = nil; if (_domain) value = _domain; - else + else if (_domainField) + value = [response objectForKey: _domainField]; + if (![value isNotNull]) value = @""; [response setObject: value forKey: @"c_domain"]; @@ -598,12 +616,13 @@ - (NSDictionary *) lookupContactEntry: (NSString *) theID { - return [self _lookupContactEntry: theID considerEmail: NO]; + return [self _lookupContactEntry: theID considerEmail: NO inDomain: nil]; } - (NSDictionary *) lookupContactEntryWithUIDorEmail: (NSString *) entryID + inDomain: (NSString *) domain { - return [self _lookupContactEntry: entryID considerEmail: YES]; + return [self _lookupContactEntry: entryID considerEmail: YES inDomain: domain]; } - (NSArray *) allEntryIDs @@ -652,12 +671,14 @@ } - (NSArray *) fetchContactsMatching: (NSString *) filter + inDomain: (NSString *) domain { EOAdaptorChannel *channel; NSMutableArray *results; GCSChannelManager *cm; NSException *ex; - NSString *sql, *lowerFilter; + NSMutableString *sql; + NSString *lowerFilter; results = [NSMutableArray array]; @@ -668,18 +689,29 @@ lowerFilter = [filter lowercaseString]; lowerFilter = [lowerFilter stringByReplacingString: @"'" withString: @"''"]; - sql = [NSString stringWithFormat: (@"SELECT *" + sql = [NSMutableString stringWithFormat: (@"SELECT *" @" FROM %@" - @" WHERE LOWER(c_cn) LIKE '%%%@%%'" - @" OR LOWER(mail) LIKE '%%%@%%'"), + @" WHERE" + @" (LOWER(c_cn) LIKE '%%%@%%'" + @" OR LOWER(mail) LIKE '%%%@%%'"), [_viewURL gcsTableName], lowerFilter, lowerFilter]; - + if (_mailFields && [_mailFields count] > 0) { - sql = [sql stringByAppendingString: [self _whereClauseFromArray: _mailFields value: lowerFilter exact: NO]]; + [sql appendString: [self _whereClauseFromArray: _mailFields value: lowerFilter exact: NO]]; } + [sql appendString: @")"]; + + if (_domainField) + { + if ([domain length]) + [sql appendFormat: @" AND %@ = '%@'", _domainField, domain]; + else + [sql appendFormat: @" AND %@ IS NULL", _domainField]; + } + ex = [channel evaluateExpressionX: sql]; if (!ex) { diff --git a/Tools/SOGoSockDOperation.m b/Tools/SOGoSockDOperation.m index 62d4d8226..c3604b865 100644 --- a/Tools/SOGoSockDOperation.m +++ b/Tools/SOGoSockDOperation.m @@ -275,7 +275,8 @@ Class SOGoContactSourceFolderKlass = Nil; = [folder lookupContactsWithFilter: filter onCriteria: @"name_or_address" sortBy: @"c_cn" - ordering: NSOrderedAscending]; + ordering: NSOrderedAscending + inDomain: nil]; } else { diff --git a/UI/Contacts/UIxContactFoldersView.m b/UI/Contacts/UIxContactFoldersView.m index e520318a7..ecfc542cb 100644 --- a/UI/Contacts/UIxContactFoldersView.m +++ b/UI/Contacts/UIxContactFoldersView.m @@ -29,6 +29,7 @@ #import #import #import +#import #import #import @@ -122,7 +123,8 @@ Class SOGoContactSourceFolderK, SOGoGCSFolderK; contactInfos = [folder lookupContactsWithFilter: nil onCriteria: nil sortBy: @"c_cn" - ordering: NSOrderedAscending]; + ordering: NSOrderedAscending + inDomain: nil]; else contactInfos = nil; @@ -159,7 +161,7 @@ Class SOGoContactSourceFolderK, SOGoGCSFolderK; { id result; SOGoFolder *folder; - NSString *searchText, *mail; + NSString *searchText, *mail, *domain; NSDictionary *data; NSArray *folders, *contacts, *descriptors, *sortedContacts; NSMutableArray *sortedFolders; @@ -174,6 +176,7 @@ Class SOGoContactSourceFolderK, SOGoGCSFolderK; // NSLog(@"Search all contacts: %@", searchText); excludeGroups = [[self queryParameterForKey: @"excludeGroups"] boolValue]; excludeLists = [[self queryParameterForKey: @"excludeLists"] boolValue]; + domain = [[context activeUser] domain]; folders = nil; NS_DURING folders = [[self clientObject] subFolders]; @@ -205,7 +208,8 @@ Class SOGoContactSourceFolderK, SOGoGCSFolderK; contacts = [folder lookupContactsWithFilter: searchText onCriteria: @"name_or_address" sortBy: @"c_cn" - ordering: NSOrderedAscending]; + ordering: NSOrderedAscending + inDomain: domain]; for (j = 0; j < [contacts count]; j++) { contact = [contacts objectAtIndex: j]; diff --git a/UI/Contacts/UIxContactsListActions.m b/UI/Contacts/UIxContactsListActions.m index cd4ddf4ea..fd7db096e 100644 --- a/UI/Contacts/UIxContactsListActions.m +++ b/UI/Contacts/UIxContactsListActions.m @@ -27,6 +27,7 @@ #import #import +#import #import #import #import @@ -110,7 +111,8 @@ contactInfos = [folder lookupContactsWithFilter: valueText onCriteria: searchText sortBy: [self sortKey] - ordering: ordering]; + ordering: ordering + inDomain: [[context activeUser] domain]]; [contactInfos retain]; } @@ -138,7 +140,7 @@ { id result; id folder; - NSString *searchText, *mail; + NSString *searchText, *mail, *domain; NSDictionary *contact, *data; NSArray *contacts, *descriptors, *sortedContacts; NSMutableDictionary *uniqueContacts; @@ -158,12 +160,14 @@ else [localException raise]; NS_ENDHANDLER - + + domain = [[context activeUser] domain]; uniqueContacts = [NSMutableDictionary dictionary]; contacts = [folder lookupContactsWithFilter: searchText onCriteria: @"name_or_address" sortBy: @"c_cn" - ordering: NSOrderedAscending]; + ordering: NSOrderedAscending + inDomain: domain]; for (i = 0; i < [contacts count]; i++) { contact = [contacts objectAtIndex: i]; diff --git a/UI/MailerUI/UIxMailEditor.m b/UI/MailerUI/UIxMailEditor.m index 26fafd12b..0d1f52597 100644 --- a/UI/MailerUI/UIxMailEditor.m +++ b/UI/MailerUI/UIxMailEditor.m @@ -417,7 +417,8 @@ static NSArray *infoKeys = nil; contactInfos = [folder lookupContactsWithFilter: nil onCriteria: nil sortBy: @"c_cn" - ordering: NSOrderedAscending]; + ordering: NSOrderedAscending + inDomain: nil]; return contactInfos; }