mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-07-08 01:45:08 +00:00
Monotone-Parent: 9deadfa49386c2d13ad45fa2c1c8d7f91bae49e3
Monotone-Revision: 652fb1324338399d044d5f01bb158d94080a27c0 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-10-25T18:46:32 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
@@ -1,3 +1,16 @@
|
||||
2010-10-25 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
|
||||
* 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 <flachapelle@inverse.ca>
|
||||
|
||||
* UI/Contacts/UIxContactFolderActions.m (-importLdifData:): use
|
||||
|
||||
@@ -33,7 +33,12 @@
|
||||
#import <Foundation/NSEnumerator.h>
|
||||
|
||||
#import <NGObjWeb/WOContext+SoObjects.h>
|
||||
#import <DOM/DOMElement.h>
|
||||
#import <DOM/DOMProtocols.h>
|
||||
|
||||
#import <SOGo/NSObject+DAV.h>
|
||||
#import <SOGo/SOGoUser.h>
|
||||
#import <SOGo/SOGoUserDefaults.h>
|
||||
#import <SOGo/SOGoUserManager.h>
|
||||
#import <SOGo/WORequest+SOGo.h>
|
||||
|
||||
@@ -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 <DOMDocument> document;
|
||||
id <DOMNodeList> 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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Executable
+63
@@ -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()
|
||||
Reference in New Issue
Block a user