[CalendarServer-changes] [11179] CalendarServer/branches/users/gaya/sharedgroups-3/txdav/carddav/ datastore/sql.py

source_changes at macosforge.org source_changes at macosforge.org
Tue May 14 13:38:48 PDT 2013


Revision: 11179
          http://trac.calendarserver.org//changeset/11179
Author:   gaya at apple.com
Date:     2013-05-14 13:38:48 -0700 (Tue, 14 May 2013)
Log Message:
-----------
add hack to fix isShared()

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

Modified: CalendarServer/branches/users/gaya/sharedgroups-3/txdav/carddav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups-3/txdav/carddav/datastore/sql.py	2013-05-14 19:14:32 UTC (rev 11178)
+++ CalendarServer/branches/users/gaya/sharedgroups-3/txdav/carddav/datastore/sql.py	2013-05-14 20:38:48 UTC (rev 11179)
@@ -372,6 +372,20 @@
     def __repr__(self):
         return '<%s: %s("%s")>' % (self.__class__.__name__, self._resourceID, self.name())
 
+    @inlineCallbacks
+    def _init_isShared(self):
+        """
+            Temporary hack to set isShared on the owner addressbook
+            1) This is not up to spec because an addressbook can be shared even without invitations
+            2) This should be setup in AddressBookHome.initFromStore, but calling asShared() from there creates a loop
+            3) It would be a better hack to change self.addressbook() to a deferred. But his is sufficient for now.
+        """
+        if not hasattr(self, "_isShared_inited"):
+            isShared = bool((yield self.asShared())) or bool((yield self.asInvited()))
+            yield self.setShared(isShared)
+            self._isShared_inited = True
+        else:
+            yield None
 
     def getCreated(self):
         return self.ownerHome()._created
@@ -641,7 +655,9 @@
         operations to keep this constant wrt the number of children.  This is an
         optimization for Depth:1 operations on the home.
         """
-        results = [home.addressbook(), ]
+        addressbook = home.addressbook()
+        yield addressbook._init_isShared()
+        results = [addressbook]
         ownerHomeToDataRowMap = {}
 
         # Load from the main table first
@@ -721,7 +737,9 @@
             exists.
         """
         if accepted and name == home.addressbook().name():
-            returnValue(home.addressbook())
+            addressbook = home.addressbook()
+            yield addressbook._init_isShared()
+            returnValue(addressbook)
 
         #all shared address books now
         rows = None
@@ -851,7 +869,9 @@
             exists.
         """
         if home._resourceID == resourceID:
-            returnValue(home.addressbook())
+            addressbook = home.addressbook()
+            yield addressbook._init_isShared()
+            returnValue(addressbook)
 
         bindRows = yield cls._bindForResourceIDAndHomeID.on(
             home._txn, resourceID=resourceID, homeID=home._resourceID
@@ -1431,6 +1451,20 @@
 
 
     @inlineCallbacks
+    def _init_isShared(self):
+        """
+            Temporary hack to set isShared on the owner group
+            1) This is not up to spec because an group can be shared even without invitations
+        """
+        if not hasattr(self, "_isShared_inited"):
+            isShared = bool((yield self.asShared())) or bool((yield self.asInvited()))
+            yield self.setShared(isShared)
+            self._isShared_inited = True
+        else:
+            yield None
+
+
+    @inlineCallbacks
     def initFromStore(self):
         """
         Initialise this object from the store. We read in and cache all the
@@ -1513,6 +1547,9 @@
                     self._bindMessage = bindMessage
                     self._bindName = bindName
 
+                    if self.owned():
+                        yield self._init_isShared()
+
             yield self._loadPropertyStore()
 
             returnValue(self)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130514/abe02f1d/attachment-0001.html>


More information about the calendarserver-changes mailing list