[CalendarServer-changes] [5737] CalendarServer/branches/new-store/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Tue Jun 15 11:29:08 PDT 2010


Revision: 5737
          http://trac.macosforge.org/projects/calendarserver/changeset/5737
Author:   glyph at apple.com
Date:     2010-06-15 11:29:06 -0700 (Tue, 15 Jun 2010)
Log Message:
-----------
Propagate transaction to distinct calendar homes via the request.

Modified Paths:
--------------
    CalendarServer/branches/new-store/twistedcaldav/directory/addressbook.py
    CalendarServer/branches/new-store/twistedcaldav/directory/calendar.py
    CalendarServer/branches/new-store/twistedcaldav/directory/principal.py
    CalendarServer/branches/new-store/twistedcaldav/scheduling/implicit.py
    CalendarServer/branches/new-store/twistedcaldav/scheduling/utils.py
    CalendarServer/branches/new-store/twistedcaldav/sharing.py
    CalendarServer/branches/new-store/twistedcaldav/static.py
    CalendarServer/branches/new-store/twistedcaldav/test/test_sharing.py
    CalendarServer/branches/new-store/twistedcaldav/test/util.py

Modified: CalendarServer/branches/new-store/twistedcaldav/directory/addressbook.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/directory/addressbook.py	2010-06-15 18:04:25 UTC (rev 5736)
+++ CalendarServer/branches/new-store/twistedcaldav/directory/addressbook.py	2010-06-15 18:29:06 UTC (rev 5737)
@@ -160,7 +160,7 @@
             if record is None:
                 return None
 
-        return self._parent.homeForDirectoryRecord(record)
+        return self._parent.homeForDirectoryRecord(record, request)
 
     def listChildren(self):
         if config.EnablePrincipalListings:

Modified: CalendarServer/branches/new-store/twistedcaldav/directory/calendar.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/directory/calendar.py	2010-06-15 18:04:25 UTC (rev 5736)
+++ CalendarServer/branches/new-store/twistedcaldav/directory/calendar.py	2010-06-15 18:29:06 UTC (rev 5737)
@@ -117,12 +117,12 @@
         # See DirectoryPrincipalProvisioningResource.__init__()
         return self.directory.principalCollection.principalForRecord(record)
 
-    def homeForDirectoryRecord(self, record):
+    def homeForDirectoryRecord(self, record, request):
         uidResource = self.getChild(uidsResourceName)
         if uidResource is None:
             return None
         else:
-            return uidResource.getChild(record.uid)
+            return uidResource.homeResourceForRecord(record, request)
 
     ##
     # DAV
@@ -154,17 +154,18 @@
     def url(self):
         return joinURL(self._parent.url(), self.recordType)
 
-    def getChild(self, name, record=None):
+    def locateChild(self, request, segments):
         self.provision()
+        name = segments[0]
         if name == "":
             return self
 
+        record = self.directory.recordWithShortName(self.recordType, name)
         if record is None:
-            record = self.directory.recordWithShortName(self.recordType, name)
-            if record is None:
-                return None
+            return None, []
 
-        return self._parent.homeForDirectoryRecord(record)
+        return (self._parent.homeForDirectoryRecord(record, request),
+                segments[1:])
 
     def listChildren(self):
         if config.EnablePrincipalListings:
@@ -217,17 +218,8 @@
         return joinURL(self.parent.url(), uidsResourceName)
 
     def getChild(self, name, record=None):
-        self.provision()
-        if name == "":
-            return self
+        raise NotImplementedError("DirectoryCalendarProvisioningResource.getChild no longer exists.")
 
-        if record is None:
-            record = self.directory.recordWithUID(name)
-            if record is None:
-                return None
-
-        return self.provisionChild(name)
-
     def listChildren(self):
         # Not a listable collection
         raise HTTPError(responsecode.FORBIDDEN)

Modified: CalendarServer/branches/new-store/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/directory/principal.py	2010-06-15 18:04:25 UTC (rev 5736)
+++ CalendarServer/branches/new-store/twistedcaldav/directory/principal.py	2010-06-15 18:29:06 UTC (rev 5737)
@@ -870,7 +870,7 @@
             return False
 
     def scheduleInbox(self, request):
-        home = self.calendarHome()
+        home = self.calendarHome(request)
         if home is None:
             return succeed(None)
 
@@ -884,7 +884,7 @@
         
         notification = None
         if config.Sharing.Enabled:
-            home = self.calendarHome()
+            home = self.calendarHome(request)
             if home is not None:    
                 notification = home.getChild("notification")
     
@@ -921,25 +921,25 @@
 
     def _homeChildURL(self, name):
         if not hasattr(self, "calendarHomeURL"):
-            home = self.calendarHome()
-            if home is None:
-                self.calendarHomeURL = None
+            if not hasattr(self.record.service, "calendarHomesCollection"):
                 return None
-            else:
-                self.calendarHomeURL = home.url()
-            
+            self.calendarHomeURL = joinURL(
+                self.record.service.calendarHomesCollection.url(),
+                uidsResourceName,
+                self.record.uid
+            )
         url = self.calendarHomeURL
         if url is None:
             return None
         else:
             return joinURL(url, name) if name else url
 
-    def calendarHome(self):
+    def calendarHome(self, request):
         # FIXME: self.record.service.calendarHomesCollection smells like a hack
         # See CalendarHomeProvisioningFile.__init__()
         service = self.record.service
         if hasattr(service, "calendarHomesCollection"):
-            return service.calendarHomesCollection.homeForDirectoryRecord(self.record)
+            return service.calendarHomesCollection.homeForDirectoryRecord(self.record, request)
         else:
             return None
 

Modified: CalendarServer/branches/new-store/twistedcaldav/scheduling/implicit.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/scheduling/implicit.py	2010-06-15 18:04:25 UTC (rev 5736)
+++ CalendarServer/branches/new-store/twistedcaldav/scheduling/implicit.py	2010-06-15 18:29:06 UTC (rev 5737)
@@ -383,8 +383,8 @@
 
         # Get owner's calendar-home
         calendar_owner_principal = (yield self.resource.resourceOwnerPrincipal(self.request))
-        calendar_home = calendar_owner_principal.calendarHome()
-        
+        calendar_home = calendar_owner_principal.calendarHome(self.request)
+
         check_parent_uri = parentForURL(check_uri)[:-1] if check_uri else None
 
         # FIXME: because of the URL->resource request mapping thing, we have to force the request

Modified: CalendarServer/branches/new-store/twistedcaldav/scheduling/utils.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/scheduling/utils.py	2010-06-15 18:04:25 UTC (rev 5736)
+++ CalendarServer/branches/new-store/twistedcaldav/scheduling/utils.py	2010-06-15 18:29:06 UTC (rev 5737)
@@ -33,7 +33,7 @@
 
     if principal and principal.locallyHosted():
         # Get principal's calendar-home
-        calendar_home = principal.calendarHome()
+        calendar_home = principal.calendarHome(request)
         
         # FIXME: because of the URL->resource request mapping thing, we have to force the request
         # to recognize this resource

Modified: CalendarServer/branches/new-store/twistedcaldav/sharing.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/sharing.py	2010-06-15 18:04:25 UTC (rev 5736)
+++ CalendarServer/branches/new-store/twistedcaldav/sharing.py	2010-06-15 18:29:06 UTC (rev 5737)
@@ -177,7 +177,7 @@
         
         # Get the home collection
         if self.isCalendarCollection():
-            home = principal.calendarHome()
+            home = principal.calendarHome(request)
         elif self.isAddressBookCollection():
             home = principal.addressBookHome()
         else:
@@ -221,7 +221,7 @@
         
         # Remove from sharee's calendar/address book home
         if self.isCalendarCollection():
-            shareeHome = self._shareePrincipal.calendarHome()
+            shareeHome = self._shareePrincipal.calendarHome(request)
         elif self.isAddressBookCollection():
             shareeHome = self._shareePrincipal.addressBookHome()
         return shareeHome.removeShare(request, self._share)
@@ -469,7 +469,7 @@
         sharee = self.principalForCalendarUserAddress(record.userid)
         if sharee:
             if self.isCalendarCollection():
-                shareeHome = sharee.calendarHome()
+                shareeHome = sharee.calendarHome(request)
             elif self.isAddressBookCollection():
                 shareeHome = sharee.addressBookHome()
             yield shareeHome.removeShareByUID(request, record.inviteuid)

Modified: CalendarServer/branches/new-store/twistedcaldav/static.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/static.py	2010-06-15 18:04:25 UTC (rev 5736)
+++ CalendarServer/branches/new-store/twistedcaldav/static.py	2010-06-15 18:29:06 UTC (rev 5737)
@@ -898,9 +898,23 @@
         else:
             self.homeResourceClass = homeResourceClass
 
-    def provisionChild(self, name):
+
+    def locateChild(self, request, segments):
+        name = segments[0]
         record = self.directory.recordWithUID(name)
+        return (self.homeResourceForRecord(record, request), segments[1:])
 
+
+    def homeResourceForRecord(self, record, request):
+        self.provision()
+        TRANSACTION_KEY = '_newStoreTransaction'
+        transaction = getattr(request, TRANSACTION_KEY, None)
+        if transaction is None:
+            transaction = self.parent._newStore.newTransaction()
+            setattr(request, TRANSACTION_KEY, transaction)
+
+        name = record.uid
+
         if record is None:
             log.msg("No directory record with GUID %r" % (name,))
             return None
@@ -913,7 +927,7 @@
         
         if record.locallyHosted():
             childPath = self.fp.child(name[0:2]).child(name[2:4]).child(name)
-            child = self.homeResourceClass(childPath.path, self, record)
+            child = self.homeResourceClass(childPath.path, self, record, transaction)
     
             if not child.exists():
                 self.provision()
@@ -997,7 +1011,7 @@
             (customxml.calendarserver_namespace, "xmpp-server"),
         )
 
-    def __init__(self, path, parent, record):
+    def __init__(self, path, parent, record, transaction):
         """
         @param path: the path to the file which will back the resource.
         """
@@ -1005,9 +1019,8 @@
         # TODO: when calendar home gets a resourceID( ) method, remove
         # the "id=record.uid" keyword from this call:
         self.clientNotifier = ClientNotifier(self, id=record.uid)
-        txn = parent.parent._newStore.newTransaction()
         self._newStoreCalendarHome = (
-            txn.calendarHomeWithUID(record.uid, create=True)
+            transaction.calendarHomeWithUID(record.uid, create=True)
         )
         CalDAVFile.__init__(self, path)
         DirectoryCalendarHomeResource.__init__(self, parent, record)
@@ -1017,7 +1030,7 @@
             self._newStoreCalendarHome.properties()
         )
 
-        self.associateWithTransaction(txn)
+        self.associateWithTransaction(transaction)
 
 
     def exists(self):

Modified: CalendarServer/branches/new-store/twistedcaldav/test/test_sharing.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/test/test_sharing.py	2010-06-15 18:04:25 UTC (rev 5736)
+++ CalendarServer/branches/new-store/twistedcaldav/test/test_sharing.py	2010-06-15 18:29:06 UTC (rev 5737)
@@ -38,7 +38,7 @@
             self.homepath = "/calendars/__uids__/%s" % (cuaddr[7:].split('@')[0],)
             self.displayname = cuaddr[7:].split('@')[0].upper()
 
-        def calendarHome(self):
+        def calendarHome(self, request):
             class FakeHome(object):
                 def removeShareByUID(self, request, uid):pass
             return FakeHome()

Modified: CalendarServer/branches/new-store/twistedcaldav/test/util.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/test/util.py	2010-06-15 18:04:25 UTC (rev 5736)
+++ CalendarServer/branches/new-store/twistedcaldav/test/util.py	2010-06-15 18:29:06 UTC (rev 5737)
@@ -295,7 +295,8 @@
         it a new transaction.
         """
         users = self.homeProvisioner.getChild("users")
-        user = users.getChild("wsanchez")
+        class norequest(object): pass
+        user, ignored = users.locateChild(norequest(), ["wsanchez"])
 
         # Force the request to succeed regardless of the implementation of
         # accessControlList.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100615/060e9fd0/attachment-0001.html>


More information about the calendarserver-changes mailing list