[CalendarServer-changes] [76] CalendarServer/branches/users/cdaboo/acl-merge

source_changes at macosforge.org source_changes at macosforge.org
Tue Aug 29 09:13:37 PDT 2006


Revision: 76
Author:   cdaboo at apple.com
Date:     2006-08-29 09:13:33 -0700 (Tue, 29 Aug 2006)

Log Message:
-----------
Fixes to defer operations in copy/move for new twisted branch merge.

Modified Paths:
--------------
    CalendarServer/branches/users/cdaboo/acl-merge/patches/Twisted/twisted.web2.dav.resource.patch
    CalendarServer/branches/users/cdaboo/acl-merge/twistedcaldav/method/copymove.py
    CalendarServer/branches/users/cdaboo/acl-merge/twistedcaldav/method/put_common.py

Added Paths:
-----------
    CalendarServer/branches/users/cdaboo/acl-merge/patches/Twisted/twisted.web2.dav.static.patch
    CalendarServer/branches/users/cdaboo/acl-merge/patches/Twisted/twisted.web2.server.patch

Modified: CalendarServer/branches/users/cdaboo/acl-merge/patches/Twisted/twisted.web2.dav.resource.patch
===================================================================
--- CalendarServer/branches/users/cdaboo/acl-merge/patches/Twisted/twisted.web2.dav.resource.patch	2006-08-29 16:12:42 UTC (rev 75)
+++ CalendarServer/branches/users/cdaboo/acl-merge/patches/Twisted/twisted.web2.dav.resource.patch	2006-08-29 16:13:33 UTC (rev 76)
@@ -33,15 +33,17 @@
              assert (
                  isinstance(item, davxml.SupportedPrivilege),
                  "Not a SupportedPrivilege: %r" % (item,)
-@@ -920,7 +920,7 @@
+@@ -920,8 +920,8 @@
          yield ign
          ign.getResult()
  
 -        for resource, subpath in resources:
+-            acl = waitForDeferred(resource.accessControlList(request))
 +        for resource, uri in resources:
-             acl = waitForDeferred(resource.accessControlList(request))
++            acl = waitForDeferred(resource.accessControlList(request, inheritedaces=inheritedaces))
              yield acl
              acl = acl.getResult()
+ 
 @@ -930,7 +930,7 @@
  
              for ace in acl.children:
@@ -60,7 +62,43 @@
  
          if errors:
              raise AccessDeniedError(errors,)
-@@ -1180,6 +1180,14 @@
+@@ -1100,7 +1100,6 @@
+ 
+     accessControlList = deferredGenerator(accessControlList)
+ 
+-    # TODO: Convert to deferredGenerator
+     def inheritedACEsforChildren(self, request):
+         """
+         Do some optimisation of access control calculation by determining any inherited ACLs outside of
+@@ -1112,11 +1111,14 @@
+         """
+         
+         # Get the parent ACLs with inheritance and preserve the <inheritable> element.
+-        parent_acl = self.accessControlList(request, inheritance=True, expanding=True)
++        parent_acl = waitForDeferred(self.accessControlList(request, inheritance=True, expanding=True))
++        yield parent_acl
++        parent_acl = parent_acl.getResult()
+         
+         # Check disabled
+         if parent_acl is None:
+-            return None
++            yield None
++            return
+ 
+         # Filter out those that are not inheritable (and remove the inheritable element from those that are)
+         aces = []
+@@ -1141,7 +1143,9 @@
+                 if not ace.invert:
+                     continue
+             filteredaces.append(ace)
+-        return filteredaces
++        yield filteredaces
++
++    inheritedACEsforChildren = deferredGenerator(inheritedACEsforChildren)
+ 
+     def inheritedACLSet(self):
+         """
+@@ -1180,6 +1184,14 @@
                  yield (principal, principalURI)
                  return
          else:
@@ -75,7 +113,7 @@
              raise HTTPError(responsecode.FORBIDDEN)
  
      findPrincipalForAuthID = deferredGenerator(findPrincipalForAuthID)
-@@ -1261,7 +1269,7 @@
+@@ -1261,7 +1273,7 @@
          assert principal2 is not None, "principal2 is None"
  
  
@@ -84,7 +122,7 @@
          if principal1 == principal2:
              yield True
              return
-@@ -1301,7 +1309,7 @@
+@@ -1301,7 +1313,7 @@
          d = request.locateResource(principal2)
          d.addCallback(_testGroup)
          return d
@@ -93,7 +131,7 @@
      def validPrincipal(self, ace_principal, request):
          """
          Check whether the supplied principal is valid for this resource.
-@@ -1317,16 +1325,16 @@
+@@ -1317,16 +1329,16 @@
              # We know that the element contains a valid element type, so all
              # we need to do is check for a valid property and a valid href.
              #
@@ -115,7 +153,7 @@
  
              return True
  
-@@ -1367,7 +1375,6 @@
+@@ -1367,7 +1379,6 @@
          @param request: the request being processed.
          @return: a deferred L{davxml.HRef} element or C{None}.
          """
@@ -123,7 +161,7 @@
  
          if isinstance(principal, davxml.Property):
              # raise NotImplementedError("Property principals are not implemented.")
-@@ -1428,15 +1435,6 @@
+@@ -1428,15 +1439,6 @@
          if isinstance(principal, davxml.HRef):
              yield principal
          else:

Added: CalendarServer/branches/users/cdaboo/acl-merge/patches/Twisted/twisted.web2.dav.static.patch
===================================================================
--- CalendarServer/branches/users/cdaboo/acl-merge/patches/Twisted/twisted.web2.dav.static.patch	                        (rev 0)
+++ CalendarServer/branches/users/cdaboo/acl-merge/patches/Twisted/twisted.web2.dav.static.patch	2006-08-29 16:13:33 UTC (rev 76)
@@ -0,0 +1,113 @@
+Index: twisted/web2/dav/static.py
+===================================================================
+--- twisted/web2/dav/static.py	(revision 17966)
++++ twisted/web2/dav/static.py	(working copy)
+@@ -29,7 +29,11 @@
+ __all__ = ["DAVFile"]
+ 
+ from twisted.python import log
+-from twisted.internet import reactor, defer
++from twisted.internet.defer import deferredGenerator, waitForDeferred
++from twisted.internet.defer import succeed
++from twisted.web2 import http
++from twisted.web2 import dirlist
++from twisted.web2 import responsecode
+ from twisted.web2.static import File
+ from twisted.web2.dav import davxml
+ from twisted.web2.dav.idav import IDAVResource
+@@ -34,7 +38,7 @@
+ from twisted.web2.dav import davxml
+ from twisted.web2.dav.idav import IDAVResource
+ from twisted.web2.dav.resource import DAVResource
+-from twisted.web2.dav.util import bindMethods, joinURL
++from twisted.web2.dav.util import bindMethods
+ 
+ try:
+     from twisted.web2.dav.xattrprops import xattrPropertyStore as DeadPropertyStore
+@@ -154,6 +158,86 @@
+     def createSimilarFile(self, path):
+         return self.__class__(path, defaultType=self.defaultType, indexNames=self.indexNames[:])
+ 
++    def listChildrenWithPrivileges(self, privileges, request):
++        """
++        NB This method looks at the actual objects in the file system.
++
++        @return: a sequence of the names of all known children of this resource that have the
++            associated privileges set.
++        """
++        children = self.listChildren()
++        
++        result = []
++
++        # Do some optimisation of access control calculation by determining any inherited ACLs outside of
++        # the child resource loop and supply those to the checkAccess on each child.
++        filteredaces = waitForDeferred(self.inheritedACEsforChildren(request))
++        yield filteredaces
++        filteredaces = filteredaces.getResult()
++
++        # Check for disabled access
++        if filteredaces is not None:
++            for name in children:
++                try:
++                    child = IDAVResource(self.getChild(name))
++                except TypeError:
++                    child = None
++    
++                if child is not None:
++                    # Check privileges of child - skip if access denied
++                    try:
++                        d = waitForDeferred(child.checkAccess(request, privileges, inheritedaces=filteredaces))
++                        yield d
++                        d.getResult()
++                    except:
++                        continue
++                    result.append(name)
++            
++        yield result
++    
++    listChildrenWithPrivileges = deferredGenerator(listChildrenWithPrivileges)
++
++    def render(self, req):
++        """
++        This is a direct copy of webs.static.render with the listChildren behavior replaced with
++        findChildrenWithPrivileges to ensure that the current authenticated principal can only list
++        directory contents that they have read permissions for.
++        """
++        if not self.fp.exists():
++            yield responsecode.NOT_FOUND
++            return
++
++        if self.fp.isdir():
++            if req.uri[-1] != "/":
++                # Redirect to include trailing '/' in URI
++                yield http.RedirectResponse(req.unparseURL(path=req.path+'/'))
++                return
++            else:
++                ifp = self.fp.childSearchPreauth(*self.indexNames)
++                if ifp:
++                    # Render from the index file
++                    standin = self.createSimilarFile(ifp.path)
++                else:
++                    children = waitForDeferred(self.listChildrenWithPrivileges((davxml.Read(),), req))
++                    yield children
++                    children = children.getResult()
++
++                    # Render from a DirectoryLister
++                    standin = dirlist.DirectoryLister(
++                        self.fp.path,
++                        children,
++                        self.contentTypes,
++                        self.contentEncodings,
++                        self.defaultType
++                    )
++                yield standin.render(req)
++                return
++
++        # Do regular resource behavior from superclass
++        yield super(DAVFile, self).render(req)
++    
++    render = deferredGenerator(render)
++
+ #
+ # Attach method handlers to DAVFile
+ #

Added: CalendarServer/branches/users/cdaboo/acl-merge/patches/Twisted/twisted.web2.server.patch
===================================================================
--- CalendarServer/branches/users/cdaboo/acl-merge/patches/Twisted/twisted.web2.server.patch	                        (rev 0)
+++ CalendarServer/branches/users/cdaboo/acl-merge/patches/Twisted/twisted.web2.server.patch	2006-08-29 16:13:33 UTC (rev 76)
@@ -0,0 +1,31 @@
+Index: twisted/web2/server.py
+===================================================================
+--- twisted/web2/server.py	(revision 17932)
++++ twisted/web2/server.py	(working copy)
+@@ -316,7 +316,7 @@
+         if newpath is StopTraversal:
+             # We need to rethink how to do this.
+             #if newres is res:
+-                self._rememberURLForResource(path, res)
++                self.rememberURLForResource(path, res)
+                 return res
+             #else:
+             #    raise ValueError("locateChild must not return StopTraversal with a resource other than self.")
+@@ -337,7 +337,7 @@
+                 self.prepath.append(self.postpath.pop(0))
+ 
+         child = self._getChild(None, newres, newpath, updatepaths=updatepaths)
+-        self._rememberURLForResource(url, child)
++        self.rememberURLForResource(url, child)
+ 
+         return child
+ 
+@@ -343,7 +343,7 @@
+ 
+     _resourcesByURL = weakref.WeakKeyDictionary()
+ 
+-    def _rememberURLForResource(self, url, resource):
++    def rememberURLForResource(self, url, resource):
+         """
+         Remember the URL of visited resources.
+         """

Modified: CalendarServer/branches/users/cdaboo/acl-merge/twistedcaldav/method/copymove.py
===================================================================
--- CalendarServer/branches/users/cdaboo/acl-merge/twistedcaldav/method/copymove.py	2006-08-29 16:12:42 UTC (rev 75)
+++ CalendarServer/branches/users/cdaboo/acl-merge/twistedcaldav/method/copymove.py	2006-08-29 16:13:33 UTC (rev 76)
@@ -24,12 +24,14 @@
 
 from urlparse import urlsplit
 
+from twisted.internet.defer import deferredGenerator, waitForDeferred
 from twisted.python import log
 from twisted.web2 import responsecode
-from twisted.web2.http import StatusResponse
 from twisted.web2.dav import davxml
 from twisted.web2.dav.filter.location import addlocation
 from twisted.web2.dav.http import ErrorResponse
+from twisted.web2.dav.util import parentForURL
+from twisted.web2.http import StatusResponse, HTTPError
 
 from twistedcaldav.caldavxml import caldav_namespace
 from twistedcaldav.method.put_common import storeCalendarObjectResource
@@ -42,60 +44,79 @@
     is not being changed in any way. We do need to do an index update for
     the destination if its a calendar collection.
     """
-    result, sourcecal, destination_uri, destination, destinationcal = checkForCalendarAction(self, request)
+
+    r = waitForDeferred(checkForCalendarAction(self, request))
+    yield r
+    result, sourcecal, sourceparent, destination_uri, destination, destinationcal, destinationparent = r.getResult()
     if not result or not destinationcal:
         # Do default WebDAV action
-        return super(CalDAVFile, self).http_COPY(request)
+        d = waitForDeferred(super(CalDAVFile, self).http_COPY(request))
+        yield d
+        yield d.getResult()
+        return
 
     #
     # Check authentication and access controls
     #
-    self.securityCheck(request, (davxml.Read(),), recurse=True)
+    x = waitForDeferred(self.securityCheck(request, (davxml.Read(),), recurse=True))
+    yield x
+    x.getResult()
 
     if destination.exists():
-        destination.securityCheck(request, (davxml.WriteContent(), davxml.WriteProperties()), recurse=True)
+        x = waitForDeferred(destination.securityCheck(request, (davxml.WriteContent(), davxml.WriteProperties()), recurse=True))
+        yield x
+        x.getResult()
     else:
-        destparent = self.locateParent(request, destination_uri)
-        destparent.securityCheck(request, (davxml.Bind(),))
+        destparent = waitForDeferred(request.locateResource(parentForURL(destination_uri)))
+        yield destparent
+        destparent = destparent.getResult()
+ 
+        x = waitForDeferred(destparent.securityCheck(request, (davxml.Bind(),)))
+        yield x
+        x.getResult()
 
     # Check for existing destination resource
     overwrite = request.headers.getHeader("overwrite", True)
     if destination.exists() and not overwrite:
         log.err("Attempt to copy onto existing file without overwrite flag enabled: %s"
                 % (destination.fp.path,))
-        return StatusResponse(
+        raise HTTPError(StatusResponse(
             responsecode.PRECONDITION_FAILED,
-            "Destination %s already exists." % (destination_uri,)
+            "Destination %s already exists." % (destination_uri,))
         )
 
     # Checks for copying a calendar collection
     if self.isCalendarCollection():
         log.err("Attempt to copy a calendar collection into another calendar collection %s" % destination)
-        return ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "calendar-collection-location-ok"))
+        raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "calendar-collection-location-ok")))
 
     # We also do not allow regular collections in calendar collections
     if self.isCollection():
         log.err("Attempt to copy a collection into a calendar collection")
-        return StatusResponse(
+        raise HTTPError(StatusResponse(
             responsecode.NOT_ALLOWED,
-            "Cannot create collection within special collection %s" % (destination,)
+            "Cannot create collection within special collection %s" % (destination,))
         )
 
     # May need to add a location header
     addlocation(request, destination_uri)
 
-    return storeCalendarObjectResource(
+    x = waitForDeferred(storeCalendarObjectResource(
         request = request,
         source = self,
         source_uri = request.uri,
-        sourceparent = self.locateParent(request, request.uri),
+        sourceparent = sourceparent,
         sourcecal = sourcecal,
         destination = destination,
         destination_uri = destination_uri,
-        destinationparent = destination.locateParent(request, destination_uri),
+        destinationparent = destinationparent,
         destinationcal = destinationcal,
-   )
+    ))
+    yield x
+    yield x.getResult()
 
+http_COPY = deferredGenerator(http_COPY)
+
 def http_MOVE(self, request):
     """
     Special handling of MOVE request if parent is a calendar collection.
@@ -103,93 +124,121 @@
     since its effectively being deleted. We do need to do an index update for
     the destination if its a calendar collection
     """
-    result, sourcecal, destination_uri, destination, destinationcal = checkForCalendarAction(self, request)
+    r = waitForDeferred(checkForCalendarAction(self, request))
+    yield r
+    result, sourcecal, sourceparent, destination_uri, destination, destinationcal, destinationparent = r.getResult()
     if not result:
         # Do default WebDAV action
-        return super(CalDAVFile, self).http_MOVE(request)
+        d = waitForDeferred(super(CalDAVFile, self).http_MOVE(request))
+        yield d
+        yield d.getResult()
+        return
         
     #
     # Check authentication and access controls
     #
-    parent = self.locateParent(request, request.uri)
-    parent.securityCheck(request, (davxml.Unbind(),))
+    parent = waitForDeferred(request.locateResource(parentForURL(request.uri)))
+    yield parent
+    parent = parent.getResult()
 
+    x = waitForDeferred(parent.securityCheck(request, (davxml.Unbind(),)))
+    yield x
+    x.getResult()
+
     if destination.exists():
-        destination.securityCheck(request, (davxml.Bind(), davxml.Unbind()), recurse=True)
+        x = waitForDeferred(destination.securityCheck(request, (davxml.Bind(), davxml.Unbind()), recurse=True))
+        yield x
+        x.getResult()
     else:
-        destparent = self.locateParent(request, destination_uri)
-        destparent.securityCheck(request, (davxml.Bind(),))
+        destparent = waitForDeferred(request.locateResource(parentForURL(destination_uri)))
+        yield destparent
+        destparent = destparent.getResult()
 
+        x = waitForDeferred(destparent.securityCheck(request, (davxml.Bind(),)))
+        yield x
+        x.getResult()
+
     # Check for existing destination resource
     overwrite = request.headers.getHeader("overwrite", True)
     if destination.exists() and not overwrite:
         log.err("Attempt to copy onto existing file without overwrite flag enabled: %s"
                 % (destination.fp.path,))
-        return StatusResponse(
+        raise HTTPError(StatusResponse(
             responsecode.PRECONDITION_FAILED,
             "Destination %s already exists." % (destination_uri,)
-        )
+        ))
 
     if destinationcal:
         # Checks for copying a calendar collection
         if self.isCalendarCollection():
             log.err("Attempt to copy a calendar collection into another calendar collection %s" % destination)
-            return ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "calendar-collection-location-ok"))
+            raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "calendar-collection-location-ok")))
     
         # We also do not allow regular collections in calendar collections
         if self.isCollection():
             log.err("Attempt to copy a collection into a calendar collection")
-            return StatusResponse(
+            raise HTTPError(StatusResponse(
                 responsecode.NOT_ALLOWED,
                 "Cannot create collection within special collection %s" % (destination,)
-            )
+            ))
 
     # May need to add a location header
     addlocation(request, destination_uri)
 
-    return storeCalendarObjectResource(
+    x = waitForDeferred(storeCalendarObjectResource(
         request = request,
         source = self,
         source_uri = request.uri,
-        sourceparent = self.locateParent(request, request.uri),
+        sourceparent = sourceparent,
         sourcecal = sourcecal,
         destination = destination,
         destination_uri = destination_uri,
-        destinationparent = destination.locateParent(request, destination_uri),
+        destinationparent = destinationparent,
         destinationcal = destinationcal,
         deletesource = True,
-   )
+    ))
+    yield x
+    yield x.getResult()
 
+http_MOVE = deferredGenerator(http_MOVE)
+
 def checkForCalendarAction(self, request):
     """
     Check to see whether the source or destination of the copy/move
     is a calendar collection, since we need to do special processing
     if that is the case.
     @return: tuple::
-        result:      True if special CalDAV processing required, False otherwise
-                     NB If there is any type of error with the request, return False
-                     and allow normal COPY/MOVE processing to return the error.
-        sourcecal:   True if source is in a calendar collection, False otherwise
-        destination_uri: The URI of the destination resource
-        destination: CalDAVFile of destination if special proccesing required,
+        result:           True if special CalDAV processing required, False otherwise
+                          NB If there is any type of error with the request, return False
+                          and allow normal COPY/MOVE processing to return the error.
+        sourcecal:        True if source is in a calendar collection, False otherwise
+        sourceparent:     The parent resource for the source
+        destination_uri:  The URI of the destination resource
+        destination:      CalDAVFile of destination if special proccesing required,
         None otherwise
-        destinationcal: True if the destination is in a calendar collection,
-                        False otherwise
+        destinationcal:   True if the destination is in a calendar collection,
+                          False otherwise
+        destinationparent:The parent resource for the destination
         
     """
     
     result = False
     sourcecal = False
-    destination = None
     destinationcal = False
     
     # Check the source path first
     if not self.fp.exists():
-        return False, False, None, None, False
+        log.err("File not found: %s" % (self.fp.path,))
+        raise HTTPError(StatusResponse(
+            responsecode.NOT_FOUND,
+            "Source resource %s not found." % (request.uri,)
+        ))
 
     # Check for parent calendar collection
-    parent = self.locateParent(request, request.uri)
-    if isCalendarCollectionResource(parent):
+    sourceparent = waitForDeferred(request.locateResource(parentForURL(request.uri)))
+    yield sourceparent
+    sourceparent = sourceparent.getResult()
+    if isCalendarCollectionResource(sourceparent):
         result = True
         sourcecal = True
     
@@ -199,18 +248,23 @@
     destination_uri = request.headers.getHeader("destination")
 
     if not destination_uri:
-        return False, False, None, None, False
+        msg = "No destination header in %s request." % (request.method,)
+        log.err(msg)
+        raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, msg))
     
-    try:
-        destination = self.locateSiblingResource(request, destination_uri)
-    except ValueError:
-        return False, False, None, None, False
+    destination = waitForDeferred(request.locateResource(destination_uri))
+    yield destination
+    destination = destination.getResult()
 
     # Check for parent calendar collection
     destination_uri = urlsplit(destination_uri)[2]
-    parent = destination.locateParent(request, destination_uri)
-    if isCalendarCollectionResource(parent):
+    destinationparent = waitForDeferred(request.locateResource(parentForURL(destination_uri)))
+    yield destinationparent
+    destinationparent = destinationparent.getResult()
+    if isCalendarCollectionResource(destinationparent):
         result = True
         destinationcal = True
 
-    return result, sourcecal, destination_uri, destination, destinationcal
+    yield (result, sourcecal, sourceparent, destination_uri, destination, destinationcal, destinationparent)
+
+checkForCalendarAction = deferredGenerator(checkForCalendarAction)

Modified: CalendarServer/branches/users/cdaboo/acl-merge/twistedcaldav/method/put_common.py
===================================================================
--- CalendarServer/branches/users/cdaboo/acl-merge/twistedcaldav/method/put_common.py	2006-08-29 16:12:42 UTC (rev 75)
+++ CalendarServer/branches/users/cdaboo/acl-merge/twistedcaldav/method/put_common.py	2006-08-29 16:13:33 UTC (rev 76)
@@ -15,7 +15,6 @@
 #
 # DRI: Cyrus Daboo, cdaboo at apple.com
 ##
-from twisted.python import failure
 
 """
 PUT/COPY/MOVE common behavior.
@@ -26,6 +25,7 @@
 __all__ = ["storeCalendarObjectResource"]
 
 from twisted.internet.defer import maybeDeferred
+from twisted.python import failure
 from twisted.python import log
 from twisted.python.filepath import FilePath
 from twisted.web2 import responsecode
@@ -36,6 +36,7 @@
 from twisted.web2.dav.fileop import put
 from twisted.web2.dav.http import ErrorResponse
 from twisted.web2.dav.util import joinURL, parentForURL
+from twisted.web2.http import HTTPError
 from twisted.web2.iweb import IResponse
 from twisted.web2.stream import MemoryStream
 
@@ -296,7 +297,7 @@
                     result, message = validContentType()
                     if not result:
                         log.err(message)
-                        return ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "supported-calendar-data"))
+                        raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "supported-calendar-data")))
                 
                     # At this point we need the calendar data to do more tests
                     calendar = source.iCalendar()
@@ -307,13 +308,13 @@
                 result, message = validCalendarDataCheck()
                 if not result:
                     log.err(message)
-                    return ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "valid-calendar-data"))
+                    raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "valid-calendar-data")))
                     
                 # Valid calendar data for CalDAV check
                 result, message = validCalDAVDataCheck()
                 if not result:
                     log.err(message)
-                    return ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "valid-calendar-object-resource"))
+                    raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "valid-calendar-object-resource")))
 
                 # Must have a valid UID at this point
                 uid = calendar.resourceUID()
@@ -323,7 +324,7 @@
                 uid = source_index.resourceUIDForName(source.fp.basename())
                 if uid is None:
                     log.err("Source calendar does not have a UID: %s" % source.fp.basename())
-                    return ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "valid-calendar-object-resource"))
+                    raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "valid-calendar-object-resource")))
 
                 # FIXME: We need this here because we have to re-index the destination. Ideally it
                 # would be better to copy the index entries from the source and add to the destination.
@@ -334,9 +335,9 @@
                 result, message, rname = noUIDConflict(uid)
                 if not result:
                     log.err(message)
-                    return ErrorResponse(responsecode.FORBIDDEN,
+                    raise HTTPError(ErrorResponse(responsecode.FORBIDDEN,
                         NoUIDConflict(davxml.HRef.fromString(joinURL(parentForURL(destination_uri), rname)))
-                    )
+                    ))
             
             # Reserve UID
             # FIXME: A race-condition could exist here if a deferred action were to be inserted between this statement
@@ -405,10 +406,10 @@
                 logging.debug("Destination indexed %s" % (destination.fp.path,), system="Store Resource")
             except TooManyInstancesError, ex:
                 log.err("Cannot index calendar resource as there are too many recurrence instances %s" % destination)
-                return ErrorResponse(
+                raise HTTPError(ErrorResponse(
                     responsecode.FORBIDDEN,
                     NumberOfRecurrencesWithinLimits(PCDATAElement(str(ex.max_allowed)))
-                )
+                ))
 
             destination.writeProperty(davxml.GETContentType.fromString("text/calendar"), request)
             return None
@@ -448,10 +449,10 @@
             try:
                 source_index.addResource(source.fp.basename(), calendar)
             except TooManyInstancesError, ex:
-                return ErrorResponse(
+                raise HTTPError(ErrorResponse(
                     responsecode.FORBIDDEN,
                     NumberOfRecurrencesWithinLimits(PCDATAElement(str(ex.max_allowed)))
-                )
+                ))
 
             source.writeProperty(davxml.GETContentType.fromString("text/calendar"), request)
             return None

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


More information about the calendarserver-changes mailing list