[CalendarServer-changes] [5959] CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/ directory
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jul 29 09:53:27 PDT 2010
Revision: 5959
http://trac.macosforge.org/projects/calendarserver/changeset/5959
Author: sagen at apple.com
Date: 2010-07-29 09:53:26 -0700 (Thu, 29 Jul 2010)
Log Message:
-----------
Adds support for record-type-based augmenting
Modified Paths:
--------------
CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/appleopendirectory.py
CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/augment.py
CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/test/augments-test-default.xml
CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/test/test_augment.py
CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/xmlfile.py
Modified: CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/appleopendirectory.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/appleopendirectory.py 2010-07-29 07:30:29 UTC (rev 5958)
+++ CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/appleopendirectory.py 2010-07-29 16:53:26 UTC (rev 5959)
@@ -527,7 +527,7 @@
# Look up augment information
# TODO: this needs to be deferred but for now we hard code the deferred result because
# we know it is completing immediately.
- d = augment.AugmentService.getAugmentRecord(record.guid)
+ d = augment.AugmentService.getAugmentRecord(record.guid, recordType)
d.addCallback(lambda x:record.addAugmentInformation(x))
# Check for disabled items
Modified: CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/augment.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/augment.py 2010-07-29 07:30:29 UTC (rev 5958)
+++ CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/augment.py 2010-07-29 16:53:26 UTC (rev 5959)
@@ -45,6 +45,13 @@
self.enabledForCalendaring = enabledForCalendaring
self.autoSchedule = autoSchedule
+recordTypesMap = {
+ "users" : "User",
+ "groups" : "Group",
+ "locations" : "Location",
+ "resources" : "Resource",
+}
+
class AugmentDB(object):
"""
Abstract base class for an augment record database.
@@ -55,7 +62,7 @@
self.cachedRecords = {}
@inlineCallbacks
- def getAugmentRecord(self, uid):
+ def getAugmentRecord(self, uid, recordType):
"""
Get an AugmentRecord for the specified UID or the default.
@@ -64,13 +71,21 @@
@return: L{Deferred}
"""
-
+ recordType = recordTypesMap[recordType]
+
result = (yield self._lookupAugmentRecord(uid))
if result is not None:
returnValue(result)
# Try wildcard/default matches next
- for lookup in ("%s*" % (uid[0:2],), "%s*" % (uid[0],), "Default"):
+ for lookup in (
+ "%s-%s*" % (recordType, uid[0:2]),
+ "%s-%s*" % (recordType, uid[0]),
+ "%s*" % (uid[0:2],),
+ "%s*" % (uid[0],),
+ "%s-Default" % (recordType,),
+ "Default",
+ ):
result = (yield self._cachedAugmentRecord(lookup))
if result is not None:
result = copy.deepcopy(result)
Modified: CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/test/augments-test-default.xml
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/test/augments-test-default.xml 2010-07-29 07:30:29 UTC (rev 5958)
+++ CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/test/augments-test-default.xml 2010-07-29 16:53:26 UTC (rev 5959)
@@ -26,6 +26,34 @@
<hosted-at>00001</hosted-at>
</record>
<record>
+ <uid>Location-Default</uid>
+ <enable>true</enable>
+ <enable-calendar>true</enable-calendar>
+ <hosted-at>00004</hosted-at>
+ <auto-schedule>true</auto-schedule>
+ </record>
+ <record>
+ <uid>Location-AA*</uid>
+ <enable>true</enable>
+ <enable-calendar>true</enable-calendar>
+ <hosted-at>00005</hosted-at>
+ <auto-schedule>true</auto-schedule>
+ </record>
+ <record>
+ <uid>Resource-Default</uid>
+ <enable>true</enable>
+ <enable-calendar>true</enable-calendar>
+ <hosted-at>00006</hosted-at>
+ <auto-schedule>true</auto-schedule>
+ </record>
+ <record>
+ <uid>Resource-AA*</uid>
+ <enable>true</enable>
+ <enable-calendar>true</enable-calendar>
+ <hosted-at>00007</hosted-at>
+ <auto-schedule>true</auto-schedule>
+ </record>
+ <record>
<uid>AA*</uid>
<enable>true</enable>
<hosted-at>00001</hosted-at>
Modified: CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/test/test_augment.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/test/test_augment.py 2010-07-29 07:30:29 UTC (rev 5958)
+++ CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/test/test_augment.py 2010-07-29 16:53:26 UTC (rev 5959)
@@ -18,6 +18,7 @@
from twistedcaldav.directory.augment import AugmentXMLDB, AugmentSqliteDB,\
AugmentPostgreSQLDB
from twisted.internet.defer import inlineCallbacks
+from twistedcaldav.directory.directory import DirectoryService
from twistedcaldav.directory.xmlaugmentsparser import XMLAugmentsParser
import cStringIO
import os
@@ -47,21 +48,28 @@
{"uid":"CCD30AD3-582F-4682-8B65-2EDE92C5656E", "enabled":True, "hostedAt":"00003", "enabledForCalendaring":True, "autoSchedule":True },
)
+testRecordTypeDefault = (
+ ("locations", {"uid":"A4318887-F2C7-4A70-9056-B88CC8DB26F1", "enabled":True, "hostedAt":"00004", "enabledForCalendaring":True, "autoSchedule":True}),
+ ("locations", {"uid":"AA5F935F-3358-4510-A649-B391D63279F2", "enabled":True, "hostedAt":"00005", "enabledForCalendaring":True, "autoSchedule":True}),
+ ("resources", {"uid":"A5318887-F2C7-4A70-9056-B88CC8DB26F1", "enabled":True, "hostedAt":"00006", "enabledForCalendaring":True, "autoSchedule":True}),
+ ("resources", {"uid":"AA6F935F-3358-4510-A649-B391D63279F2", "enabled":True, "hostedAt":"00007", "enabledForCalendaring":True, "autoSchedule":True}),
+)
+
class AugmentTests(TestCase):
@inlineCallbacks
- def _checkRecord(self, db, items):
+ def _checkRecord(self, db, items, recordType=DirectoryService.recordType_users):
- record = (yield db.getAugmentRecord(items["uid"]))
+ record = (yield db.getAugmentRecord(items["uid"], recordType))
self.assertTrue(record is not None)
for k,v in items.iteritems():
self.assertEqual(getattr(record, k), v)
@inlineCallbacks
- def _checkNoRecord(self, db, uid):
+ def _checkNoRecord(self, db, uid, recordType=DirectoryService.recordType_users):
- record = (yield db.getAugmentRecord(uid))
+ record = (yield db.getAugmentRecord(uid, recordType))
self.assertTrue(record is None)
class AugmentTestsMixin(object):
@@ -102,6 +110,7 @@
for item in testRecordWildcardDefault:
yield self._checkRecord(db, item)
+
class AugmentXMLTests(AugmentTests, AugmentTestsMixin):
@inlineCallbacks
@@ -125,6 +134,26 @@
for item in testRecordWildcardDefault:
yield self._checkRecord(db, item)
+ @inlineCallbacks
+ def test_read_typed_default(self):
+ """
+ Augments key ("uid" element in xml) can be any of the following, in
+ this order of precedence:
+
+ full uid
+ <recordType>-XX*
+ <recordType>-X*
+ XX*
+ X*
+ <recordType>-Default
+ Default
+ """
+
+ db = AugmentXMLDB((xmlFileDefault,))
+
+ for recordType, item in testRecordTypeDefault:
+ yield self._checkRecord(db, item, recordType)
+
def test_parseErrors(self):
db = {}
Modified: CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/xmlfile.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/xmlfile.py 2010-07-29 07:30:29 UTC (rev 5958)
+++ CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/directory/xmlfile.py 2010-07-29 16:53:26 UTC (rev 5959)
@@ -72,7 +72,7 @@
# Look up augment information
# TODO: this needs to be deferred but for now we hard code the deferred result because
# we know it is completing immediately.
- d = augment.AugmentService.getAugmentRecord(record.guid)
+ d = augment.AugmentService.getAugmentRecord(record.guid, recordType)
d.addCallback(lambda x:record.addAugmentInformation(x))
yield record
@@ -90,7 +90,7 @@
# Look up augment information
# TODO: this needs to be deferred but for now we hard code the deferred result because
# we know it is completing immediately.
- d = augment.AugmentService.getAugmentRecord(record.guid)
+ d = augment.AugmentService.getAugmentRecord(record.guid, recordType)
d.addCallback(lambda x:record.addAugmentInformation(x))
return record
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100729/0f2f1afe/attachment-0001.html>
More information about the calendarserver-changes
mailing list