[CalendarServer-changes] [5317] CalendarServer/branches/users/cdaboo/shared-calendars-5187/ twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Tue Mar 16 13:07:18 PDT 2010


Revision: 5317
          http://trac.macosforge.org/projects/calendarserver/changeset/5317
Author:   cdaboo at apple.com
Date:     2010-03-16 13:07:16 -0700 (Tue, 16 Mar 2010)
Log Message:
-----------
Various clean-up on sharing actions. Use the equivalent of a wrapper resource for the shared calendar.

Modified Paths:
--------------
    CalendarServer/branches/users/cdaboo/shared-calendars-5187/twistedcaldav/customxml.py
    CalendarServer/branches/users/cdaboo/shared-calendars-5187/twistedcaldav/sharedcalendar.py
    CalendarServer/branches/users/cdaboo/shared-calendars-5187/twistedcaldav/sharing.py

Modified: CalendarServer/branches/users/cdaboo/shared-calendars-5187/twistedcaldav/customxml.py
===================================================================
--- CalendarServer/branches/users/cdaboo/shared-calendars-5187/twistedcaldav/customxml.py	2010-03-16 15:46:21 UTC (rev 5316)
+++ CalendarServer/branches/users/cdaboo/shared-calendars-5187/twistedcaldav/customxml.py	2010-03-16 20:07:16 UTC (rev 5317)
@@ -637,6 +637,17 @@
     namespace = calendarserver_namespace
     name = "shared-url"
 
+class SharedCalendar (davxml.WebDAVElement):
+    """
+    The url for a shared calendar.
+    """
+    namespace = calendarserver_namespace
+    name = "shared-calendar"
+
+    allowed_children = {
+        davxml.HRef.qname()    : (1, 1),
+    }
+
 class SharedAcceptEmailNotification (davxml.WebDAVTextElement):
     """
     The accept email flag for a shared calendar.

Modified: CalendarServer/branches/users/cdaboo/shared-calendars-5187/twistedcaldav/sharedcalendar.py
===================================================================
--- CalendarServer/branches/users/cdaboo/shared-calendars-5187/twistedcaldav/sharedcalendar.py	2010-03-16 15:46:21 UTC (rev 5316)
+++ CalendarServer/branches/users/cdaboo/shared-calendars-5187/twistedcaldav/sharedcalendar.py	2010-03-16 20:07:16 UTC (rev 5317)
@@ -31,6 +31,9 @@
 """
 
 class SharedCalendarResource(CalDAVComplianceMixIn, SharedCollectionMixin, DAVResource, LoggingMixIn):
+    """
+    This is similar to a WrapperResource except that we locate our shared calendar resource dynamically. 
+    """
     
     def __init__(self, parent, share):
         self.parent = parent
@@ -49,33 +52,16 @@
     def isCollection(self):
         return True
 
-    @inlineCallbacks
     def locateChild(self, request, segments):
-        hosted = (yield self.hostedResource(request))
-        result = (yield hosted.locateChild(request, segments))
-        returnValue(result)
+        
+        def _defer(result):
+            return (result, segments)
+        d = self.hostedResource(request)
+        d.addCallback(_defer)
+        return d
 
     def renderHTTP(self, request):
         return self.hostedResource(request)
 
-    @inlineCallbacks
     def getChild(self, name):
         return self._hostedResource.getChild(name)
-
-    @inlineCallbacks
-    def hasProperty(self, property, request):
-        hosted = (yield self.hostedResource(request))
-        result = (yield hosted.hasProperty(property, request))
-        returnValue(result)
-
-    @inlineCallbacks
-    def readProperty(self, property, request):
-        hosted = (yield self.hostedResource(request))
-        result = (yield hosted.readProperty(property, request))
-        returnValue(result)
-
-    @inlineCallbacks
-    def writeProperty(self, property, request):
-        hosted = (yield self.hostedResource(request))
-        result = (yield hosted.writeProperty(property, request))
-        returnValue(result)

Modified: CalendarServer/branches/users/cdaboo/shared-calendars-5187/twistedcaldav/sharing.py
===================================================================
--- CalendarServer/branches/users/cdaboo/shared-calendars-5187/twistedcaldav/sharing.py	2010-03-16 15:46:21 UTC (rev 5316)
+++ CalendarServer/branches/users/cdaboo/shared-calendars-5187/twistedcaldav/sharing.py	2010-03-16 20:07:16 UTC (rev 5317)
@@ -13,7 +13,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 ##
-from twext.web2.dav.resource import TwistedACLInheritable
 
 __all__ = [
     "SharedCollectionMixin",
@@ -23,21 +22,18 @@
 from twext.web2 import responsecode
 from twext.web2.dav import davxml
 from twext.web2.dav.http import ErrorResponse, MultiStatusResponse
+from twext.web2.dav.resource import TwistedACLInheritable
 from twext.web2.dav.util import allDataFromStream, joinURL
-from twext.web2.http import HTTPError, Response, StatusResponse
-
+from twext.web2.http import HTTPError, Response, StatusResponse, XMLResponse
 from twisted.internet.defer import succeed, inlineCallbacks, DeferredList,\
-    returnValue, fail
-
+    returnValue
 from twistedcaldav import customxml, caldavxml
 from twistedcaldav.config import config
+from twistedcaldav.customxml import SharedCalendar
 from twistedcaldav.extensions import updateCacheTokenOnCallback
 from twistedcaldav.sql import AbstractSQLDatabase, db_prefix
-
 from uuid import uuid4
-
 from vobject.icalendar import dateTimeToString, utc
-
 import datetime
 import os
 import types
@@ -801,36 +797,47 @@
                 self.putChild(share.localname, child)
             self._provisionedShares = True
 
-    @updateCacheTokenOnCallback
+    @inlineCallbacks
     def acceptShare(self, request, hostUrl, inviteUID, displayname=None):
         
+        # Do this first to make sure we have a valid share
+        yield self._changeShare(request, "ACCEPTED", hostUrl, inviteUID, displayname)
+
         # Add or update in DB
         oldShare = self.sharesDB().recordForInviteUID(inviteUID)
         if not oldShare:
-            share = SharedCalendarRecord(inviteUID, hostUrl, str(uuid4()), displayname)
+            oldShare = share = SharedCalendarRecord(inviteUID, hostUrl, str(uuid4()), displayname)
             self.sharesDB().addOrUpdateRecord(share)
+        
+        # Return the URL of the shared calendar
+        returnValue(XMLResponse(
+            code = responsecode.OK,
+            element = SharedCalendar(
+                davxml.HRef.fromString(joinURL(self.url(), oldShare.localname))
+            )
+        ))
 
-        return self._changeShare(request, "ACCEPTED", hostUrl, inviteUID, displayname)
-
     def wouldAcceptShare(self, hostUrl, request):
         return succeed(True)
 
     def removeShare(self, request, share):
-        """ Remove a shared calendar named in resourceName """
+        """ Remove a shared calendar named in resourceName and send a decline """
         return self.declineShare(request, share.hosturl, share.inviteuid)
 
     def removeShareByUID(self, request, inviteuid):
-        """ Remove a shared calendar named in resourceName """
-        share = self.sharesDB().recordForInviteUID(inviteuid)
-        return self.removeShare(request, share) if share else succeed(None)
+        """ Remove a shared calendar but do not send a decline back """
+        self.sharesDB().removeRecordForInviteUID(inviteuid)
+        return succeed(True)
 
-    @updateCacheTokenOnCallback
+    @inlineCallbacks
     def declineShare(self, request, hostUrl, inviteUID):
 
         # Remove it if its in the DB
         self.sharesDB().removeRecordForInviteUID(inviteUID)
 
-        return self._changeShare(request, "DECLINED", hostUrl, inviteUID)
+        yield self._changeShare(request, "DECLINED", hostUrl, inviteUID)
+        
+        returnValue(Response(code=responsecode.NO_CONTENT))
 
     @inlineCallbacks
     def _changeShare(self, request, state, hostUrl, replytoUID, displayname=None):
@@ -885,9 +892,6 @@
 
     @updateCacheTokenOnCallback
     def xmlPOSTNoAuth(self, encoding, request):
-        def _handleResponse(result):
-            response = Response(code=responsecode.OK)
-            return response
 
         def _handleErrorResponse(error):
             if isinstance(error.value, HTTPError) and hasattr(error.value, "response"):
@@ -937,9 +941,10 @@
                 customxml.InviteReply: _handleInviteReply,          
             }
             if type(root) in xmlDocHanders:
-                return xmlDocHanders[type(root)](root).addCallbacks(_handleResponse, errback=_handleErrorResponse)
+                return xmlDocHanders[type(root)](root).addErrback(_handleErrorResponse)
             else:
-                return fail(True)
+                self.log_error("Unsupported XML (%s)" % (root,))
+                raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (customxml.calendarserver_namespace, "valid-request")))
 
         return allDataFromStream(request.stream).addCallback(_getData)
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100316/fa92cb32/attachment-0001.html>


More information about the calendarserver-changes mailing list