[CalendarServer-changes] [9461] CalendarServer/branches/users/gaya/inviteclean
source_changes at macosforge.org
source_changes at macosforge.org
Tue Jul 17 18:08:06 PDT 2012
Revision: 9461
http://trac.macosforge.org/projects/calendarserver/changeset/9461
Author: gaya at apple.com
Date: 2012-07-17 18:08:06 -0700 (Tue, 17 Jul 2012)
Log Message:
-----------
Move Invitation object to sql and use it from sharing
Modified Paths:
--------------
CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/sharing.py
CalendarServer/branches/users/gaya/inviteclean/txdav/caldav/datastore/sql.py
CalendarServer/branches/users/gaya/inviteclean/txdav/carddav/datastore/sql.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-17 21:20:17 UTC (rev 9460)
+++ CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/sharing.py 2012-07-18 01:08:06 UTC (rev 9461)
@@ -49,6 +49,81 @@
import os
import types
+'''
+ TEMP FOR NOW - Invitation is duplicated in txdav.common.datastore.sql
+ But importing Invitation causes a circular dependency.
+
+ Invitation is needed now for _invitationFromLegecyInvite and _legacyInviteFromInvitation
+'''
+class Invitation(object):
+ """
+ """
+ def __init__(self, uid, sharerUID, shareeUID, shareeAccess, state, summary):
+ self._uid = uid
+ self._sharerUID = sharerUID
+ self._shareeUID = shareeUID
+ self._shareeAccess = shareeAccess
+ self._state = state
+ self._summary = summary
+
+ def uid(self):
+ """
+ Unique identifier for this record. Randomly generated.
+
+ @return: the invite unique identifier
+ @rtype: C{str}
+ """
+ return self._uid
+
+ def sharerUID(self):
+ """
+ Sharer's unique identifier.
+
+ @return: the Sharer's unique identifier.
+ @rtype: C{str}
+ """
+ return self._sharerUID
+
+ def shareeUID(self):
+ """
+ Sharee's unique identifier.
+
+ @return: the Sharee's unique identifier.
+ @rtype: C{str}
+ """
+ return self._shareeUID
+
+ def shareeAccess(self):
+ """
+ Sharee's access. Currently, one of "own", "read-only", or "read-write".
+
+ @return: the Sharee's access to the shared resource
+ @rtype: C{str}
+ """
+ return self._shareeAccess
+
+ def state(self):
+ """
+ Invitation or bind state. Currently, one of "NEEDS-ACTION","ACCEPTED", "DECLINED", "INVALID".
+
+ @return: the record state
+ @rtype: C{str}
+ """
+ return self._state
+
+ def summary(self):
+ """
+ The shared resource's name, purpose, or description.
+
+ @return: the summary
+ @rtype: C{str}
+ """
+ return self._summary
+'''
+ END FOR TEMP
+'''
+
+
# Types of sharing mode
SHARETYPE_INVITE = "I" # Invite based sharing
SHARETYPE_DIRECT = "D" # Direct linking based sharing
@@ -494,6 +569,14 @@
hosturl = (yield self.canonicalURL(request))
returnValue("%s:%s" % (hosturl, userid))
+
+ def _invitationFromLegecyInvite(self, legacyInvite):
+ return Invitation(uid=legacyInvite.inviteuid,
+ sharerUID=None,
+ shareeUID=legacyInvite.principalUID,
+ shareeAccess=legacyInvite.access,
+ state=legacyInvite.state,
+ summary=legacyInvite.summary, )
def _legacyInviteFromInvitation(self, invitation):
"""
@@ -508,8 +591,15 @@
summary=invitation.summary() )
@inlineCallbacks
- def _createInvitation(self, invitation):
+ def _createInvitation(self, uid, sharerUID, shareeUID, shareeAccess, state, summary,):
+ invitation = Invitation(uid=uid,
+ sharerUID=sharerUID,
+ shareeUID=shareeUID,
+ shareeAccess=shareeAccess,
+ state=state,
+ summary=summary, )
yield self.invitesDB().addOrUpdateRecord(self._legacyInviteFromInvitation(invitation))
+ returnValue(invitation)
@inlineCallbacks
@@ -530,8 +620,11 @@
"""
replaces self.invitesDB().allRecords()
"""
- records = yield self.invitesDB().allRecords()
- invitations = [record.invitationFromLegecyInvite() for record in records]
+ ''' OLD
+ legecyInvites = yield self.invitesDB().allRecords()
+ invitations = [self._invitationFromLegecyInvite(legecyInvite) for legecyInvite in legecyInvites]
+ '''
+ invitations = yield self._newStoreObject.invitations()
returnValue(invitations)
@inlineCallbacks
@@ -582,17 +675,14 @@
invitation = yield self._invitationForShareeUID(shareeUID)
if invitation:
invitation = yield self._updateInvitationForUID(invitation.uid(), shareeAccess=inviteAccessMapFromXML[type(ace)], summary=summary)
-
else:
- invitation = Invitation(uid=str(uuid4()),
- sharerUID=None,
+ ownerPrincipal = (yield self.ownerPrincipal(request))
+ invitation = yield self._createInvitation(uid=str(uuid4()),
+ sharerUID=ownerPrincipal.principalUID(),
shareeUID=shareeUID,
shareeAccess=inviteAccessMapFromXML[type(ace)],
state="NEEDS-ACTION",
summary=summary)
-
- yield self._createInvitation(invitation)
-
# Send invite
yield self.sendInviteNotification(invitation, request)
@@ -955,88 +1045,8 @@
self.access = access
self.state = state
self.summary = summary
-
- def invitationFromLegecyInvite(self):
- return Invitation(uid=self.inviteuid,
- sharerUID=None,
- shareeUID=self.principalUID,
- shareeAccess=self.access,
- state=self.state,
- summary=self.summary, )
-
-from zope.interface import implements
-from txdav.common.iinvitation import IInvitation
-
-class Invitation(object):
- implements(IInvitation)
-
-
- def __init__(self, uid, sharerUID, shareeUID, shareeAccess, state, summary):
- self._uid = uid
- self._sharerUID = sharerUID
- self._shareeUID = shareeUID
- self._shareeAccess = shareeAccess
- self._state = state
- self._summary = summary
-
- def uid(self):
- """
- Unique identifier for this record. Randomly generated.
-
- @return: the invite unique identifier
- @rtype: C{str}
- """
- return self._uid
-
- def sharerUID(self):
- """
- Sharer's unique identifier.
-
- @return: the Sharer's unique identifier.
- @rtype: C{str}
- """
- return self._sharerUID
-
- def shareeUID(self):
- """
- Sharee's unique identifier.
-
- @return: the Sharee's unique identifier.
- @rtype: C{str}
- """
- return self._shareeUID
-
- def shareeAccess(self):
- """
- Sharee's access. Currently, one of "own", "read-only", or "read-write".
-
- @return: the Sharee's access to the shared resource
- @rtype: C{str}
- """
- return self._shareeAccess
-
- def state(self):
- """
- Invitation or bind state. Currently, one of "NEEDS-ACTION","ACCEPTED", "DECLINED", "INVALID".
-
- @return: the record state
- @rtype: C{str}
- """
- return self._state
-
- def summary(self):
- """
- The shared resource's name, purpose, or description.
-
- @return: the summary
- @rtype: C{str}
- """
- return self._summary
-
-
-
class InvitesDatabase(AbstractSQLDatabase, LoggingMixIn):
db_basename = db_prefix + "invites"
Modified: CalendarServer/branches/users/gaya/inviteclean/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/txdav/caldav/datastore/sql.py 2012-07-17 21:20:17 UTC (rev 9460)
+++ CalendarServer/branches/users/gaya/inviteclean/txdav/caldav/datastore/sql.py 2012-07-18 01:08:06 UTC (rev 9461)
@@ -397,6 +397,7 @@
implements(ICalendar)
# structured tables. (new, preferred)
+ _homeSchema = schema.CALENDAR_HOME
_bindSchema = schema.CALENDAR_BIND
_homeChildSchema = schema.CALENDAR
_homeChildMetaDataSchema = schema.CALENDAR_METADATA
Modified: CalendarServer/branches/users/gaya/inviteclean/txdav/carddav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/txdav/carddav/datastore/sql.py 2012-07-17 21:20:17 UTC (rev 9460)
+++ CalendarServer/branches/users/gaya/inviteclean/txdav/carddav/datastore/sql.py 2012-07-18 01:08:06 UTC (rev 9461)
@@ -148,6 +148,7 @@
implements(IAddressBook)
# structured tables. (new, preferred)
+ _homeSchema = schema.ADDRESSBOOK_HOME
_bindSchema = schema.ADDRESSBOOK_BIND
_homeChildSchema = schema.ADDRESSBOOK
_homeChildMetaDataSchema = schema.ADDRESSBOOK_METADATA
Modified: CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py 2012-07-17 21:20:17 UTC (rev 9460)
+++ CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py 2012-07-18 01:08:06 UTC (rev 9461)
@@ -56,7 +56,9 @@
from txdav.common.datastore.sql_tables import schema
from txdav.common.datastore.sql_tables import _BIND_MODE_OWN, \
- _BIND_STATUS_ACCEPTED, NOTIFICATION_OBJECT_REVISIONS_TABLE
+ _BIND_MODE_READ, _BIND_MODE_WRITE, _BIND_STATUS_INVITED, \
+ _BIND_STATUS_ACCEPTED, _BIND_STATUS_DECLINED, _BIND_STATUS_INVALID, \
+ NOTIFICATION_OBJECT_REVISIONS_TABLE
from txdav.common.icommondatastore import HomeChildNameNotAllowedError, \
HomeChildNameAlreadyExistsError, NoSuchHomeChildError, \
ObjectResourceNameNotAllowedError, ObjectResourceNameAlreadyExistsError, \
@@ -1876,7 +1878,89 @@
"""
+from txdav.common.iinvitation import IInvitation
+invitationStateToBindStatusMap = {
+ "NEEDS-ACTION": _BIND_STATUS_INVITED,
+ "ACCEPTED": _BIND_STATUS_ACCEPTED,
+ "DECLINED": _BIND_STATUS_DECLINED,
+ "INVALID": _BIND_STATUS_INVALID,
+}
+invitationStateFromBindStatusMap = dict((v,k) for k, v in invitationStateToBindStatusMap.iteritems())
+invitationShareeAccessToBindModeMap = {
+ "own": _BIND_MODE_OWN,
+ "read-only": _BIND_MODE_READ,
+ "read-write": _BIND_MODE_WRITE,
+ }
+invitationShareeAccessFromBindModeMap = dict((v,k) for k, v in invitationShareeAccessToBindModeMap.iteritems())
+
+class Invitation(object):
+ implements(IInvitation)
+ """
+ """
+ def __init__(self, uid, sharerUID, shareeUID, shareeAccess, state, summary):
+ self._uid = uid
+ self._sharerUID = sharerUID
+ self._shareeUID = shareeUID
+ self._shareeAccess = shareeAccess
+ self._state = state
+ self._summary = summary
+
+ def uid(self):
+ """
+ Unique identifier for this record. Randomly generated.
+
+ @return: the invite unique identifier
+ @rtype: C{str}
+ """
+ return self._uid
+
+ def sharerUID(self):
+ """
+ Sharer's unique identifier.
+
+ @return: the Sharer's unique identifier.
+ @rtype: C{str}
+ """
+ return self._sharerUID
+
+ def shareeUID(self):
+ """
+ Sharee's unique identifier.
+
+ @return: the Sharee's unique identifier.
+ @rtype: C{str}
+ """
+ return self._shareeUID
+
+ def shareeAccess(self):
+ """
+ Sharee's access. Currently, one of "own", "read-only", or "read-write".
+
+ @return: the Sharee's access to the shared resource
+ @rtype: C{str}
+ """
+ return self._shareeAccess
+
+ def state(self):
+ """
+ Invitation or bind state. Currently, one of "NEEDS-ACTION","ACCEPTED", "DECLINED", "INVALID".
+
+ @return: the record state
+ @rtype: C{str}
+ """
+ return self._state
+
+ def summary(self):
+ """
+ The shared resource's name, purpose, or description.
+
+ @return: the summary
+ @rtype: C{str}
+ """
+ return self._summary
+
+
class CommonHomeChild(LoggingMixIn, FancyEqMixin, _SharedSyncLogic):
"""
Common ancestor class of AddressBooks and Calendars.
@@ -2192,7 +2276,7 @@
@classproperty
- def _bindEntriesFor(cls):
+ def _bindEntriesFor(cls): #@NoSelf
bind = cls._bindSchema
return Select([bind.BIND_MODE, bind.HOME_RESOURCE_ID,
bind.RESOURCE_NAME],
@@ -2231,6 +2315,52 @@
returnValue(result)
+ @classproperty
+ def _allInvitationsQuery(cls): #@NoSelf
+ inv = schema.INVITE
+ home = cls._homeSchema
+ bind = cls._bindSchema
+ return Select(
+ [inv.INVITE_UID,
+ home.OWNER_UID,
+ bind.BIND_MODE,
+ bind.BIND_STATUS,
+ bind.MESSAGE],
+ From=inv.join(home).join(bind),
+ Where=(
+ (inv.RESOURCE_ID == Parameter("resourceID"))
+ .And(inv.RESOURCE_ID == bind.RESOURCE_ID)
+ .And(inv.HOME_RESOURCE_ID == home.RESOURCE_ID)
+ .And(inv.HOME_RESOURCE_ID == bind.HOME_RESOURCE_ID)),
+ OrderBy=home.OWNER_UID, Ascending=True
+ )
+
+
+ @inlineCallbacks
+ def invitations(self):
+ """
+ Get a list of invitations for sharing of this item
+ @return: a L{Deferred} which will fires with a L{list} of L{IInvitation}s.
+ """
+ values = []
+ rows = yield self._allInvitationsQuery.on(
+ self._txn, resourceID=self._resourceID
+ )
+ for row in rows:
+ [uid, shareeUID, bindMode, bindStatus, summary] = row
+ state = invitationStateFromBindStatusMap[bindStatus]
+ shareeAccess = invitationShareeAccessFromBindModeMap[bindMode]
+
+ #FIXME: get sharerUID == this items's home.OWNER_UID
+ invitation = Invitation(uid=uid,
+ sharerUID=None,
+ shareeUID=shareeUID,
+ shareeAccess=shareeAccess,
+ state=state,
+ summary=summary, )
+ values.append(invitation)
+ returnValue(values)
+
@classmethod
@inlineCallbacks
def loadAllObjects(cls, home, owned):
@@ -2428,7 +2558,7 @@
@classproperty
- def _bindInsertQuery(cls, **kw):
+ def _bindInsertQuery(cls, **kw): #@NoSelf
"""
DAL statement to create a bind entry that connects a collection to its
owner's home.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120717/bc01a887/attachment-0001.html>
More information about the calendarserver-changes
mailing list