[CalendarServer-changes] [8764] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Feb 24 10:42:03 PST 2012


Revision: 8764
          http://trac.macosforge.org/projects/calendarserver/changeset/8764
Author:   cdaboo at apple.com
Date:     2012-02-24 10:42:03 -0800 (Fri, 24 Feb 2012)
Log Message:
-----------
Oracle treats null's as valid values for a constraint and that causes problems when a sharee is invited to two or more
shares and has not accepted. Instead of using NULL to represent a share that has not yet been accepted in the bind table,
we now initialise the resource name to the invite uid (and later set a new uid when the acceptance is done). That will avoid
the constraint violation on the bind table.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/sharing.py
    CalendarServer/trunk/txdav/common/datastore/sql.py
    CalendarServer/trunk/txdav/common/datastore/sql_legacy.py

Modified: CalendarServer/trunk/twistedcaldav/sharing.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/sharing.py	2012-02-24 18:38:07 UTC (rev 8763)
+++ CalendarServer/trunk/twistedcaldav/sharing.py	2012-02-24 18:42:03 UTC (rev 8764)
@@ -1068,22 +1068,27 @@
     @inlineCallbacks
     def acceptInviteShare(self, request, hostUrl, inviteUID, displayname=None):
         
+        # Check for old share
+        oldShare = yield self.sharesDB().recordForShareUID(inviteUID)
+
         # Send the invite reply then add the link
         yield self._changeShare(request, "ACCEPTED", hostUrl, inviteUID, displayname)
 
-        response = (yield self._acceptShare(request, SHARETYPE_INVITE, hostUrl, inviteUID, displayname))
+        response = (yield self._acceptShare(request, oldShare, SHARETYPE_INVITE, hostUrl, inviteUID, displayname))
         returnValue(response)
 
+    @inlineCallbacks
     def acceptDirectShare(self, request, hostUrl, resourceUID, displayname=None):
 
         # Just add the link
-        return self._acceptShare(request, SHARETYPE_DIRECT, hostUrl, resourceUID, displayname)
+        oldShare = yield self.sharesDB().recordForShareUID(resourceUID)
+        response = (yield self._acceptShare(request, oldShare, SHARETYPE_DIRECT, hostUrl, resourceUID, displayname))
+        returnValue(response)
 
     @inlineCallbacks
-    def _acceptShare(self, request, sharetype, hostUrl, shareUID, displayname=None):
+    def _acceptShare(self, request, oldShare, sharetype, hostUrl, shareUID, displayname=None):
 
         # Add or update in DB
-        oldShare = yield self.sharesDB().recordForShareUID(shareUID)
         if oldShare:
             share = oldShare
         else:

Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py	2012-02-24 18:38:07 UTC (rev 8763)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py	2012-02-24 18:42:03 UTC (rev 8764)
@@ -1820,7 +1820,7 @@
                       Where=(bind.HOME_RESOURCE_ID ==
                              Parameter("resourceID")).And(
                                  bind.BIND_MODE != _BIND_MODE_OWN).And(
-                                 bind.RESOURCE_NAME != None))
+                                 bind.BIND_STATUS == _BIND_STATUS_ACCEPTED))
 
     @classmethod
     @inlineCallbacks
@@ -1850,7 +1850,7 @@
             ownedPiece = bind.BIND_MODE == _BIND_MODE_OWN
         else:
             ownedPiece = (bind.BIND_MODE != _BIND_MODE_OWN).And(
-                bind.RESOURCE_NAME != None)
+                bind.BIND_STATUS == _BIND_STATUS_ACCEPTED)
         
         columns = [child.RESOURCE_ID, bind.RESOURCE_NAME,]
         columns.extend(cls.metadataColumns())
@@ -1965,7 +1965,8 @@
         (C{homeID}).
         """
         return cls._homeChildLookup(
-            cls._bindSchema.BIND_MODE != _BIND_MODE_OWN)
+            (cls._bindSchema.BIND_MODE != _BIND_MODE_OWN).And(
+                cls._bindSchema.BIND_STATUS == _BIND_STATUS_ACCEPTED))
 
 
     @classmethod

Modified: CalendarServer/trunk/txdav/common/datastore/sql_legacy.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql_legacy.py	2012-02-24 18:38:07 UTC (rev 8763)
+++ CalendarServer/trunk/txdav/common/datastore/sql_legacy.py	2012-02-24 18:42:03 UTC (rev 8764)
@@ -310,10 +310,7 @@
                 bind.BIND_MODE: Parameter("mode"),
                 bind.BIND_STATUS: Parameter("status"),
                 bind.MESSAGE: Parameter("message"),
-
-                # name is NULL because the resource is not bound yet, just
-                # invited; let's be explicit about that.
-                bind.RESOURCE_NAME: None,
+                bind.RESOURCE_NAME: Parameter("resourceName"),
                 bind.SEEN_BY_OWNER: False,
                 bind.SEEN_BY_SHAREE: False,
             }
@@ -366,6 +363,7 @@
                 self._txn,
                 homeID=shareeHome._resourceID,
                 resourceID=self._collection._resourceID,
+                resourceName=record.inviteuid,
                 mode=bindMode,
                 status=bindStatus,
                 message=record.summary
@@ -492,7 +490,7 @@
             From=bind,
             Where=(bind.HOME_RESOURCE_ID == Parameter("homeID"))
             .And(bind.BIND_MODE != _BIND_MODE_OWN)
-            .And(bind.RESOURCE_NAME != None)
+            .And(bind.BIND_STATUS == _BIND_STATUS_ACCEPTED)
         )
 
 
@@ -654,7 +652,7 @@
     def _unbindShareQuery(cls): #@NoSelf
         bind = cls._bindSchema
         return Update({
-            bind.RESOURCE_NAME: None
+            bind.BIND_STATUS: _BIND_STATUS_DECLINED
         }, Where=(bind.RESOURCE_NAME == Parameter("name"))
         .And(bind.HOME_RESOURCE_ID == Parameter("homeID")))
 
@@ -678,7 +676,7 @@
         bind = cls._bindSchema
         inv = schema.INVITE
         return Update(
-            {bind.RESOURCE_NAME: None},
+            {bind.BIND_STATUS: _BIND_STATUS_DECLINED},
             Where=(bind.HOME_RESOURCE_ID, bind.RESOURCE_ID) ==
             Select([inv.HOME_RESOURCE_ID, inv.RESOURCE_ID],
                    From=inv, Where=inv.INVITE_UID == Parameter("uid")))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120224/1bb86af6/attachment.html>


More information about the calendarserver-changes mailing list