[CalendarServer-changes] [6149] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Aug 20 08:41:43 PDT 2010
Revision: 6149
http://trac.macosforge.org/projects/calendarserver/changeset/6149
Author: glyph at apple.com
Date: 2010-08-20 08:41:42 -0700 (Fri, 20 Aug 2010)
Log Message:
-----------
since you already always have to call _setPerUserID, let's just make that the only way to set the property store's peruser ID.
Modified Paths:
--------------
CalendarServer/trunk/txcaldav/calendarstore/file.py
CalendarServer/trunk/txcaldav/calendarstore/postgres.py
CalendarServer/trunk/txcaldav/calendarstore/postgres_schema_v1.sql
CalendarServer/trunk/txcaldav/icalendarstore.py
CalendarServer/trunk/txcarddav/iaddressbookstore.py
CalendarServer/trunk/txdav/common/datastore/file.py
CalendarServer/trunk/txdav/common/icommondatastore.py
CalendarServer/trunk/txdav/propertystore/base.py
CalendarServer/trunk/txdav/propertystore/none.py
CalendarServer/trunk/txdav/propertystore/xattr.py
Modified: CalendarServer/trunk/txcaldav/calendarstore/file.py
===================================================================
--- CalendarServer/trunk/txcaldav/calendarstore/file.py 2010-08-20 15:41:22 UTC (rev 6148)
+++ CalendarServer/trunk/txcaldav/calendarstore/file.py 2010-08-20 15:41:42 UTC (rev 6149)
@@ -459,7 +459,7 @@
def properties(self):
uid = self._calendarObject._parentCollection._home.uid()
- return PropertyStore(uid, uid, lambda :self._path)
+ return PropertyStore(uid, lambda :self._path)
def store(self, contentType):
Modified: CalendarServer/trunk/txcaldav/calendarstore/postgres.py
===================================================================
--- CalendarServer/trunk/txcaldav/calendarstore/postgres.py 2010-08-20 15:41:22 UTC (rev 6148)
+++ CalendarServer/trunk/txcaldav/calendarstore/postgres.py 2010-08-20 15:41:42 UTC (rev 6149)
@@ -56,8 +56,8 @@
NoSuchHomeChildError, NoSuchObjectResourceError)
from txcaldav.calendarstore.util import (validateCalendarComponent,
validateAddressBookComponent, dropboxIDFromCalendarObject, SyncTokenHelper)
+from txdav.datastore.file import cached
-
from txcaldav.icalendarstore import (ICalendarTransaction, ICalendarHome,
ICalendar, ICalendarObject, IAttachment)
from txcarddav.iaddressbookstore import (IAddressBookTransaction,
@@ -214,8 +214,8 @@
class PropertyStore(AbstractPropertyStore):
- def __init__(self, peruser, defaultuser, txn, resourceID):
- super(PropertyStore, self).__init__(peruser, defaultuser)
+ def __init__(self, defaultuser, txn, resourceID):
+ super(PropertyStore, self).__init__(defaultuser)
self._txn = txn
self._resourceID = resourceID
@@ -311,10 +311,10 @@
return self.component().mainType()
+ @cached
def properties(self):
return PropertyStore(
self.uid(),
- self.uid(),
self._txn,
self._resourceID
)
@@ -749,7 +749,7 @@
for row in self._txn.execSQL(
"""
select
- INVITE.INVITE_UID, INVITE.NAME, INVITE.SENDER_ADDRESS,
+ INVITE.INVITE_UID, INVITE.NAME, INVITE.RECIPIENT_ADDRESS,
CALENDAR_HOME.OWNER_UID, CALENDAR_BIND.BIND_MODE,
CALENDAR_BIND.BIND_STATUS, CALENDAR_BIND.MESSAGE
from
@@ -813,11 +813,12 @@
"INVALID": _BIND_STATUS_INVALID,
}[record.state]
# principalURL is derived from a directory record's principalURL() so
- # it will always contain the UID.
- principalUID = record.principalURL.split("/")[-2]
+ # it will always contain the UID. The form is '/principals/__uids__/x'
+ # (and may contain a trailing slash).
+ principalUID = record.principalURL.split("/")[3]
shareeHome = self._txn.calendarHomeWithUID(principalUID, create=True)
rows = self._txn.execSQL(
- "select RESOURCE_ID, HOME_RESOURCE_ID from INVITE where SENDER_ADDRESS = %s",
+ "select RESOURCE_ID, HOME_RESOURCE_ID from INVITE where RECIPIENT_ADDRESS = %s",
[record.userid]
)
if rows:
@@ -833,13 +834,27 @@
resourceID, homeResourceID])
self._txn.execSQL("""
update INVITE set NAME = %s, INVITE_UID = %s
- where SENDER_ADDRESS = %s
+ where RECIPIENT_ADDRESS = %s
""",
[record.name, record.inviteuid, record.userid]
)
else:
self._txn.execSQL(
"""
+ insert into INVITE (
+ INVITE_UID, NAME,
+ HOME_RESOURCE_ID, RESOURCE_ID,
+ RECIPIENT_ADDRESS
+ )
+ values (%s, %s, %s, %s, %s)
+ """,
+ [
+ record.inviteuid, record.name,
+ shareeHome._resourceID, self._calendar._resourceID,
+ record.userid
+ ])
+ self._txn.execSQL(
+ """
insert into CALENDAR_BIND
(
CALENDAR_HOME_RESOURCE_ID, CALENDAR_RESOURCE_ID,
@@ -859,20 +874,6 @@
False,
record.summary
])
- self._txn.execSQL(
- """
- insert into INVITE (
- INVITE_UID, NAME,
- HOME_RESOURCE_ID, RESOURCE_ID,
- SENDER_ADDRESS
- )
- values (%s, %s, %s, %s, %s)
- """,
- [
- record.inviteuid, record.name,
- shareeHome._resourceID, self._calendar._resourceID,
- record.userid
- ])
def removeRecordForUserID(self, userid):
@@ -1374,6 +1375,10 @@
return self._home._txn
+ def setSharingUID(self, uid):
+ pass
+
+
def retrieveOldInvites(self):
return PostgresLegacyInvitesEmulator(self)
@@ -1526,11 +1531,10 @@
raise NotImplementedError()
+ @cached
def properties(self):
- ownerUID = self.ownerCalendarHome().uid()
return PropertyStore(
- ownerUID,
- ownerUID,
+ self.ownerCalendarHome().uid(),
self._txn,
self._resourceID
)
@@ -1720,10 +1724,10 @@
self._txn.postCommit(self._notifier.notify)
+ @cached
def properties(self):
return PropertyStore(
self.uid(),
- self.uid(),
self._txn,
self._resourceID
)
@@ -1816,11 +1820,13 @@
return self._fieldQuery("NOTIFICATION_UID")
+ @cached
def properties(self):
- return PropertyStore(self._home.uid(),
- self._home.uid(),
- self._txn,
- self._resourceID)
+ return PropertyStore(
+ self._home.uid(),
+ self._txn,
+ self._resourceID
+ )
def md5(self):
@@ -1972,9 +1978,12 @@
return (changed, removed, token)
+ @cached
def properties(self):
return PropertyStore(
- self._uid, self._uid, self._txn, self._resourceID
+ self._uid,
+ self._txn,
+ self._resourceID
)
@@ -2174,10 +2183,10 @@
return self.component().mainType()
+ @cached
def properties(self):
return PropertyStore(
self.uid(),
- self.uid(),
self._txn,
self._resourceID
)
@@ -2489,6 +2498,10 @@
return self._home._txn
+ def setSharingUID(self, uid):
+ pass
+
+
def retrieveOldInvites(self):
return PostgresLegacyInvitesEmulator(self)
@@ -2637,11 +2650,10 @@
raise NotImplementedError()
+ @cached
def properties(self):
- ownerUID = self.ownerAddressBookHome().uid()
return PropertyStore(
- ownerUID,
- ownerUID,
+ self.ownerAddressBookHome().uid(),
self._txn,
self._resourceID
)
@@ -2821,10 +2833,10 @@
self._txn.postCommit(self._notifier.notify)
+ @cached
def properties(self):
return PropertyStore(
self.uid(),
- self.uid(),
self._txn,
self._resourceID
)
Modified: CalendarServer/trunk/txcaldav/calendarstore/postgres_schema_v1.sql
===================================================================
--- CalendarServer/trunk/txcaldav/calendarstore/postgres_schema_v1.sql 2010-08-20 15:41:22 UTC (rev 6148)
+++ CalendarServer/trunk/txcaldav/calendarstore/postgres_schema_v1.sql 2010-08-20 15:41:42 UTC (rev 6149)
@@ -34,7 +34,7 @@
create table INVITE (
INVITE_UID varchar(255) not null,
NAME varchar(255) not null,
- SENDER_ADDRESS varchar(255) not null,
+ RECIPIENT_ADDRESS varchar(255) not null,
HOME_RESOURCE_ID integer not null,
RESOURCE_ID integer not null
);
Modified: CalendarServer/trunk/txcaldav/icalendarstore.py
===================================================================
--- CalendarServer/trunk/txcaldav/icalendarstore.py 2010-08-20 15:41:22 UTC (rev 6148)
+++ CalendarServer/trunk/txcaldav/icalendarstore.py 2010-08-20 15:41:42 UTC (rev 6149)
@@ -19,10 +19,10 @@
Calendar store interfaces
"""
-from txdav.common.icommondatastore import ICommonTransaction
+from txdav.common.icommondatastore import ICommonTransaction,\
+ IShareableCollection
from txdav.idav import IDataStoreResource
-from zope.interface import Interface
from txdav.idav import INotifier
@@ -138,7 +138,7 @@
"""
-class ICalendar(INotifier, IDataStoreResource):
+class ICalendar(INotifier, IShareableCollection, IDataStoreResource):
"""
Calendar
Modified: CalendarServer/trunk/txcarddav/iaddressbookstore.py
===================================================================
--- CalendarServer/trunk/txcarddav/iaddressbookstore.py 2010-08-20 15:41:22 UTC (rev 6148)
+++ CalendarServer/trunk/txcarddav/iaddressbookstore.py 2010-08-20 15:41:42 UTC (rev 6149)
@@ -19,7 +19,8 @@
Address book store interfaces
"""
-from txdav.common.icommondatastore import ICommonTransaction
+from txdav.common.icommondatastore import ICommonTransaction,\
+ IShareableCollection
from txdav.idav import INotifier
from txdav.idav import IDataStoreResource
@@ -109,7 +110,7 @@
"""
-class IAddressBook(INotifier, IDataStoreResource):
+class IAddressBook(INotifier, IShareableCollection, IDataStoreResource):
"""
AddressBook
Modified: CalendarServer/trunk/txdav/common/datastore/file.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/file.py 2010-08-20 15:41:22 UTC (rev 6148)
+++ CalendarServer/trunk/txdav/common/datastore/file.py 2010-08-20 15:41:42 UTC (rev 6149)
@@ -460,7 +460,7 @@
# FIXME: needs tests for actual functionality
# FIXME: needs to be cached
# FIXME: transaction tests
- props = PropertyStore(self.uid(), self.uid(), lambda : self._path)
+ props = PropertyStore(self.uid(), lambda : self._path)
self._transaction.addOperation(props.flush, "flush home properties")
return props
@@ -499,7 +499,6 @@
self._name = name
self._home = home
self._notifier = notifier
- self._peruser_uid = home.uid()
self._transaction = home._transaction
self._newObjectResources = {}
self._cachedObjectResources = {}
@@ -561,10 +560,11 @@
def ownerHome(self):
return self._home
+
def setSharingUID(self, uid):
- self._peruser_uid = uid
- self.properties().setPerUserUID(uid)
+ self.properties()._setPerUserUID(uid)
+
def objectResources(self):
"""
Return a list of object resource objects.
@@ -685,18 +685,23 @@
def properties(self):
# FIXME: needs direct tests - only covered by store tests
# FIXME: transactions
- props = PropertyStore(
- self._peruser_uid, self._home.uid(), lambda: self._path
- )
+ props = PropertyStore(self._home.uid(), lambda: self._path)
self.initPropertyStore(props)
- self._transaction.addOperation(props.flush, "flush object resource properties")
+ self._transaction.addOperation(props.flush,
+ "flush object resource properties")
return props
def initPropertyStore(self, props):
- pass
+ """
+ A hook for subclasses to override in order to set up their property
+ store after it's been created.
+ @param props: the L{PropertyStore} from C{properties()}.
+ """
+
+
def _doValidate(self, component):
raise NotImplementedError
@@ -751,7 +756,7 @@
@cached
def properties(self):
uid = self._parentCollection._home.uid()
- props = PropertyStore(uid, uid, lambda : self._path)
+ props = PropertyStore(uid, lambda : self._path)
self._transaction.addOperation(props.flush, "object properties flush")
return props
Modified: CalendarServer/trunk/txdav/common/icommondatastore.py
===================================================================
--- CalendarServer/trunk/txdav/common/icommondatastore.py 2010-08-20 15:41:22 UTC (rev 6148)
+++ CalendarServer/trunk/txdav/common/icommondatastore.py 2010-08-20 15:41:42 UTC (rev 6149)
@@ -19,6 +19,7 @@
requirements for both CalDAV and CardDAV extensions.
"""
+from zope.interface import Interface
from txdav.idav import ITransaction
__all__ = [
@@ -128,3 +129,25 @@
+class IShareableCollection(Interface):
+ """
+ A collection resource which may be shared.
+ """
+
+ def setSharingUID(shareeUID):
+ """
+ This is a temporary shim method due to the way L{twistedcaldav.sharing}
+ works, which is that it expects to look in the 'sharesDB' object to
+ find what calendars are shared by whom, separately looks up the owner's
+ calendar home based on that information, then sets the sharee's UID on
+ that calendar, the main effect of which is to change the per-user uid
+ of the properties for that calendar object.
+
+ What I{should} be happening is that the calendars
+ just show up in the sharee's calendar home, and have a separate methods
+ to determine the sharee's and the owner's calendar homes, so the front
+ end can tell it's shared.
+
+ @param shareeUID: the UID of the sharee.
+ @type shareeUID: C{str]
+ """
Modified: CalendarServer/trunk/txdav/propertystore/base.py
===================================================================
--- CalendarServer/trunk/txdav/propertystore/base.py 2010-08-20 15:41:22 UTC (rev 6148)
+++ CalendarServer/trunk/txdav/propertystore/base.py 2010-08-20 15:41:42 UTC (rev 6149)
@@ -108,26 +108,24 @@
PropertyName.fromElement(TwistedQuotaRootProperty),
))
- def __init__(self, peruser, defaultuser):
+ def __init__(self, defaultuser):
"""
Instantiate the property store for a user. The default is the default user
(owner) property to read in the case of global or shadowable properties.
- @param peruser: the user uid
- @type peruser: C{str}
-
@param defaultuser: the default user uid
@type defaultuser: C{str}
"""
- self._peruser = peruser
- self._defaultuser = defaultuser
+ self._peruser = self._defaultuser = defaultuser
self._shadowableKeys = set(AbstractPropertyStore._defaultShadowableKeys)
self._globalKeys = set(AbstractPropertyStore._defaultGlobalKeys)
- def setPerUserUID(self, uid):
+
+ def _setPerUserUID(self, uid):
self._peruser = uid
+
def setSpecialProperties(self, shadowableKeys, globalKeys):
self._shadowableKeys.update(shadowableKeys)
self._globalKeys.update(globalKeys)
Modified: CalendarServer/trunk/txdav/propertystore/none.py
===================================================================
--- CalendarServer/trunk/txdav/propertystore/none.py 2010-08-20 15:41:22 UTC (rev 6148)
+++ CalendarServer/trunk/txdav/propertystore/none.py 2010-08-20 15:41:42 UTC (rev 6149)
@@ -31,8 +31,8 @@
properties = {}
- def __init__(self, peruser, defaultuser):
- super(PropertyStore, self).__init__(peruser, defaultuser)
+ def __init__(self, defaultuser):
+ super(PropertyStore, self).__init__(defaultuser)
self.modified = {}
self.removed = set()
Modified: CalendarServer/trunk/txdav/propertystore/xattr.py
===================================================================
--- CalendarServer/trunk/txdav/propertystore/xattr.py 2010-08-20 15:41:22 UTC (rev 6148)
+++ CalendarServer/trunk/txdav/propertystore/xattr.py 2010-08-20 15:41:42 UTC (rev 6149)
@@ -84,13 +84,13 @@
}
_namespaceExpand = dict([ (v, k) for k, v in _namespaceCompress.iteritems() ])
- def __init__(self, peruser, defaultuser, pathFactory):
+ def __init__(self, defaultuser, pathFactory):
"""
Initialize a L{PropertyStore}.
@param pathFactory: a 0-arg callable that returns the L{CachingFilePath} to set extended attributes on.
"""
- super(PropertyStore, self).__init__(peruser, defaultuser)
+ super(PropertyStore, self).__init__(defaultuser)
self._pathFactory = pathFactory
# self.attrs = xattr(path.path)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100820/bd64b956/attachment-0001.html>
More information about the calendarserver-changes
mailing list