[CalendarServer-changes] [11668] CalendarServer/branches/users/gaya/sharedgroupfixes/txdav

source_changes at macosforge.org source_changes at macosforge.org
Wed Sep 11 11:47:57 PDT 2013


Revision: 11668
          http://trac.calendarserver.org//changeset/11668
Author:   gaya at apple.com
Date:     2013-09-11 11:47:57 -0700 (Wed, 11 Sep 2013)
Log Message:
-----------
roll in fixes from sharedgroupfixes2 branch

Modified Paths:
--------------
    CalendarServer/branches/users/gaya/sharedgroupfixes/txdav/carddav/datastore/sql.py
    CalendarServer/branches/users/gaya/sharedgroupfixes/txdav/common/datastore/sql.py

Modified: CalendarServer/branches/users/gaya/sharedgroupfixes/txdav/carddav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroupfixes/txdav/carddav/datastore/sql.py	2013-09-11 17:36:20 UTC (rev 11667)
+++ CalendarServer/branches/users/gaya/sharedgroupfixes/txdav/carddav/datastore/sql.py	2013-09-11 18:47:57 UTC (rev 11668)
@@ -542,7 +542,7 @@
         ).on(self._txn)
         groupIDToChangedMemberIDMap = {}
         for groupID, memberID, removed in memberRows:
-            if groupIDToChangedMemberIDMap.get(groupID) is None:
+            if groupID not in groupIDToChangedMemberIDMap:
                 groupIDToChangedMemberIDMap[groupID] = set()
             groupIDToChangedMemberIDMap[groupID].add(memberID)
         print("sharedChildResourceNamesSinceRevision:%s memberRows:%s groupIDToChangedMemberIDMap=%s" % (self, memberRows, groupIDToChangedMemberIDMap,))
@@ -975,7 +975,7 @@
             # Retrieve data from cache
             cacheKey = queryCacher.keyForObjectWithName(home._resourceID, name)
             cachedRows = yield queryCacher.get(cacheKey)
-            if cachedRows and (cachedRows[0][4] == _BIND_STATUS_ACCEPTED) == bool(accepted):
+            if cachedRows and (cachedRows[0][8] == _BIND_STATUS_ACCEPTED) == bool(accepted): #cachedRows[0][8] == cachedBindStatus
                 rows = cachedRows
 
         if not rows:
@@ -999,14 +999,18 @@
                     matchingGroupBindRows = [groupBindRow for groupBindRow in groupBindRows if (groupBindRow[4] == _BIND_STATUS_ACCEPTED) == bool(accepted)]
                     if matchingGroupBindRows:
                         groupBindRows = matchingGroupBindRows
+                    elif bindRows:
+                        bindRows[0].insert(cls.bindColumnCount, ownerAddressBook._resourceID)
+                        bindRows[0].insert(cls.bindColumnCount + 1, bindRows[0][4])  # cachedStatus = bindStatus
+                        rows = bindRows
 
-                    for groupBindRow in groupBindRows:
+                    if not rows and groupBindRows:
+                        groupBindRow = groupBindRows[0]
                         groupBindRow.insert(AddressBookObject.bindColumnCount, ownerAddressBook._resourceID)
                         groupBindRow.insert(AddressBookObject.bindColumnCount + 1, groupBindRow[4])
                         groupBindRow[0] = _BIND_MODE_WRITE
                         groupBindRow[3:7] = 4 * [None]  # bindName, bindStatus, bindRevision, bindMessage
                         rows = [groupBindRow]
-                        break
 
             if rows and queryCacher:
                 # Cache the result
@@ -1051,8 +1055,7 @@
         """
         bindRows = yield cls._bindForNameAndHomeID.on(home._txn, name=name, homeID=home._resourceID)
         if bindRows and (bindRows[0][4] == _BIND_STATUS_ACCEPTED) == bool(accepted):
-            bindRow = bindRows[0]
-            bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = bindRow[:cls.bindColumnCount] #@UnusedVariable
+            resourceID = bindRows[0][2]
 
             # alt:
             # returnValue((yield cls.objectWithID(home, resourceID)))
@@ -1066,8 +1069,7 @@
             home._txn, name=name, homeID=home._resourceID
         )
         if groupBindRows and (groupBindRows[0][4] == _BIND_STATUS_ACCEPTED) == bool(accepted):
-            groupBindRow = groupBindRows[0]
-            bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = groupBindRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
+            resourceID = groupBindRows[0][2]
 
             ownerAddressBookID = yield AddressBookObject.ownerAddressBookIDFromGroupID(home._txn, resourceID)
             # alt:
@@ -1105,8 +1107,7 @@
             home._txn, resourceID=resourceID, homeID=home._resourceID
         )
         if bindRows and (bindRows[0][4] == _BIND_STATUS_ACCEPTED) == bool(accepted):
-            bindRow = bindRows[0]
-            bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = bindRow[:cls.bindColumnCount] #@UnusedVariable
+            resourceID = bindRows[0][2]
 
             ownerHome = yield home.ownerHomeWithChildID(resourceID)
             if accepted:
@@ -1118,8 +1119,7 @@
                     home._txn, homeID=home._resourceID, addressbookID=resourceID
         )
         if groupBindRows and (groupBindRows[0][4] == _BIND_STATUS_ACCEPTED) == bool(accepted):
-            groupBindRow = groupBindRows[0]
-            bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = groupBindRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
+            resourceID = groupBindRows[0][2]
 
             ownerAddressBookID = yield AddressBookObject.ownerAddressBookIDFromGroupID(home._txn, resourceID)
             ownerHome = yield home.ownerHomeWithChildID(ownerAddressBookID)
@@ -1156,7 +1156,7 @@
             home._txn, homeID=home._resourceID
         )
         for row in rows:
-            bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = row[:cls.bindColumnCount] #@UnusedVariable
+            resourceID = row[2]
             ownerHome = yield home._txn.homeWithResourceID(home._homeType, resourceID, create=True)
             names.add(ownerHome.shareeAddressBookName())
 
@@ -1164,7 +1164,7 @@
             home._txn, homeID=home._resourceID
         )
         for groupRow in groupRows:
-            bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = groupRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
+            resourceID = groupRow[2]
             ownerAddressBookID = yield AddressBookObject.ownerAddressBookIDFromGroupID(home._txn, resourceID)
             ownerHome = yield home._txn.homeWithResourceID(home._homeType, ownerAddressBookID, create=True)
             names.add(ownerHome.shareeAddressBookName())
@@ -1347,15 +1347,18 @@
 
         # remove None parameters, and substitute None for empty string
         bind = self._bindSchema
-        columnMap = dict([(k, v if v != "" else None)
-                          for k, v in {bind.BIND_MODE:mode,
-                            bind.BIND_STATUS:status,
-                            bind.MESSAGE:message}.iteritems() if v is not None])
+        columnMap = {}
+        if mode != None and mode != shareeView._bindMode:
+            columnMap[bind.BIND_MODE] = mode
+        if status != None and status != shareeView._bindStatus:
+            columnMap[bind.BIND_STATUS] = status
+        if message != None and message != shareeView._bindMessage:
+            columnMap[bind.MESSAGE] = message
 
-        if len(columnMap):
+        if columnMap:
 
             # count accepted
-            if status is not None:
+            if bind.BIND_STATUS in columnMap:
                 previouslyAcceptedBindCount = 1 if shareeView.fullyShared() else 0
                 previouslyAcceptedBindCount += len((yield AddressBookObject._acceptedBindForHomeIDAndAddressBookID.on(
                         self._txn, homeID=shareeView.viewerHome()._resourceID, addressbookID=shareeView._resourceID
@@ -1368,10 +1371,10 @@
             )
 
             # update affected attributes
-            if mode is not None:
+            if bind.BIND_MODE in columnMap:
                 shareeView._bindMode = columnMap[bind.BIND_MODE]
 
-            if status is not None:
+            if bind.BIND_STATUS in columnMap:
                 shareeView._bindStatus = columnMap[bind.BIND_STATUS]
                 if shareeView._bindStatus == _BIND_STATUS_ACCEPTED:
                     if 0 == previouslyAcceptedBindCount:
@@ -1385,7 +1388,7 @@
                         shareeView.viewerHome()._children.pop(self.shareeName(), None)
                         shareeView.viewerHome()._children.pop(shareeView._resourceID, None)
 
-            if message is not None:
+            if bind.MESSAGE in columnMap:
                 shareeView._bindMessage = columnMap[bind.MESSAGE]
 
             queryCacher = self._txn._queryCacher
@@ -1954,7 +1957,7 @@
 
         self._componentChanged = False
 
-        if self._options.get("coaddedUIDs") is None:
+        if "coaddedUIDs" not in self._options:
             # Handle all validation operations here.
             self.fullValidation(component, inserting)
 
@@ -2120,7 +2123,7 @@
             if not self.owned() and not self.addressbook().fullyShared():
                 # in partially shared addressbook, all members UIDs must be inside the shared groups
                 # except during bulk operations, when other UIDs added are OK
-                coaddedUIDs = set() if self._options.get("coaddedUIDs") is None else self._options["coaddedUIDs"]
+                coaddedUIDs = self._options.get("coaddedUIDs", set())
                 if missingUIDs - coaddedUIDs:
                     raise GroupWithUnsharedAddressNotAllowedError(missingUIDs)
 
@@ -2255,24 +2258,6 @@
                     revision=self._syncTokenRevision,
                )
 
-            if memberIDsToAdd or memberIDsToRemove:
-                # get expanded remove
-                memberIDsToAddRemoved = yield AddressBook.expandGroupIDs(self.txn, memberIDsToAdd | memberIDsToRemove, includeGroupIDs=False)
-                if memberIDsToAddRemoved:
-                    print("updateDatabase:%s _insertMemberIDQuery:revision=%s groupID=%s memberIDsToAddRemoved=%s" % (self, self._syncTokenRevision, self._resourceID, memberIDsToAddRemoved,))
-                for memberIDToAddRemoved in memberIDsToAddRemoved:
-                    aboMembers = schema.ABO_MEMBERS
-                    return Insert(
-                        {aboMembers.GROUP_ID: self._resourceID,
-                         aboMembers.ADDRESSBOOK_ID: self._ownerAddressBookResourceID,
-                         aboMembers.MEMBER_ID: memberIDToAddRemoved,
-                         aboMembers.REVISION: self._syncTokenRevision,
-                         aboMembers.REMOVED: True,
-                        }
-                )
-
-
-
             # don't bother with aboForeignMembers on address books
             if self._resourceID != self._ownerAddressBookResourceID:
 
@@ -2650,6 +2635,11 @@
 
 
     @inlineCallbacks
+    def syncToken(self):
+        returnValue((yield self.addressbook().syncToken()))
+
+
+    @inlineCallbacks
     def updateShare(self, shareeView, mode=None, status=None, message=None):
         """
         Update share mode, status, and message for a home child shared with
@@ -2679,15 +2669,18 @@
 
         # remove None parameters, and substitute None for empty string
         bind = self._bindSchema
-        columnMap = dict([(k, v if v != "" else None)
-                          for k, v in {bind.BIND_MODE:mode,
-                            bind.BIND_STATUS:status,
-                            bind.MESSAGE:message}.iteritems() if v is not None])
+        columnMap = {}
+        if mode != None and mode != shareeView._bindMode:
+            columnMap[bind.BIND_MODE] = mode
+        if status != None and status != shareeView._bindStatus:
+            columnMap[bind.BIND_STATUS] = status
+        if message != None and message != shareeView._bindMessage:
+            columnMap[bind.MESSAGE] = message
 
-        if len(columnMap):
+        if columnMap:
 
             # count accepted
-            if status is not None:
+            if bind.BIND_STATUS in columnMap:
                 previouslyAcceptedBindCount = 1 if self.addressbook().fullyShared() else 0
                 previouslyAcceptedBindCount += len((
                     yield AddressBookObject._acceptedBindForHomeIDAndAddressBookID.on(
@@ -2702,10 +2695,10 @@
             )
 
             # update affected attributes
-            if mode is not None:
+            if bind.BIND_MODE in columnMap:
                 shareeView._bindMode = columnMap[bind.BIND_MODE]
 
-            if status is not None:
+            if bind.BIND_STATUS in columnMap:
                 shareeView._bindStatus = columnMap[bind.BIND_STATUS]
                 if shareeView._bindStatus == _BIND_STATUS_ACCEPTED:
                     if 0 == previouslyAcceptedBindCount:
@@ -2719,7 +2712,7 @@
                         shareeView.viewerHome()._children.pop(self.addressbook().shareeName(), None)
                         shareeView.viewerHome()._children.pop(shareeView._resourceID, None)
 
-            if message is not None:
+            if bind.MESSAGE in columnMap:
                 shareeView._bindMessage = columnMap[bind.MESSAGE]
 
             # safer to just invalidate in all cases rather than calculate when to invalidate

Modified: CalendarServer/branches/users/gaya/sharedgroupfixes/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroupfixes/txdav/common/datastore/sql.py	2013-09-11 17:36:20 UTC (rev 11667)
+++ CalendarServer/branches/users/gaya/sharedgroupfixes/txdav/common/datastore/sql.py	2013-09-11 18:47:57 UTC (rev 11668)
@@ -1905,7 +1905,6 @@
         @type depth: C{str}
         """
 
-        print("CommonHome: resourceNamesSinceRevision:%s revision:%s, depth:%s" % (self, revision, depth))
         results = [
             (
                 path if path else (collection if collection else ""),
@@ -2321,7 +2320,6 @@
         @type revision: C{int}
         """
 
-        print("_SharedSyncLogic: resourceNamesSinceRevision:%s revision:%s" % (self, revision,))
         results = [
             (name if name else "", deleted)
             for name, deleted in
@@ -2909,9 +2907,10 @@
         # Look up the shared child - might be accepted or not. If accepted use the resource name
         # to look it up, else use the invitation uid (bind name)
         shareeHome = yield self._txn.homeWithUID(self._home._homeType, invitation.shareeUID())
-        shareeView = yield shareeHome.childWithName(invitation.resourceName())
+        shareeView = yield shareeHome.objectWithShareUID(invitation.uid())
         if shareeView is None:
             shareeView = yield shareeHome.invitedObjectWithShareUID(invitation.uid())
+            assert shareeView
 
         result = yield self.updateShare(shareeView, mode, status, message)
         returnValue(result)
@@ -2947,12 +2946,15 @@
 
         #remove None parameters, and substitute None for empty string
         bind = self._bindSchema
-        columnMap = dict([(k, v if v != "" else None)
-                          for k, v in {bind.BIND_MODE:mode,
-                            bind.BIND_STATUS:status,
-                            bind.MESSAGE:message}.iteritems() if v is not None])
+        columnMap = {}
+        if mode != None and mode != shareeView._bindMode:
+            columnMap[bind.BIND_MODE] = mode
+        if status != None and status != shareeView._bindStatus:
+            columnMap[bind.BIND_STATUS] = status
+        if message != None and message != shareeView._bindMessage:
+            columnMap[bind.MESSAGE] = message
 
-        if len(columnMap):
+        if columnMap:
 
             sharedname = yield self._updateBindColumnsQuery(columnMap).on(
                             self._txn,
@@ -2960,10 +2962,10 @@
                         )
 
             #update affected attributes
-            if mode is not None:
+            if bind.BIND_MODE in columnMap:
                 shareeView._bindMode = columnMap[bind.BIND_MODE]
 
-            if status is not None:
+            if bind.BIND_STATUS in columnMap:
                 shareeView._bindStatus = columnMap[bind.BIND_STATUS]
                 if shareeView._bindStatus == _BIND_STATUS_ACCEPTED:
                     yield shareeView._initSyncToken()
@@ -2975,7 +2977,7 @@
                     shareeView._home._children.pop(shareeView._name, None)
                     shareeView._home._children.pop(shareeView._resourceID, None)
 
-            if message is not None:
+            if bind.MESSAGE in columnMap:
                 shareeView._bindMessage = columnMap[bind.MESSAGE]
 
             queryCacher = self._txn._queryCacher
@@ -3099,6 +3101,7 @@
 
     @inlineCallbacks
     def _initBindRevision(self):
+        yield self.syncToken()
         self._bindRevision = self._syncTokenRevision
 
         bind = self._bindSchema
@@ -4109,7 +4112,6 @@
         @type revision: C{int}
         """
 
-        print("CommonHomeChild: resourceNamesSinceRevision:%s revision:%s" % (self, revision,))
         if revision < self._bindRevision:
             revision = 0
         return super(CommonHomeChild, self).resourceNamesSinceRevision(revision)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130911/5e53f277/attachment-0001.html>


More information about the calendarserver-changes mailing list