[CalendarServer-changes] [2788] CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Fri Aug 8 12:12:45 PDT 2008
Revision: 2788
http://trac.macosforge.org/projects/calendarserver/changeset/2788
Author: cdaboo at apple.com
Date: 2008-08-08 12:12:45 -0700 (Fri, 08 Aug 2008)
Log Message:
-----------
Support new CALDAV:schedule-calendar-transp property whilst being backwards compatible with the
free-busy-set property.
Modified Paths:
--------------
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/directory/calendar.py
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/copymove.py
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/delete.py
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/resource.py
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/schedule.py
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/static.py
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/directory/calendar.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/directory/calendar.py 2008-08-08 17:12:20 UTC (rev 2787)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/directory/calendar.py 2008-08-08 19:12:45 UTC (rev 2788)
@@ -328,6 +328,9 @@
def owner(self, request):
return succeed(davxml.HRef(self.principalForRecord().principalURL()))
+ def ownerPrincipal(self, request):
+ return succeed(self.principalForRecord())
+
def defaultAccessControlList(self):
myPrincipal = self.principalForRecord()
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/copymove.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/copymove.py 2008-08-08 17:12:20 UTC (rev 2787)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/copymove.py 2008-08-08 19:12:45 UTC (rev 2788)
@@ -32,7 +32,8 @@
from twistedcaldav.caldavxml import caldav_namespace
from twistedcaldav.method.put_common import StoreCalendarObjectResource
-from twistedcaldav.resource import isCalendarCollectionResource
+from twistedcaldav.resource import isCalendarCollectionResource,\
+ isPseudoCalendarCollectionResource
from twistedcaldav.log import Logger
log = Logger()
@@ -113,8 +114,15 @@
"""
result, sourcecal, sourceparent, destination_uri, destination, destinationcal, destinationparent = (yield checkForCalendarAction(self, request))
if not result:
+ is_calendar_collection = isPseudoCalendarCollectionResource(self)
+
# Do default WebDAV action
result = (yield super(CalDAVFile, self).http_MOVE(request))
+
+ if is_calendar_collection:
+ # Do some clean up
+ yield self.movedCalendar(request, destination, destination_uri)
+
returnValue(result)
#
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/delete.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/delete.py 2008-08-08 17:12:20 UTC (rev 2787)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/delete.py 2008-08-08 19:12:45 UTC (rev 2788)
@@ -40,13 +40,20 @@
parentURL = parentForURL(request.uri)
parent = (yield request.locateResource(parentURL))
- if isPseudoCalendarCollectionResource(parent) and self.exists():
- calendar = self.iCalendar()
+ calendar = None
+ is_calendar_collection = False
+ is_calendar_resource = False
+ if self.exists():
+ if isPseudoCalendarCollectionResource(parent):
+ is_calendar_resource = True
+ calendar = self.iCalendar()
+ elif isPseudoCalendarCollectionResource(self):
+ is_calendar_collection = True
response = (yield super(CalDAVFile, self).http_DELETE(request))
if response == responsecode.NO_CONTENT:
- if isPseudoCalendarCollectionResource(parent):
+ if is_calendar_resource:
index = parent.index()
index.deleteResource(self.fp.basename())
@@ -57,5 +64,10 @@
# Do scheduling
scheduler = ImplicitScheduler()
yield scheduler.doImplicitScheduling(request, self, calendar, True)
+
+ elif is_calendar_collection:
+
+ # Do some clean up
+ yield self.deletedCalendar(request)
returnValue(response)
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/resource.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/resource.py 2008-08-08 17:12:20 UTC (rev 2787)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/resource.py 2008-08-08 19:12:45 UTC (rev 2788)
@@ -225,6 +225,7 @@
return super(CalDAVResource, self).readProperty(property, request)
+ @inlineCallbacks
def writeProperty(self, property, request):
assert isinstance(property, davxml.WebDAVElement)
@@ -257,8 +258,25 @@
(caldav_namespace, "valid-calendar-data")
))
- return super(CalDAVResource, self).writeProperty(property, request)
+ elif property.qname() == (caldav_namespace, "schedule-calendar-transp"):
+ if not self.isCalendarCollection():
+ raise HTTPError(StatusResponse(
+ responsecode.FORBIDDEN,
+ "Property %s may only be set on calendar collection." % (property,)
+ ))
+ # For backwards compatibility we need to sync this up with the calendar-free-busy-set on the inbox
+ principal = (yield self.ownerPrincipal(request))
+
+ # Map owner to their inbox
+ inboxURL = principal.scheduleInboxURL()
+ if inboxURL:
+ inbox = (yield request.locateResource(inboxURL))
+ inbox.processFreeBusyCalendar(request.path, property.children[0] == caldavxml.Opaque())
+
+ result = (yield super(CalDAVResource, self).writeProperty(property, request))
+ returnValue(result)
+
def writeDeadProperty(self, property):
val = super(CalDAVResource, self).writeDeadProperty(property)
@@ -324,6 +342,18 @@
returnValue(None)
@inlineCallbacks
+ def ownerPrincipal(self, request):
+ """
+ Return the DAV:owner property value (MUST be a DAV:href or None).
+ """
+ parent = (yield self.locateParent(request, request.urlForResource(self)))
+ if parent and isinstance(parent, CalDAVResource):
+ result = (yield parent.ownerPrincipal(request))
+ returnValue(result)
+ else:
+ returnValue(None)
+
+ @inlineCallbacks
def isOwner(self, request):
"""
Determine whether the DAV:owner of this resource matches the currently authorized principal
@@ -423,6 +453,49 @@
"""
unimplemented(self)
+ @inlineCallbacks
+ def deletedCalendar(self, request):
+ """
+ Calendar has been deleted. Need to do some extra clean-up.
+
+ @param request:
+ @type request:
+ """
+
+ # For backwards compatibility we need to sync this up with the calendar-free-busy-set on the inbox
+ principal = (yield self.ownerPrincipal(request))
+ inboxURL = principal.scheduleInboxURL()
+ if inboxURL:
+ inbox = (yield request.locateResource(inboxURL))
+ inbox.processFreeBusyCalendar(request.path, False)
+
+ @inlineCallbacks
+ def movedCalendar(self, request, destination, destination_uri):
+ """
+ Calendar has been deleted. Need to do some extra clean-up.
+
+ @param request:
+ @type request:
+ """
+
+ # For backwards compatibility we need to sync this up with the calendar-free-busy-set on the inbox
+ principal = (yield self.ownerPrincipal(request))
+ inboxURL = principal.scheduleInboxURL()
+ if inboxURL:
+ inbox = (yield request.locateResource(inboxURL))
+ inbox.processFreeBusyCalendar(request.path, False)
+ inbox.processFreeBusyCalendar(destination_uri, destination.isCalendarOpaque())
+
+ def isCalendarOpaque(self):
+
+ assert self.isCalendarCollection()
+
+ if self.hasDeadProperty((caldav_namespace, "schedule-calendar-transp")):
+ property = self.readDeadProperty((caldav_namespace, "schedule-calendar-transp"))
+ return property.children[0] == caldavxml.Opaque()
+ else:
+ return False
+
def iCalendar(self, name=None):
"""
See L{ICalDAVResource.iCalendar}.
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/schedule.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/schedule.py 2008-08-08 17:12:20 UTC (rev 2787)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/schedule.py 2008-08-08 19:12:45 UTC (rev 2788)
@@ -164,6 +164,20 @@
yield super(ScheduleInboxResource, self).writeProperty(property, request)
+ def processFreeBusyCalendar(self, uri, addit):
+ if not self.hasDeadProperty((caldav_namespace, "calendar-free-busy-set")):
+ fbset = set()
+ else:
+ fbset = set([str(href) for href in self.readDeadProperty((caldav_namespace, "calendar-free-busy-set")).children])
+ if addit:
+ if uri not in fbset:
+ fbset.add(uri)
+ self.writeDeadProperty(caldavxml.CalendarFreeBusySet(*[davxml.HRef(url) for url in fbset]))
+ else:
+ if uri in fbset:
+ fbset.remove(uri)
+ self.writeDeadProperty(caldavxml.CalendarFreeBusySet(*[davxml.HRef(url) for url in fbset]))
+
class ScheduleOutboxResource (CalendarSchedulingCollectionResource):
"""
CalDAV schedule Outbox resource.
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/static.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/static.py 2008-08-08 17:12:20 UTC (rev 2787)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/static.py 2008-08-08 19:12:45 UTC (rev 2788)
@@ -146,6 +146,9 @@
# Initialize CTag on the calendar collection
d1 = self.updateCTag()
+ # Calendar is initially transparent to freebusy
+ self.writeDeadProperty(caldavxml.ScheduleCalendarTransp(caldavxml.Transparent()))
+
# Create the index so its ready when the first PUTs come in
d1.addCallback(lambda _: self.index().create())
d1.addCallback(lambda _: status)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080808/3adb93e5/attachment-0001.html
More information about the calendarserver-changes
mailing list