[CalendarServer-changes] [85] CalendarServer/branches/users/cdaboo/acl-merge/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Wed Aug 30 13:00:22 PDT 2006


Revision: 85
Author:   cdaboo at apple.com
Date:     2006-08-30 13:00:15 -0700 (Wed, 30 Aug 2006)

Log Message:
-----------
Rework findCalendarCollections to follow the new findChild method from twisted.

Modified Paths:
--------------
    CalendarServer/branches/users/cdaboo/acl-merge/twistedcaldav/resource.py
    CalendarServer/branches/users/cdaboo/acl-merge/twistedcaldav/static.py

Modified: CalendarServer/branches/users/cdaboo/acl-merge/twistedcaldav/resource.py
===================================================================
--- CalendarServer/branches/users/cdaboo/acl-merge/twistedcaldav/resource.py	2006-08-30 17:16:36 UTC (rev 84)
+++ CalendarServer/branches/users/cdaboo/acl-merge/twistedcaldav/resource.py	2006-08-30 20:00:15 UTC (rev 85)
@@ -36,22 +36,21 @@
 from weakref import WeakValueDictionary
 
 from zope.interface import implements
-import twisted.web2.server
-from twisted.internet.defer import maybeDeferred
-from twisted.internet.defer import succeed
+
+from twisted.internet import reactor
+from twisted.internet.defer import Deferred, maybeDeferred, succeed
 from twisted.web2 import responsecode
-from twisted.web2.iweb import IResponse
+from twisted.web2.dav import auth, davxml
+from twisted.web2.dav.acl import DAVPrincipalResource
+from twisted.web2.dav.davxml import dav_namespace
+from twisted.web2.dav.http import ErrorResponse
+from twisted.web2.dav.resource import DAVResource, TwistedACLInheritable
+from twisted.web2.dav.util import joinURL, parentForURL, unimplemented
 from twisted.web2.http import HTTPError, RedirectResponse, StatusResponse, Response
 from twisted.web2.http_headers import MimeType
+from twisted.web2.iweb import IResponse
 from twisted.web2.stream import MemoryStream
-from twisted.web2.dav import auth
-from twisted.web2.dav import davxml
-from twisted.web2.dav.acl import DAVPrincipalResource
-from twisted.web2.dav.davxml import dav_namespace
-from twisted.web2.dav.http import ErrorResponse
-from twisted.web2.dav.resource import DAVResource
-from twisted.web2.dav.resource import TwistedACLInheritable
-from twisted.web2.dav.util import parentForURL, unimplemented
+import twisted.web2.server
 
 import twistedcaldav
 from twistedcaldav import caldavxml
@@ -210,24 +209,64 @@
         """
         return self.isCalendarCollection()
 
-    def findCalendarCollections(self, depth):
+    def findCalendarCollections(self, depth, request, callback, privileges=None):
         """
-        See L{ICalDAVResource.findCalendarCollections}.
-        This implementation raises L{NotImplementedError}; a subclass must
-        override it.
-        """
-        # FIXME: Can this be implemented genericly by using findChildren()?
-        unimplemented(self)
+        See L{IDAVResource.findChildren}.
 
-    def findCalendarCollectionsWithPrivileges(self, depth, privileges, request):
+        This implementation works for C{depth} values of C{"0"}, C{"1"}, 
+        and C{"infinity"}.  As long as C{self.listChildren} is implemented
         """
-        See L{ICalDAVResource.findCalendarCollectionsWithPrivileges}.
-        This implementation raises L{NotImplementedError}; a subclass must
-        override it.
-        """
-        # FIXME: Can this be implemented genericly by using findChildren()?
-        unimplemented(self)
+        assert depth in ("0", "1", "infinity"), "Invalid depth: %s" % (depth,)
 
+        def _checkAccessEb(failure):
+            from twisted.web2.dav.acl import AccessDeniedError
+            failure.trap(AccessDeniedError)
+            
+            reactor.callLater(0, _getChild)
+
+        def _checkAccess(child):
+            if privileges is None:
+                return child
+   
+            ca = child.checkAccess(request, privileges)
+            ca.addCallback(lambda ign: child)
+            return ca
+
+        def _gotChild(child, childpath):
+            if child.isCalendarCollection():
+                callback(child, childpath)
+            elif child.isCollection():
+                callback(child, childpath + '/')
+                if depth == 'infinity': 
+                    fc = child.findCalendarCollections(depth, request, callback, privileges)
+                    fc.addCallback(lambda x: reactor.callLater(0, _getChild))
+                    return fc
+
+            reactor.callLater(0, _getChild)
+
+        def _getChild():
+            try:
+                childname = children.pop()
+            except IndexError:
+                completionDeferred.callback(None)
+            else:
+                childpath = joinURL(basepath, childname)
+                child = request.locateResource(childpath)
+                child.addCallback(_checkAccess)
+                child.addCallbacks(_gotChild, _checkAccessEb, (childpath,))
+                child.addErrback(completionDeferred.errback)
+
+        completionDeferred = Deferred()
+
+        if depth != "0" and self.isCollection():
+            basepath = request.urlForResource(self)
+            children = self.listChildren()
+            _getChild()
+        else:
+            completionDeferred.callback(None)
+
+        return completionDeferred
+
     def createCalendar(self, request):
         """
         See L{ICalDAVResource.createCalendar}.

Modified: CalendarServer/branches/users/cdaboo/acl-merge/twistedcaldav/static.py
===================================================================
--- CalendarServer/branches/users/cdaboo/acl-merge/twistedcaldav/static.py	2006-08-30 17:16:36 UTC (rev 84)
+++ CalendarServer/branches/users/cdaboo/acl-merge/twistedcaldav/static.py	2006-08-30 20:00:15 UTC (rev 85)
@@ -78,58 +78,6 @@
     # CalDAV
     ##
 
-    def findCalendarCollections(self, depth):
-        """
-        Find all calendar collections within this collection down to the specified depth.
-        Note that we only want 'regular' calendar collections returned - not schedule-inbox or schedule-outbox.
-        
-        @param depth:    string with the appropriate depth -on ly "0", "1" or "infinity" allowed.
-        """
-        
-        assert depth in ("0", "1", "infinity"), "Invalid depth: %s" % (depth,)
-        if depth != "0" and self.isCollection():
-            for name in self.listChildren():
-                try:
-                    child = ICalDAVResource(self.getChild(name))
-                except TypeError:
-                    child = None
-
-                if child is not None:
-                    if child.isCalendarCollection():
-                        yield (child, name)
-                    elif child.isCollection():
-                        if depth == "infinity":
-                            for grandchild in child.findCalendarCollections(depth):
-                                yield (grandchild[0], name + "/" + grandchild[1])
-
-    def findCalendarCollectionsWithPrivileges(self, depth, privileges, request):
-        """
-        Find all calendar collections within this collection down to the specified depth.
-        Note that we only want 'regular' calendar collections returned - not schedule-inbox or schedule-outbox.
-        
-        @param depth:    string with the appropriate depth -on ly "0", "1" or "infinity" allowed.
-        """
-        
-        assert depth in ("0", "1", "infinity"), "Invalid depth: %s" % (depth,)
-        if depth != "0" and self.isCollection():
-            for name in self.listChildren():
-                try:
-                    child = ICalDAVResource(self.getChild(name))
-                except TypeError:
-                    child = None
-
-                if child is not None:
-                    # Check privileges of child - skip if access denied
-                    if child.checkAccess(request, privileges):
-                        continue
-
-                    if child.isCalendarCollection():
-                        yield (child, name)
-                    elif child.isCollection():
-                        if depth == "infinity":
-                            for grandchild in child.findCalendarCollections(depth):
-                                yield (grandchild[0], name + "/" + grandchild[1])
-
     def createCalendar(self, request):
         #
         # request object is required because we need to validate against parent

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


More information about the calendarserver-changes mailing list