[CalendarServer-changes] [10818] CalendarServer/branches/users/gaya/sharedgroups

source_changes at macosforge.org source_changes at macosforge.org
Tue Feb 26 16:28:42 PST 2013


Revision: 10818
          http://trac.calendarserver.org//changeset/10818
Author:   gaya at apple.com
Date:     2013-02-26 16:28:42 -0800 (Tue, 26 Feb 2013)
Log Message:
-----------
More fixes.

Modified Paths:
--------------
    CalendarServer/branches/users/gaya/sharedgroups/twistedcaldav/sharing.py
    CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/sql.py

Modified: CalendarServer/branches/users/gaya/sharedgroups/twistedcaldav/sharing.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups/twistedcaldav/sharing.py	2013-02-26 22:10:58 UTC (rev 10817)
+++ CalendarServer/branches/users/gaya/sharedgroups/twistedcaldav/sharing.py	2013-02-27 00:28:42 UTC (rev 10818)
@@ -687,6 +687,7 @@
         # Remove any shared calendar or address book
         sharee = self.principalForUID(invitation.shareeUID())
         if sharee:
+            previousInvitationState = invitation.state()
             if self.isCalendarCollection():
                 shareeHomeResource = yield sharee.calendarHome(request)
                 displayName = yield shareeHomeResource.removeShareByUID(request, invitation.uid())
@@ -696,9 +697,9 @@
                 displayName = None
             # 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":
+            if previousInvitationState != "ACCEPTED":
                 yield self.removeInviteNotification(invitation, request)
-            elif invitation:
+            else:
                 yield self.sendInviteNotification(invitation, request, displayName=displayName, notificationState="DELETED")
 
         # Direct shares for  with valid sharee principal will already be deleted
@@ -1320,10 +1321,12 @@
         Remove a shared collection but do not send a decline back. Return the
         current display name of the shared collection.
         """
+        #FIXME: This is only works for calendar
         shareURL = joinURL(self.url(), share.name())
         shared = (yield request.locateResource(shareURL))
         displayname = shared.displayName()
 
+        #FIXME: remove if not needed
         if self.isCalendarCollection():
             # For backwards compatibility we need to sync this up with the calendar-free-busy-set on the inbox
             principal = (yield self.resourceOwnerPrincipal(request))

Modified: CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/sql.py	2013-02-26 22:10:58 UTC (rev 10817)
+++ CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/sql.py	2013-02-27 00:28:42 UTC (rev 10818)
@@ -551,7 +551,7 @@
         for groupBindRow in groupBindRows:
             bindMode, homeID, resourceID, bindName, bindStatus, bindMessage = groupBindRow[:6] #@UnusedVariable        
             ownerAddressBookID = yield AddressBookObject.ownerAddressBookFromGroupID(home._txn, resourceID)
-            ownerHome = yield home.ownerHomeIDFromChildID(home._txn, ownerAddressBookID)
+            ownerHome = yield home.ownerHomeWithChildID(home._txn, ownerAddressBookID)
             ownerHomeID = ownerHome._resourceID
             if ownerHomeID not in ownerHomeIDToDataRowMap:
                 groupBindRow[0] = _BIND_MODE_WRITE
@@ -560,56 +560,52 @@
                 groupBindRow[5] = None # bindMessage
                 ownerHomeIDToDataRowMap[ownerHomeID] = groupBindRow
 
+        # Get property stores for all these child resources (if any found)
+        propertyStores = (yield PropertyStore.forMultipleResources(
+            home.uid(), home._txn,
+            cls._bindSchema.RESOURCE_ID, cls._bindSchema.HOME_RESOURCE_ID,
+            home._resourceID
+        ))
+        revisions = yield cls._revisionsForHomeID.on(home._txn, homeID=home._resourceID)
+        revisions = dict(revisions)
 
-        if ownerHomeIDToDataRowMap:
+        # Create the actual objects merging in properties
+        for dataRow in ownerHomeIDToDataRowMap.values():
+            bindMode, homeID, resourceID, bindName, bindStatus, bindMessage = dataRow[:6] #@UnusedVariable
+            metadata = dataRow[6:]
 
-            # Get property stores for all these child resources (if any found)
-            propertyStores = (yield PropertyStore.forMultipleResources(
-                home.uid(), home._txn,
-                cls._bindSchema.RESOURCE_ID, cls._bindSchema.HOME_RESOURCE_ID,
-                home._resourceID
-            ))
+            if bindStatus == _BIND_MODE_OWN:
+                child = cls(
+                    home=home,
+                    name=bindName, resourceID=resourceID,
+                    mode=bindMode, status=bindStatus,
+                    message=bindMessage,
+                )
+            else:
+                ownerHome = yield home.ownerHomeWithChildID(resourceID)
+                ownerAddressBook = yield ownerHome.addressbook()
 
-            revisions = yield cls._revisionsForHomeID.on(home._txn, homeID=home._resourceID)
-            revisions = dict(revisions)
+                child = cls(
+                    home=home,
+                    name=ownerAddressBook.shareeABName(), resourceID=ownerAddressBook._resourceID,
+                    mode=bindMode, status=bindStatus,
+                    message=bindMessage, ownerHome=ownerHome,
+                    bindName=bindName
+                )
 
-            # Create the actual objects merging in properties
-            for dataRow in ownerHomeIDToDataRowMap.values():
-                bindMode, homeID, resourceID, bindName, bindStatus, bindMessage = dataRow[:6] #@UnusedVariable
-                metadata = dataRow[6:]
+            for attr, value in zip(cls.metadataAttributes(), metadata):
+                setattr(child, attr, value)
+            #FIXME
+            child._syncTokenRevision = revisions[resourceID]
+            propstore = propertyStores.get(resourceID, None)
 
-                if bindStatus == _BIND_MODE_OWN:
-                    child = cls(
-                        home=home,
-                        name=bindName, resourceID=resourceID,
-                        mode=bindMode, status=bindStatus,
-                        message=bindMessage,
-                    )
-                else:
-                    ownerHome = yield home.ownerHomeWithChildID(resourceID)
-                    ownerAddressBook = yield ownerHome.addressbook()
+            # We have to re-adjust the property store object to account for possible shared
+            # collections as previously we loaded them all as if they were owned
+            if bindStatus != _BIND_MODE_OWN:
+                propstore._setDefaultUserUID(ownerHome.uid())
+            yield child._loadPropertyStore(propstore)
+            results.append(child)
 
-                    child = cls(
-                        home=home,
-                        name=ownerAddressBook.shareeABName(), resourceID=ownerAddressBook._resourceID,
-                        mode=bindMode, status=bindStatus,
-                        message=bindMessage, ownerHome=ownerHome,
-                        bindName=bindName
-                    )
-
-                for attr, value in zip(cls.metadataAttributes(), metadata):
-                    setattr(child, attr, value)
-                #FIXME
-                child._syncTokenRevision = revisions[resourceID]
-                propstore = propertyStores.get(resourceID, None)
-
-                # We have to re-adjust the property store object to account for possible shared
-                # collections as previously we loaded them all as if they were owned
-                if bindStatus != _BIND_MODE_OWN:
-                    propstore._setDefaultUserUID(ownerHome.uid())
-                yield child._loadPropertyStore(propstore)
-                results.append(child)
-
         returnValue(results)
 
 
@@ -660,7 +656,7 @@
                 )
                 if rows:
                     rows[0].append(ownerAddressBook._resourceID)
-                    rows[0].append(rows[4]) # cachedStatus = bindStatus
+                    rows[0].append(rows[0][4]) # cachedStatus = bindStatus
                 else:
                     groupBindRows = yield AddressBookObject._bindWithHomeIDAndAddressBookID.on(
                             home._txn, homeID=home._resourceID, addressbookID=ownerAddressBook._resourceID
@@ -769,7 +765,7 @@
         )
         if bindRows:
             bindMode, homeID, resourceID, bindName, bindStatus, bindMessage = bindRows[0] #@UnusedVariable
-            ownerHome = yield home.ownerHomeIDFromChildID(resourceID)
+            ownerHome = yield home.ownerHomeWithChildID(resourceID)
             ownerAddressBook = yield ownerHome.addressbook()
             if bindStatus == _BIND_STATUS_ACCEPTED:
                 returnValue((yield home.childWithName(ownerAddressBook.shareeABName())))
@@ -2011,6 +2007,7 @@
 
 
     @inlineCallbacks
+    #TODO:  This is almost the same as AddressBook.updateShare(): combine
     def updateShare(self, shareeView, mode=None, status=None, message=None, name=None):
         """
         Update share mode, status, and message for a home child shared with
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130226/b34ae604/attachment-0001.html>


More information about the calendarserver-changes mailing list