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

source_changes at macosforge.org source_changes at macosforge.org
Fri Aug 3 09:43:08 PDT 2012


Revision: 9520
          http://trac.macosforge.org/projects/calendarserver/changeset/9520
Author:   gaya at apple.com
Date:     2012-08-03 09:43:06 -0700 (Fri, 03 Aug 2012)
Log Message:
-----------
remove sync token in updateShare(), unshareWith()

Modified Paths:
--------------
    CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/sharing.py
    CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/test/test_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-08-02 23:20:09 UTC (rev 9519)
+++ CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/sharing.py	2012-08-03 16:43:06 UTC (rev 9520)
@@ -186,11 +186,11 @@
                 (calendarserver_namespace, "valid-principal"),
                 "Current user principal not specified",
             ))
-        principal = (yield request.locateResource(principalURL))
+        sharee = (yield request.locateResource(principalURL))
         
         # Check enabled for service
         from twistedcaldav.directory.principal import DirectoryCalendarPrincipalResource
-        if not isinstance(principal, DirectoryCalendarPrincipalResource):
+        if not isinstance(sharee, DirectoryCalendarPrincipalResource):
             raise HTTPError(ErrorResponse(
                 responsecode.FORBIDDEN,
                 (calendarserver_namespace, "invalid-principal"),
@@ -199,9 +199,9 @@
         
         # Get the home collection
         if self.isCalendarCollection():
-            home = yield principal.calendarHome(request)
+            shareeHomeResource = yield sharee.calendarHome(request)
         elif self.isAddressBookCollection():
-            home = yield principal.addressBookHome(request)
+            shareeHomeResource = yield sharee.addressBookHome(request)
         else:
             raise HTTPError(ErrorResponse(
                 responsecode.FORBIDDEN,
@@ -210,9 +210,9 @@
             ))
             
         # TODO: Make sure principal is not sharing back to themselves
-        compareURL = (yield self.canonicalURL(request))
-        homeURL = home.url()
-        if compareURL.startswith(homeURL):
+        hostURL = (yield self.canonicalURL(request))
+        shareeHomeURL = shareeHomeResource.url()
+        if hostURL.startswith(shareeHomeURL):
             raise HTTPError(ErrorResponse(
                 responsecode.FORBIDDEN,
                 (calendarserver_namespace, "invalid-share"),
@@ -220,8 +220,8 @@
             ))
 
         # Accept it
-        directID = home.sharesDB().directShareID(home, self)
-        response = (yield home.acceptDirectShare(request, compareURL, directID, self.displayName()))
+        directUID = Share.directUID(shareeHomeResource._newStoreHome, self._newStoreObject)
+        response = (yield shareeHomeResource.acceptDirectShare(request, hostURL, directUID, self.displayName()))
 
         # Return the URL of the shared calendar
         returnValue(response)
@@ -589,7 +589,6 @@
             elif self.isAddressBookCollection():
                 shareeHomeResource = yield sharee.addressBookHome(request)
             yield shareeHomeResource.removeShareByUID(request, invitation.uid())
-    
             # If current user state is accepted then we send an invite with the new state, otherwise
             # we cancel any existing invites for the user
             if invitation and invitation.state() != "ACCEPTED":
@@ -597,7 +596,7 @@
             elif invitation:
                 yield self.sendInviteNotification(invitation, request, notificationState="DELETED")
         
-        # use new API
+        # Direct shares for  with valid sharee principal will already be deleted
         yield self._newStoreObject.unshareWith(invitation._shareeHomeChild._home)
     
         returnValue(True)            
@@ -1143,10 +1142,6 @@
 
             self._allShares = dict([(share.name(), share) for share in shares])
             
-            print ("allShares: GENERATED %d records, refresh=%s" % (len(self._allShares), refresh))
-        else:
-            print ("allShares: RETURNING %d records" % (len(self._allShares),))
-            
         returnValue(self._allShares)
 
 
@@ -1282,11 +1277,13 @@
                 inbox = (yield request.locateResource(inboxURL))
                 inbox.processFreeBusyCalendar(shareURL, False)
 
-        yield self.sharesDB().removeRecordForShareUID(share.uid())
- 
-        # Notify client of changes
-        yield self.notifyChanged()
+        
+        if share.direct():
+            yield share._sharerHomeChild.unshareWith(share._shareeHomeChild._home)
+        else:
+            yield share._sharerHomeChild.updateShare(share._shareeHomeChild, status=_BIND_STATUS_DECLINED )
 
+
     @inlineCallbacks
     def declineShare(self, request, hostUrl, inviteUID):
 
@@ -1410,10 +1407,14 @@
         self._sharerHomeChild = sharerHomeChild
         self._sharedResourceURL = url
         
+    @classmethod
+    def directUID(cls, shareeHome, sharerHomeChild):
+        return "Direct-%s-%s" % (shareeHome._resourceID, sharerHomeChild._resourceID,)
+        
     def uid(self):
         # Move to CommonHomeChild shareUID?
         if self._shareeHomeChild.shareMode() == _BIND_MODE_DIRECT:
-            return "Direct-%s-%s" % (self._shareeHomeChild._home._resourceID, self._sharerHomeChild._resourceID,)
+            return self.directUID(shareeHome=self._shareeHomeChild._home, sharerHomeChild=self._sharerHomeChild,)
         else:
             return self._shareeHomeChild.shareUID()
     

Modified: CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/test/test_sharing.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/test/test_sharing.py	2012-08-02 23:20:09 UTC (rev 9519)
+++ CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/test/test_sharing.py	2012-08-03 16:43:06 UTC (rev 9520)
@@ -569,7 +569,16 @@
             def __init__(self):
                 self.sharetype = SHARETYPE_DIRECT
                 self.hosturl = "/wikifoo"
+            
+            def shareType(self):
+                return self.shareType
 
+            def hostURL(self):
+                return self.hosturl
+
+            def uid(self):
+                return "012345"
+
         class TestCollection(SharedCollectionMixin, StubCollection):
             pass
 

Modified: CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py	2012-08-02 23:20:09 UTC (rev 9519)
+++ CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py	2012-08-03 16:43:06 UTC (rev 9520)
@@ -56,7 +56,8 @@
 
 from txdav.common.datastore.sql_tables import schema
 from txdav.common.datastore.sql_tables import _BIND_MODE_OWN, \
-    _BIND_MODE_DIRECT, _BIND_STATUS_ACCEPTED, NOTIFICATION_OBJECT_REVISIONS_TABLE
+    _BIND_MODE_DIRECT, _BIND_STATUS_ACCEPTED, _BIND_STATUS_DECLINED, \
+    NOTIFICATION_OBJECT_REVISIONS_TABLE
 from txdav.common.icommondatastore import HomeChildNameNotAllowedError, \
     HomeChildNameAlreadyExistsError, NoSuchHomeChildError, \
     ObjectResourceNameNotAllowedError, ObjectResourceNameAlreadyExistsError, \
@@ -2146,8 +2147,7 @@
         @type message: L{str}
 
         @return: the name of the shared item in the sharee's home.
-        @rtype: L{str}
-        @return: L{Deferred}
+        @rtype: a L{Deferred} which fires with a L{str}
         """
         # TODO: raise a nice exception if shareeView is not, in fact, a shared
         # version of this same L{CommonHomeChild}
@@ -2162,7 +2162,6 @@
                                 
         if len(columnMap):
 
-            # yield self.shareWith(shared._home, mode, status, message)
             dn = PropertyName.fromElement(DisplayName)
             dnprop = (self.properties().get(dn) or
                       DisplayName.fromString(self.name()))
@@ -2182,11 +2181,15 @@
             #update affected attributes
             if mode:
                 shareeView._bindMode = columnMap[bind.BIND_MODE]
+                
             if status:
                 shareeView._bindStatus = columnMap[bind.BIND_STATUS]
                 #TODO: Is is OK to always call _initSyncToken ?
                 if shareeView._bindStatus == _BIND_STATUS_ACCEPTED:
                     yield shareeView._initSyncToken()
+                elif shareeView._bindStatus == _BIND_STATUS_DECLINED:
+                    shareeView._deletedSyncToken(sharedRemoval=True);
+
             if message:
                 shareeView._bindMessage = columnMap[bind.MESSAGE]
             
@@ -2210,6 +2213,14 @@
         @return: a L{Deferred} which will fire with the previously-used name.
         """
         
+        
+        #remove sync tokens
+        shareeChildren = yield shareeHome.children()
+        for shareeChild in shareeChildren:
+            if not shareeChild.owned() and shareeChild._resourceID == self._resourceID:
+                shareeChild._deletedSyncToken(sharedRemoval=True);
+                break;
+
         # first delete the invite table row
         inv = schema.INVITE
         yield Delete(
@@ -2221,15 +2232,19 @@
         
         #now delete the bind table row
         bind = self._bindSchema
-        resourceName = (yield Delete(
+        rows = yield Delete(
             From=bind,
             Where=(bind.RESOURCE_ID == Parameter("resourceID"))
                   .And(bind.HOME_RESOURCE_ID == Parameter("homeID")),
             Return=bind.RESOURCE_NAME,
         ).on(self._txn, resourceID=self._resourceID,
-             homeID=shareeHome._resourceID))[0][0]
-        shareeHome._children.pop(resourceName, None)
+             homeID=shareeHome._resourceID)
         
+        resourceName = None
+        if rows:
+            resourceName = rows[0][0]
+            shareeHome._children.pop(resourceName, None)
+        
         # Must send notification to ensure cache invalidation occurs
         yield self.notifyChanged()
        
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120803/1e264feb/attachment-0001.html>


More information about the calendarserver-changes mailing list