[CalendarServer-changes] [10964] CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/ datastore/sql.py
source_changes at macosforge.org
source_changes at macosforge.org
Fri Mar 22 10:05:06 PDT 2013
Revision: 10964
http://trac.calendarserver.org//changeset/10964
Author: gaya at apple.com
Date: 2013-03-22 10:05:05 -0700 (Fri, 22 Mar 2013)
Log Message:
-----------
fix AddressBook.listObjectResources(), AddressBook.countObjectResources()
Modified Paths:
--------------
CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/sql.py
Modified: CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/sql.py 2013-03-21 22:21:13 UTC (rev 10963)
+++ CalendarServer/branches/users/gaya/sharedgroups/txdav/carddav/datastore/sql.py 2013-03-22 17:05:05 UTC (rev 10964)
@@ -478,29 +478,57 @@
raise HTTPError(FORBIDDEN)
+ @classmethod
+ def _objectResourceNamesWithResourceIDsQuery(cls, resourceIDs):
+ """
+ DAL statement to retrieve addressbook object name with given resourceIDs
+ """
+ obj = cls._objectSchema
+ return Select([obj.RESOURCE_NAME], From=obj,
+ Where=obj.RESOURCE_ID.In(Parameter("resourceIDs", len(resourceIDs))),)
+
+
@inlineCallbacks
def listObjectResources(self):
+ if self._objectNames is None:
+ if self.owned() or self.fullyShared():
+ rows = yield self._objectResourceNamesQuery.on(
+ self._txn, resourceID=self._resourceID)
+ else:
+ acceptedGroupIDs = yield self.acceptedGroupIDs()
+ allowedObjectIDs = yield self.expandGroupIDs(self._txn, acceptedGroupIDs)
+ rows = (yield self._objectResourceNamesWithResourceIDsQuery(allowedObjectIDs).on(
+ self._txn, resourceIDs=allowedObjectIDs
+ ))
+ objectNames = [row[0] for row in rows]
- result = yield super(AddressBook, self).listObjectResources()
- if not self.owned() and not self.fullyShared():
- groupForSharedAB = yield self._groupForEntireAB_Name()
- if not groupForSharedAB in result:
- result.append(groupForSharedAB)
- returnValue(result)
+ # account for fully-shared address book group
+ if self.fullyShared():
+ groupForSharedAB = yield self._groupForEntireAB_Name()
+ if not groupForSharedAB in objectNames:
+ objectNames.append(groupForSharedAB)
+ self._objectNames = sorted(objectNames)
+ returnValue(self._objectNames)
+
@inlineCallbacks
def countObjectResources(self):
if self._objectNames is None:
- rows = yield self._objectCountQuery.on(
- self._txn, resourceID=self._resourceID
- )
- count = rows[0][0]
+ if self.owned() or self.fullyShared():
+ rows = yield self._objectCountQuery.on(
+ self._txn, resourceID=self._resourceID
+ )
+ count = rows[0][0]
+ else:
+ acceptedGroupIDs = yield self.acceptedGroupIDs()
+ count = len((yield self.expandGroupIDs(self._txn, acceptedGroupIDs)))
- #add in group for shared address book
- if not self.owned() and not self.fullyShared():
+ # account for fully-shared address book group
+ if self.fullyShared():
count += 1
returnValue(count)
+
returnValue(len(self._objectNames))
@@ -883,7 +911,6 @@
home._txn, homeID=home._resourceID
)))
for bindMode, homeID, resourceID, bindName, bindStatus, bindMessage in rows: #@UnusedVariable
- assert bindMode != _BIND_MODE_OWN
ownerHome = yield home._txn.homeWithResourceID(home._homeType, homeID)
names |= set([ownerHome.shareeAddressBookName()])
returnValue(tuple(names))
@@ -1247,6 +1274,9 @@
super(AddressBookObject, self).__init__(addressbook, name, uid, resourceID)
+ def __repr__(self):
+ return '<%s: %s("%s")>' % (self.__class__.__name__, self._resourceID, self.name())
+
@property
def _addressbook(self):
return self._parentCollection
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130322/304aa9eb/attachment-0001.html>
More information about the calendarserver-changes
mailing list