[CalendarServer-changes] [2208] CalendarServer/trunk/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Thu Mar 6 12:33:28 PST 2008


Revision: 2208
          http://trac.macosforge.org/projects/calendarserver/changeset/2208
Author:   wsanchez at apple.com
Date:     2008-03-06 12:33:27 -0800 (Thu, 06 Mar 2008)

Log Message:
-----------
Undo r2206, should be on branch

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/directory/calendar.py
    CalendarServer/trunk/twistedcaldav/directory/principal.py
    CalendarServer/trunk/twistedcaldav/extensions.py
    CalendarServer/trunk/twistedcaldav/schedule.py
    CalendarServer/trunk/twistedcaldav/static.py

Modified: CalendarServer/trunk/twistedcaldav/directory/calendar.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/calendar.py	2008-03-06 20:15:49 UTC (rev 2207)
+++ CalendarServer/trunk/twistedcaldav/directory/calendar.py	2008-03-06 20:33:27 UTC (rev 2208)
@@ -19,10 +19,8 @@
 """
 
 __all__ = [
-    "uidsResourceName",
     "DirectoryCalendarHomeProvisioningResource",
     "DirectoryCalendarHomeTypeProvisioningResource",
-    "DirectoryCalendarHomeUIDProvisioningResource",
     "DirectoryCalendarHomeResource",
 ]
 
@@ -41,9 +39,6 @@
 from twistedcaldav.directory.idirectory import IDirectoryService
 from twistedcaldav.directory.resource import AutoProvisioningResourceMixIn
 
-# Use __underbars__ convention to avoid conflicts with directory resource types.
-uidsResourceName = "__uids__"
-
 class DirectoryCalendarHomeProvisioningResource (AutoProvisioningResourceMixIn, ReadOnlyResourceMixIn, DAVResource):
     """
     Resource which provisions calendar home collections as needed.    
@@ -64,17 +59,10 @@
         # FIXME: Smells like a hack
         directory.calendarHomesCollection = self
 
-        #
         # Create children
-        #
-        def provisionChild(name):
-            self.putChild(name, self.provisionChild(name))
-
         for recordType in self.directory.recordTypes():
-            provisionChild(recordType)
+            self.putChild(recordType, self.provisionChild(recordType))
 
-        provisionChild(uidsResourceName)
-
     def provisionChild(self, recordType):
         raise NotImplementedError("Subclass must implement provisionChild()")
 
@@ -98,11 +86,11 @@
         return self.directory.principalCollection.principalForRecord(record)
 
     def homeForDirectoryRecord(self, record):
-        uidResource = self.getChild(uidsResourceName)
-        if uidResource is None:
+        typeResource = self.getChild(record.recordType)
+        if typeResource is None:
             return None
         else:
-            return uidResource.getChild(record.guid)
+            return typeResource.getChild(record.shortName)
 
     ##
     # DAV
@@ -125,7 +113,8 @@
     """
     def __init__(self, parent, recordType):
         """
-        @param parent: the parent of this resource
+        @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.
         """
         assert parent is not None
@@ -142,6 +131,7 @@
 
     def getChild(self, name, record=None):
         self.provision()
+
         if name == "":
             return self
 
@@ -149,8 +139,11 @@
             record = self.directory.recordWithShortName(self.recordType, name)
             if record is None:
                 return None
+        else:
+            assert name is None
+            name = record.shortName
 
-        return self._parent.homeForDirectoryRecord(record)
+        return self.provisionChild(name)
 
     def listChildren(self):
         return (
@@ -180,61 +173,6 @@
         return self._parent.principalForRecord(record)
 
 
-class DirectoryCalendarHomeUIDProvisioningResource (AutoProvisioningResourceMixIn, ReadOnlyResourceMixIn, DAVResource):
-    def __init__(self, parent):
-        """
-        @param parent: the parent of this resource
-        """
-        assert parent is not None
-
-        DAVResource.__init__(self)
-
-        self.directory = parent.directory
-        self.parent = parent
-
-    def url(self):
-        return joinURL(self.parent.url(), uidsResourceName)
-
-    def getChild(self, name, record=None):
-        self.provision()
-        if name == "":
-            return self
-
-        if record is None:
-            record = self.directory.recordWithGUID(name)
-            if record is None:
-                return None
-
-        return self.provisionChild(name)
-
-    def listChildren(self):
-        return (
-            record.guid
-            for record in self.directory.listRecords(self.recordType)
-            if record.enabledForCalendaring
-        )
-
-    ##
-    # DAV
-    ##
-    
-    def isCollection(self):
-        return True
-
-    ##
-    # ACL
-    ##
-
-    def defaultAccessControlList(self):
-        return readOnlyACL
-
-    def principalCollections(self):
-        return self.parent.principalCollections()
-
-    def principalForRecord(self, record):
-        return self.parent.principalForRecord(record)
-
-
 class DirectoryCalendarHomeResource (AutoProvisioningResourceMixIn, CalDAVResource):
     """
     Calendar home collection resource.
@@ -249,7 +187,7 @@
         CalDAVResource.__init__(self)
 
         self.record = record
-        self.parent = parent
+        self._parent = parent
 
         # Cache children which must be of a specific type
         childlist = (
@@ -305,13 +243,7 @@
         raise NotImplementedError("Subclass must implement provisionChild()")
 
     def url(self):
-        return joinURL(self.parent.url(), self.record.guid)
-        ##
-        ## While the underlying primary location is GUID-based, we want
-        ## the canonical user-facing location to be recordType &
-        ## shortName-based, because that's friendlier.
-        ##
-        #return joinURL(self.parent.parent.getChild(self.record.recordType).url(), self.record.shortName)
+        return joinURL(self._parent.url(), self.record.shortName)
 
     ##
     # DAV
@@ -328,6 +260,8 @@
         return succeed(davxml.HRef(self.principalForRecord().principalURL()))
 
     def defaultAccessControlList(self):
+        # FIXME: directory.principalCollection smells like a hack
+        # See DirectoryPrincipalProvisioningResource.__init__()
         myPrincipal = self.principalForRecord()
 
         aces = (
@@ -372,10 +306,10 @@
         return davxml.ACL(*aces)
 
     def principalCollections(self):
-        return self.parent.principalCollections()
+        return self._parent.principalCollections()
 
     def principalForRecord(self):
-        return self.parent.principalForRecord(self.record)
+        return self._parent.principalForRecord(self.record)
 
     ##
     # Quota

Modified: CalendarServer/trunk/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/principal.py	2008-03-06 20:15:49 UTC (rev 2207)
+++ CalendarServer/trunk/twistedcaldav/directory/principal.py	2008-03-06 20:33:27 UTC (rev 2208)
@@ -19,10 +19,8 @@
 """
 
 __all__ = [
-    "DirectoryProvisioningResource",
     "DirectoryPrincipalProvisioningResource",
     "DirectoryPrincipalTypeProvisioningResource",
-    "DirectoryPrincipalUIDProvisioningResource",
     "DirectoryPrincipalResource",
     "DirectoryCalendarPrincipalResource",
 ]
@@ -60,7 +58,11 @@
     def defaultAccessControlList(self):
         return authReadACL
 
-class DirectoryProvisioningResource (
+    def accessControlList(self, request, inheritance=True, expanding=False, inherited_aces=None):
+        # Permissions here are fixed, and are not subject to inherritance rules, etc.
+        return succeed(self.defaultAccessControlList())
+
+class DirectoryProvisioningResource(
     AutoProvisioningFileMixIn,
     PermissionsMixIn,
     CalendarPrincipalCollectionResource,
@@ -182,8 +184,6 @@
         if record is not None:
             return self.principalForRecord(record)
 
-        log.err("No principal for calendar user address: %r" % (address,))
-
         return None
 
     ##

Modified: CalendarServer/trunk/twistedcaldav/extensions.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/extensions.py	2008-03-06 20:15:49 UTC (rev 2207)
+++ CalendarServer/trunk/twistedcaldav/extensions.py	2008-03-06 20:33:27 UTC (rev 2208)
@@ -620,10 +620,6 @@
     def writeProperty(self, property, request):
         raise HTTPError(self.readOnlyResponse)
 
-    def accessControlList(self, request, inheritance=True, expanding=False, inherited_aces=None):
-        # Permissions here are fixed, and are not subject to inherritance rules, etc.
-        return succeed(self.defaultAccessControlList())
-
 class XMLResponse (Response):
     """
     XML L{Response} object.

Modified: CalendarServer/trunk/twistedcaldav/schedule.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/schedule.py	2008-03-06 20:15:49 UTC (rev 2207)
+++ CalendarServer/trunk/twistedcaldav/schedule.py	2008-03-06 20:33:27 UTC (rev 2208)
@@ -35,6 +35,7 @@
 from twisted.web2.dav.util import joinURL
 
 from twistedcaldav import caldavxml
+from twistedcaldav import customxml
 from twistedcaldav import itip
 from twistedcaldav import logging
 from twistedcaldav.resource import CalDAVResource
@@ -354,7 +355,7 @@
             # Map recipient to their inbox
             inbox = None
             if principal is None:
-                logging.err("No schedulable principal for calendar user address: %r" % (recipient,), system="CalDAV Outbox POST")
+                logging.err("No principal for calendar user address: %s" % (recipient,), system="CalDAV Outbox POST")
             else:
                 inboxURL = principal.scheduleInboxURL()
                 if inboxURL:

Modified: CalendarServer/trunk/twistedcaldav/static.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/static.py	2008-03-06 20:15:49 UTC (rev 2207)
+++ CalendarServer/trunk/twistedcaldav/static.py	2008-03-06 20:33:27 UTC (rev 2208)
@@ -22,9 +22,7 @@
     "CalDAVFile",
     "AutoProvisioningFileMixIn",
     "CalendarHomeProvisioningFile",
-    "CalendarHomeUIDProvisioningFile",
     "CalendarHomeFile",
-    "ScheduleFile",
     "ScheduleInboxFile",
     "ScheduleOutboxFile",
     "DropBoxHomeFile",
@@ -64,10 +62,8 @@
 from twistedcaldav.resource import CalDAVResource, isCalendarCollectionResource, isPseudoCalendarCollectionResource
 from twistedcaldav.schedule import ScheduleInboxResource, ScheduleOutboxResource
 from twistedcaldav.dropbox import DropBoxHomeResource, DropBoxCollectionResource, DropBoxChildResource
-from twistedcaldav.directory.calendar import uidsResourceName
 from twistedcaldav.directory.calendar import DirectoryCalendarHomeProvisioningResource
 from twistedcaldav.directory.calendar import DirectoryCalendarHomeTypeProvisioningResource
-from twistedcaldav.directory.calendar import DirectoryCalendarHomeUIDProvisioningResource
 from twistedcaldav.directory.calendar import DirectoryCalendarHomeResource
 from twistedcaldav.directory.resource import AutoProvisioningResourceMixIn
 
@@ -443,68 +439,43 @@
         DirectoryCalendarHomeProvisioningResource.__init__(self, directory, url)
 
     def provisionChild(self, name):
-        if name == uidsResourceName:
-            return CalendarHomeUIDProvisioningFile(self.fp.child(name).path, self)
-
         return CalendarHomeTypeProvisioningFile(self.fp.child(name).path, self, name)
 
     def createSimilarFile(self, path):
         raise HTTPError(responsecode.NOT_FOUND)
 
 class CalendarHomeTypeProvisioningFile (AutoProvisioningFileMixIn, DirectoryCalendarHomeTypeProvisioningResource, DAVFile):
+    """
+    Resource which provisions calendar home collections of a specific
+    record type as needed.
+    """
     def __init__(self, path, parent, recordType):
         """
         @param path: the path to the file which will back the resource.
-        @param parent: the parent of this resource
+        @param directory: an L{IDirectoryService} to provision calendars from.
         @param recordType: the directory record type to provision.
         """
         DAVFile.__init__(self, path)
         DirectoryCalendarHomeTypeProvisioningResource.__init__(self, parent, recordType)
 
-class CalendarHomeUIDProvisioningFile (AutoProvisioningFileMixIn, DirectoryCalendarHomeUIDProvisioningResource, DAVFile):
-    def __init__(self, path, parent):
-        """
-        @param path: the path to the file which will back the resource.
-        """
-        DAVFile.__init__(self, path)
-        DirectoryCalendarHomeUIDProvisioningResource.__init__(self, parent)
-
     def provisionChild(self, name):
-        record = self.directory.recordWithGUID(name)
+        record = self.directory.recordWithShortName(self.recordType, name)
 
         if record is None:
-            log.msg("No directory record with GUID %r" % (name,))
+            log.msg("No directory record %r of type %r" % (name, self.recordType))
             return None
 
         if not record.enabledForCalendaring:
-            log.msg("Directory record %r is not enabled for calendaring" % (record,))
+            log.msg("Directory record %r of type %r is not enabled for calendaring" % (name, self.recordType))
             return None
 
-        childPath = self.fp.child(name)
-        child = CalendarHomeFile(childPath.path, self, record)
+        child = CalendarHomeFile(self.fp.child(name).path, self, record)
         if not child.exists():
-            #
-            # Find out if the child exists at the old (pre-1.2)
-            # location (ie. in the types hierarchy instead of the GUID
-            # hierarchy).
-            #
-            oldPath = self.parent.getChild(record.recordType).fp.child(record.shortName)
-            if oldPath.exists():
-                log.msg("Moving calendar home from old location %r to new location %r." % (oldPath, childPath))
-                try:
-                    oldPath.moveTo(childPath)
-                except (OSError, IOError), e:
-                    log.err("Error moving calendar home %r: %s" % (oldPath, e))
-                    raise HTTPError(StatusResponse(
-                        responsecode.INTERNAL_SERVER_ERROR,
-                        "Unable to move calendar home."
-                    ))
-            else:
-                # NOTE: provisionDefaultCalendars() returns a deferred, which we are ignoring.
-                # The result being that the default calendars will be present at some point
-                # in the future, not necessarily right now, and we don't have a way to wait
-                # on that to finish.
-                child.provisionDefaultCalendars()
+            # NOTE: provisionDefaultCalendars() returns a deferred, which we are ignoring.
+            # The result being that the default calendars will be present at some point
+            # in the future, not necessarily right now, and we don't have a way to wait
+            # on that to finish.
+            child.provisionDefaultCalendars()
         return child
 
     def createSimilarFile(self, path):
@@ -703,7 +674,7 @@
     http_MKCOL =               NotificationsCollectionResource.http_MKCOL
     http_MKCALENDAR =          NotificationsCollectionResource.http_MKCALENDAR
 
-class NotificationFile (NotificationResource, DAVFile):
+class NotificationFile(NotificationResource, DAVFile):
     def __init__(self, path, parent):
         super(NotificationFile, self).__init__(path, principalCollections=parent.principalCollections())
 

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


More information about the calendarserver-changes mailing list