[CalendarServer-changes] [673] CalendarServer/trunk/twistedcaldav/directory

source_changes at macosforge.org source_changes at macosforge.org
Tue Dec 5 00:35:00 PST 2006


Revision: 673
          http://trac.macosforge.org/projects/calendarserver/changeset/673
Author:   wsanchez at apple.com
Date:     2006-12-05 00:35:00 -0800 (Tue, 05 Dec 2006)

Log Message:
-----------
 - Add recordWithCalendarUserAddress to IDirectoryService.

 - Implement missing methods of IDirectoryService in DirectoryService
   as abstract.

 - Add concrete implementation of recordWithCalendarUserAddress and
   recordWithGUID in DirectoryService.

 - Test recordWithCalendarUserAddress and recordWithGUID.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/directory/apache.py
    CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py
    CalendarServer/trunk/twistedcaldav/directory/directory.py
    CalendarServer/trunk/twistedcaldav/directory/idirectory.py
    CalendarServer/trunk/twistedcaldav/directory/principal.py
    CalendarServer/trunk/twistedcaldav/directory/sqldb.py
    CalendarServer/trunk/twistedcaldav/directory/test/util.py
    CalendarServer/trunk/twistedcaldav/directory/xmlfile.py

Modified: CalendarServer/trunk/twistedcaldav/directory/apache.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/apache.py	2006-12-05 07:57:03 UTC (rev 672)
+++ CalendarServer/trunk/twistedcaldav/directory/apache.py	2006-12-05 08:35:00 UTC (rev 673)
@@ -103,9 +103,6 @@
 
         return None
 
-    def recordWithGUID(self, guid):
-        raise NotImplementedError()
-
     def entriesForRecordType(self, recordType):
         if recordType == "user":
             recordFile = self.userFile

Modified: CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py	2006-12-05 07:57:03 UTC (rev 672)
+++ CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py	2006-12-05 08:35:00 UTC (rev 673)
@@ -142,13 +142,6 @@
     def recordWithShortName(self, recordType, shortName):
         return self._cacheRecords(recordType).get(shortName, None)
 
-    def recordWithGUID(self, guid):
-        for recordType in self.recordTypes():
-            for record in self._cacheRecords(recordType).itervalues():
-                if record.guid == guid:
-                    return record
-        return None
-
 #    def recordWithShortName(self, recordType, shortName):
 #        if recordType == "user":
 #            listRecords = opendirectory.listUsersWithAttributes

Modified: CalendarServer/trunk/twistedcaldav/directory/directory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/directory.py	2006-12-05 07:57:03 UTC (rev 672)
+++ CalendarServer/trunk/twistedcaldav/directory/directory.py	2006-12-05 08:35:00 UTC (rev 673)
@@ -71,6 +71,33 @@
         else:
             raise UnauthorizedLogin("Incorrect credentials for %s" % (user,)) 
 
+    def recordTypes(self):
+        raise NotImplementedError("Subclass must implement recordTypes()")
+
+    def listRecords(self, recordType):
+        raise NotImplementedError("Subclass must implement listRecords()")
+
+    def recordWithShortName(self, recordType, shortName):
+        raise NotImplementedError("Subclass must implement recordWithShortName()")
+
+    def recordWithGUID(self, guid):
+        for record in self.allRecords():
+            if record.guid == guid:
+                return record
+        return None
+
+    def recordWithCalendarUserAddress(self, address):
+        for record in self.allRecords():
+            if address in record.calendarUserAddresses:
+                return record
+        return None
+
+    def allRecords(self):
+        for recordType in self.recordTypes():
+            for record in self.listRecords(recordType):
+                yield record
+
+
 class DirectoryRecord(object):
     implements(IDirectoryRecord)
 

Modified: CalendarServer/trunk/twistedcaldav/directory/idirectory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/idirectory.py	2006-12-05 07:57:03 UTC (rev 672)
+++ CalendarServer/trunk/twistedcaldav/directory/idirectory.py	2006-12-05 08:35:00 UTC (rev 673)
@@ -60,6 +60,13 @@
             if no such record exists.
         """
 
+    def recordWithCalendarUserAddress(address):
+        """
+        @param address: the calendar user address of the record to look up.
+        @return: an L{IDirectoryRecord} provider with the given calendar user
+            address, or C{None} if no such record exists.
+        """
+
 class IDirectoryRecord(Interface):
     """
     Directory Record

Modified: CalendarServer/trunk/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/principal.py	2006-12-05 07:57:03 UTC (rev 672)
+++ CalendarServer/trunk/twistedcaldav/directory/principal.py	2006-12-05 08:35:00 UTC (rev 673)
@@ -38,7 +38,7 @@
 from twistedcaldav.extensions import ReadOnlyResourceMixIn, DAVFile
 from twistedcaldav.resource import CalendarPrincipalCollectionResource, CalendarPrincipalResource
 from twistedcaldav.static import provisionFile
-from twistedcaldav.dropbox import Dropbox
+from twistedcaldav.dropbox import DropBox
 from twistedcaldav.directory.idirectory import IDirectoryService
 
 # FIXME: These should not be tied to DAVFile
@@ -91,6 +91,13 @@
             return None
         return typeResource.getChild(record.shortName)
 
+    def principalForCalendarUserAddress(self, address):
+        record = self.directory.recordWithCalendarUserAddress(address)
+        if record is None:
+            return None
+        else:
+            return self.principalForRecord(record)
+
     ##
     # Static
     ##
@@ -140,6 +147,9 @@
     def principalForRecord(self, record):
         return self._parent.principalForRecord(record)
 
+    def principalForCalendarUserAddress(self, address):
+        return self._parent.principalForCalendarUserAddress(address)
+
     ##
     # Static
     ##

Modified: CalendarServer/trunk/twistedcaldav/directory/sqldb.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/sqldb.py	2006-12-05 07:57:03 UTC (rev 672)
+++ CalendarServer/trunk/twistedcaldav/directory/sqldb.py	2006-12-05 08:35:00 UTC (rev 673)
@@ -291,9 +291,6 @@
 
         return None
 
-    def recordWithGUID(self, guid):
-        raise NotImplementedError()
-
 class SQLDirectoryRecord(DirectoryRecord):
     """
     XML based implementation implementation of L{IDirectoryRecord}.

Modified: CalendarServer/trunk/twistedcaldav/directory/test/util.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/util.py	2006-12-05 07:57:03 UTC (rev 672)
+++ CalendarServer/trunk/twistedcaldav/directory/test/util.py	2006-12-05 08:35:00 UTC (rev 673)
@@ -121,6 +121,31 @@
             record = service.recordWithShortName("resource", shortName)
             self.compare(record, shortName, self.resources[shortName])
 
+    def test_recordWithGUID(self):
+        service = self.service()
+        record = None
+
+        for shortName, what in self.allEntries():
+            guid = what["guid"]
+            if guid is not None:
+                record = service.recordWithGUID(guid)
+                self.compare(record, shortName, what)
+
+        if record is None:
+            raise SkipTest("No GUIDs provided to test")
+
+    def test_recordWithCalendarUserAddress(self):
+        service = self.service()
+        record = None
+
+        for shortName, what in self.allEntries():
+            for address in what["addresses"]:
+                record = service.recordWithCalendarUserAddress(address)
+                self.compare(record, shortName, what)
+
+        if record is None:
+            raise SkipTest("No calendar user addresses provided to test")
+
     def test_groupMembers(self):
         """
         IDirectoryRecord.members()
@@ -156,6 +181,15 @@
     def recordNames(self, recordType):
         return set(r.shortName for r in self.service().listRecords(recordType))
 
+    def allEntries(self):
+        for data, recordType in (
+            (self.users,     "user"    ),
+            (self.groups,    "group"   ),
+            (self.resources, "resource"),
+        ):
+            for item in data.iteritems():
+                yield item
+
     def compare(self, record, shortName, data):
         def value(key):
             if key in data:

Modified: CalendarServer/trunk/twistedcaldav/directory/xmlfile.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/xmlfile.py	2006-12-05 07:57:03 UTC (rev 672)
+++ CalendarServer/trunk/twistedcaldav/directory/xmlfile.py	2006-12-05 08:35:00 UTC (rev 673)
@@ -72,9 +72,6 @@
 
         return None
 
-    def recordWithGUID(self, guid):
-        raise NotImplementedError()
-
     def _entriesForRecordType(self, recordType):
         for entry in self._accounts().itervalues():
             if entry.recordType == recordType:

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20061205/d536b514/attachment.html


More information about the calendarserver-changes mailing list