diff --git a/ChangeLog b/ChangeLog index 6d4e4c3c8..c26c05cdc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-10-23 Wolfgang Sourdeau + + * SoObjects/SOGo/SOGoUserManager.m (_registerSource:): added + sanity checks and warnings to the user. + 2009-10-22 Ludovic Marcotte * SoObjects/SOGo/SOGoUserManager.m diff --git a/SoObjects/SOGo/SOGoUserManager.m b/SoObjects/SOGo/SOGoUserManager.m index 7acc5a271..fdeedc50a 100644 --- a/SoObjects/SOGo/SOGoUserManager.m +++ b/SoObjects/SOGo/SOGoUserManager.m @@ -104,36 +104,54 @@ static NSLock *lock = nil; NSString *sourceID, *value, *type; NSMutableDictionary *metadata; id ldapSource; + BOOL isAddressBook; Class c; sourceID = [udSource objectForKey: @"id"]; - type = [udSource objectForKey: @"type"]; + if ([sourceID length] > 0) + { + type = [udSource objectForKey: @"type"]; - if (!type || [type caseInsensitiveCompare: @"ldap"] == NSOrderedSame) - c = [LDAPSource class]; - else - c = [SQLSource class]; + if (!type || [type caseInsensitiveCompare: @"ldap"] == NSOrderedSame) + c = [LDAPSource class]; + else + c = [SQLSource class]; - ldapSource = [c sourceFromUDSource: udSource]; - if (sourceID) - [_sources setObject: ldapSource forKey: sourceID]; + ldapSource = [c sourceFromUDSource: udSource]; + if (sourceID) + [_sources setObject: ldapSource forKey: sourceID]; + else + [self errorWithFormat: @"id field missing in an user source," + @" check the SOGoUserSources defaults"]; + metadata = [NSMutableDictionary dictionary]; + value = [udSource objectForKey: @"canAuthenticate"]; + if (value) + [metadata setObject: value forKey: @"canAuthenticate"]; + value = [udSource objectForKey: @"isAddressBook"]; + if (value) + { + [metadata setObject: value forKey: @"isAddressBook"]; + isAddressBook = [value boolValue]; + } + else + isAddressBook = NO; + value = [udSource objectForKey: @"displayName"]; + if (value) + [metadata setObject: value forKey: @"displayName"]; + else + { + if (isAddressBook) + [self errorWithFormat: @"addressbook source '%@' has" + @" no displayname", sourceID]; + } + value = [udSource objectForKey: @"MailFieldNames"]; + if (value) + [metadata setObject: value forKey: @"MailFieldNames"]; + [_sourcesMetadata setObject: metadata forKey: sourceID]; + } else - [self errorWithFormat: @"id field missing in an user source," - @" check the SOGoUserSources defaults"]; - metadata = [NSMutableDictionary dictionary]; - value = [udSource objectForKey: @"canAuthenticate"]; - if (value) - [metadata setObject: value forKey: @"canAuthenticate"]; - value = [udSource objectForKey: @"isAddressBook"]; - if (value) - [metadata setObject: value forKey: @"isAddressBook"]; - value = [udSource objectForKey: @"displayName"]; - if (value) - [metadata setObject: value forKey: @"displayName"]; - value = [udSource objectForKey: @"MailFieldNames"]; - if (value) - [metadata setObject: value forKey: @"MailFieldNames"]; - [_sourcesMetadata setObject: metadata forKey: sourceID]; + [self errorWithFormat: @"attempted to register a contact/user source" + @" without id (skipped)"]; } - (void) _prepareSourcesWithDefaults: (NSUserDefaults *) ud