diff --git a/ChangeLog b/ChangeLog index 7c2377114..e1364034b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2012-02-21 Wolfgang Sourdeau + + * SoObjects/Appointments/SOGoAppointmentFolders.m + (-davEventsDefaultClassification,) + (setDavEventsDefaultClassification:) + (-davTasksDefaultClassification) + (-setDavTasksDefaultClassification:): new DAV accessors for the + default classification preferences. + + * Tests/Integration/test-default-classification.py: new test + module for setting/getting defaults classification preferences. + 2012-02-20 Wolfgang Sourdeau * UI/Scheduler/UIxComponentEditor.m (-setComponent:): fetch diff --git a/SoObjects/Appointments/SOGoAppointmentFolders.m b/SoObjects/Appointments/SOGoAppointmentFolders.m index 95efe3ae0..3a8e020aa 100644 --- a/SoObjects/Appointments/SOGoAppointmentFolders.m +++ b/SoObjects/Appointments/SOGoAppointmentFolders.m @@ -398,6 +398,69 @@ static SoSecurityManager *sm = nil; return componentSet; } +- (NSString *) _davDefaultClassWithSelector: (SEL) selector +{ + SOGoUser *ownerUser; + SOGoUserDefaults *defaults; + NSString *classification; + + ownerUser = [SOGoUser userWithLogin: [self ownerInContext: context]]; + defaults = [ownerUser userDefaults]; + classification = [defaults performSelector: selector]; + + return classification; +} + +- (NSException *) _davSetDefaultClass: (NSString *) newClass + withSelector: (SEL) selector +{ + NSException *error; + static NSArray *validClassifications = nil; + SOGoUser *ownerUser; + SOGoUserDefaults *defaults; + + if (!validClassifications) + validClassifications = [[NSArray alloc] initWithObjects: @"PUBLIC", + @"CONFIDENTIAL", @"PRIVATE", nil]; + + if (newClass && [validClassifications containsObject: newClass]) + { + error = nil; + ownerUser = [SOGoUser userWithLogin: [self ownerInContext: context]]; + defaults = [ownerUser userDefaults]; + [defaults performSelector: selector withObject: newClass]; + [defaults synchronize]; + } + else + error = [NSException exceptionWithHTTPStatus: 403 + reason: @"invalid" + @" classification value"]; + + return error; +} + +- (NSString *) davEventsDefaultClassification +{ + return [self _davDefaultClassWithSelector: @selector (calendarEventsDefaultClassification)]; +} + +- (NSException *) setDavEventsDefaultClassification: (NSString *) newClass +{ + return [self _davSetDefaultClass: newClass + withSelector: @selector (setCalendarEventsDefaultClassification:)]; +} + +- (NSString *) davTasksDefaultClassification +{ + return [self _davDefaultClassWithSelector: @selector (calendarTasksDefaultClassification)]; +} + +- (NSException *) setDavTasksDefaultClassification: (NSString *) newClass +{ + return [self _davSetDefaultClass: newClass + withSelector: @selector (setCalendarTasksDefaultClassification:)]; +} + /* This method fixes an issue that occurred previously in _migrateWebCalendarsSettings, where the active user, rather than the owner's login would be taken to compose the expected key prefix, leading to diff --git a/Tests/Integration/test-default-classification.py b/Tests/Integration/test-default-classification.py new file mode 100755 index 000000000..8994b6aff --- /dev/null +++ b/Tests/Integration/test-default-classification.py @@ -0,0 +1,52 @@ +#!/usr/bin/python + +import sogotests +import unittest +import webdavlib + +from config import * + +class HTTPDefaultClassificationTest(unittest.TestCase): + def _setClassification(self, user, component, classification = ""): + resource = '/SOGo/dav/%s/Calendar/' % user + props = { "{urn:inverse:params:xml:ns:inverse-dav}%s-default-classification" % component: classification } + proppatch = webdavlib.WebDAVPROPPATCH(resource, props) + client = webdavlib.WebDAVClient(hostname, port, username, password) + client.execute(proppatch) + + return (proppatch.response["status"] == 207); + + def _getClassification(self, user, component): + resource = '/SOGo/dav/%s/Calendar/' % user + property_name = "{urn:inverse:params:xml:ns:inverse-dav}%s-default-classification" % component + propfind = webdavlib.WebDAVPROPFIND(resource, [ property_name ], "0") + client = webdavlib.WebDAVClient(hostname, port, username, password) + client.execute(propfind) + classification = None + propstat_nodes = propfind.response["document"].findall("{DAV:}response/{DAV:}propstat") + for propstat_node in propstat_nodes: + status_nodes = propstat_node.findall("{DAV:}status") + if status_nodes[0].text.lower() == "http/1.1 200 ok": + property_nodes = propstat_node.findall("{DAV:}prop/%s" % property_name) + if len(property_nodes) > 0: + classification = property_nodes[0].text + + return classification + + def test(self): + self.assertFalse(self._setClassification(username, "123456", "PUBLIC"), + "expected failure when setting a classification with an invalid property") + self.assertFalse(self._setClassification(username, "events", ""), + "expected failure when setting an empty classification") + self.assertFalse(self._setClassification(username, "events", "pouet"), + "expected failure when setting an invalid classification") + for component in [ "events", "tasks" ]: + for classification in [ "PUBLIC", "PRIVATE", "CONFIDENTIAL" ]: + self.assertTrue(self._setClassification(username, component, classification), + "error when setting classification to '%s'" % classification) + fetched_class = self._getClassification(username, component) + self.assertTrue(classification == fetched_class, + "set and fetched classifications do not match (%s != %s)" % (classification, fetched_class)) + +if __name__ == "__main__": + sogotests.runTests()