[CalendarServer-changes] [5956] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Tue Jul 27 18:14:45 PDT 2010


Revision: 5956
          http://trac.macosforge.org/projects/calendarserver/changeset/5956
Author:   sagen at apple.com
Date:     2010-07-27 18:14:45 -0700 (Tue, 27 Jul 2010)
Log Message:
-----------
Adds support for record-type-based augmenting

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/principals.py
    CalendarServer/trunk/calendarserver/tools/test/test_resources.py
    CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py
    CalendarServer/trunk/twistedcaldav/directory/augment.py
    CalendarServer/trunk/twistedcaldav/directory/principal.py
    CalendarServer/trunk/twistedcaldav/directory/test/augments-test-default.xml
    CalendarServer/trunk/twistedcaldav/directory/test/test_augment.py
    CalendarServer/trunk/twistedcaldav/directory/xmlfile.py

Modified: CalendarServer/trunk/calendarserver/tools/principals.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/principals.py	2010-07-28 01:14:04 UTC (rev 5955)
+++ CalendarServer/trunk/calendarserver/tools/principals.py	2010-07-28 01:14:45 UTC (rev 5956)
@@ -744,7 +744,7 @@
     else:
         directory.updateRecord(recordType, **kwargs)
 
-    augmentRecord = (yield augment.AugmentService.getAugmentRecord(kwargs['guid']))
+    augmentRecord = (yield augment.AugmentService.getAugmentRecord(kwargs['guid'], recordType))
     augmentRecord.autoSchedule = autoSchedule
     (yield augment.AugmentService.addAugmentRecords([augmentRecord]))
     directory.updateRecord(recordType, **kwargs)

Modified: CalendarServer/trunk/calendarserver/tools/test/test_resources.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_resources.py	2010-07-28 01:14:04 UTC (rev 5955)
+++ CalendarServer/trunk/calendarserver/tools/test/test_resources.py	2010-07-28 01:14:45 UTC (rev 5956)
@@ -67,7 +67,7 @@
     records = {}
 
     @classmethod
-    def getAugmentRecord(cls, guid):
+    def getAugmentRecord(cls, guid, recordType):
         if not cls.records.has_key(guid):
             record = StubAugmentRecord(guid=guid)
             cls.records[guid] = record

Modified: CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py	2010-07-28 01:14:04 UTC (rev 5955)
+++ CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py	2010-07-28 01:14:45 UTC (rev 5956)
@@ -457,7 +457,8 @@
                     # 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
@@ -711,7 +712,8 @@
             # 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))
 
             if not unrestricted:

Modified: CalendarServer/trunk/twistedcaldav/directory/augment.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/augment.py	2010-07-28 01:14:04 UTC (rev 5955)
+++ CalendarServer/trunk/twistedcaldav/directory/augment.py	2010-07-28 01:14:45 UTC (rev 5956)
@@ -57,6 +57,13 @@
         self.autoSchedule = autoSchedule
         self.clonedFromDefault = False
 
+recordTypesMap = {
+    "users" : "User",
+    "groups" : "Group",
+    "locations" : "Location",
+    "resources" : "Resource",
+}
+
 class AugmentDB(object):
     """
     Abstract base class for an augment record database.
@@ -67,7 +74,7 @@
         self.cachedRecords = {}
     
     @inlineCallbacks
-    def getAugmentRecord(self, uid):
+    def getAugmentRecord(self, uid, recordType):
         """
         Get an AugmentRecord for the specified UID or the default.
 
@@ -77,12 +84,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/trunk/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/principal.py	2010-07-28 01:14:04 UTC (rev 5955)
+++ CalendarServer/trunk/twistedcaldav/directory/principal.py	2010-07-28 01:14:45 UTC (rev 5956)
@@ -788,7 +788,7 @@
     @inlineCallbacks
     def setAutoSchedule(self, autoSchedule):
         self.record.autoSchedule = autoSchedule
-        augmentRecord = (yield augment.AugmentService.getAugmentRecord(self.record.guid))
+        augmentRecord = (yield augment.AugmentService.getAugmentRecord(self.record.guid, self.record.recordType))
         augmentRecord.autoSchedule = autoSchedule
         (yield augment.AugmentService.addAugmentRecords([augmentRecord]))
 

Modified: CalendarServer/trunk/twistedcaldav/directory/test/augments-test-default.xml
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/augments-test-default.xml	2010-07-28 01:14:04 UTC (rev 5955)
+++ CalendarServer/trunk/twistedcaldav/directory/test/augments-test-default.xml	2010-07-28 01:14:45 UTC (rev 5956)
@@ -27,6 +27,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/trunk/twistedcaldav/directory/test/test_augment.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/test_augment.py	2010-07-28 01:14:04 UTC (rev 5955)
+++ CalendarServer/trunk/twistedcaldav/directory/test/test_augment.py	2010-07-28 01:14:45 UTC (rev 5956)
@@ -17,6 +17,7 @@
 from twistedcaldav.test.util import TestCase
 from twistedcaldav.directory.augment import AugmentXMLDB, AugmentSqliteDB,\
     AugmentPostgreSQLDB, AugmentRecord
+from twistedcaldav.directory.directory import DirectoryService
 from twisted.internet.defer import inlineCallbacks
 from twistedcaldav.directory.xmlaugmentsparser import XMLAugmentsParser
 import cStringIO
@@ -48,7 +49,14 @@
     {"uid":"CCD30AD3-582F-4682-8B65-2EDE92C5656E", "enabled":True,  "hostedAt":"00003", "enabledForCalendaring":True,  "enabledForAddressBooks":True,  "autoSchedule":True },
 )
 
+testRecordTypeDefault = (
+    ("locations", {"uid":"A4318887-F2C7-4A70-9056-B88CC8DB26F1", "enabled":True,  "hostedAt":"00004", "enabledForCalendaring":True,  "enabledForAddressBooks":False,  "autoSchedule":True}),
+    ("locations", {"uid":"AA5F935F-3358-4510-A649-B391D63279F2", "enabled":True,  "hostedAt":"00005", "enabledForCalendaring":True, "enabledForAddressBooks":False, "autoSchedule":True}),
+    ("resources", {"uid":"A5318887-F2C7-4A70-9056-B88CC8DB26F1", "enabled":True,  "hostedAt":"00006", "enabledForCalendaring":True,  "enabledForAddressBooks":False,  "autoSchedule":True}),
+    ("resources", {"uid":"AA6F935F-3358-4510-A649-B391D63279F2", "enabled":True,  "hostedAt":"00007", "enabledForCalendaring":True, "enabledForAddressBooks":False, "autoSchedule":True}),
+)
 
+
 testAddRecords = (
     {"uid":"D11F03A0-97EA-48AF-9A6C-FAC7F3975767", "enabled":True,  "hostedAt":"", "enabledForCalendaring":False, "enabledForAddressBooks":False, "autoSchedule":False},
 )
@@ -61,18 +69,18 @@
 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, "Failed record uid: %s" % (items["uid"],))
         
         for k,v in items.iteritems():
             self.assertEqual(getattr(record, k), v, "Failed record uid: %s, attribute: %s" % (items["uid"], k, ))
 
     @inlineCallbacks
-    def _checkRecordExists(self, db, uid):
+    def _checkRecordExists(self, db, uid, recordType=DirectoryService.recordType_users):
         
-        record = (yield db.getAugmentRecord(uid))
+        record = (yield db.getAugmentRecord(uid, recordType))
         self.assertTrue(record is not None, "Failed record uid: %s" % (uid,))
 
 class AugmentTestsMixin(object):
@@ -116,6 +124,31 @@
             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
+        """
+
+        dbpath = os.path.abspath(self.mktemp())
+        db = self._db(dbpath)
+
+        dbxml = AugmentXMLDB((xmlFileDefault,))
+        yield db.addAugmentRecords(dbxml.db.values())
+
+        for recordType, item in testRecordTypeDefault:
+            yield self._checkRecord(db, item, recordType)
+
+
+    @inlineCallbacks
     def test_add_modify(self):
         
         dbpath = os.path.abspath(self.mktemp())

Modified: CalendarServer/trunk/twistedcaldav/directory/xmlfile.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/xmlfile.py	2010-07-28 01:14:04 UTC (rev 5955)
+++ CalendarServer/trunk/twistedcaldav/directory/xmlfile.py	2010-07-28 01:14:45 UTC (rev 5956)
@@ -152,7 +152,8 @@
                 # 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))
 
                 matched = False
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100727/1cf2cedc/attachment-0001.html>


More information about the calendarserver-changes mailing list