[CalendarServer-changes] [9505] CalendarServer/branches/users/gaya/inviteclean

source_changes at macosforge.org source_changes at macosforge.org
Fri Jul 27 17:11:05 PDT 2012


Revision: 9505
          http://trac.macosforge.org/projects/calendarserver/changeset/9505
Author:   gaya at apple.com
Date:     2012-07-27 17:11:04 -0700 (Fri, 27 Jul 2012)
Log Message:
-----------
remove CommonHomeChild.sharedChildWithName(), CommonHomeChild.listSharedChildren(), etc.

Modified Paths:
--------------
    CalendarServer/branches/users/gaya/inviteclean/calendarserver/tools/purge.py
    CalendarServer/branches/users/gaya/inviteclean/calendarserver/tools/test/test_purge.py
    CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/resource.py
    CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/sharing.py
    CalendarServer/branches/users/gaya/inviteclean/txdav/caldav/datastore/test/common.py
    CalendarServer/branches/users/gaya/inviteclean/txdav/caldav/datastore/test/test_sql.py
    CalendarServer/branches/users/gaya/inviteclean/txdav/caldav/icalendarstore.py
    CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py
    CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql_legacy.py

Modified: CalendarServer/branches/users/gaya/inviteclean/calendarserver/tools/purge.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/calendarserver/tools/purge.py	2012-07-27 19:38:10 UTC (rev 9504)
+++ CalendarServer/branches/users/gaya/inviteclean/calendarserver/tools/purge.py	2012-07-28 00:11:04 UTC (rev 9505)
@@ -666,19 +666,7 @@
     # If in "completely" mode, unshare collections, remove notifications
     if calHomeProvisioned and completely:
 
-        # Process shared-to-me calendars
-        names = list((yield storeCalHome.listSharedChildren()))
-        for name in names:
-            if verbose:
-                if dryrun:
-                    print "Would unshare: %s" % (name,)
-                else:
-                    print "Unsharing: %s" % (name,)
-            if not dryrun:
-                child = (yield storeCalHome.sharedChildWithName(name))
-                (yield child.unshare())
-
-        # Process shared calendars
+        # Process shared and shared-to-me calendars
         children = list((yield storeCalHome.children()))
         for child in children:
             if verbose:

Modified: CalendarServer/branches/users/gaya/inviteclean/calendarserver/tools/test/test_purge.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/calendarserver/tools/test/test_purge.py	2012-07-27 19:38:10 UTC (rev 9504)
+++ CalendarServer/branches/users/gaya/inviteclean/calendarserver/tools/test/test_purge.py	2012-07-28 00:11:04 UTC (rev 9505)
@@ -847,10 +847,10 @@
 
         txn = self._sqlCalendarStore.newTransaction()
         home = (yield txn.calendarHomeWithUID(self.uid))
-        calendar2 = (yield home.sharedChildWithName(self.sharedName))
+        calendar2 = (yield home.childWithName(self.sharedName))
         self.assertNotEquals(calendar2, None)
         home2 = (yield txn.calendarHomeWithUID(self.uid2))
-        calendar1 = (yield home2.sharedChildWithName(self.sharedName2))
+        calendar1 = (yield home2.childWithName(self.sharedName2))
         self.assertNotEquals(calendar1, None)
         (yield txn.commit())
 
@@ -890,7 +890,7 @@
         self.assertEquals(home, None)
         # Verify calendar1 was unshared to uid2
         home2 = (yield txn.calendarHomeWithUID(self.uid2))
-        self.assertEquals((yield home2.sharedChildWithName(self.sharedName)), None)
+        self.assertEquals((yield home2.childWithName(self.sharedName)), None)
         (yield txn.commit())
 
         count, ignored = (yield purgeUID(self.storeUnderTest(), self.uid, self.directory,

Modified: CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/resource.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/resource.py	2012-07-27 19:38:10 UTC (rev 9504)
+++ CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/resource.py	2012-07-28 00:11:04 UTC (rev 9505)
@@ -2274,7 +2274,6 @@
         children = set(self._provisionedChildren.keys())
         children.update(self._provisionedLinks.keys())
         children.update((yield self._newStoreHome.listChildren()))
-        children.update((yield self._newStoreHome.listSharedChildren()))
         returnValue(children)
 
 
@@ -2591,6 +2590,9 @@
     @inlineCallbacks
     def makeRegularChild(self, name):
         newCalendar = yield self._newStoreHome.calendarWithName(name)
+        if newCalendar and not newCalendar.owned():
+            newCalendar = None
+
         from twistedcaldav.storebridge import CalendarCollectionResource
         similar = CalendarCollectionResource(
             newCalendar, self, name=name,
@@ -2841,6 +2843,8 @@
                 mainCls = GlobalAddressBookCollectionResource
 
         newAddressBook = yield self._newStoreHome.addressbookWithName(name)
+        if newAddressBook and not newAddressBook.owned():
+            newAddressBook = None
         similar = mainCls(
             newAddressBook, self, name,
             principalCollections=self.principalCollections()

Modified: CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/sharing.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/sharing.py	2012-07-27 19:38:10 UTC (rev 9504)
+++ CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/sharing.py	2012-07-28 00:11:04 UTC (rev 9505)
@@ -907,7 +907,7 @@
         return self._homeChild
 
     def uid(self):
-        return self._homeChild.inviteUID()
+        return self._homeChild.shareUID()
     
     def shareeUID(self):
         return self._homeChild._home.uid()

Modified: CalendarServer/branches/users/gaya/inviteclean/txdav/caldav/datastore/test/common.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/txdav/caldav/datastore/test/common.py	2012-07-27 19:38:10 UTC (rev 9504)
+++ CalendarServer/branches/users/gaya/inviteclean/txdav/caldav/datastore/test/common.py	2012-07-28 00:11:04 UTC (rev 9505)
@@ -996,7 +996,7 @@
         yield self.commit()
         normalCal = yield self.calendarUnderTest()
         otherHome = yield self.homeUnderTest(name=OTHER_HOME_UID)
-        otherCal = yield otherHome.sharedChildWithName(newCalName)
+        otherCal = yield otherHome.childWithName(newCalName)
         self.assertNotIdentical(otherCal, None)
         self.assertEqual(
             (yield
@@ -1024,7 +1024,7 @@
         cal = yield self.calendarUnderTest()
         other = yield self.homeUnderTest(name=OTHER_HOME_UID)
         newName = yield cal.shareWith(other, _BIND_MODE_READ)
-        otherCal = yield other.sharedChildWithName(self.sharedName)
+        otherCal = yield other.childWithName(self.sharedName)
 
         # Name should not change just because we updated the mode.
         self.assertEqual(newName, self.sharedName)
@@ -1047,7 +1047,7 @@
         cal = yield self.calendarUnderTest()
         other = yield self.homeUnderTest(name=OTHER_HOME_UID)
         newName = yield cal.unshareWith(other)
-        otherCal = yield other.sharedChildWithName(newName)
+        otherCal = yield other.childWithName(newName)
         self.assertIdentical(otherCal, None)
         invitedCals = yield cal.asShared()
         self.assertEqual(len(invitedCals), 0)
@@ -1065,10 +1065,10 @@
             yield self.commit()
         cal = yield self.calendarUnderTest()
         other = yield self.homeUnderTest(name=OTHER_HOME_UID)
-        otherCal = yield other.sharedChildWithName(self.sharedName)
+        otherCal = yield other.childWithName(self.sharedName)
         self.assertNotEqual(otherCal, None)
         yield cal.unshare()
-        otherCal = yield other.sharedChildWithName(self.sharedName)
+        otherCal = yield other.childWithName(self.sharedName)
         self.assertEqual(otherCal, None)
         invitedCals = yield cal.asShared()
         self.assertEqual(len(invitedCals), 0)
@@ -1086,10 +1086,10 @@
             yield self.commit()
         cal = yield self.calendarUnderTest()
         other = yield self.homeUnderTest(name=OTHER_HOME_UID)
-        otherCal = yield other.sharedChildWithName(self.sharedName)
+        otherCal = yield other.childWithName(self.sharedName)
         self.assertNotEqual(otherCal, None)
         yield otherCal.unshare()
-        otherCal = yield other.sharedChildWithName(self.sharedName)
+        otherCal = yield other.childWithName(self.sharedName)
         self.assertEqual(otherCal, None)
         invitedCals = yield cal.asShared()
         self.assertEqual(len(invitedCals), 0)

Modified: CalendarServer/branches/users/gaya/inviteclean/txdav/caldav/datastore/test/test_sql.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/txdav/caldav/datastore/test/test_sql.py	2012-07-27 19:38:10 UTC (rev 9504)
+++ CalendarServer/branches/users/gaya/inviteclean/txdav/caldav/datastore/test/test_sql.py	2012-07-28 00:11:04 UTC (rev 9505)
@@ -976,9 +976,9 @@
             bind.SEEN_BY_SHAREE: True,
         })
         yield _bindCreate.on(self.transactionUnderTest())
-        sharedCalendar = yield shareeHome.sharedChildWithName("shared_1")
+        sharedCalendar = yield shareeHome.childWithName("shared_1")
         self.assertTrue(sharedCalendar is not None)
-        sharedCalendar = yield shareeHome.sharedChildWithName("shared_1_vtodo")
+        sharedCalendar = yield shareeHome.childWithName("shared_1_vtodo")
         self.assertTrue(sharedCalendar is None)
 
         # Now do the transfer and see if a new binding exists
@@ -986,11 +986,11 @@
             "home_splits")).createCalendarWithName("calendar_new")
         yield calendar._transferSharingDetails(newcalendar, "VTODO")
 
-        sharedCalendar = yield shareeHome.sharedChildWithName("shared_1")
+        sharedCalendar = yield shareeHome.childWithName("shared_1")
         self.assertTrue(sharedCalendar is not None)
         self.assertEqual(sharedCalendar._resourceID, calendar._resourceID)
 
-        sharedCalendar = yield shareeHome.sharedChildWithName("shared_1-vtodo")
+        sharedCalendar = yield shareeHome.childWithName("shared_1-vtodo")
         self.assertTrue(sharedCalendar is not None)
         self.assertEqual(sharedCalendar._resourceID, newcalendar._resourceID)
 

Modified: CalendarServer/branches/users/gaya/inviteclean/txdav/caldav/icalendarstore.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/txdav/caldav/icalendarstore.py	2012-07-27 19:38:10 UTC (rev 9504)
+++ CalendarServer/branches/users/gaya/inviteclean/txdav/caldav/icalendarstore.py	2012-07-28 00:11:04 UTC (rev 9505)
@@ -408,7 +408,7 @@
         C{txn.calendarHomeWithUID("alice") ...
         .calendarWithName("calendar").viewerCalendarHome()} will return Alice's
         home, whereas C{txn.calendarHomeWithUID("bob") ...
-        .sharedChildWithName("alice's calendar").viewerCalendarHome()} will
+        .childWithName("alice's calendar").viewerCalendarHome()} will
         return Bob's calendar home.
 
         @return: (synchronously) the calendar home of the user into which this
@@ -417,12 +417,6 @@
         """
         # TODO: implement this for the file store.
 
-        # TODO: implement home-child- retrieval APIs to retrieve shared items
-        # from the store; the example in the docstring ought to be
-        # calendarWithName not sharedChildWithName.
-
-
-
 class ICalendarObject(IDataStoreObject):
     """
     Calendar object

Modified: CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py	2012-07-27 19:38:10 UTC (rev 9504)
+++ CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py	2012-07-28 00:11:04 UTC (rev 9505)
@@ -900,7 +900,6 @@
         self._shares = None
         self._childrenLoaded = False
         self._children = {}
-        self._sharedChildren = {}
         self._notifiers = notifiers
         self._quotaUsedBytes = None
         self._created = None
@@ -1101,16 +1100,12 @@
         """
         Load and cache all children - Depth:1 optimization
         """
-        results1 = (yield self._childClass.loadAllObjects(self, owned=True))
-        for result in results1:
+        results = (yield self._childClass.loadAllObjects(self))
+        for result in results:
             self._children[result.name()] = result
-        results2 = (yield self._childClass.loadAllObjects(self, owned=False))
-        for result in results2:
-            self._sharedChildren[result.name()] = result
         self._childrenLoaded = True
-        returnValue(results1 + results2)
+        returnValue(results)
 
-
     def listChildren(self):
         """
         Retrieve the names of the children in this home.
@@ -1121,21 +1116,9 @@
         if self._childrenLoaded:
             return succeed(self._children.keys())
         else:
-            return self._childClass.listObjects(self, owned=True)
+            return self._childClass.listObjects(self)
 
 
-    def listSharedChildren(self):
-        """
-        Retrieve the names of the children in this home.
-
-        @return: an iterable of C{str}s.
-        """ 
-        if self._childrenLoaded:
-            return succeed(self._sharedChildren.keys())
-        else:
-            return self._childClass.listObjects(self, owned=False)
-
-
     def listInvitedChildren(self):
         """
         Retrieve the names of the invited children in this home.
@@ -1154,7 +1137,7 @@
         @param name: a string.
         @return: an L{ICalendar} or C{None} if no such child exists.
         """
-        return self._childClass.objectWithName(self, name, owned=True)
+        return self._childClass.objectWithName(self, name)
 
     @memoizedKey("resourceID", "_children")
     def childWithID(self, resourceID):
@@ -1167,24 +1150,6 @@
         """
         return self._childClass.objectWithID(self, resourceID)
 
-    @memoizedKey("name", "_sharedChildren")
-    def sharedChildWithName(self, name):
-        """
-        Retrieve the shared child with the given C{name} contained in this
-        home. Return a child object with this home and the name.
-
-        IMPORTANT: take care when using this. Shared calendars should normally
-        be accessed through the owner home collection, not the sharee home collection.
-        The only reason for access through sharee home is to do some housekeeping
-        for maintaining the revisions database to show shared calendars appearing and
-        disappearing in the sharee home.
-
-        @param name: a string.
-        @return: an L{ICalendar} or C{None} if no such child
-            exists.
-        """
-        return self._childClass.objectWithName(self, name, owned=False)
-
     def invitedChildWithName(self, name):
         """
         Retrieve the invited child with the given C{name} contained in this
@@ -1315,37 +1280,38 @@
         # Now deal with shared collections
         bind = self._bindSchema
         rev = self._revisionsSchema
-        shares = yield self.listSharedChildren()
-        for sharename in shares:
-            sharetoken = 0 if sharename in changed_collections else token
-            shareID = (yield Select(
-                [bind.RESOURCE_ID], From=bind,
-                Where=(bind.RESOURCE_NAME == sharename).And(
-                    bind.HOME_RESOURCE_ID == self._resourceID).And(
-                        bind.BIND_MODE != _BIND_MODE_OWN)
-            ).on(self._txn))[0][0]
-            results = [
-                (
-                    sharename,
-                    name if name else "",
-                    wasdeleted
-                )
-                for name, wasdeleted in
-                (yield Select([rev.RESOURCE_NAME, rev.DELETED],
-                                 From=rev,
-                                Where=(rev.REVISION > sharetoken).And(
-                                rev.RESOURCE_ID == shareID)).on(self._txn))
-                if name
-            ]
+        shares = yield self.children()
+        for share in shares:
+            if not share.owned():
+                sharetoken = 0 if share.name() in changed_collections else token
+                shareID = (yield Select(
+                    [bind.RESOURCE_ID], From=bind,
+                    Where=(bind.RESOURCE_NAME == share.name()).And(
+                        bind.HOME_RESOURCE_ID == self._resourceID).And(
+                            bind.BIND_MODE != _BIND_MODE_OWN)
+                ).on(self._txn))[0][0]
+                results = [
+                    (
+                        share.name(),
+                        name if name else "",
+                        wasdeleted
+                    )
+                    for name, wasdeleted in
+                    (yield Select([rev.RESOURCE_NAME, rev.DELETED],
+                                     From=rev,
+                                    Where=(rev.REVISION > sharetoken).And(
+                                    rev.RESOURCE_ID == shareID)).on(self._txn))
+                    if name
+                ]
+    
+                for path, name, wasdeleted in results:
+                    if wasdeleted:
+                        if sharetoken:
+                            deleted.append("%s/%s" % (path, name,))
+    
+                for path, name, wasdeleted in results:
+                    changed.append("%s/%s" % (path, name,))
 
-            for path, name, wasdeleted in results:
-                if wasdeleted:
-                    if sharetoken:
-                        deleted.append("%s/%s" % (path, name,))
-
-            for path, name, wasdeleted in results:
-                changed.append("%s/%s" % (path, name,))
-
         changed.sort()
         deleted.sort()
         returnValue((changed, deleted))
@@ -1949,12 +1915,13 @@
 
 
     @classproperty
-    def _ownedChildListQuery(cls): #@NoSelf
+    def _childListQuery(cls): #@NoSelf
         bind = cls._bindSchema
         return Select([bind.RESOURCE_NAME], From=bind,
                       Where=(bind.HOME_RESOURCE_ID ==
                              Parameter("resourceID")).And(
-                                 bind.BIND_MODE == _BIND_MODE_OWN))
+                                (bind.BIND_MODE == _BIND_MODE_OWN).Or(
+                                bind.BIND_STATUS == _BIND_STATUS_ACCEPTED)))
 
 
     @classmethod
@@ -1987,35 +1954,22 @@
             "_modified",
         )
         
-    @classproperty
-    def _sharedChildListQuery(cls): #@NoSelf
-        bind = cls._bindSchema
-        return Select([bind.RESOURCE_NAME], From=bind,
-                      Where=(bind.HOME_RESOURCE_ID ==
-                             Parameter("resourceID")).And(
-                                 bind.BIND_MODE != _BIND_MODE_OWN).And(
-                                 bind.BIND_STATUS == _BIND_STATUS_ACCEPTED))
-
     @classmethod
     @inlineCallbacks
-    def listObjects(cls, home, owned):
+    def listObjects(cls, home):
         """
         Retrieve the names of the children that exist in the given home.
 
         @return: an iterable of C{str}s.
         """
         # FIXME: tests don't cover this as directly as they should.
-        if owned:
-            rows = yield cls._ownedChildListQuery.on(
+        rows = yield cls._childListQuery.on(
                 home._txn, resourceID=home._resourceID)
-        else:
-            rows = yield cls._sharedChildListQuery.on(
-                home._txn, resourceID=home._resourceID)
         names = [row[0] for row in rows]
         returnValue(names)
 
+
     @classproperty
-    @classproperty
     def _invitedChildListQuery(cls): #@NoSelf
         bind = cls._bindSchema
         return cls._invitedBindFor((bind.HOME_RESOURCE_ID == Parameter("homeID"))
@@ -2037,18 +1991,18 @@
         returnValue(names)
 
 
-    @classmethod
-    def _allHomeChildrenQuery(cls, owned):
+    @classproperty
+    def _allHomeChildrenQuery(cls): #@NoSelf
         bind = cls._bindSchema
         child = cls._homeChildSchema
         childMetaData = cls._homeChildMetaDataSchema
-        if owned:
-            ownedPiece = bind.BIND_MODE == _BIND_MODE_OWN
-        else:
-            ownedPiece = (bind.BIND_MODE != _BIND_MODE_OWN).And(
-                bind.BIND_STATUS == _BIND_STATUS_ACCEPTED)
 
-        columns = [child.RESOURCE_ID, bind.RESOURCE_NAME, bind.BIND_MODE]
+        columns = [bind.BIND_MODE, 
+                   bind.HOME_RESOURCE_ID,
+                   bind.RESOURCE_ID,
+                   bind.RESOURCE_NAME,
+                   bind.BIND_STATUS,
+                   bind.MESSAGE]
         columns.extend(cls.metadataColumns())
         return Select(columns,
                      From=child.join(
@@ -2056,21 +2010,13 @@
                          'left outer').join(
                          childMetaData, childMetaData.RESOURCE_ID == bind.RESOURCE_ID,
                          'left outer'),
-                     Where=(bind.HOME_RESOURCE_ID == Parameter("resourceID")
-                           ).And(ownedPiece))
+                     Where=(bind.HOME_RESOURCE_ID == Parameter("homeID")
+                           ).And(
+                                 (bind.BIND_MODE == _BIND_MODE_OWN).Or(
+                                  bind.BIND_STATUS == _BIND_STATUS_ACCEPTED)))
 
 
     @classproperty
-    def _ownedHomeChildrenQuery(cls): #@NoSelf
-        return cls._allHomeChildrenQuery(True)
-
-
-    @classproperty
-    def _sharedHomeChildrenQuery(cls): #@NoSelf
-        return cls._allHomeChildrenQuery(False)
-
-
-    @classproperty
     def _inviteInsertQuery(cls): #@NoSelf
         inv = schema.INVITE
         return Insert(
@@ -2248,7 +2194,7 @@
             Return=bind.RESOURCE_NAME,
         ).on(self._txn, resourceID=self._resourceID,
              homeID=shareeHome._resourceID))[0][0]
-        shareeHome._sharedChildren.pop(resourceName, None)
+        shareeHome._children.pop(resourceName, None)
         
         # Must send notification to ensure cache invalidation occurs
         yield self.notifyChanged()
@@ -2280,9 +2226,9 @@
         """
         return self._bindMessage
 
-    def inviteUID(self):
+    def shareUID(self):
         """
-        @see: L{ICalendar.inviteUID}
+        @see: L{ICalendar.shareUID}
         """
         return self._inviteUID
 
@@ -2376,14 +2322,14 @@
 
         cls = self.__class__ # for ease of grepping...
         result = []
-        for bindMode, homeResourceID, resourceID, sharedResourceName, bindStatus, bindMessage, inviteUID in mergedRowDict.values(): #@UnusedVariable
+        for bindMode, homeResourceID, resourceID, resourceName, bindStatus, bindMessage, inviteUID in mergedRowDict.values(): #@UnusedVariable
             assert bindStatus == _BIND_STATUS_ACCEPTED
             # TODO: this could all be issued in parallel; no need to serialize
             # the loop.
             new = cls(
                 home=(yield self._txn.homeWithResourceID(self._home._homeType,
                                                     homeResourceID)),
-                name=sharedResourceName, resourceID=self._resourceID,
+                name=resourceName, resourceID=self._resourceID,
                 mode=bindMode, status=bindStatus, 
                 message=bindMessage, inviteUID=inviteUID,
             )
@@ -2416,13 +2362,13 @@
         cls = self.__class__ # for ease of grepping...
 
         result = []
-        for bindMode, homeResourceID, resourceID, sharedResourceName, bindStatus, bindMessage, inviteUID in rows: #@UnusedVariable
+        for bindMode, homeResourceID, resourceID, resourceName, bindStatus, bindMessage, inviteUID in rows: #@UnusedVariable
             # TODO: this could all be issued in parallel; no need to serialize
             # the loop.
             new = cls(
                 home=(yield self._txn.homeWithResourceID(self._home._homeType,
                                                     homeResourceID)),
-                name=sharedResourceName, resourceID=self._resourceID,
+                name=resourceName, resourceID=self._resourceID,
                 mode=bindMode, status=bindStatus, 
                 message=bindMessage, inviteUID=inviteUID,
             )
@@ -2434,7 +2380,7 @@
 
     @classmethod
     @inlineCallbacks
-    def loadAllObjects(cls, home, owned):
+    def loadAllObjects(cls, home):
         """
         Load all L{CommonHomeChild} instances which are children of a given
         L{CommonHome} and return a L{Deferred} firing a list of them.  This must
@@ -2445,13 +2391,24 @@
         results = []
 
         # Load from the main table first
-        if owned:
-            query = cls._ownedHomeChildrenQuery
-        else:
-            query = cls._sharedHomeChildrenQuery
-        dataRows = (yield query.on(home._txn, resourceID=home._resourceID))
+        dataRows = (yield cls._allHomeChildrenQuery.on(home._txn, homeID=home._resourceID))
 
         if dataRows:
+            
+            # get inviteUID for indirect shared children
+            invitedRows = yield cls._invitedChildListQuery.on(home._txn, homeID=home._resourceID)
+            for i in range(len(dataRows)):
+                dataRowResourceID = dataRows[i][2]
+                for invitedRow in invitedRows:
+                    invitedRowResourceID = invitedRow[2]
+                    if invitedRowResourceID==dataRowResourceID:
+                        inviteUID = invitedRow[7]
+                        break
+                else:
+                    inviteUID = None
+                
+                dataRows[i] = dataRows[i][:6] + [inviteUID,] + dataRows[i][6:]                        
+            
             # Get property stores for all these child resources (if any found)
             propertyStores = (yield PropertyStore.forMultipleResources(
                 home.uid(), home._txn,
@@ -2461,15 +2418,10 @@
 
             bind = cls._bindSchema
             rev = cls._revisionsSchema
-            if owned:
-                ownedCond = bind.BIND_MODE == _BIND_MODE_OWN
-            else:
-                ownedCond = bind.BIND_MODE != _BIND_MODE_OWN
             revisions = (yield Select(
                 [rev.RESOURCE_ID, Max(rev.REVISION)],
                 From=rev.join(bind, rev.RESOURCE_ID == bind.RESOURCE_ID, 'left'),
                 Where=(bind.HOME_RESOURCE_ID == home._resourceID).
-                    And(ownedCond).
                     And((rev.RESOURCE_NAME != None).Or(rev.DELETED == False)),
                 GroupBy=rev.RESOURCE_ID
             ).on(home._txn))
@@ -2477,9 +2429,14 @@
 
         # Create the actual objects merging in properties
         for items in dataRows:
-            resourceID, resourceName, bindMode = items[:3]
-            metadata = items[3:]
-            child = cls(home, resourceName, resourceID, bindMode)
+            bindMode, homeResourceID, resourceID, resourceName, bindStatus, bindMessage, inviteUID = items[:7] #@UnusedVariable
+            metadata=items[7:]
+            child = cls(
+                home=home,
+                name=resourceName, resourceID=resourceID,
+                mode=bindMode, status=bindStatus, 
+                message=bindMessage, inviteUID=inviteUID,
+            )
             for attr, value in zip(cls.metadataAttributes(), metadata):
                 setattr(child, attr, value)
             child._syncTokenRevision = revisions[resourceID]
@@ -2518,10 +2475,10 @@
         if not rows:
             returnValue(None)
 
-        bindMode, homeResourceID, resourceID, sharedResourceName, bindStatus, bindMessage, inviteUID = rows[0] #@UnusedVariable
+        bindMode, homeResourceID, resourceID, resourceName, bindStatus, bindMessage, inviteUID = rows[0] #@UnusedVariable
         child = cls(
             home=home,
-            name=sharedResourceName, resourceID=resourceID,
+            name=resourceName, resourceID=resourceID,
             mode=bindMode, status=bindStatus, 
             message=bindMessage, inviteUID=inviteUID,
         )
@@ -2529,28 +2486,8 @@
         returnValue(child)
 
 
-    @classmethod
-    @inlineCallbacks
-    def objectWithName(cls, home, name, owned):
-        """
-        Retrieve the child with the given C{name} contained in the given
-        C{home}.
-
-        @param home: a L{CommonHome}.
-
-        @param name: a string; the name of the L{CommonHomeChild} to retrieve.
-
-        @param owned: a boolean - whether or not to get a shared child
-        @return: an L{CommonHomeChild} or C{None} if no such child
-            exists.
-        """
-        child = yield cls._objectWithName(home, name)
-        result = child if child and child.owned()==owned else None
-        returnValue(result)
-
-
     @classproperty
-    def _anyHomeChildLookup(cls): #@NoSelf
+    def _homeChildLookup(cls): #@NoSelf
         bind = cls._bindSchema
         return Select(
             [bind.BIND_MODE, 
@@ -2575,7 +2512,7 @@
 
     @classmethod
     @inlineCallbacks
-    def _objectWithName(cls, home, name):
+    def objectWithName(cls, home, name):
         # replaces objectWithName()
         """
         Retrieve the child with the given C{name} contained in the given
@@ -2607,7 +2544,7 @@
             rows = yield cls._sharedWithInviteAndNameFor.on(home._txn, name=name, homeID=home._resourceID)
             if not rows:
                 # or all owned or accepted binds w/o inviteUID
-                rows = yield cls._anyHomeChildLookup.on(home._txn, name=name, homeID=home._resourceID)
+                rows = yield cls._homeChildLookup.on(home._txn, name=name, homeID=home._resourceID)
                 if rows:
                     rows[0] += [None,] # add inviteUID col
                     
@@ -2707,7 +2644,7 @@
     @classmethod
     @inlineCallbacks
     def create(cls, home, name):
-        child = (yield cls.objectWithName(home, name, owned=True))
+        child = (yield cls.objectWithName(home, name))
         if child is not None:
             raise HomeChildNameAlreadyExistsError(name)
 

Modified: CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql_legacy.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql_legacy.py	2012-07-27 19:38:10 UTC (rev 9504)
+++ CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql_legacy.py	2012-07-28 00:11:04 UTC (rev 9505)
@@ -295,7 +295,7 @@
             else:
                 yield savepoint.release(self._txn)
 
-        shareeCollection = yield self._home.sharedChildWithName(record.localname)
+        shareeCollection = yield self._home.childWithName(record.localname)
         yield shareeCollection._initSyncToken()
 
 
@@ -311,7 +311,7 @@
     @inlineCallbacks
     def removeRecordForLocalName(self, localname):
         record = yield self.recordForLocalName(localname)
-        shareeCollection = yield self._home.sharedChildWithName(record.localname)
+        shareeCollection = yield self._home.childWithName(record.localname)
         yield shareeCollection._deletedSyncToken(sharedRemoval=True)
 
         result = yield self._unbindShareQuery.on(self._txn, name=localname,
@@ -348,7 +348,7 @@
     def removeRecordForShareUID(self, shareUID):
 
         record = yield self.recordForShareUID(shareUID)
-        shareeCollection = yield self._home.sharedChildWithName(record.localname)
+        shareeCollection = yield self._home.childWithName(record.localname)
         yield shareeCollection._deletedSyncToken(sharedRemoval=True)
 
         if not shareUID.startswith("Direct"):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120727/4d4b6bc6/attachment-0001.html>


More information about the calendarserver-changes mailing list