[CalendarServer-changes] [9471] CalendarServer/branches/users/gaya/inviteclean
source_changes at macosforge.org
source_changes at macosforge.org
Fri Jul 20 15:45:01 PDT 2012
Revision: 9471
http://trac.macosforge.org/projects/calendarserver/changeset/9471
Author: gaya at apple.com
Date: 2012-07-20 15:45:01 -0700 (Fri, 20 Jul 2012)
Log Message:
-----------
remove invitesDB
Modified Paths:
--------------
CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/sharing.py
CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/storebridge.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
CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql_legacy.py
Modified: CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/sharing.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/sharing.py 2012-07-20 20:13:16 UTC (rev 9470)
+++ CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/sharing.py 2012-07-20 22:45:01 UTC (rev 9471)
@@ -58,31 +58,26 @@
"""
Invitation is a read-only wrapper for CommonHomeChild, that's similar to the old sharing.py code base.
"""
- def __init__(self, uid=None, shareeUID=None, shareeAccess=None, state=None, summary=None, homeChild=None):
- self._uid = uid
- self._shareeUID = shareeUID
- self._shareeAccess = shareeAccess
- self._state = state
- self._summary = summary
+ def __init__(self, homeChild):
self._homeChild = homeChild
def homeChild(self):
return self._homeChild
def uid(self):
- return self._homeChild.inviteUID() if self._homeChild else self._uid
+ return self._homeChild.inviteUID()
def shareeUID(self):
- return self._homeChild._home.uid() if self._homeChild else self._shareeUID
+ return self._homeChild._home.uid()
def shareeAccess(self):
- return invitationShareeAccessFromBindModeMap[self._homeChild.shareMode()] if self._homeChild else self._shareeAccess
+ return invitationShareeAccessFromBindModeMap[self._homeChild.shareMode()]
def state(self):
- return invitationStateFromBindStatusMap[self._homeChild.shareStatus()] if self._homeChild else self._state
+ return invitationStateFromBindStatusMap[self._homeChild.shareStatus()]
def summary(self):
- return self._homeChild.shareMessage() if self._homeChild else self._summary
+ return self._homeChild.shareMessage()
invitationStateToBindStatusMap = {
"NEEDS-ACTION": _BIND_STATUS_INVITED,
@@ -165,9 +160,6 @@
rtype = element.ResourceType(*(rtype.children + (customxml.SharedOwner(),)))
self.writeDeadProperty(rtype)
- # Create invites database
- self.invitesDB().create()
-
@inlineCallbacks
def downgradeFromShare(self, request):
@@ -181,10 +173,6 @@
for invitation in (yield self._allInvitations()):
yield self.uninviteFromShare(invitation, request)
- # Remove invites database
- self.invitesDB().remove()
- delattr(self, "_invitesDB")
-
returnValue(True)
@@ -544,35 +532,10 @@
returnValue("%s:%s" % (hosturl, userid))
- def _invitationFromLegecyInvite(self, legacyInvite):
- return Invitation(uid=legacyInvite.inviteuid,
- shareeUID=legacyInvite.principalUID,
- shareeAccess=legacyInvite.access,
- state=legacyInvite.state,
- summary=legacyInvite.summary, )
-
- def _legacyInviteFromInvitation(self, invitation):
- """
- compatibilityHack
- """
- return LegacyInvite(inviteuid=invitation.uid(),
- userid="userid",
- principalUID=invitation.shareeUID(),
- common_name="common_name",
- access=invitation.shareeAccess(),
- state=invitation.state(),
- summary=invitation.summary() )
-
@inlineCallbacks
def _createInvitation(self, shareeUID, shareeAccess, summary,):
'''
- invitation = Invitation(uid=uid,
- shareeUID=shareeUID,
- shareeAccess=shareeAccess,
- state=state,
- summary=summary, )
- yield self.invitesDB().addOrUpdateRecord(self._legacyInviteFromInvitation(invitation))
- invitation = yield self._invitationForUID(uid)
+ Create a new homeChild and wrap it in an Invitation
'''
if self.isCalendarCollection():
shareeHome = yield self._newStoreObject._txn.calendarHomeWithUID(shareeUID, create=True)
@@ -583,7 +546,7 @@
mode=invitationShareeAccessToBindModeMap[shareeAccess],
status=_BIND_STATUS_INVITED,
message=summary )
- invitation = Invitation(homeChild=homeChild)
+ invitation = Invitation(homeChild)
returnValue(invitation)
@@ -594,59 +557,30 @@
message = invitation.summary() if summary is None else summary
yield self._newStoreObject.updateShare(invitation.homeChild(), mode, status, message )
- assert not shareeAccess or shareeAccess == invitation.shareeAccess(), "shareeAccess=%s, invitation.shareeAccess()=%s" % (shareeAccess, invitation.shareeAccess())
- assert not state or state == invitation.state(), "state=%s, invitation.state()=%s" % (state, invitation.state())
- assert not summary or summary == invitation.summary(), "summary=%s, invitation.summary()=%s" % (summary, invitation.summary())
+ assert not shareeAccess or shareeAccess == invitation.shareeAccess(), "shareeAccess=%s != invitation.shareeAccess()=%s" % (shareeAccess, invitation.shareeAccess())
+ assert not state or state == invitation.state(), "state=%s != invitation.state()=%s" % (state, invitation.state())
+ assert not summary or summary == invitation.summary(), "summary=%s != invitation.summary()=%s" % (summary, invitation.summary())
@inlineCallbacks
- def _oallInvitations(self):
- """
- replaces self.invitesDB().allRecords()
- """
- legecyInvites = yield self.invitesDB().allRecords()
- invitations = [self._invitationFromLegecyInvite(legecyInvite) for legecyInvite in legecyInvites]
- returnValue(invitations)
-
- @inlineCallbacks
def _allInvitations(self):
"""
- replaces self.invitesDB().allRecords()
+ Get list of all invitations to this object
"""
invitedHomeChildren = yield self._newStoreObject.asInvited()
invitations = []
for homeChild in invitedHomeChildren:
- invitation = Invitation(homeChild=homeChild)
+ invitation = Invitation(homeChild)
invitations.append(invitation)
invitations.sort(key=lambda invitation:invitation.shareeUID())
- oinvitations = yield self._oallInvitations()
-
- oinvitationsTestStrings = []
- for i in range(len(oinvitations)):
- invitation = oinvitations[i]
- testStr = "i=%s, uid=%s, shareeUID=%s, shareeAccess=%s, state=%s, summary=%s" % (i, invitation.uid(), invitation.shareeUID(), invitation.shareeAccess(), invitation.state(), invitation.summary(), )
- oinvitationsTestStrings += [testStr,]
-
- invitationsTestStrings = []
- for i in range(len(invitations)):
- invitation = invitations[i]
- testStr = "i=%s, uid=%s, shareeUID=%s, shareeAccess=%s, state=%s, summary=%s" % (i, invitation.uid(), invitation.shareeUID(), invitation.shareeAccess(), invitation.state(), invitation.summary(), )
- invitationsTestStrings += [testStr,]
-
- if oinvitationsTestStrings != invitationsTestStrings:
- print("MISMATCH old: %s" % oinvitationsTestStrings)
- print("MISMATCH new: %s" % invitationsTestStrings)
- assert False
-
-
returnValue(invitations)
@inlineCallbacks
def _invitationForShareeUID(self, shareeUID):
"""
- replaces self.invitesDB().recordForPrincipalUID(principalUID)
+ Get an invitation for this sharee principal UID
"""
invitations = yield self._allInvitations()
for invitation in invitations:
@@ -658,14 +592,13 @@
@inlineCallbacks
def _invitationForUID(self, uid):
"""
- replaces self.invitesDB().recordForInviteUID(inviteUID)
+ Get an invitation for an invitation for a uid
"""
invitations = yield self._allInvitations()
for invitation in invitations:
if invitation.uid() == uid:
returnValue(invitation)
returnValue(None)
-
@@ -756,9 +689,6 @@
# use new API
yield self._newStoreObject.unshareWith(invitation.homeChild()._home)
- #old code
- # yield self.invitesDB().removeRecordForInviteUID(invitation.uid())
-
returnValue(True)
def inviteSingleUserUpdateToShare(self, userid, commonName, acesOLD, aceNEW, summary, request):
Modified: CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/storebridge.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/storebridge.py 2012-07-20 20:13:16 UTC (rev 9470)
+++ CalendarServer/branches/users/gaya/inviteclean/twistedcaldav/storebridge.py 2012-07-20 22:45:01 UTC (rev 9471)
@@ -264,15 +264,6 @@
return self._newStoreObject.retrieveOldIndex()
- def invitesDB(self):
- """
- Retrieve the new-style invites DB wrapper.
- """
- if not hasattr(self, "_invitesDB"):
- self._invitesDB = self._newStoreObject.retrieveOldInvites()
- return self._invitesDB
-
-
def exists(self):
# FIXME: tests
return self._newStoreObject is not None
@@ -1518,28 +1509,36 @@
@inlineCallbacks
def sharedDropboxACEs(self):
+
+ #TODO: verify that this this works!
+ from txdav.common.datastore.sql_tables import _BIND_MODE_OWN, _BIND_MODE_READ, _BIND_MODE_WRITE
+
aces = ()
- records = yield self._newStoreCalendarObject._parentCollection.retrieveOldInvites().allRecords()
- for record in records:
+ calendars = yield self._newStoreCalendarObject._parentCollection.asShared()
+ for calendar in calendars:
# Invite shares use access mode from the invite
- if record.state != "ACCEPTED":
- continue
+ #if record.state != "ACCEPTED":
+ # continue
+
userprivs = [
]
- if record.access in ("read-only", "read-write", "read-write-schedule",):
+ #if record.access in ("read-only", "read-write", "read-write-schedule",):
+ if calendar.shareMode() in (_BIND_MODE_READ, _BIND_MODE_WRITE, _BIND_MODE_OWN,):
userprivs.append(davxml.Privilege(davxml.Read()))
userprivs.append(davxml.Privilege(davxml.ReadACL()))
userprivs.append(davxml.Privilege(davxml.ReadCurrentUserPrivilegeSet()))
- if record.access in ("read-only",):
+ #if record.access in ("read-only",):
+ if calendar.shareMode() in (_BIND_MODE_READ,):
userprivs.append(davxml.Privilege(davxml.WriteProperties()))
- if record.access in ("read-write", "read-write-schedule",):
+ #if record.access in ("read-write", "read-write-schedule",):
+ if calendar.shareMode() in (_BIND_MODE_WRITE, _BIND_MODE_OWN,):
userprivs.append(davxml.Privilege(davxml.Write()))
proxyprivs = list(userprivs)
proxyprivs.remove(davxml.Privilege(davxml.ReadACL()))
- principal = self.principalForUID(record.principalUID)
+ principal = self.principalForUID(calendar._home.uid())
aces += (
# Inheritable specific access for the resource's associated principal.
davxml.ACE(
Modified: CalendarServer/branches/users/gaya/inviteclean/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/txdav/caldav/datastore/sql.py 2012-07-20 20:13:16 UTC (rev 9470)
+++ CalendarServer/branches/users/gaya/inviteclean/txdav/caldav/datastore/sql.py 2012-07-20 22:45:01 UTC (rev 9471)
@@ -52,8 +52,7 @@
IAttachment
from txdav.common.datastore.sql import CommonHome, CommonHomeChild,\
CommonObjectResource, ECALENDARTYPE
-from txdav.common.datastore.sql_legacy import \
- PostgresLegacyIndexEmulator, SQLLegacyCalendarInvites,\
+from txdav.common.datastore.sql_legacy import PostgresLegacyIndexEmulator,\
SQLLegacyCalendarShares, PostgresLegacyInboxIndexEmulator
from txdav.common.datastore.sql_tables import CALENDAR_TABLE,\
CALENDAR_BIND_TABLE, CALENDAR_OBJECT_REVISIONS_TABLE, CALENDAR_OBJECT_TABLE,\
@@ -424,7 +423,6 @@
self._index = PostgresLegacyInboxIndexEmulator(self)
else:
self._index = PostgresLegacyIndexEmulator(self)
- self._invites = SQLLegacyCalendarInvites(self)
@classmethod
Modified: CalendarServer/branches/users/gaya/inviteclean/txdav/carddav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/txdav/carddav/datastore/sql.py 2012-07-20 20:13:16 UTC (rev 9470)
+++ CalendarServer/branches/users/gaya/inviteclean/txdav/carddav/datastore/sql.py 2012-07-20 22:45:01 UTC (rev 9471)
@@ -39,8 +39,7 @@
from twistedcaldav.vcard import Component as VCard, InvalidVCardDataError
from txdav.common.datastore.sql_legacy import \
- PostgresLegacyABIndexEmulator, SQLLegacyAddressBookInvites,\
- SQLLegacyAddressBookShares
+ PostgresLegacyABIndexEmulator, SQLLegacyAddressBookShares
from txdav.carddav.datastore.util import validateAddressBookComponent
from txdav.carddav.iaddressbookstore import IAddressBookHome, IAddressBook,\
@@ -166,9 +165,8 @@
def __init__(self, *args, **kw):
super(AddressBook, self).__init__(*args, **kw)
self._index = PostgresLegacyABIndexEmulator(self)
- self._invites = SQLLegacyAddressBookInvites(self)
+
-
@property
def _addressbookHome(self):
return self._home
Modified: CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py 2012-07-20 20:13:16 UTC (rev 9470)
+++ CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql.py 2012-07-20 22:45:01 UTC (rev 9471)
@@ -56,7 +56,7 @@
from txdav.common.datastore.sql_tables import schema
from txdav.common.datastore.sql_tables import _BIND_MODE_OWN, \
- _BIND_STATUS_INVITED, _BIND_STATUS_ACCEPTED, NOTIFICATION_OBJECT_REVISIONS_TABLE
+ _BIND_STATUS_ACCEPTED, NOTIFICATION_OBJECT_REVISIONS_TABLE
from txdav.common.icommondatastore import HomeChildNameNotAllowedError, \
HomeChildNameAlreadyExistsError, NoSuchHomeChildError, \
ObjectResourceNameNotAllowedError, ObjectResourceNameAlreadyExistsError, \
@@ -1933,7 +1933,6 @@
self._syncTokenRevision = None
self._notifiers = notifiers
self._index = None # Derived classes need to set this
- self._invites = None # Derived classes need to set this
@classproperty
@@ -2756,10 +2755,6 @@
return self._index
- def retrieveOldInvites(self):
- return self._invites
-
-
def __repr__(self):
return "<%s: %s>" % (self.__class__.__name__, self._resourceID)
Modified: CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql_legacy.py
===================================================================
--- CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql_legacy.py 2012-07-20 20:13:16 UTC (rev 9470)
+++ CalendarServer/branches/users/gaya/inviteclean/txdav/common/datastore/sql_legacy.py 2012-07-20 22:45:01 UTC (rev 9471)
@@ -34,7 +34,6 @@
calendarqueryfilter, calendarquery, addressbookquery, expression, \
addressbookqueryfilter
from twistedcaldav.query.sqlgenerator import sqlgenerator
-from twistedcaldav.sharing import LegacyInvite
from twistedcaldav.sharing import SharedCollectionRecord
from txdav.caldav.icalendarstore import TimeRangeLowerLimit, TimeRangeUpperLimit
@@ -42,9 +41,8 @@
ReservationError, NoSuchObjectResourceError
from txdav.common.datastore.sql_tables import (
- _BIND_MODE_OWN, _BIND_MODE_READ, _BIND_MODE_WRITE, _BIND_MODE_DIRECT,
- _BIND_STATUS_INVITED, _BIND_STATUS_ACCEPTED, _BIND_STATUS_DECLINED,
- _BIND_STATUS_INVALID, CALENDAR_BIND_TABLE, CALENDAR_HOME_TABLE,
+ _BIND_MODE_OWN, _BIND_MODE_DIRECT,_BIND_STATUS_ACCEPTED,
+ _BIND_STATUS_DECLINED,CALENDAR_BIND_TABLE, CALENDAR_HOME_TABLE,
ADDRESSBOOK_HOME_TABLE, ADDRESSBOOK_BIND_TABLE, schema)
from twext.enterprise.dal.syntax import Delete, Insert, Parameter, \
SavepointAction, Select, Update
@@ -104,350 +102,6 @@
return self._collection.removeNotificationObjectWithName(name)
-
-class SQLLegacyInvites(object):
- """
- Emulator for the implicit interface specified by
- L{twistedcaldav.sharing.InvitesDatabase}.
- """
-
- _homeTable = None
- _bindTable = None
-
- _homeSchema = None
- _bindSchema = None
-
- def __init__(self, collection):
- self._collection = collection
-
- # Since we do multi-table requests we need a dict that combines tables
- self._combinedTable = {}
- for key, value in self._homeTable.iteritems():
- self._combinedTable["HOME:%s" % (key,)] = value
- for key, value in self._bindTable.iteritems():
- self._combinedTable["BIND:%s" % (key,)] = value
-
-
- @property
- def _txn(self):
- return self._collection._txn
-
-
- def _getHomeWithUID(self, uid):
- raise NotImplementedError()
-
-
- def create(self):
- "No-op, because the index implicitly always exists in the database."
-
-
- def remove(self):
- "No-op, because the index implicitly always exists in the database."
-
-
- @classmethod
- def _allColumnsQuery(cls, condition):
- inv = schema.INVITE
- home = cls._homeSchema
- bind = cls._bindSchema
- return Select(
- [inv.INVITE_UID,
- inv.NAME,
- inv.RECIPIENT_ADDRESS,
- home.OWNER_UID,
- bind.BIND_MODE,
- bind.BIND_STATUS,
- bind.MESSAGE],
- From=inv.join(home).join(bind),
- Where=(
- condition
- .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
- )
-
-
- @classproperty
- def _allRecordsQuery(cls): #@NoSelf
- """
- DAL query for all invite records with a given resource ID.
- """
- inv = schema.INVITE
- return cls._allColumnsQuery(inv.RESOURCE_ID == Parameter("resourceID"))
-
-
- @inlineCallbacks
- def allRecords(self):
- values = []
- rows = yield self._allRecordsQuery.on(
- self._txn, resourceID=self._collection._resourceID
- )
- for row in rows:
- values.append(self._makeInvite(row))
- returnValue(values)
-
-
- @classproperty
- def _inviteForRecipientQuery(cls): #@NoSelf
- """
- DAL query to retrieve an invite record for a given recipient address.
- """
- inv = schema.INVITE
- return cls._allColumnsQuery(
- (inv.RESOURCE_ID == Parameter("resourceID")).And(inv.RECIPIENT_ADDRESS == Parameter("recipient"))
- )
-
-
- @inlineCallbacks
- def recordForUserID(self, userid):
- rows = yield self._inviteForRecipientQuery.on(
- self._txn,
- resourceID=self._collection._resourceID,
- recipient=userid
- )
- returnValue(self._makeInvite(rows[0]) if rows else None)
-
-
- @classproperty
- def _inviteForPrincipalUIDQuery(cls): #@NoSelf
- """
- DAL query to retrieve an invite record for a given principal UID.
- """
- inv = schema.INVITE
- home = cls._homeSchema
- return cls._allColumnsQuery(
- (inv.RESOURCE_ID == Parameter("resourceID")).And(home.OWNER_UID == Parameter("principalUID"))
- )
-
-
- @inlineCallbacks
- def recordForPrincipalUID(self, principalUID):
- rows = yield self._inviteForPrincipalUIDQuery.on(
- self._txn,
- resourceID=self._collection._resourceID,
- principalUID=principalUID
- )
- returnValue(self._makeInvite(rows[0]) if rows else None)
-
-
- @classproperty
- def _inviteForUIDQuery(cls): #@NoSelf
- """
- DAL query to retrieve an invite record for a given recipient address.
- """
- inv = schema.INVITE
- return cls._allColumnsQuery(inv.INVITE_UID == Parameter("uid"))
-
-
- @inlineCallbacks
- def recordForInviteUID(self, inviteUID):
- rows = yield self._inviteForUIDQuery.on(self._txn, uid=inviteUID)
- returnValue(self._makeInvite(rows[0]) if rows else None)
-
-
- def _makeInvite(self, row):
- [inviteuid, common_name, userid, ownerUID,
- bindMode, bindStatus, summary] = row
- # FIXME: this is really the responsibility of the protocol layer.
- state = {
- _BIND_STATUS_INVITED: "NEEDS-ACTION",
- _BIND_STATUS_ACCEPTED: "ACCEPTED",
- _BIND_STATUS_DECLINED: "DECLINED",
- _BIND_STATUS_INVALID: "INVALID",
- }[bindStatus]
- access = {
- _BIND_MODE_OWN: "own",
- _BIND_MODE_READ: "read-only",
- _BIND_MODE_WRITE: "read-write"
- }[bindMode]
- return LegacyInvite(
- inviteuid, userid, ownerUID, common_name,
- access, state, summary
- )
-
-
- @classproperty
- def _updateBindQuery(cls): #@NoSelf
- bind = cls._bindSchema
-
- return Update({bind.BIND_MODE: Parameter("mode"),
- bind.BIND_STATUS: Parameter("status"),
- bind.MESSAGE: Parameter("message")},
- Where=
- (bind.RESOURCE_ID == Parameter("resourceID"))
- .And(bind.HOME_RESOURCE_ID == Parameter("homeID")))
-
-
- @classproperty
- def _idsForInviteUID(cls): #@NoSelf
- inv = schema.INVITE
- return Select([inv.RESOURCE_ID, inv.HOME_RESOURCE_ID],
- From=inv,
- Where=inv.INVITE_UID == Parameter("inviteuid"))
-
-
- @classproperty
- def _updateInviteQuery(cls): #@NoSelf
- """
- DAL query to update an invitation for a given recipient.
- """
- inv = schema.INVITE
- return Update({inv.NAME: Parameter("name")},
- Where=inv.INVITE_UID == Parameter("uid"))
-
-
- @classproperty
- def _insertBindQuery(cls): #@NoSelf
- bind = cls._bindSchema
- return Insert(
- {
- bind.HOME_RESOURCE_ID: Parameter("homeID"),
- bind.RESOURCE_ID: Parameter("resourceID"),
- bind.BIND_MODE: Parameter("mode"),
- bind.BIND_STATUS: Parameter("status"),
- bind.MESSAGE: Parameter("message"),
- bind.RESOURCE_NAME: Parameter("resourceName"),
- bind.SEEN_BY_OWNER: False,
- bind.SEEN_BY_SHAREE: False,
- }
- )
-
-
- @classproperty
- def _insertInviteQuery(cls): #@NoSelf
- inv = schema.INVITE
- return Insert(
- {
- inv.INVITE_UID: Parameter("uid"),
- inv.NAME: Parameter("name"),
- inv.HOME_RESOURCE_ID: Parameter("homeID"),
- inv.RESOURCE_ID: Parameter("resourceID"),
- inv.RECIPIENT_ADDRESS: Parameter("recipient")
- }
- )
-
-
- @inlineCallbacks
- def addOrUpdateRecord(self, record):
- bindMode = {'read-only': _BIND_MODE_READ,
- 'read-write': _BIND_MODE_WRITE}[record.access]
- bindStatus = {
- "NEEDS-ACTION": _BIND_STATUS_INVITED,
- "ACCEPTED": _BIND_STATUS_ACCEPTED,
- "DECLINED": _BIND_STATUS_DECLINED,
- "INVALID": _BIND_STATUS_INVALID,
- }[record.state]
- shareeHome = yield self._getHomeWithUID(record.principalUID)
- rows = yield self._idsForInviteUID.on(self._txn,
- inviteuid=record.inviteuid)
-
- # FIXME: Do the BIND table query before the INVITE table query because BIND currently has proper
- # constraints in place, whereas INVITE does not. Really we need to do this in a sub-transaction so
- # we can roll back if any one query fails.
- if rows:
- [[resourceID, homeResourceID]] = rows
- yield self._updateBindQuery.on(
- self._txn,
- mode=bindMode, status=bindStatus, message=record.summary,
- resourceID=resourceID, homeID=homeResourceID
- )
- yield self._updateInviteQuery.on(
- self._txn, name="name", uid=record.inviteuid
- )
- else:
- yield self._insertBindQuery.on(
- self._txn,
- homeID=shareeHome._resourceID,
- resourceID=self._collection._resourceID,
- resourceName=record.inviteuid,
- mode=bindMode,
- status=bindStatus,
- message=record.summary
- )
- yield self._insertInviteQuery.on(
- self._txn, uid=record.inviteuid, name="name",
- homeID=shareeHome._resourceID,
- resourceID=self._collection._resourceID,
- recipient="userid"
- )
-
- # Must send notification to ensure cache invalidation occurs
- self._collection.notifyChanged()
-
-
- @classmethod
- def _deleteOneBindQuery(cls, constraint):
- inv = schema.INVITE
- bind = cls._bindSchema
- return Delete(
- From=bind, Where=(bind.HOME_RESOURCE_ID, bind.RESOURCE_ID) ==
- Select([inv.HOME_RESOURCE_ID, inv.RESOURCE_ID],
- From=inv, Where=constraint))
-
-
- @classmethod
- def _deleteOneInviteQuery(cls, constraint):
- inv = schema.INVITE
- return Delete(From=inv, Where=constraint)
-
-
- @classproperty
- def _deleteBindByUID(cls): #@NoSelf
- inv = schema.INVITE
- return cls._deleteOneBindQuery(inv.INVITE_UID == Parameter("uid"))
-
-
- @classproperty
- def _deleteInviteByUID(cls): #@NoSelf
- inv = schema.INVITE
- return cls._deleteOneInviteQuery(inv.INVITE_UID == Parameter("uid"))
-
-
- @inlineCallbacks
- def removeRecordForInviteUID(self, inviteUID):
- yield self._deleteBindByUID.on(self._txn, uid=inviteUID)
- yield self._deleteInviteByUID.on(self._txn, uid=inviteUID)
-
- # Must send notification to ensure cache invalidation occurs
- self._collection.notifyChanged()
-
-
-
-class SQLLegacyCalendarInvites(SQLLegacyInvites):
- """
- Emulator for the implicit interface specified by
- L{twistedcaldav.sharing.InvitesDatabase}.
- """
-
- _homeTable = CALENDAR_HOME_TABLE
- _bindTable = CALENDAR_BIND_TABLE
-
- _homeSchema = schema.CALENDAR_HOME
- _bindSchema = schema.CALENDAR_BIND
-
- def _getHomeWithUID(self, uid):
- return self._txn.calendarHomeWithUID(uid, create=True)
-
-
-
-class SQLLegacyAddressBookInvites(SQLLegacyInvites):
- """
- Emulator for the implicit interface specified by
- L{twistedcaldav.sharing.InvitesDatabase}.
- """
-
- _homeTable = ADDRESSBOOK_HOME_TABLE
- _bindTable = ADDRESSBOOK_BIND_TABLE
-
- _homeSchema = schema.ADDRESSBOOK_HOME
- _bindSchema = schema.ADDRESSBOOK_BIND
-
- def _getHomeWithUID(self, uid):
- return self._txn.addressbookHomeWithUID(uid, create=True)
-
-
-
class SQLLegacyShares(object):
_homeTable = None
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120720/d05bd4e8/attachment-0001.html>
More information about the calendarserver-changes
mailing list