Enhance collection discovering

When the request path leads to a non-existing item, try to create the
Collection object according to an existing collection at request path's
parent.

This change means that the requests whose path leads to a collection
that doesn't exist (at least MKCOL, MKCALENDAR and PUT) need to rely on
the request path more than on the Collection path. It was already done
for PUT, it's been fixed for MKCOL and MKCALENDAR.

Fix #378.
This commit is contained in:
Guillaume Ayoub 2016-04-19 10:39:52 +09:00
parent 65659fc909
commit 6adc7f5fed
2 changed files with 11 additions and 4 deletions

View File

@ -430,7 +430,7 @@ class Application(object):
# TODO: use this? # TODO: use this?
# timezone = props.get("C:calendar-timezone") # timezone = props.get("C:calendar-timezone")
collection = storage.Collection.create_collection( collection = storage.Collection.create_collection(
collection.path, tag="VCALENDAR") environ["PATH_INFO"], tag="VCALENDAR")
for key, value in props.items(): for key, value in props.items():
collection.set_meta(key, value) collection.set_meta(key, value)
return client.CREATED, {}, None return client.CREATED, {}, None
@ -444,7 +444,7 @@ class Application(object):
collection = write_collections[0] collection = write_collections[0]
props = xmlutils.props_from_request(content) props = xmlutils.props_from_request(content)
collection = storage.Collection.create_collection(collection.path) collection = storage.Collection.create_collection(environ["PATH_INFO"])
for key, value in props.items(): for key, value in props.items():
collection.set_meta(key, value) collection.set_meta(key, value)
return client.CREATED, {}, None return client.CREATED, {}, None

View File

@ -175,8 +175,15 @@ class Collection:
return return
# Try to guess if the path leads to a collection or an item # Try to guess if the path leads to a collection or an item
if not os.path.isdir(path_to_filesystem(FOLDER, sane_path)):
# path is not a collection
if os.path.isfile(path_to_filesystem(FOLDER, sane_path)): if os.path.isfile(path_to_filesystem(FOLDER, sane_path)):
# path is an item
attributes.pop() attributes.pop()
elif os.path.isdir(path_to_filesystem(FOLDER, *attributes[:-1])):
# path parent is a collection
attributes.pop()
# TODO: else: return?
path = "/".join(attributes) path = "/".join(attributes)