[CalendarServer-changes] [7457] CalendarServer/branches/users/glyph/new-export/txdav/caldav/ datastore
source_changes at macosforge.org
source_changes at macosforge.org
Mon May 16 07:42:32 PDT 2011
Revision: 7457
http://trac.macosforge.org/projects/calendarserver/changeset/7457
Author: glyph at apple.com
Date: 2011-05-16 07:42:32 -0700 (Mon, 16 May 2011)
Log Message:
-----------
Add filteredComponent and a test for (part of) it, and remove mutable component() caching logic that was in the filesystem, but not the SQL, back-end. (If this were a good idea, the behavior would have been consistent between implementations; as the SQL implementation is ascendant, matching its behavior is better anyway.)
Modified Paths:
--------------
CalendarServer/branches/users/glyph/new-export/txdav/caldav/datastore/file.py
CalendarServer/branches/users/glyph/new-export/txdav/caldav/datastore/sql.py
CalendarServer/branches/users/glyph/new-export/txdav/caldav/datastore/test/common.py
CalendarServer/branches/users/glyph/new-export/txdav/caldav/datastore/test/test_file.py
CalendarServer/branches/users/glyph/new-export/txdav/caldav/datastore/util.py
Modified: CalendarServer/branches/users/glyph/new-export/txdav/caldav/datastore/file.py
===================================================================
--- CalendarServer/branches/users/glyph/new-export/txdav/caldav/datastore/file.py 2011-05-16 14:42:18 UTC (rev 7456)
+++ CalendarServer/branches/users/glyph/new-export/txdav/caldav/datastore/file.py 2011-05-16 14:42:32 UTC (rev 7457)
@@ -55,13 +55,12 @@
from txdav.caldav.datastore.index_file import Index as OldIndex,\
IndexSchedule as OldInboxIndex
from txdav.caldav.datastore.util import (
- validateCalendarComponent, dropboxIDFromCalendarObject
+ validateCalendarComponent, dropboxIDFromCalendarObject, CalendarObjectBase
)
from txdav.common.datastore.file import (
CommonDataStore, CommonStoreTransaction, CommonHome, CommonHomeChild,
- CommonObjectResource
-, CommonStubResource)
+ CommonObjectResource, CommonStubResource)
from txdav.common.icommondatastore import (NoSuchObjectResourceError,
InternalDataStoreError)
@@ -262,7 +261,7 @@
-class CalendarObject(CommonObjectResource):
+class CalendarObject(CommonObjectResource, CalendarObjectBase):
"""
@ivar _path: The path of the .ics file on disk
@@ -340,8 +339,6 @@
def component(self):
- if self._component is not None:
- return self._component
text = self.text()
try:
Modified: CalendarServer/branches/users/glyph/new-export/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/glyph/new-export/txdav/caldav/datastore/sql.py 2011-05-16 14:42:18 UTC (rev 7456)
+++ CalendarServer/branches/users/glyph/new-export/txdav/caldav/datastore/sql.py 2011-05-16 14:42:32 UTC (rev 7457)
@@ -67,8 +67,8 @@
from twext.enterprise.dal.syntax import Parameter
from twext.enterprise.dal.syntax import utcNowSQL
from twext.enterprise.dal.syntax import Len
-from twistedcaldav.datafilters.privateevents import PrivateEventFilter
-from twistedcaldav.datafilters.peruserdata import PerUserDataFilter
+
+from txdav.caldav.datastore.util import CalendarObjectBase
from txdav.common.icommondatastore import IndexedSearchException
from pycalendar.datetime import PyCalendarDateTime
@@ -307,7 +307,7 @@
-class CalendarObject(CommonObjectResource):
+class CalendarObject(CommonObjectResource, CalendarObjectBase):
implements(ICalendarObject)
_objectTable = CALENDAR_OBJECT_TABLE
@@ -614,18 +614,6 @@
returnValue(VComponent.fromString((yield self.iCalendarText())))
- @inlineCallbacks
- def filteredComponent(self, accessUID):
- component = yield self.component()
- calendar = self.calendar()
- isOwner = (calendar._owned and
- calendar.ownerCalendarHome().uid() == accessUID)
- for filter in [PrivateEventFilter(self.accessMode, isOwner),
- PerUserDataFilter(accessUID)]:
- component = filter.filter(component)
- returnValue(component)
-
-
iCalendarText = CommonObjectResource.text
Modified: CalendarServer/branches/users/glyph/new-export/txdav/caldav/datastore/test/common.py
===================================================================
--- CalendarServer/branches/users/glyph/new-export/txdav/caldav/datastore/test/common.py 2011-05-16 14:42:18 UTC (rev 7456)
+++ CalendarServer/branches/users/glyph/new-export/txdav/caldav/datastore/test/common.py 2011-05-16 14:42:32 UTC (rev 7457)
@@ -912,7 +912,100 @@
self.assertEquals(component.resourceUID(), "uid1")
+ perUserComponent = lambda self: VComponent.fromString("""BEGIN:VCALENDAR
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+VERSION:2.0
+BEGIN:VEVENT
+DTSTART:20110101T120000Z
+DTEND:20110101T120100Z
+UID:event-with-some-per-user-data
+ATTENDEE:urn:uuid:home1
+ORGANIZER:urn:uuid:home1
+END:VEVENT
+BEGIN:X-CALENDARSERVER-PERUSER
+X-CALENDARSERVER-PERUSER-UID:some-other-user
+BEGIN:X-CALENDARSERVER-PERINSTANCE
+BEGIN:VALARM
+ACTION:DISPLAY
+DESCRIPTION:somebody else
+END:VALARM
+END:X-CALENDARSERVER-PERINSTANCE
+END:X-CALENDARSERVER-PERUSER
+BEGIN:X-CALENDARSERVER-PERUSER
+X-CALENDARSERVER-PERUSER-UID:home1
+BEGIN:X-CALENDARSERVER-PERINSTANCE
+BEGIN:VALARM
+ACTION:DISPLAY
+DESCRIPTION:the owner
+END:VALARM
+END:X-CALENDARSERVER-PERINSTANCE
+END:X-CALENDARSERVER-PERUSER
+END:VCALENDAR
+""".replace("\n", "\r\n"))
+
+
+ asSeenByOwner = lambda self: VComponent.fromString("""BEGIN:VCALENDAR
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+VERSION:2.0
+BEGIN:VEVENT
+DTSTART:20110101T120000Z
+DTEND:20110101T120100Z
+UID:event-with-some-per-user-data
+ATTENDEE:urn:uuid:home1
+ORGANIZER:urn:uuid:home1
+BEGIN:VALARM
+ACTION:DISPLAY
+DESCRIPTION:the owner
+END:VALARM
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n"))
+
+
+ asSeenByOther = lambda self: VComponent.fromString("""BEGIN:VCALENDAR
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+VERSION:2.0
+BEGIN:VEVENT
+DTSTART:20110101T120000Z
+DTEND:20110101T120100Z
+UID:event-with-some-per-user-data
+ATTENDEE:urn:uuid:home1
+ORGANIZER:urn:uuid:home1
+BEGIN:VALARM
+ACTION:DISPLAY
+DESCRIPTION:somebody else
+END:VALARM
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n"))
+
+
@inlineCallbacks
+ def setUpPerUser(self):
+ """
+ Set up state for testing of per-user components.
+ """
+ cal = yield self.calendarUnderTest()
+ yield cal.createCalendarObjectWithName(
+ "per-user-stuff.ics",
+ self.perUserComponent())
+ returnValue((yield cal.calendarObjectWithName("per-user-stuff.ics")))
+
+
+ @inlineCallbacks
+ def test_filteredComponent(self):
+ """
+ L{ICalendarObject.filteredComponent} returns a L{VComponent} that has
+ filtered per-user data.
+ """
+ obj = yield self.setUpPerUser()
+ otherComp = (yield obj.filteredComponent("some-other-user"))
+ self.assertEquals(otherComp, self.asSeenByOther())
+ ownerComp = (yield obj.filteredComponent("home1"))
+ self.assertEquals(ownerComp, self.asSeenByOwner())
+
+
+ @inlineCallbacks
def test_iCalendarText(self):
"""
L{ICalendarObject.iCalendarText} returns a C{str} describing the same
Modified: CalendarServer/branches/users/glyph/new-export/txdav/caldav/datastore/test/test_file.py
===================================================================
--- CalendarServer/branches/users/glyph/new-export/txdav/caldav/datastore/test/test_file.py 2011-05-16 14:42:18 UTC (rev 7456)
+++ CalendarServer/branches/users/glyph/new-export/txdav/caldav/datastore/test/test_file.py 2011-05-16 14:42:32 UTC (rev 7457)
@@ -375,23 +375,6 @@
)
- @inlineCallbacks
- def test_modifyCalendarObjectCaches(self):
- """
- Modifying a calendar object should cache the modified component in
- memory, to avoid unnecessary parsing round-trips.
- """
- self.addCleanup(self.txn.commit)
- modifiedComponent = VComponent.fromString(event1modified_text)
- (yield self.calendar1.calendarObjectWithName("1.ics")).setComponent(
- modifiedComponent
- )
- self.assertIdentical(
- modifiedComponent,
- (yield self.calendar1.calendarObjectWithName("1.ics")).component()
- )
-
-
@featureUnimplemented
def test_removeCalendarObjectWithUID_absent(self):
"""
Modified: CalendarServer/branches/users/glyph/new-export/txdav/caldav/datastore/util.py
===================================================================
--- CalendarServer/branches/users/glyph/new-export/txdav/caldav/datastore/util.py 2011-05-16 14:42:18 UTC (rev 7456)
+++ CalendarServer/branches/users/glyph/new-export/txdav/caldav/datastore/util.py 2011-05-16 14:42:32 UTC (rev 7457)
@@ -28,6 +28,8 @@
from txdav.common.icommondatastore import InvalidObjectResourceError, \
NoSuchObjectResourceError, InternalDataStoreError
+from twistedcaldav.datafilters.privateevents import PrivateEventFilter
+from twistedcaldav.datafilters.peruserdata import PerUserDataFilter
from twext.python.log import Logger
log = Logger()
@@ -215,3 +217,46 @@
# No migration for notifications, since they weren't present in earlier
# released versions of CalendarServer.
+
+
+class CalendarObjectBase(object):
+ """
+ Base logic shared between file- and sql-based L{ICalendarObject}
+ implementations.
+ """
+
+ @inlineCallbacks
+ def filteredComponent(self, accessUID, asAdmin=False):
+ """
+ Filter this calendar object's iCalendar component as it would be
+ perceived by a particular user, accounting for per-user iCalendar data
+ and private events, and return a L{Deferred} that fires with that
+ object.
+
+ Unlike the result of C{component()}, which contains storage-specific
+ iCalendar properties, this is a valid iCalendar object which could be
+ serialized and displayed to other iCalendar-processing software.
+
+ @param accessUID: the UID of the principal who is accessing this
+ component.
+ @type accessUID: C{str} (UTF-8 encoded)
+
+ @param asAdmin: should the given UID be treated as an administrator? If
+ this is C{True}, the resulting component will have an unobscured
+ view of private events, even if the given UID is not actually the
+ owner of said events. (However, per-instance overridden values will
+ still be seen as the given C{accessUID}.)
+
+ @return: a L{Deferred} which fires with a
+ L{twistedcaldav.ical.Component}.
+ """
+ component = yield self.component()
+ calendar = self.calendar()
+ isOwner = (calendar._owned and
+ calendar.ownerCalendarHome().uid() == accessUID)
+ for filter in [PrivateEventFilter(self.accessMode, isOwner),
+ PerUserDataFilter(accessUID)]:
+ component = filter.filter(component)
+ returnValue(component)
+
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110516/4bea16c2/attachment-0001.html>
More information about the calendarserver-changes
mailing list