[CalendarServer-changes] [374] CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Fri Nov 3 19:50:26 PST 2006


Revision: 374
          http://trac.macosforge.org/projects/calendarserver/changeset/374
Author:   cdaboo at apple.com
Date:     2006-11-03 19:50:25 -0800 (Fri, 03 Nov 2006)

Log Message:
-----------
Updated subscribe/unsubscribe. Switch to apple.com namespace for these extensions. Probably should do the same for
all elements in customxml.py.

Modified Paths:
--------------
    CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/customxml.py
    CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/dropbox.py
    CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/method/__init__.py
    CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/notifications.py

Added Paths:
-----------
    CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/method/x_apple_subscribe.py
    CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/method/x_apple_unsubscribe.py

Modified: CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/customxml.py
===================================================================
--- CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/customxml.py	2006-11-04 03:35:06 UTC (rev 373)
+++ CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/customxml.py	2006-11-04 03:50:25 UTC (rev 374)
@@ -28,6 +28,8 @@
 from twisted.web2.dav.resource import twisted_dav_namespace
 from twisted.web2.dav import davxml
 
+apple_namespace = "http://apple.com/ns/calendarserver/"
+
 class TwistedGUIDProperty (davxml.WebDAVTextElement):
     """
     Contains the GUID value for a directory record corresponding to a principal.
@@ -84,7 +86,7 @@
     Denotes a drop box home collection (a collection that will contain drop boxes).
     (Apple Extension to CalDAV)
     """
-    namespace = twisted_dav_namespace
+    namespace = apple_namespace
     name = "dropbox-home"
 
 class DropBox (davxml.WebDAVEmptyElement):
@@ -92,7 +94,7 @@
     Denotes a drop box collection.
     (Apple Extension to CalDAV)
     """
-    namespace = twisted_dav_namespace
+    namespace = apple_namespace
     name = "dropbox"
 
 class Notifications (davxml.WebDAVEmptyElement):
@@ -100,7 +102,7 @@
     Denotes a notifications collection.
     (Apple Extension to CalDAV)
     """
-    namespace = twisted_dav_namespace
+    namespace = apple_namespace
     name = "notifications"
 
 class DropBoxHomeURL (davxml.WebDAVElement):
@@ -108,7 +110,7 @@
     A principal property to indicate the location of the drop box home.
     (Apple Extension to CalDAV)
     """
-    namespace = twisted_dav_namespace
+    namespace = apple_namespace
     name = "dropbox-home-URL"
     hidden = True
     protected = True
@@ -120,7 +122,7 @@
     A principal property to indicate the location of the notification collection.
     (Apple Extension to CalDAV)
     """
-    namespace = twisted_dav_namespace
+    namespace = apple_namespace
     name = "notifications-URL"
     hidden = True
     protected = True
@@ -131,17 +133,17 @@
     """
     Root element for XML data in a notification resource.
     """
-    namespace = twisted_dav_namespace
+    namespace = apple_namespace
     name = "notification"
 
     allowed_children = {
-        (twisted_dav_namespace, "action"     ): (1, 1),
-        (twisted_dav_namespace, "time-stamp" ): (1, 1),
-        (twisted_dav_namespace, "auth-id"    ): (0, 1),
-        (twisted_dav_namespace, "old-uri"    ): (0, 1),
-        (twisted_dav_namespace, "new-uri"    ): (0, 1),
-        (twisted_dav_namespace, "old-etag"   ): (0, 1),
-        (twisted_dav_namespace, "new-etag"   ): (0, 1),
+        (apple_namespace, "action"     ): (1, 1),
+        (apple_namespace, "time-stamp" ): (1, 1),
+        (apple_namespace, "auth-id"    ): (0, 1),
+        (apple_namespace, "old-uri"    ): (0, 1),
+        (apple_namespace, "new-uri"    ): (0, 1),
+        (apple_namespace, "old-etag"   ): (0, 1),
+        (apple_namespace, "new-etag"   ): (0, 1),
     }
 
 class Action (davxml.WebDAVElement):
@@ -149,19 +151,19 @@
     A property to indicate the action of a notification resource.
     (Apple Extension to CalDAV)
     """
-    namespace = twisted_dav_namespace
+    namespace = apple_namespace
     name = "action"
     hidden = True
     protected = True
 
     allowed_children = {
-        (twisted_dav_namespace, "created"    ): (0, 1),
-        (twisted_dav_namespace, "modified"   ): (0, 1),
-        (twisted_dav_namespace, "deleted"    ): (0, 1),
-        (twisted_dav_namespace, "copiedto"   ): (0, 1),
-        (twisted_dav_namespace, "copiedfrom" ): (0, 1),
-        (twisted_dav_namespace, "movedout"   ): (0, 1),
-        (twisted_dav_namespace, "movedin"    ): (0, 1),
+        (apple_namespace, "created"    ): (0, 1),
+        (apple_namespace, "modified"   ): (0, 1),
+        (apple_namespace, "deleted"    ): (0, 1),
+        (apple_namespace, "copiedto"   ): (0, 1),
+        (apple_namespace, "copiedfrom" ): (0, 1),
+        (apple_namespace, "movedout"   ): (0, 1),
+        (apple_namespace, "movedin"    ): (0, 1),
     }
 
 class Created (davxml.WebDAVEmptyElement):
@@ -169,7 +171,7 @@
     A property value to indicate the created action of a notification resource.
     (Apple Extension to CalDAV)
     """
-    namespace = twisted_dav_namespace
+    namespace = apple_namespace
     name = "created"
 
 class Modified (davxml.WebDAVEmptyElement):
@@ -177,7 +179,7 @@
     A property value to indicate the modified action of a notification resource.
     (Apple Extension to CalDAV)
     """
-    namespace = twisted_dav_namespace
+    namespace = apple_namespace
     name = "modified"
 
 class Deleted (davxml.WebDAVEmptyElement):
@@ -185,7 +187,7 @@
     A property value to indicate the deleted action of a notification resource.
     (Apple Extension to CalDAV)
     """
-    namespace = twisted_dav_namespace
+    namespace = apple_namespace
     name = "deleted"
 
 class CopiedTo (davxml.WebDAVEmptyElement):
@@ -193,7 +195,7 @@
     A property value to indicate the copied to action of a notification resource.
     (Apple Extension to CalDAV)
     """
-    namespace = twisted_dav_namespace
+    namespace = apple_namespace
     name = "copiedto"
 
 class CopiedFrom (davxml.WebDAVEmptyElement):
@@ -201,7 +203,7 @@
     A property value to indicate the copied from action of a notification resource.
     (Apple Extension to CalDAV)
     """
-    namespace = twisted_dav_namespace
+    namespace = apple_namespace
     name = "copiedfrom"
 
 class MovedTo (davxml.WebDAVEmptyElement):
@@ -209,7 +211,7 @@
     A property value to indicate the moved to action of a notification resource.
     (Apple Extension to CalDAV)
     """
-    namespace = twisted_dav_namespace
+    namespace = apple_namespace
     name = "movedto"
 
 class MovedFrom (davxml.WebDAVEmptyElement):
@@ -217,7 +219,7 @@
     A property value to indicate the moved from action of a notification resource.
     (Apple Extension to CalDAV)
     """
-    namespace = twisted_dav_namespace
+    namespace = apple_namespace
     name = "movedfrom"
 
 class TimeStamp (davxml.WebDAVTextElement):
@@ -225,7 +227,7 @@
     A property to indicate the timestamp of a notification resource.
     (Apple Extension to CalDAV)
     """
-    namespace = twisted_dav_namespace
+    namespace = apple_namespace
     name = "time-stamp"
     hidden = True
     protected = True
@@ -235,7 +237,7 @@
     A property to indicate the authorization identitifer of a notification resource.
     (Apple Extension to CalDAV)
     """
-    namespace = twisted_dav_namespace
+    namespace = apple_namespace
     name = "auth-id"
     hidden = True
     protected = True
@@ -245,7 +247,7 @@
     A property to indicate the old URI of a notification resource.
     (Apple Extension to CalDAV)
     """
-    namespace = twisted_dav_namespace
+    namespace = apple_namespace
     name = "old-uri"
     hidden = True
     protected = True
@@ -257,7 +259,7 @@
     A property to indicate the new URI of a notification resource.
     (Apple Extension to CalDAV)
     """
-    namespace = twisted_dav_namespace
+    namespace = apple_namespace
     name = "new-uri"
     hidden = True
     protected = True
@@ -269,7 +271,7 @@
     A property to indicate the old ETag of a notification resource.
     (Apple Extension to CalDAV)
     """
-    namespace = twisted_dav_namespace
+    namespace = apple_namespace
     name = "old-etag"
     hidden = True
     protected = True
@@ -279,7 +281,7 @@
     A property to indicate the new ETag of a notification resource.
     (Apple Extension to CalDAV)
     """
-    namespace = twisted_dav_namespace
+    namespace = apple_namespace
     name = "new-etag"
     hidden = True
     protected = True
@@ -289,7 +291,7 @@
     A property to indicate which principals will receive notifications.
     (Apple Extension to CalDAV)
     """
-    namespace = twisted_dav_namespace
+    namespace = apple_namespace
     name = "subscribed"
     hidden = True
     protected = True

Modified: CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/dropbox.py
===================================================================
--- CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/dropbox.py	2006-11-04 03:35:06 UTC (rev 373)
+++ CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/dropbox.py	2006-11-04 03:50:25 UTC (rev 374)
@@ -25,10 +25,8 @@
     "DropBox",
 ]
 
-from twisted.web2.dav.resource import twisted_dav_namespace
+from twistedcaldav.customxml import davxml, apple_namespace
 
-from twistedcaldav.customxml import davxml
-
 import os
 
 class DropBox(object):
@@ -69,12 +67,12 @@
 
             # Need to setup live properties
             from twistedcaldav.resource import CalendarPrincipalResource
-            assert (twisted_dav_namespace, "dropbox-home-URL") not in CalendarPrincipalResource.liveProperties, \
+            assert (apple_namespace, "dropbox-home-URL") not in CalendarPrincipalResource.liveProperties, \
                 "DropBox.enable must only be called once"
 
             CalendarPrincipalResource.liveProperties += (
-                (twisted_dav_namespace, "dropbox-home-URL"  ),
-                (twisted_dav_namespace, "notifications-URL" ),
+                (apple_namespace, "dropbox-home-URL"  ),
+                (apple_namespace, "notifications-URL" ),
             )
 
     @classmethod

Modified: CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/method/__init__.py
===================================================================
--- CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/method/__init__.py	2006-11-04 03:35:06 UTC (rev 373)
+++ CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/method/__init__.py	2006-11-04 03:50:25 UTC (rev 374)
@@ -36,6 +36,6 @@
     "report_multiget",
     "report_freebusy",
     "schedule_common",
-    "x_twisted_subscribe",
-    "x_twisted_unsubscribe",
+    "x_apple_subscribe",
+    "x_apple_unsubscribe",
 ]

Added: CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/method/x_apple_subscribe.py
===================================================================
--- CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/method/x_apple_subscribe.py	                        (rev 0)
+++ CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/method/x_apple_subscribe.py	2006-11-04 03:50:25 UTC (rev 374)
@@ -0,0 +1,70 @@
+##
+# Copyright (c) 2005-2006 Apple Computer, Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# DRI: Cyrus Daboo, cdaboo at apple.com
+##
+
+"""
+CalDAV X_APPLE_SUBSCRIBE method.
+"""
+
+__all__ = ["http_X_APPLE_SUBSCRIBE"]
+
+from twisted.internet.defer import deferredGenerator, waitForDeferred
+from twisted.python import log
+from twisted.web2 import responsecode
+from twisted.web2.dav import davxml
+from twisted.web2.dav.element.base import twisted_dav_namespace
+from twisted.web2.dav.http import ErrorResponse
+from twisted.web2.http import HTTPError, StatusResponse
+
+from twistedcaldav import customxml
+from twistedcaldav.dropbox import DropBox
+
+def http_X_APPLE_SUBSCRIBE(self, request):
+    
+    # Only for drop box collections
+    if not DropBox.enabled or not self.isSpecialCollection(customxml.DropBox):
+        log.err("Cannot x-apple-subscribe to resource %s" % (request.uri,))
+        raise HTTPError(StatusResponse(
+            responsecode.FORBIDDEN,
+            "Cannot x-apple-subscribe to resource %s" % (request.uri,))
+        )
+
+    d = waitForDeferred(self.authorize(request, (davxml.Read(),)))
+    yield d
+    d.getResult()
+    authid = request.authnUser
+    
+    # Get current list of subscribed principals
+    principals = []
+    if self.hasDeadProperty(customxml.Subscribed):
+        subs = self.readDeadProperty(customxml.Subscribed).children
+        principals.extend(subs)
+    
+    # Error if attempt to subscribe more than once
+    if authid in principals:
+        log.err("Cannot x_apple_subscribe to resource %s as principal %s is already subscribed" % (request.uri, repr(authid),))
+        raise HTTPError(ErrorResponse(
+            responsecode.FORBIDDEN,
+            (twisted_dav_namespace, "principal-must-not-be-subscribed"))
+        )
+
+    principals.append(authid)
+    self.writeDeadProperty(customxml.Subscribed(*principals))
+
+    yield responsecode.OK
+
+http_X_APPLE_SUBSCRIBE = deferredGenerator(http_X_APPLE_SUBSCRIBE)

Added: CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/method/x_apple_unsubscribe.py
===================================================================
--- CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/method/x_apple_unsubscribe.py	                        (rev 0)
+++ CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/method/x_apple_unsubscribe.py	2006-11-04 03:50:25 UTC (rev 374)
@@ -0,0 +1,71 @@
+##
+# Copyright (c) 2005-2006 Apple Computer, Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# DRI: Cyrus Daboo, cdaboo at apple.com
+##
+
+"""
+CalDAV X_APPLE_UNSUBSCRIBE method.
+"""
+
+__all__ = ["http_X_APPLE_UNSUBSCRIBE"]
+
+from twisted.internet.defer import deferredGenerator, waitForDeferred
+from twisted.python import log
+from twisted.web2 import responsecode
+from twisted.web2.dav.element.base import twisted_dav_namespace
+from twisted.web2.dav.http import ErrorResponse
+from twisted.web2.http import HTTPError, StatusResponse
+
+from twistedcaldav import customxml
+from twistedcaldav.dropbox import DropBox
+
+def http_X_APPLE_UNSUBSCRIBE(self, request):
+    
+    # Only for drop box collections
+    if not DropBox.enabled or not self.isSpecialCollection(customxml.DropBox):
+        log.err("Cannot x_apple_unsubscribe to resource %s" % (request.uri,))
+        raise HTTPError(StatusResponse(
+            responsecode.FORBIDDEN,
+            "Cannot x_apple_unsubscribe to resource %s" % (request.uri,))
+        )
+
+    # We do not check any privileges. If a principal is subscribed we always allow them to
+    # unsubscribe provided they have at least authenticated.
+    d = waitForDeferred(self.authorize(request, ()))
+    yield d
+    d.getResult()
+    authid = request.authnUser
+    
+    # Get current list of subscribed principals
+    principals = []
+    if self.hasDeadProperty(customxml.Subscribed):
+        subs = self.readDeadProperty(customxml.Subscribed).children
+        principals.extend(subs)
+    
+    # Error if attempt to subscribe more than once
+    if authid not in principals:
+        log.err("Cannot x_apple_unsubscribe from resource %s as principal %s is not currently subscribed" % (request.uri, repr(authid),))
+        raise HTTPError(ErrorResponse(
+            responsecode.FORBIDDEN,
+            (twisted_dav_namespace, "principal-must-be-subscribed"))
+        )
+
+    principals.remove(authid)
+    self.writeDeadProperty(customxml.Subscribed(*principals))
+
+    yield responsecode.OK
+
+http_X_APPLE_UNSUBSCRIBE = deferredGenerator(http_X_APPLE_UNSUBSCRIBE)

Modified: CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/notifications.py
===================================================================
--- CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/notifications.py	2006-11-04 03:35:06 UTC (rev 373)
+++ CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/notifications.py	2006-11-04 03:50:25 UTC (rev 374)
@@ -15,14 +15,16 @@
 #
 # DRI: Cyrus Daboo, cdaboo at apple.com
 ##
-from twistedcaldav.extensions import DAVFile
+
 from twisted.internet.defer import deferredGenerator
 from twisted.internet.defer import waitForDeferred
 from twisted.web2.dav.method import put_common
 from twisted.web2.dav.resource import DAVPrincipalResource
 from twisted.web2.dav import davxml
+
 from twistedcaldav import customxml
-from twisted.web2.dav.element.base import twisted_dav_namespace
+from twistedcaldav.customxml import apple_namespace
+from twistedcaldav.extensions import DAVFile
 from twistedcaldav.extensions import DAVResource
 
 import datetime
@@ -162,13 +164,13 @@
     """
 
     liveProperties = DAVResource.liveProperties + (
-        (twisted_dav_namespace, "action"      ),
-        (twisted_dav_namespace, "time-stamp"  ),
-        (twisted_dav_namespace, "auth-id"     ),
-        (twisted_dav_namespace, "old-uri"     ),
-        (twisted_dav_namespace, "new-uri"     ),
-        (twisted_dav_namespace, "old-etag"    ),
-        (twisted_dav_namespace, "new-etag"    ),
+        (apple_namespace, "action"      ),
+        (apple_namespace, "time-stamp"  ),
+        (apple_namespace, "auth-id"     ),
+        (apple_namespace, "old-uri"     ),
+        (apple_namespace, "new-uri"     ),
+        (apple_namespace, "old-etag"    ),
+        (apple_namespace, "new-etag"    ),
     )
 
 class NotificationFile(DAVResource, DAVFile):

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20061103/80237d17/attachment.html


More information about the calendarserver-changes mailing list