[CalendarServer-changes] [9495] CalendarServer/branches/users/gaya/inviteclean
source_changes at macosforge.org
source_changes at macosforge.org
Wed Jul 25 11:54:58 PDT 2012
Revision: 9495
http://trac.macosforge.org/projects/calendarserver/changeset/9495
Author: gaya at apple.com
Date: 2012-07-25 11:54:57 -0700 (Wed, 25 Jul 2012)
Log Message:
-----------
fix asShared() so it returns direct shares
Modified Paths:
--------------
CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/sharing.py
CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py
Modified: CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/sharing.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/sharing.py 2012-07-25 02:19:47 UTC (rev 9494)
+++ CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/sharing.py 2012-07-25 18:54:57 UTC (rev 9495)
@@ -32,7 +32,8 @@
from twext.web2.dav.util import allDataFromStream, joinURL
from txdav.common.datastore.sql_tables import _BIND_MODE_OWN, \
_BIND_MODE_READ, _BIND_MODE_WRITE, _BIND_STATUS_INVITED, \
- _BIND_STATUS_ACCEPTED, _BIND_STATUS_DECLINED, _BIND_STATUS_INVALID
+ _BIND_MODE_DIRECT, _BIND_STATUS_ACCEPTED, _BIND_STATUS_DECLINED, \
+ _BIND_STATUS_INVALID
from txdav.xml import element
from twisted.internet.defer import succeed, inlineCallbacks, DeferredList,\
@@ -534,17 +535,16 @@
"""
Get list of all invitations to this object
- For legacy reasons, all invitations are all invited + shared (accepted).
- Combine these two into a single sorted list, sorted for easy testing
+ For legacy reasons, all invitations are all invited + shared (accepted, not direct).
+ Combine these two into a single sorted list so code is similar to that for legacy invite db
"""
invitedHomeChildren = yield self._newStoreObject.asInvited()
if includeAccepted:
acceptedHomeChildren = yield self._newStoreObject.asShared()
- if invitedHomeChildren and acceptedHomeChildren:
- invitedHomeChildren += acceptedHomeChildren
- invitedHomeChildren = set(invitedHomeChildren)
- elif acceptedHomeChildren:
- invitedHomeChildren = acceptedHomeChildren
+ # remove direct shares (it might be OK not to filter, that would be different from legacy db code)
+ indirectAccceptedHomeChildren = [homeChild for homeChild in acceptedHomeChildren
+ if homeChild.shareMode() != _BIND_MODE_DIRECT]
+ invitedHomeChildren += indirectAccceptedHomeChildren
invitations = [Invitation(homeChild) for homeChild in invitedHomeChildren]
invitations.sort(key=lambda invitation:invitation.shareeUID())
Modified: CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py 2012-07-25 02:19:47 UTC (rev 9494)
+++ CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py 2012-07-25 18:54:57 UTC (rev 9495)
@@ -2268,7 +2268,7 @@
@classmethod
- def _bindEntriesFor(cls, condition): #@NoSelf
+ def _invitedBindFor(cls, condition): #@NoSelf
bind = cls._bindSchema
inv = schema.INVITE
return Select(
@@ -2288,18 +2288,55 @@
)
@classproperty
- def _sharedFor(cls): #@NoSelf
+ def _acceptedBindFor(cls): #@NoSelf
bind = cls._bindSchema
- return cls._bindEntriesFor(bind.BIND_STATUS == _BIND_STATUS_ACCEPTED)
+ return Select(
+ [bind.BIND_MODE,
+ bind.HOME_RESOURCE_ID,
+ bind.RESOURCE_NAME,
+ bind.BIND_STATUS,
+ bind.MESSAGE],
+ From=bind,
+ Where=((bind.BIND_STATUS == _BIND_STATUS_ACCEPTED)
+ .And(bind.RESOURCE_ID == Parameter("resourceID"))
+ .And(bind.BIND_MODE != _BIND_MODE_OWN)
+ )
+ )
+
+
+ @classproperty
+ def _invitedSharedFor(cls): #@NoSelf
+ bind = cls._bindSchema
+ return cls._invitedBindFor(bind.BIND_STATUS == _BIND_STATUS_ACCEPTED)
+
@inlineCallbacks
- def _asBound(self, query):
- rows = yield query.on(self._txn,
- resourceID=self._resourceID)
+ def asShared(self):
+ """
+ Retrieve all the versions of this L{CommonHomeChild} as it is shared to
+ everyone.
+ @see: L{ICalendarHome.asShared}
+
+ @return: L{CommonHomeChild} objects that represent this
+ L{CommonHomeChild} as a child of different L{CommonHome}s
+ @rtype: a L{Deferred} which fires with a L{list} of L{ICalendar}s.
+ """
+ # get all accepted binds, add inviteUID=None, and put in dict by home homeResourceID
+ acceptedRows = yield self._acceptedBindFor.on(self._txn, resourceID=self._resourceID)
+ acceptedRowDict = dict([(row[1], row + [None,]) for row in acceptedRows])
+
+ # get accepted binds with associated inviteUID, and put in dict by home homeResourceID
+ inviteRows = yield self._invitedSharedFor.on(self._txn, resourceID=self._resourceID)
+ inviteRowDict = dict([(row[1], row) for row in inviteRows])
+
+ # merge together homeResourceID, setting inviteUID if known
+ mergedRowDict = dict(acceptedRowDict, **inviteRowDict)
+
cls = self.__class__ # for ease of grepping...
result = []
- for bindMode, homeResourceID, sharedResourceName, bindStatus, bindMessage, inviteUID in rows:
+ for bindMode, homeResourceID, sharedResourceName, bindStatus, bindMessage, inviteUID in mergedRowDict.values():
+ assert bindStatus == _BIND_STATUS_ACCEPTED
# TODO: this could all be issued in parallel; no need to serialize
# the loop.
new = cls(
@@ -2312,28 +2349,12 @@
yield new.initFromStore()
result.append(new)
returnValue(result)
-
- @inlineCallbacks
- def asShared(self):
- """
- Retrieve all the versions of this L{CommonHomeChild} as it is shared to
- everyone.
- @see: L{ICalendarHome.asShared}
-
- @return: L{CommonHomeChild} objects that represent this
- L{CommonHomeChild} as a child of different L{CommonHome}s
- @rtype: a L{Deferred} which fires with a L{list} of L{ICalendar}s.
- """
- result = yield self._asBound(self._sharedFor)
- returnValue(result)
-
-
@classproperty
def _invitedFor(cls): #@NoSelf
bind = cls._bindSchema
- return cls._bindEntriesFor(bind.BIND_STATUS != _BIND_STATUS_ACCEPTED)
+ return cls._invitedBindFor(bind.BIND_STATUS != _BIND_STATUS_ACCEPTED)
@inlineCallbacks
def asInvited(self):
@@ -2347,9 +2368,28 @@
L{CommonHomeChild} as a child of different L{CommonHome}s
@rtype: a L{Deferred} which fires with a L{list} of L{ICalendar}s.
"""
- result = yield self._asBound(self._invitedFor)
+ rows = yield self._invitedFor.on(
+ self._txn, resourceID=self._resourceID
+ )
+ cls = self.__class__ # for ease of grepping...
+
+ result = []
+ for bindMode, homeResourceID, sharedResourceName, bindStatus, bindMessage, inviteUID in rows:
+ # TODO: this could all be issued in parallel; no need to serialize
+ # the loop.
+ new = cls(
+ home=(yield self._txn.homeWithResourceID(self._home._homeType,
+ homeResourceID)),
+ name=sharedResourceName, resourceID=self._resourceID,
+ owned=False, mode=bindMode, status=bindStatus,
+ message=bindMessage, inviteUID=inviteUID,
+ )
+ yield new.initFromStore()
+
+ result.append(new)
returnValue(result)
+
@classmethod
@inlineCallbacks
def loadAllObjects(cls, home, owned):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120725/09b571fc/attachment-0001.html>
More information about the calendarserver-changes
mailing list