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

source_changes at macosforge.org source_changes at macosforge.org
Tue Jul 24 17:31:48 PDT 2012


Revision: 9493
          http://trac.macosforge.org/projects/calendarserver/changeset/9493
Author:   gaya at apple.com
Date:     2012-07-24 17:31:47 -0700 (Tue, 24 Jul 2012)
Log Message:
-----------
asShared() fills in CommonHomeChild._inviteUID. asInvited() now only returns non-accepted children

Modified Paths:
--------------
    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/common/datastore/sql.py

Modified: CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/sharing.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/sharing.py	2012-07-24 18:19:54 UTC (rev 9492)
+++ CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/sharing.py	2012-07-25 00:31:47 UTC (rev 9493)
@@ -505,11 +505,11 @@
                                                     mode=invitationAccessToBindModeMap[access],
                                                     status=_BIND_STATUS_INVITED,
                                                     message=summary )
-        # no way to get an unaccepted child similar to 
-        #    homeChild = yield shareeHome.sharedChildWithName(sharedName)
+        # TODO:  add  invitedChildWithName
+        #    homeChild = yield shareeHome.invitedChildWithName(sharedName)
         #    invitation = Invitation(homeChild)
-        # so get all invites and filter
-        invitation = yield self._invitationForShareeUID(shareeUID)
+        # for now, get all invites and filter
+        invitation = yield self._invitationForShareeUID(shareeUID, includeAccepted=False)
         assert sharedName == invitation.uid()
         returnValue(invitation)
         
@@ -533,31 +533,30 @@
     def _allInvitations(self, includeAccepted=True):
         """
         Get list of all invitations to this object
+        
+        For legacy reasons, all invitations are all invited + shared (accepted).
+        Combine these two into a single sorted list, sorted for easy testing
         """
         invitedHomeChildren = yield self._newStoreObject.asInvited()
-        ''' FUTURE
         if includeAccepted:
             acceptedHomeChildren = yield self._newStoreObject.asShared()
             if invitedHomeChildren and acceptedHomeChildren:
                 invitedHomeChildren += acceptedHomeChildren
+                invitedHomeChildren = set(invitedHomeChildren)
             elif acceptedHomeChildren:
                 invitedHomeChildren = acceptedHomeChildren
-        '''
         
-        invitations = []
-        for homeChild in invitedHomeChildren:
-            invitation = Invitation(homeChild)
-            invitations.append(invitation)
+        invitations = [Invitation(homeChild) for homeChild in invitedHomeChildren]
         invitations.sort(key=lambda invitation:invitation.shareeUID())
         
         returnValue(invitations)
 
     @inlineCallbacks
-    def _invitationForShareeUID(self, shareeUID):
+    def _invitationForShareeUID(self, shareeUID, includeAccepted=True):
         """
         Get an invitation for this sharee principal UID
         """
-        invitations = yield self._allInvitations()
+        invitations = yield self._allInvitations(includeAccepted=includeAccepted)
         for invitation in invitations:
             if invitation.shareeUID() == shareeUID:
                 returnValue(invitation)
@@ -565,11 +564,11 @@
 
 
     @inlineCallbacks
-    def _invitationForUID(self, uid):
+    def _invitationForUID(self, uid, includeAccepted=True):
         """
-        Get an invitation for an invitation for a uid 
+        Get an invitation for an invitations uid 
         """
-        invitations = yield self._allInvitations()
+        invitations = yield self._allInvitations(includeAccepted=includeAccepted)
         for invitation in invitations:
             if invitation.uid() == uid:
                 returnValue(invitation)

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-24 18:19:54 UTC (rev 9492)
+++ CalendarServer/branches/users/gaya/inviteclean/txdav/caldav/datastore/test/common.py	2012-07-25 00:31:47 UTC (rev 9493)
@@ -1030,7 +1030,7 @@
         self.assertEqual(newName, self.sharedName)
         self.assertNotIdentical(otherCal, None)
 
-        invitedCals = yield cal.asInvited()
+        invitedCals = yield cal.asShared()
         self.assertEqual(len(invitedCals), 1)
         self.assertEqual(invitedCals[0].shareMode(), _BIND_MODE_READ)
 
@@ -1049,7 +1049,7 @@
         newName = yield cal.unshareWith(other)
         otherCal = yield other.sharedChildWithName(newName)
         self.assertIdentical(otherCal, None)
-        invitedCals = yield cal.asInvited()
+        invitedCals = yield cal.asShared()
         self.assertEqual(len(invitedCals), 0)
         shares = yield other.retrieveOldShares().allRecords()
         self.assertEqual(len(shares), 0)
@@ -1070,7 +1070,7 @@
         yield cal.unshare()
         otherCal = yield other.sharedChildWithName(self.sharedName)
         self.assertEqual(otherCal, None)
-        invitedCals = yield cal.asInvited()
+        invitedCals = yield cal.asShared()
         self.assertEqual(len(invitedCals), 0)
         shares = yield other.retrieveOldShares().allRecords()
         self.assertEqual(len(shares), 0)
@@ -1091,7 +1091,7 @@
         yield otherCal.unshare()
         otherCal = yield other.sharedChildWithName(self.sharedName)
         self.assertEqual(otherCal, None)
-        invitedCals = yield cal.asInvited()
+        invitedCals = yield cal.asShared()
         self.assertEqual(len(invitedCals), 0)
         shares = yield other.retrieveOldShares().allRecords()
         self.assertEqual(len(shares), 0)

Modified: CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py	2012-07-24 18:19:54 UTC (rev 9492)
+++ CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py	2012-07-25 00:31:47 UTC (rev 9493)
@@ -2267,17 +2267,33 @@
 
 
 
-    @classproperty
-    def _bindEntriesFor(cls): #@NoSelf
+    @classmethod
+    def _bindEntriesFor(cls, condition): #@NoSelf
         bind = cls._bindSchema
-        return Select([bind.BIND_MODE, bind.HOME_RESOURCE_ID,
-                       bind.RESOURCE_NAME],
-                      From=bind,
-                      Where=(bind.RESOURCE_ID == Parameter("resourceID")).And
-                            (bind.BIND_STATUS == _BIND_STATUS_ACCEPTED).And
-                            (bind.BIND_MODE != _BIND_MODE_OWN))
+        inv = schema.INVITE
+        return Select(
+            [bind.BIND_MODE, 
+             bind.HOME_RESOURCE_ID,
+             bind.RESOURCE_NAME,
+             bind.BIND_STATUS,
+             bind.MESSAGE,
+             inv.INVITE_UID],
+                  From=inv.join(bind),
+                  Where=(condition
+                        .And(bind.RESOURCE_ID == Parameter("resourceID"))
+                        .And(bind.BIND_MODE != _BIND_MODE_OWN)
+                        .And(inv.RESOURCE_ID == bind.RESOURCE_ID)
+                        .And(inv.HOME_RESOURCE_ID == bind.HOME_RESOURCE_ID)
+                        )
+        )
 
 
+    @classproperty
+    def _sharedFor(cls): #@NoSelf
+        bind = cls._bindSchema
+        return cls._bindEntriesFor(bind.BIND_STATUS == _BIND_STATUS_ACCEPTED)
+    
+
     @inlineCallbacks
     def asShared(self):
         """
@@ -2290,17 +2306,21 @@
             L{CommonHomeChild} as a child of different L{CommonHome}s
         @rtype: a L{Deferred} which fires with a L{list} of L{ICalendar}s.
         """
-        rows = yield self._bindEntriesFor.on(self._txn,
-                                             resourceID=self._resourceID)
+        rows = yield self._sharedFor.on(self._txn, 
+                                        resourceID=self._resourceID)
+
         cls = self.__class__ # for ease of grepping...
         result = []
-        for mode, homeResourceID, sharedResourceName in rows:
+        for bindMode, homeResourceID, sharedResourceName, bindStatus, bindMessage, inviteUID in rows:
+            assert bindStatus == _BIND_STATUS_ACCEPTED
             # TODO: this could all be issued in parallel; no need to serialize
             # the loop.
             new = cls(
-                (yield self._txn.homeWithResourceID(self._home._homeType,
+                home=(yield self._txn.homeWithResourceID(self._home._homeType,
                                                     homeResourceID)),
-                sharedResourceName, self._resourceID, False, mode
+                name=sharedResourceName, resourceID=self._resourceID,
+                owned=False, mode=bindMode, status=bindStatus, 
+                message=bindMessage, inviteUID=inviteUID,
             )
             yield new.initFromStore()
             result.append(new)
@@ -2308,33 +2328,10 @@
 
 
     @classproperty
-    def _allInvitedQuery(cls): #@NoSelf
-        #FIXME performance: change schema to get rid if INVITE table -> no join
-        #
-        # similar to sql_legacy.py
-        inv = schema.INVITE
-        home = cls._homeSchema
+    def _invitedFor(cls): #@NoSelf
         bind = cls._bindSchema
-        return Select(
-            [bind.BIND_MODE, 
-             bind.HOME_RESOURCE_ID,
-             bind.RESOURCE_NAME,    # same as inv.INVITE_UID when not accepted
-             bind.BIND_STATUS,
-             bind.MESSAGE,
-             inv.INVITE_UID],
-            From=inv.join(home).join(bind),
-            Where=(
-                (inv.RESOURCE_ID == Parameter("resourceID"))
-                .And(inv.RESOURCE_ID == bind.RESOURCE_ID)
-                .And(inv.HOME_RESOURCE_ID == home.RESOURCE_ID)
-                .And(inv.HOME_RESOURCE_ID == bind.HOME_RESOURCE_ID)
-                # FIXME: test that this next line effectively obscures already-
-                # accepted and owned stuff!
-                #.And(bind.BIND_STATUS != _BIND_STATUS_ACCEPTED)
-                )
-        )
+        return cls._bindEntriesFor(bind.BIND_STATUS != _BIND_STATUS_ACCEPTED)
 
-
     @inlineCallbacks
     def asInvited(self):
         """
@@ -2347,7 +2344,7 @@
             L{CommonHomeChild} as a child of different L{CommonHome}s
         @rtype: a L{Deferred} which fires with a L{list} of L{ICalendar}s.
         """
-        rows = yield self._allInvitedQuery.on(
+        rows = yield self._invitedFor.on(
             self._txn, resourceID=self._resourceID
         )
         cls = self.__class__ # for ease of grepping...
@@ -2361,7 +2358,7 @@
                                                     homeResourceID)),
                 name=sharedResourceName, resourceID=self._resourceID,
                 owned=False, mode=bindMode, status=bindStatus, 
-                message=bindMessage, inviteUID= inviteUID,
+                message=bindMessage, inviteUID=inviteUID,
             )
             yield new.initFromStore()
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120724/abca2bc0/attachment-0001.html>


More information about the calendarserver-changes mailing list