diff --git a/ChangeLog b/ChangeLog index 80b3474f3..e087f1f66 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2010-10-25 Wolfgang Sourdeau + + * SoObjects/SOGo/SOGoUserDefaults.m (-setContactCategories) + (-contactCategories): new accessors for the + "SOGoContactCategories" user default. Accept/return an array of + strings. + + * SoObjects/Contacts/SOGoContactFolders.m + (-setDavContactCategories, -davContactCategories): new accessors + for the new + "{urn:ietf:params:xml:ns:inverse-dav}contact-categories" custom + property. Make use of the new methods above. + 2010-10-25 Francis Lachapelle * UI/Contacts/UIxContactFolderActions.m (-importLdifData:): use diff --git a/SoObjects/Contacts/SOGoContactFolders.m b/SoObjects/Contacts/SOGoContactFolders.m index 189326215..82af5a7de 100644 --- a/SoObjects/Contacts/SOGoContactFolders.m +++ b/SoObjects/Contacts/SOGoContactFolders.m @@ -33,7 +33,12 @@ #import #import +#import +#import + +#import #import +#import #import #import @@ -41,6 +46,7 @@ #import "SOGoContactSourceFolder.h" #import "SOGoContactFolders.h" +#define XMLNS_INVERSEDAV @"urn:ietf:params:xml:ns:inverse-dav" @implementation SOGoContactFolders + (NSString *) gcsFolderType @@ -105,4 +111,69 @@ return keys; } +- (NSException *) setDavContactCategories: (NSString *) newCategories +{ + SOGoUser *ownerUser; + NSMutableArray *categories; + DOMElement *documentElement, *catNode, *textNode; + id document; + id catNodes; + NSUInteger count, max; + SOGoUserDefaults *ud; + + categories = [NSMutableArray array]; + + if ([newCategories length] > 0) + { + document = [[context request] contentAsDOMDocument]; + documentElement = (DOMElement *) [document documentElement]; + catNodes = [documentElement getElementsByTagName: @"category"]; + max = [catNodes length]; + for (count = 0; count < max; count++) + { + catNode = [catNodes objectAtIndex: count]; + if ([catNode hasChildNodes]) + { + textNode = [[catNode childNodes] objectAtIndex: 0]; + [categories addObject: [textNode nodeValue]]; + } + } + } + + NSLog (@"setting categories to : %@", categories); + ownerUser = [SOGoUser userWithLogin: owner]; + ud = [ownerUser userDefaults]; + [ud setContactCategories: categories]; + [ud synchronize]; + + return nil; +} + +- (SOGoWebDAVValue *) davContactCategories +{ + NSMutableArray *davCategories; + NSArray *categories; + NSUInteger count, max; + SOGoUser *ownerUser; + NSDictionary *catElement; + + ownerUser = [SOGoUser userWithLogin: owner]; + categories = [[ownerUser userDefaults] contactCategories]; + + max = [categories count]; + davCategories = [NSMutableArray arrayWithCapacity: max]; + for (count = 0; count < max; count++) + { + catElement = davElementWithContent (@"category", + XMLNS_INVERSEDAV, + [categories objectAtIndex: count]); + [davCategories addObject: catElement]; + } + + return [davElementWithContent (@"contact-categories", + XMLNS_INVERSEDAV, + davCategories) + asWebDAVValue]; +} + @end diff --git a/SoObjects/SOGo/SOGoUserDefaults.h b/SoObjects/SOGo/SOGoUserDefaults.h index 95845e686..a4f3144f3 100644 --- a/SoObjects/SOGo/SOGoUserDefaults.h +++ b/SoObjects/SOGo/SOGoUserDefaults.h @@ -39,6 +39,7 @@ extern NSString *SOGoWeekStartFirstFullWeek; + (SOGoUserDefaults *) defaultsForUser: (NSString *) userId inDomain: (NSString *) domainId; +/* general */ - (void) setLoginModule: (NSString *) newLoginModule; - (NSString *) loginModule; @@ -80,6 +81,7 @@ extern NSString *SOGoWeekStartFirstFullWeek; - (void) setLanguage: (NSString *) newValue; - (NSString *) language; +/* mail */ - (void) setMailShowSubscribedFoldersOnly: (BOOL) newValue; - (BOOL) mailShowSubscribedFoldersOnly; @@ -134,6 +136,16 @@ extern NSString *SOGoWeekStartFirstFullWeek; - (void) setAuxiliaryMailAccounts: (NSArray *) newAccounts; - (NSArray *) auxiliaryMailAccounts; +- (void) setSieveFilters: (NSArray *) newValue; +- (NSArray *) sieveFilters; + +- (void) setVacationOptions: (NSDictionary *) newValue; +- (NSDictionary *) vacationOptions; + +- (void) setForwardOptions: (NSDictionary *) newValue; +- (NSDictionary *) forwardOptions; + +/* calendar */ - (void) setCalendarCategories: (NSArray *) newValues; - (NSArray *) calendarCategories; @@ -152,14 +164,9 @@ extern NSString *SOGoWeekStartFirstFullWeek; - (void) setRemindWithASound: (BOOL) newValue; - (BOOL) remindWithASound; -- (void) setSieveFilters: (NSArray *) newValue; -- (NSArray *) sieveFilters; - -- (void) setVacationOptions: (NSDictionary *) newValue; -- (NSDictionary *) vacationOptions; - -- (void) setForwardOptions: (NSDictionary *) newValue; -- (NSDictionary *) forwardOptions; +/* contacts */ +- (void) setContactCategories: (NSArray *) newValues; +- (NSArray *) contactCategories; @end diff --git a/SoObjects/SOGo/SOGoUserDefaults.m b/SoObjects/SOGo/SOGoUserDefaults.m index 7bab51af8..dfd932756 100644 --- a/SoObjects/SOGo/SOGoUserDefaults.m +++ b/SoObjects/SOGo/SOGoUserDefaults.m @@ -651,4 +651,14 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek"; return [self dictionaryForKey: @"Forward"]; } +- (void) setContactCategories: (NSArray *) newValues +{ + [self setObject: newValues forKey: @"SOGoContactCategories"]; +} + +- (NSArray *) contactCategories +{ + return [self stringArrayForKey: @"SOGoContactCategories"]; +} + @end diff --git a/Tests/Integration/test-contact-categories.py b/Tests/Integration/test-contact-categories.py new file mode 100755 index 000000000..0771ac06f --- /dev/null +++ b/Tests/Integration/test-contact-categories.py @@ -0,0 +1,63 @@ +#!/usr/bin/python + +import sogotests +import unittest +import webdavlib + +from config import * + +class HTTPContactCategoriesTest(unittest.TestCase): + def _setCategories(self, user, categories = None): + resource = '/SOGo/dav/%s/Contacts/' % user + if categories is None: + categories = [] + elements = [ { "{urn:ietf:params:xml:ns:inverse-dav}category": x } + for x in categories ] + props = { "{urn:ietf:params:xml:ns:inverse-dav}contact-categories": elements } + proppatch = webdavlib.WebDAVPROPPATCH(resource, props) + client = webdavlib.WebDAVClient(hostname, port, username, password) + client.execute(proppatch) + self.assertEquals(proppatch.response["status"], 207, + "failure (%s) setting '%s' categories on %s's contacts" + % (proppatch.response["status"], + "', '".join(categories), user)) + + def _getCategories(self, user): + resource = '/SOGo/dav/%s/Contacts/' % user + props = [ "{urn:ietf:params:xml:ns:inverse-dav}contact-categories" ] + propfind = webdavlib.WebDAVPROPFIND(resource, props, "0") + client = webdavlib.WebDAVClient(hostname, port, username, password) + client.execute(propfind) + self.assertEquals(propfind.response["status"], 207, + "failure (%s) getting categories on %s's contacts" + % (propfind.response["status"], user)) + + categories = [] + prop_nodes = propfind.response["document"].findall("{DAV:}response/{DAV:}propstat/{DAV:}prop/{urn:ietf:params:xml:ns:inverse-dav}contact-categories") + for prop_node in prop_nodes: + cat_nodes = prop_node.findall("{urn:ietf:params:xml:ns:inverse-dav}category") + if cat_nodes is not None: + for cat_node in cat_nodes: + categories.append(cat_node.text) + + return categories + + + def test(self): + self._setCategories(username, []) + cats = self._getCategories(username) + self.assertTrue(cats is not None and len(cats) == 0) + + self._setCategories(username, [ "Coucou" ]) + cats = self._getCategories(username) + self.assertTrue(cats is not None and len(cats) == 1) + self.assertEquals(cats[0], "Coucou") + + self._setCategories(username, [ "Toto", "Cuicui" ]) + cats = self._getCategories(username) + self.assertTrue(cats is not None and len(cats) == 2) + self.assertEquals(cats[0], "Toto") + self.assertEquals(cats[1], "Cuicui") + +if __name__ == "__main__": + sogotests.runTests()