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

source_changes at macosforge.org source_changes at macosforge.org
Mon Jul 23 18:03:31 PDT 2012


Revision: 9486
          http://trac.macosforge.org/projects/calendarserver/changeset/9486
Author:   gaya at apple.com
Date:     2012-07-23 18:03:31 -0700 (Mon, 23 Jul 2012)
Log Message:
-----------
merge shareWithOptions() into shareWith().  Remove changes to _allInvitesQuery() for now (fix later).

Modified Paths:
--------------
    CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/sharing.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 00:02:33 UTC (rev 9485)
+++ CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/sharing.py	2012-07-24 01:03:31 UTC (rev 9486)
@@ -501,12 +501,20 @@
         elif self.isAddressBookCollection():
             shareeHome = yield self._newStoreObject._txn.addressbookHomeWithUID(shareeUID, create=True)
 
-        homeChild =  yield self._newStoreObject.shareWithOptions(shareeHome,
+        sharedName =  yield self._newStoreObject.shareWith(shareeHome,
                                                     mode=invitationAccessToBindModeMap[access],
                                                     status=_BIND_STATUS_INVITED,
                                                     message=summary )
-        invitation = Invitation(homeChild)
+        # no way to get an unaccepted child similar to 
+        #    homeChild = yield shareeHome.sharedChildWithName(sharedName)
+        #    invitation = Invitation(homeChild)
+        # so get all invites and filter
+        invitation = yield self._invitationForShareeUID(shareeUID)
+        assert sharedName == invitation.uid()
         returnValue(invitation)
+        
+        
+        returnValue(invitation)
 
 
     @inlineCallbacks
@@ -522,11 +530,19 @@
 
 
     @inlineCallbacks
-    def _allInvitations(self):
+    def _allInvitations(self, includeAccepted=True):
         """
         Get list of all invitations to this object
         """
         invitedHomeChildren = yield self._newStoreObject.asInvited()
+        ''' FUTURE
+        if includeAccepted:
+            acceptedHomeChildren = yield self._newStoreObject.asShared()
+            if invitedHomeChildren and acceptedHomeChildren:
+                invitedHomeChildren += acceptedHomeChildren
+            elif acceptedHomeChildren:
+                invitedHomeChildren = acceptedHomeChildren
+        '''
         
         invitations = []
         for homeChild in invitedHomeChildren:

Modified: CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py	2012-07-24 00:02:33 UTC (rev 9485)
+++ CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py	2012-07-24 01:03:31 UTC (rev 9486)
@@ -2062,7 +2062,7 @@
 
 
     @inlineCallbacks
-    def shareWith(self, shareeHome, mode, recipient=None):
+    def shareWith(self, shareeHome, mode, status=None, message=None):
         """
         Share this (owned) L{CommonHomeChild} with another home.
 
@@ -2073,22 +2073,21 @@
             L{_BIND_MODE_WRITE}.
         @type mode: L{str}
 
-        @param recipient: The sharing recipient
-            if None, defaults to "urn:uuid:" + shareeHome.uid()
-        @type recipient: L{str}
+        @param status: The sharing mode; L{_BIND_STATUS_INVITED} or
+            L{_BIND_STATUS_ACCEPTED} or L{_BIND_STATUS_DECLINED} or
+            L{_BIND_STATUS_INVALID}.
+        @type mode: L{str}
 
+        @param message: The proposed message to go along with the share, which
+            will be used as the default display name.
+
         @return: the name of the shared calendar in the new calendar home.
         @rtype: L{str}
         """
         
-        # recipient is needed for current legacy invites
-        if recipient is None:
-            recipient = "urn:uuid:" + shareeHome.uid()
-
-        dn = PropertyName.fromElement(DisplayName)
-        dnprop = (self.properties().get(dn) or
-                  DisplayName.fromString(self.name()))
-
+        if status is None:
+            status = _BIND_STATUS_ACCEPTED
+        
         @inlineCallbacks
         def doInsert(subt):
             newName = str(uuid4())
@@ -2096,12 +2095,12 @@
                 subt, homeID=shareeHome._resourceID,
                 resourceID=self._resourceID, name=newName, mode=mode,
                 seenByOwner=True, seenBySharee=True,
-                bindStatus=_BIND_STATUS_ACCEPTED, message=None
+                bindStatus=status, message=message
             )
             yield self._insertInviteQuery.on(
-                subt, uid=newName, name=str(dnprop),
+                subt, uid=newName, name="unused",
                 homeID=shareeHome._resourceID, resourceID=self._resourceID,
-                recipient=recipient
+                recipient="unused"
             )
             returnValue(newName)
         try:
@@ -2110,7 +2109,7 @@
             # FIXME: catch more specific exception
             sharedName = (yield self._updateBindQuery.on(
                 self._txn,
-                mode=mode, status=_BIND_STATUS_ACCEPTED, message=None,
+                mode=mode, status=status, message=message,
                 resourceID=self._resourceID, homeID=shareeHome._resourceID
             ))[0][0]
             # Invite already exists; no need to update it, since the name will
@@ -2118,83 +2117,16 @@
 
         shareeProps = yield PropertyStore.load(shareeHome.uid(), self._txn,
                                                self._resourceID)
-        shareeProps[dn] = dnprop
-        
-        # Must send notification to ensure cache invalidation occurs
-        yield self.notifyChanged()
-
-        returnValue(sharedName)
-
-
-    @inlineCallbacks
-    def shareWithOptions(self, shareeHome, mode, status, message):
-        """
-        Share this (owned) L{CommonHomeChild} with another home.
-
-        @param shareeHome: The home of the sharee.
-        @type shareeHome: L{CommonHome}
-
-        @param mode: The sharing mode; L{_BIND_MODE_READ} or
-            L{_BIND_MODE_WRITE}.
-        @type mode: L{str}
-
-        @param status: The sharing mode; L{_BIND_STATUS_INVITED} or
-            L{_BIND_STATUS_ACCEPTED} or L{_BIND_STATUS_DECLINED} or
-            L{_BIND_STATUS_INVALID}.
-        @type mode: L{str}
-
-        @param message: The proposed share name
-        @type recipient: L{str}
-
-        @return: L{CommonHomeChild} objects that represent the created
-            L{CommonHomeChild} as a child of the shareeHome
-        @rtype: a L{Deferred} which fires with a L{CommonHomeChild}
-        """
-        
-        # recipient is needed for current legacy invites
-        recipient = "urn:uuid:" + shareeHome.uid()
-
         dn = PropertyName.fromElement(DisplayName)
         dnprop = (self.properties().get(dn) or
                   DisplayName.fromString(self.name()))
 
-        @inlineCallbacks
-        def doInsert(subt):
-            newName = str(uuid4())
-            yield self._bindInsertQuery.on(
-                subt, homeID=shareeHome._resourceID,
-                resourceID=self._resourceID, name=newName, mode=mode,
-                seenByOwner=True, seenBySharee=True,
-                bindStatus=status, message=message
-            )
-            yield self._insertInviteQuery.on(
-                subt, uid=newName, name=str(dnprop),
-                homeID=shareeHome._resourceID, resourceID=self._resourceID,
-                recipient=recipient
-            )
-            returnValue(newName)
-
-        sharedName = yield self._txn.subtransaction(doInsert)
-
-        shareeProps = yield PropertyStore.load(shareeHome.uid(), self._txn,
-                                               self._resourceID)
         shareeProps[dn] = dnprop
         
         # Must send notification to ensure cache invalidation occurs
         yield self.notifyChanged()
-        
-        # return homeChild
-        cls = self.__class__ # for ease of grepping...
-        homeChild = cls(
-            home=(yield self._txn.homeWithResourceID(shareeHome._homeType,
-                                                shareeHome._resourceID)),
-            name=sharedName, resourceID=self._resourceID,
-            owned=False, mode=mode, status=status, 
-            message=message, inviteUID=sharedName,
-        )
-        yield homeChild.initFromStore()
 
-        returnValue(homeChild)
+        returnValue(sharedName)
 
 
     @inlineCallbacks
@@ -2396,7 +2328,8 @@
                 .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))
+                #.And(bind.BIND_STATUS != _BIND_STATUS_ACCEPTED)
+                )
         )
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120723/0a6d3586/attachment.html>


More information about the calendarserver-changes mailing list