[CalendarServer-changes] [310] CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Thu Oct 26 13:15:07 PDT 2006


Revision: 310
          http://trac.macosforge.org/projects/calendarserver/changeset/310
Author:   cdaboo at apple.com
Date:     2006-10-26 13:15:07 -0700 (Thu, 26 Oct 2006)

Log Message:
-----------
Drop box collection restrictions.

Modified Paths:
--------------
    CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/dropbox.py
    CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/icaldav.py
    CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/method/mkcol.py
    CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/method/put.py
    CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/resource.py
    CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/static.py

Modified: CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/dropbox.py
===================================================================
--- CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/dropbox.py	2006-10-26 20:11:28 UTC (rev 309)
+++ CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/dropbox.py	2006-10-26 20:15:07 UTC (rev 310)
@@ -28,8 +28,6 @@
 from twisted.web2.dav.resource import twisted_dav_namespace
 
 from twistedcaldav.customxml import davxml
-from twistedcaldav.resource import CalendarPrincipalResource
-from twistedcaldav.static import CalDAVFile
 
 import os
 
@@ -70,6 +68,7 @@
         if DropBox.enabled:
 
             # Need to setup live properties
+            from twistedcaldav.resource import CalendarPrincipalResource
             assert (twisted_dav_namespace, "dropbox-home-URL") not in CalendarPrincipalResource.liveProperties, \
                 "DropBox.enable must only be called once"
 
@@ -94,6 +93,7 @@
         
         # Create drop box collection in calendar-home collection resource if not already present.
         
+        from twistedcaldav.static import CalDAVFile
         child = CalDAVFile(os.path.join(cuhome[1].fp.path, DropBox.dropboxName))
         child_exists = child.exists()
         if not child_exists:

Modified: CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/icaldav.py
===================================================================
--- CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/icaldav.py	2006-10-26 20:11:28 UTC (rev 309)
+++ CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/icaldav.py	2006-10-26 20:15:07 UTC (rev 310)
@@ -50,6 +50,20 @@
             otherwise.
         """
 
+    def isNonCalendarCollectionParent():
+        """
+        @return: True if this resource is a collection that does not allow
+            calendar collections to be created inside of it anywhere, False
+            otherwise.
+        """
+
+    def isNonCollectionParent():
+        """
+        @return: True if this resource is a collection that does not allow
+            collections to be created inside of it anywhere, False
+            otherwise.
+        """
+
     def findCalendarCollections(depth):
         """
         Returns an iterable of child calendar collection resources for the given

Modified: CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/method/mkcol.py
===================================================================
--- CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/method/mkcol.py	2006-10-26 20:11:28 UTC (rev 309)
+++ CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/method/mkcol.py	2006-10-26 20:15:07 UTC (rev 310)
@@ -29,13 +29,13 @@
 from twisted.web2.http import HTTPError, StatusResponse
 
 from twistedcaldav import customxml
-from twistedcaldav.resource import isPseudoCalendarCollectionResource
+from twistedcaldav.resource import isNonCollectionParentResource
 
 def http_MKCOL(self, request):
     #
     # Don't allow DAV collections in a calendar collection for now
     #
-    parent = waitForDeferred(self._checkParents(request, isPseudoCalendarCollectionResource))
+    parent = waitForDeferred(self._checkParents(request, isNonCollectionParentResource))
     yield parent
     parent = parent.getResult()
     if parent is not None:

Modified: CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/method/put.py
===================================================================
--- CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/method/put.py	2006-10-26 20:11:28 UTC (rev 309)
+++ CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/method/put.py	2006-10-26 20:15:07 UTC (rev 310)
@@ -25,11 +25,14 @@
 from twisted.internet.defer import deferredGenerator, waitForDeferred
 from twisted.python import log
 from twisted.web2 import responsecode
+from twisted.web2.dav.element.base import twisted_dav_namespace
 from twisted.web2.dav.http import ErrorResponse
 from twisted.web2.dav.util import allDataFromStream, parentForURL
 from twisted.web2.http import HTTPError, StatusResponse
 
+from twistedcaldav import customxml
 from twistedcaldav.caldavxml import caldav_namespace
+from twistedcaldav.dropbox import DropBox
 from twistedcaldav.method.put_common import storeCalendarObjectResource
 from twistedcaldav.resource import isPseudoCalendarCollectionResource
 
@@ -75,6 +78,9 @@
             log.err("Error while handling (calendar) PUT: %s" % (e,))
             raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(e)))
 
+    elif DropBox.enabled and parent.isSpecialCollection(customxml.DropBoxHome):
+        # Cannot create resources in a drop box home collection
+        raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (twisted_dav_namespace, "valid-drop-box")))
     else:
         d = waitForDeferred(super(CalDAVFile, self).http_PUT(request))
         yield d

Modified: CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/resource.py
===================================================================
--- CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/resource.py	2006-10-26 20:11:28 UTC (rev 309)
+++ CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/resource.py	2006-10-26 20:15:07 UTC (rev 310)
@@ -254,6 +254,22 @@
         """
         return self.isCalendarCollection()
 
+    def isNonCalendarCollectionParent(self):
+        """
+        See L{ICalDAVResource.isNonCalendarCollectionParent}.
+        """
+        
+        # Cannot create calendars inside other calendars or a drop box home
+        return self.isPseudoCalendarCollection() or self.isSpecialCollection(customxml.DropBoxHome)
+
+    def isNonCollectionParent(self):
+        """
+        See L{ICalDAVResource.isNonCalendarCollectionParent}.
+        """
+        
+        # Cannot create collections inside a drop box
+        return self.isSpecialCollection(customxml.DropBox)
+
     def findCalendarCollections(self, depth, request, callback, privileges=None):
         """
         See L{ICalDAVResource.findCalendarCollections}.
@@ -806,6 +822,22 @@
     else:
         return resource.isPseudoCalendarCollection()
 
+def isNonCalendarCollectionParentResource(resource):
+    try:
+        resource = ICalDAVResource(resource)
+    except TypeError:
+        return False
+    else:
+        return resource.isNonCalendarCollectionParent()
+
+def isNonCollectionParentResource(resource):
+    try:
+        resource = ICalDAVResource(resource)
+    except TypeError:
+        return False
+    else:
+        return resource.isNonCollectionParent()
+
 def isScheduleInboxResource(resource):
     try:
         resource = ICalendarSchedulingCollectionResource(resource)

Modified: CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/static.py
===================================================================
--- CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/static.py	2006-10-26 20:11:28 UTC (rev 309)
+++ CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/static.py	2006-10-26 20:15:07 UTC (rev 310)
@@ -54,7 +54,7 @@
 from twistedcaldav.ical import Component as iComponent
 from twistedcaldav.ical import Property as iProperty
 from twistedcaldav.index import Index, IndexSchedule, db_basename
-from twistedcaldav.resource import CalDAVResource, isPseudoCalendarCollectionResource, CalendarPrincipalResource
+from twistedcaldav.resource import CalDAVResource, isNonCalendarCollectionParentResource, CalendarPrincipalResource
 from twistedcaldav.resource import ScheduleInboxResource, ScheduleOutboxResource, CalendarPrincipalCollectionResource
 from twistedcaldav.resource import isCalendarCollectionResource
 
@@ -102,7 +102,7 @@
     
             return self.createCalendarCollection()
             
-        parent = self._checkParents(request, isPseudoCalendarCollectionResource)
+        parent = self._checkParents(request, isNonCalendarCollectionParentResource)
         parent.addCallback(_defer)
         return parent
 

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


More information about the calendarserver-changes mailing list