[CalendarServer-changes] [1719] CalendarServer/branches/users/wsanchez/deleted-uids/twistedcaldav/ directory/principal.py

source_changes at macosforge.org source_changes at macosforge.org
Thu Jul 26 17:10:15 PDT 2007


Revision: 1719
          http://trac.macosforge.org/projects/calendarserver/changeset/1719
Author:   wsanchez at apple.com
Date:     2007-07-26 17:10:15 -0700 (Thu, 26 Jul 2007)

Log Message:
-----------
Add /principals/__uids__/ resource which provisions children named by
UID which are the same principal resources as navigated to via record
type and short name.

This will be necessary to support UID-based URIs for use in ACLs.

Also implement __init__ in provisioning superclass and simplify
__init__ args to DirectoryPrincipalTypeResource.  This is also used by
DirectoryPrincipalProvisioningResource and the new
DirectoryPrincipalUIDProvisioningResource to avoid duplicate code.

Modified Paths:
--------------
    CalendarServer/branches/users/wsanchez/deleted-uids/twistedcaldav/directory/principal.py

Modified: CalendarServer/branches/users/wsanchez/deleted-uids/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deleted-uids/twistedcaldav/directory/principal.py	2007-07-26 23:23:54 UTC (rev 1718)
+++ CalendarServer/branches/users/wsanchez/deleted-uids/twistedcaldav/directory/principal.py	2007-07-27 00:10:15 UTC (rev 1719)
@@ -46,6 +46,9 @@
 from twistedcaldav.static import AutoProvisioningFileMixIn
 from twistedcaldav.directory.idirectory import IDirectoryService
 
+# Use __underbars__ convention to avoid conflicts with directory resource types.
+uidsResourceName = "__uids__"
+
 # FIXME: These should not be tied to DAVFile
 # The reason that they is that web2.dav only implements DAV methods on
 # DAVFile instead of DAVResource.  That should change.
@@ -64,6 +67,19 @@
     CalendarPrincipalCollectionResource,
     DAVFile,
 ):
+    def __init__(self, path, url, directory):
+        """
+        @param path: the path to the file which will back the resource.
+        @param url: the canonical URL for the resource.
+        @param directory: an L{IDirectoryService} to provision principals from.
+        """
+        assert url.endswith("/"), "Collection URL must end in '/'"
+
+        CalendarPrincipalCollectionResource.__init__(self, url)
+        DAVFile.__init__(self, path)
+
+        self.directory = IDirectoryService(directory)
+
     def principalForShortName(self, type, name):
         raise NotImplementedError("Subclass must implement principalForShortName()")
 
@@ -97,25 +113,19 @@
     Collection resource which provisions directory principals as its children.
     """
     def __init__(self, path, url, directory):
-        """
-        @param path: the path to the file which will back the resource.
-        @param url: the canonical URL for the resource.
-        @param directory: an L{IDirectoryService} to provision principals from.
-        """
-        assert url.endswith("/"), "Collection URL must end in '/'"
+        DirectoryProvisioningResource.__init__(self, path, url, directory)
 
-        CalendarPrincipalCollectionResource.__init__(self, url)
-        DAVFile.__init__(self, path)
-
-        self.directory = IDirectoryService(directory)
-
         # FIXME: Smells like a hack
         self.directory.principalCollection = self
 
+        #
         # Create children
+        #
         for recordType in self.directory.recordTypes():
-            self.putChild(recordType, DirectoryPrincipalTypeResource(self.fp.child(recordType).path, self, recordType))
+            self.putChild(recordType, DirectoryPrincipalTypeResource(self, recordType))
 
+        self.putChild(uidsResourceName, DirectoryPrincipalUIDProvisioningResource(self))
+
     def principalForShortName(self, type, name):
         typeResource = self.getChild(type)
         if typeResource is None:
@@ -199,7 +209,7 @@
         return self.putChildren.get(name, None)
 
     def listChildren(self):
-        return self.putChildren.keys()
+        return self.directory.recordTypes()
 
     ##
     # ACL
@@ -208,20 +218,25 @@
     def principalCollections(self):
         return (self,)
 
+# FIXME: Rename to DirectoryPrincipalTypeProvisioningResource
 class DirectoryPrincipalTypeResource (DirectoryProvisioningResource):
     """
-    Collection resource which provisions directory principals of a specific type as its children.
+    Collection resource which provisions directory principals of a
+    specific type as its children, indexed by short name.
     """
-    def __init__(self, path, parent, recordType):
+    def __init__(self, parent, recordType):
         """
         @param path: the path to the file which will back the resource.
-        @param directory: an L{IDirectoryService} to provision calendars from.
+        @param parent: the parent L{DirectoryPrincipalProvisioningResource}.
         @param recordType: the directory record type to provision.
         """
-        CalendarPrincipalCollectionResource.__init__(self, joinURL(parent.principalCollectionURL(), recordType) + "/")
-        DAVFile.__init__(self, path)
+        DirectoryProvisioningResource.__init__(
+            self,
+            parent.fp.child(recordType).path,
+            joinURL(parent.principalCollectionURL(), recordType) + "/",
+            parent.directory
+        )
 
-        self.directory = parent.directory
         self.recordType = recordType
         self.parent = parent
 
@@ -265,6 +280,59 @@
     def principalCollections(self):
         return self.parent.principalCollections()
 
+class DirectoryPrincipalUIDProvisioningResource (DirectoryProvisioningResource):
+    """
+    Collection resource which provisions directory principals indexed
+    by UID.
+    """
+    # FIXME: Remove path argument
+    def __init__(self, parent):
+        """
+        @param path: the path to the file which will back the resource.
+        @param directory: an L{IDirectoryService} to provision calendars from.
+        @param recordType: the directory record type to provision.
+        """
+        DirectoryProvisioningResource.__init__(
+            self,
+            parent.fp.child(uidsResourceName).path,
+            joinURL(parent.principalCollectionURL(), uidsResourceName) + "/",
+            parent.directory
+        )
+
+        self.parent = parent
+
+    def principalForShortName(self, type, name):
+        return self.parent.principalForShortName(type, name)
+
+    def principalForCalendarUserAddress(self, address):
+        return self.parent.principalForCalendarUserAddress(address)
+
+    ##
+    # Static
+    ##
+
+    def createSimilarFile(self, path):
+        log.err("Attempt to create clone %r of resource %r" % (path, self))
+        raise HTTPError(responsecode.NOT_FOUND)
+
+    def getChild(self, name):
+        self.provision()
+        if name == "":
+            return self
+
+        return self.principalForUID(name)
+
+    def listChildren(self):
+        # Not a listable collection
+        raise HTTPError(responsecode.FORBIDDEN)
+
+    ##
+    # ACL
+    ##
+
+    def principalCollections(self):
+        return self.parent.principalCollections()
+
 class DirectoryPrincipalResource (AutoProvisioningFileMixIn, PermissionsMixIn, CalendarPrincipalResource, DAVFile):
     """
     Directory principal resource.

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


More information about the calendarserver-changes mailing list