[CalendarServer-changes] [11033] CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Fri Apr 12 11:59:06 PDT 2013
Revision: 11033
http://trac.calendarserver.org//changeset/11033
Author: cdaboo at apple.com
Date: 2013-04-12 11:59:06 -0700 (Fri, 12 Apr 2013)
Log Message:
-----------
POST;add-member uses the new api.
Modified Paths:
--------------
CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/method/post.py
CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/storebridge.py
Modified: CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/method/post.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/method/post.py 2013-04-12 18:26:01 UTC (rev 11032)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/method/post.py 2013-04-12 18:59:06 UTC (rev 11033)
@@ -14,30 +14,18 @@
# limitations under the License.
# #
-from hashlib import md5
-from twext.web2.dav.http import ErrorResponse
-from twext.web2.dav.util import allDataFromStream, joinURL
-from twext.web2.filter.location import addLocation
-from twext.web2.http import HTTPError, StatusResponse
-
-from twistedcaldav.caldavxml import caldav_namespace
-from twistedcaldav.carddavxml import carddav_namespace
-from twistedcaldav.method.put_addressbook_common import StoreAddressObjectResource
-from twistedcaldav.method.put_common import StoreCalendarObjectResource
-
-import time
-
"""
CalDAV POST method.
"""
__all__ = ["http_POST"]
-from twisted.internet.defer import inlineCallbacks, returnValue
-
from twext.web2 import responsecode
+from twext.web2.http import StatusResponse
+from twisted.internet.defer import inlineCallbacks, returnValue
+
from twistedcaldav.config import config
@inlineCallbacks
@@ -48,8 +36,8 @@
# First look at query params
if request.params:
if request.params == "add-member":
- if config.EnableAddMember:
- result = (yield POST_handler_add_member(self, request))
+ if config.EnableAddMember and hasattr(self, "POST_handler_add_member"):
+ result = (yield self.POST_handler_add_member(request))
returnValue(result)
# Look for query arguments
@@ -73,147 +61,3 @@
returnValue(result)
returnValue(responsecode.FORBIDDEN)
-
-
-
- at inlineCallbacks
-def POST_handler_add_member(self, request):
-
- # Handle ;add-member
- if self.isCalendarCollection():
-
- parentURL = request.path
- parent = self
-
- # Content-type check
- content_type = request.headers.getHeader("content-type")
- if content_type is not None and (content_type.mediaType, content_type.mediaSubtype) != ("text", "calendar"):
- self.log_error("MIME type %s not allowed in calendar collection" % (content_type,))
- raise HTTPError(ErrorResponse(
- responsecode.FORBIDDEN,
- (caldav_namespace, "supported-calendar-data"),
- "Wrong MIME type for calendar collection",
- ))
-
- # Read the calendar component from the stream
- try:
- calendardata = (yield allDataFromStream(request.stream))
- if not hasattr(request, "extendedLogItems"):
- request.extendedLogItems = {}
- request.extendedLogItems["cl"] = str(len(calendardata)) if calendardata else "0"
-
- # We must have some data at this point
- if calendardata is None:
- # Use correct DAV:error response
- raise HTTPError(ErrorResponse(
- responsecode.FORBIDDEN,
- (caldav_namespace, "valid-calendar-data"),
- description="No calendar data"
- ))
-
- # Create a new name if one was not provided
- name = md5(str(calendardata) + str(time.time()) + request.path).hexdigest() + ".ics"
-
- # Get a resource for the new item
- newchildURL = joinURL(parentURL, name)
- newchild = (yield request.locateResource(newchildURL))
-
- storer = StoreCalendarObjectResource(
- request=request,
- destination=newchild,
- destination_uri=newchildURL,
- destinationcal=True,
- destinationparent=parent,
- calendar=calendardata,
- )
- result = (yield storer.run())
-
- # May need to add a location header
- addLocation(request, request.unparseURL(path=newchildURL, params=""))
-
- # Look for Prefer header
- prefer = request.headers.getHeader("prefer", {})
- returnRepresentation = any([key == "return" and value == "representation" for key, value, _ignore_args in prefer])
-
- if returnRepresentation and result.code / 100 == 2:
- result = (yield newchild.http_GET(request))
- result.code = responsecode.CREATED
- result.headers.removeHeader("content-location")
- result.headers.setHeader("content-location", newchildURL)
-
- returnValue(result)
-
- except ValueError, e:
- self.log_error("Error while handling (calendar) POST: %s" % (e,))
- raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(e)))
-
- elif self.isAddressBookCollection():
-
- parentURL = request.path
- parent = self
-
- # Content-type check
- content_type = request.headers.getHeader("content-type")
- if content_type is not None and (content_type.mediaType, content_type.mediaSubtype) != ("text", "vcard"):
- self.log_error("MIME type %s not allowed in address book collection" % (content_type,))
- raise HTTPError(ErrorResponse(
- responsecode.FORBIDDEN,
- (carddav_namespace, "supported-address-data"),
- "Wrong MIME type for address book collection",
- ))
-
- # Read the calendar component from the stream
- try:
- vcarddata = (yield allDataFromStream(request.stream))
- if not hasattr(request, "extendedLogItems"):
- request.extendedLogItems = {}
- request.extendedLogItems["cl"] = str(len(vcarddata)) if vcarddata else "0"
-
- # We must have some data at this point
- if vcarddata is None:
- # Use correct DAV:error response
- raise HTTPError(ErrorResponse(
- responsecode.FORBIDDEN,
- (carddav_namespace, "valid-address-data"),
- description="No address data"
- ))
-
- # Create a new name if one was not provided
- name = md5(str(vcarddata) + str(time.time()) + request.path).hexdigest() + ".vcf"
-
- # Get a resource for the new item
- newchildURL = joinURL(parentURL, name)
- newchild = (yield request.locateResource(newchildURL))
-
- storer = StoreAddressObjectResource(
- request=request,
- sourceadbk=False,
- destination=newchild,
- destination_uri=newchildURL,
- destinationadbk=True,
- destinationparent=parent,
- vcard=vcarddata,
- )
- result = (yield storer.run())
-
- # May need to add a location header
- addLocation(request, request.unparseURL(path=newchildURL, params=""))
-
- # Look for Prefer header
- prefer = request.headers.getHeader("prefer", {})
- returnRepresentation = any([key == "return" and value == "representation" for key, value, _ignore_args in prefer])
-
- if returnRepresentation and result.code / 100 == 2:
- result = (yield newchild.http_GET(request))
- result.code = responsecode.CREATED
- result.headers.removeHeader("content-location")
- result.headers.setHeader("content-location", newchildURL)
-
- returnValue(result)
-
- except ValueError, e:
- self.log_error("Error while handling (calendar) POST: %s" % (e,))
- raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(e)))
-
- # Default behavior
- returnValue(responsecode.FORBIDDEN)
Modified: CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/storebridge.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/storebridge.py 2013-04-12 18:26:01 UTC (rev 11032)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/storebridge.py 2013-04-12 18:59:06 UTC (rev 11033)
@@ -322,6 +322,7 @@
similar = self._childClass(
newStoreObject,
self._newStoreObject,
+ self,
name,
principalCollections=self._principalCollections
)
@@ -556,6 +557,32 @@
@inlineCallbacks
+ def POST_handler_add_member(self, request):
+ """
+ Handle a POST ;add-member request on this collection
+
+ @param request: the request object
+ @type request: L{Request}
+ """
+
+ # Create a name for the new child
+ name = str(uuid.uuid4()) + self.resourceSuffix()
+
+ # Get a resource for the new child
+ parentURL = request.path
+ newchildURL = joinURL(parentURL, name)
+ newchild = (yield request.locateResource(newchildURL))
+
+ # Treat as if it were a regular PUT to a new resource
+ response = (yield newchild.http_PUT(request))
+
+ # May need to add a location header
+ addLocation(request, request.unparseURL(path=newchildURL, params=""))
+
+ returnValue(response)
+
+
+ @inlineCallbacks
def _readGlobalProperty(self, qname, prop, request):
if config.EnableBatchUpload and qname == customxml.BulkRequests.qname():
@@ -2116,7 +2143,7 @@
_componentFromStream = None
- def __init__(self, storeObject, parentObject, name, *args, **kw):
+ def __init__(self, storeObject, parentObject, parentResource, name, *args, **kw):
"""
Construct a L{_CommonObjectResource} from an L{CommonObjectResource}.
@@ -2125,6 +2152,7 @@
"""
super(_CommonObjectResource, self).__init__(*args, **kw)
self._initializeWithObject(storeObject, parentObject)
+ self._parentResource = parentResource
self._name = name
self._metadata = {}
@@ -2137,6 +2165,10 @@
) if self._newStoreObject and self._newStoreParent.objectResourcesHaveProperties() else NonePropertyStore(self)
+ def url(self):
+ return joinURL(self._parentResource.url(), self.name())
+
+
def isCollection(self):
return False
@@ -2563,7 +2595,8 @@
response = (yield self.http_GET(request))
if oldcode == responsecode.CREATED:
response.code = responsecode.CREATED
- response.headers.setHeader("content-location", request.path)
+ response.headers.removeHeader("content-location")
+ response.headers.setHeader("content-location", self.url())
returnValue(response)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130412/12c7b53b/attachment-0001.html>
More information about the calendarserver-changes
mailing list