|
@@ -29,7 +29,6 @@ should have been included in this package.
|
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
import os
|
|
|
-import posixpath
|
|
|
|
|
import pprint
|
|
import pprint
|
|
|
import base64
|
|
import base64
|
|
|
import socket
|
|
import socket
|
|
@@ -151,28 +150,19 @@ class Application(object):
|
|
|
else:
|
|
else:
|
|
|
content = None
|
|
content = None
|
|
|
|
|
|
|
|
- # Find calendar
|
|
|
|
|
- attributes = posixpath.normpath(
|
|
|
|
|
- environ["PATH_INFO"].strip("/")).split("/")
|
|
|
|
|
- if attributes:
|
|
|
|
|
- if attributes[-1].endswith(".ics"):
|
|
|
|
|
- attributes.pop()
|
|
|
|
|
- path = "/".join(attributes[:min(len(attributes), 2)])
|
|
|
|
|
- calendar = ical.Calendar(path)
|
|
|
|
|
- else:
|
|
|
|
|
- calendar = None
|
|
|
|
|
|
|
+ # Find calendar(s)
|
|
|
|
|
+ items = ical.Calendar.from_path(environ["PATH_INFO"],
|
|
|
|
|
+ environ.get("HTTP_DEPTH", "0"))
|
|
|
|
|
|
|
|
# Get function corresponding to method
|
|
# Get function corresponding to method
|
|
|
function = getattr(self, environ["REQUEST_METHOD"].lower())
|
|
function = getattr(self, environ["REQUEST_METHOD"].lower())
|
|
|
|
|
|
|
|
# Check rights
|
|
# Check rights
|
|
|
- if not calendar or not self.acl:
|
|
|
|
|
|
|
+ if not items or not self.acl:
|
|
|
# No calendar or no acl, don't check rights
|
|
# No calendar or no acl, don't check rights
|
|
|
- status, headers, answer = function(environ, calendar, content)
|
|
|
|
|
|
|
+ status, headers, answer = function(environ, items, content)
|
|
|
else:
|
|
else:
|
|
|
# Ask authentication backend to check rights
|
|
# Ask authentication backend to check rights
|
|
|
- log.LOGGER.info(
|
|
|
|
|
- "Checking rights for calendar owned by %s" % calendar.owner)
|
|
|
|
|
authorization = environ.get("HTTP_AUTHORIZATION", None)
|
|
authorization = environ.get("HTTP_AUTHORIZATION", None)
|
|
|
|
|
|
|
|
if authorization:
|
|
if authorization:
|
|
@@ -182,11 +172,27 @@ class Application(object):
|
|
|
else:
|
|
else:
|
|
|
user = password = None
|
|
user = password = None
|
|
|
|
|
|
|
|
- if self.acl.has_right(calendar.owner, user, password):
|
|
|
|
|
- log.LOGGER.info("%s allowed" % (user or "anonymous user"))
|
|
|
|
|
- status, headers, answer = function(environ, calendar, content)
|
|
|
|
|
|
|
+ last_allowed = False
|
|
|
|
|
+ calendars = []
|
|
|
|
|
+ for calendar in items:
|
|
|
|
|
+ if not isinstance(calendar, ical.Calendar):
|
|
|
|
|
+ if last_allowed:
|
|
|
|
|
+ calendars.append(calendar)
|
|
|
|
|
+ continue
|
|
|
|
|
+ log.LOGGER.info(
|
|
|
|
|
+ "Checking rights for calendar owned by %s" % calendar.owner)
|
|
|
|
|
+
|
|
|
|
|
+ if self.acl.has_right(calendar.owner, user, password):
|
|
|
|
|
+ log.LOGGER.info("%s allowed" % (user or "anonymous user"))
|
|
|
|
|
+ calendars.append(calendar)
|
|
|
|
|
+ last_allowed = True
|
|
|
|
|
+ else:
|
|
|
|
|
+ log.LOGGER.info("%s refused" % (user or "anonymous user"))
|
|
|
|
|
+ last_allowed = False
|
|
|
|
|
+
|
|
|
|
|
+ if calendars:
|
|
|
|
|
+ status, headers, answer = function(environ, calendars, content)
|
|
|
else:
|
|
else:
|
|
|
- log.LOGGER.info("%s refused" % (user or "anonymous user"))
|
|
|
|
|
status = client.UNAUTHORIZED
|
|
status = client.UNAUTHORIZED
|
|
|
headers = {
|
|
headers = {
|
|
|
"WWW-Authenticate":
|
|
"WWW-Authenticate":
|
|
@@ -209,8 +215,9 @@ class Application(object):
|
|
|
# All these functions must have the same parameters, some are useless
|
|
# All these functions must have the same parameters, some are useless
|
|
|
# pylint: disable=W0612,W0613,R0201
|
|
# pylint: disable=W0612,W0613,R0201
|
|
|
|
|
|
|
|
- def get(self, environ, calendar, content):
|
|
|
|
|
|
|
+ def get(self, environ, calendars, content):
|
|
|
"""Manage GET request."""
|
|
"""Manage GET request."""
|
|
|
|
|
+ calendar = calendars[0]
|
|
|
item_name = xmlutils.name_from_path(environ["PATH_INFO"], calendar)
|
|
item_name = xmlutils.name_from_path(environ["PATH_INFO"], calendar)
|
|
|
if item_name:
|
|
if item_name:
|
|
|
# Get calendar item
|
|
# Get calendar item
|
|
@@ -235,13 +242,14 @@ class Application(object):
|
|
|
answer = answer_text.encode(self.encoding)
|
|
answer = answer_text.encode(self.encoding)
|
|
|
return client.OK, headers, answer
|
|
return client.OK, headers, answer
|
|
|
|
|
|
|
|
- def head(self, environ, calendar, content):
|
|
|
|
|
|
|
+ def head(self, environ, calendars, content):
|
|
|
"""Manage HEAD request."""
|
|
"""Manage HEAD request."""
|
|
|
- status, headers, answer = self.get(environ, calendar, content)
|
|
|
|
|
|
|
+ status, headers, answer = self.get(environ, calendars, content)
|
|
|
return status, headers, None
|
|
return status, headers, None
|
|
|
|
|
|
|
|
- def delete(self, environ, calendar, content):
|
|
|
|
|
|
|
+ def delete(self, environ, calendars, content):
|
|
|
"""Manage DELETE request."""
|
|
"""Manage DELETE request."""
|
|
|
|
|
+ calendar = calendars[0]
|
|
|
item = calendar.get_item(
|
|
item = calendar.get_item(
|
|
|
xmlutils.name_from_path(environ["PATH_INFO"], calendar))
|
|
xmlutils.name_from_path(environ["PATH_INFO"], calendar))
|
|
|
if item and environ.get("HTTP_IF_MATCH", item.etag) == item.etag:
|
|
if item and environ.get("HTTP_IF_MATCH", item.etag) == item.etag:
|
|
@@ -254,8 +262,9 @@ class Application(object):
|
|
|
status = client.PRECONDITION_FAILED
|
|
status = client.PRECONDITION_FAILED
|
|
|
return status, {}, answer
|
|
return status, {}, answer
|
|
|
|
|
|
|
|
- def mkcalendar(self, environ, calendar, content):
|
|
|
|
|
|
|
+ def mkcalendar(self, environ, calendars, content):
|
|
|
"""Manage MKCALENDAR request."""
|
|
"""Manage MKCALENDAR request."""
|
|
|
|
|
+ calendar = calendars[0]
|
|
|
props = xmlutils.props_from_request(content)
|
|
props = xmlutils.props_from_request(content)
|
|
|
tz = props.get('C:calendar-timezone')
|
|
tz = props.get('C:calendar-timezone')
|
|
|
if tz:
|
|
if tz:
|
|
@@ -267,7 +276,7 @@ class Application(object):
|
|
|
calendar.write()
|
|
calendar.write()
|
|
|
return client.CREATED, {}, None
|
|
return client.CREATED, {}, None
|
|
|
|
|
|
|
|
- def options(self, environ, calendar, content):
|
|
|
|
|
|
|
+ def options(self, environ, calendars, content):
|
|
|
"""Manage OPTIONS request."""
|
|
"""Manage OPTIONS request."""
|
|
|
headers = {
|
|
headers = {
|
|
|
"Allow": "DELETE, HEAD, GET, MKCALENDAR, " \
|
|
"Allow": "DELETE, HEAD, GET, MKCALENDAR, " \
|
|
@@ -275,26 +284,27 @@ class Application(object):
|
|
|
"DAV": "1, calendar-access"}
|
|
"DAV": "1, calendar-access"}
|
|
|
return client.OK, headers, None
|
|
return client.OK, headers, None
|
|
|
|
|
|
|
|
- def propfind(self, environ, calendar, content):
|
|
|
|
|
|
|
+ def propfind(self, environ, calendars, content):
|
|
|
"""Manage PROPFIND request."""
|
|
"""Manage PROPFIND request."""
|
|
|
headers = {
|
|
headers = {
|
|
|
"DAV": "1, calendar-access",
|
|
"DAV": "1, calendar-access",
|
|
|
"Content-Type": "text/xml"}
|
|
"Content-Type": "text/xml"}
|
|
|
answer = xmlutils.propfind(
|
|
answer = xmlutils.propfind(
|
|
|
- environ["PATH_INFO"], content, calendar,
|
|
|
|
|
- environ.get("HTTP_DEPTH", "infinity"))
|
|
|
|
|
|
|
+ environ["PATH_INFO"], content, calendars)
|
|
|
return client.MULTI_STATUS, headers, answer
|
|
return client.MULTI_STATUS, headers, answer
|
|
|
|
|
|
|
|
- def proppatch(self, environ, calendar, content):
|
|
|
|
|
|
|
+ def proppatch(self, environ, calendars, content):
|
|
|
"""Manage PROPPATCH request."""
|
|
"""Manage PROPPATCH request."""
|
|
|
|
|
+ calendar = calendars[0]
|
|
|
answer = xmlutils.proppatch(environ["PATH_INFO"], content, calendar)
|
|
answer = xmlutils.proppatch(environ["PATH_INFO"], content, calendar)
|
|
|
headers = {
|
|
headers = {
|
|
|
"DAV": "1, calendar-access",
|
|
"DAV": "1, calendar-access",
|
|
|
"Content-Type": "text/xml"}
|
|
"Content-Type": "text/xml"}
|
|
|
return client.MULTI_STATUS, headers, answer
|
|
return client.MULTI_STATUS, headers, answer
|
|
|
|
|
|
|
|
- def put(self, environ, calendar, content):
|
|
|
|
|
|
|
+ def put(self, environ, calendars, content):
|
|
|
"""Manage PUT request."""
|
|
"""Manage PUT request."""
|
|
|
|
|
+ calendar = calendars[0]
|
|
|
headers = {}
|
|
headers = {}
|
|
|
item_name = xmlutils.name_from_path(environ["PATH_INFO"], calendar)
|
|
item_name = xmlutils.name_from_path(environ["PATH_INFO"], calendar)
|
|
|
item = calendar.get_item(item_name)
|
|
item = calendar.get_item(item_name)
|
|
@@ -312,8 +322,10 @@ class Application(object):
|
|
|
status = client.PRECONDITION_FAILED
|
|
status = client.PRECONDITION_FAILED
|
|
|
return status, headers, None
|
|
return status, headers, None
|
|
|
|
|
|
|
|
- def report(self, environ, calendar, content):
|
|
|
|
|
|
|
+ def report(self, environ, calendars, content):
|
|
|
"""Manage REPORT request."""
|
|
"""Manage REPORT request."""
|
|
|
|
|
+ # TODO: support multiple calendars here
|
|
|
|
|
+ calendar = calendars[0]
|
|
|
headers = {'Content-Type': 'text/xml'}
|
|
headers = {'Content-Type': 'text/xml'}
|
|
|
answer = xmlutils.report(environ["PATH_INFO"], content, calendar)
|
|
answer = xmlutils.report(environ["PATH_INFO"], content, calendar)
|
|
|
return client.MULTI_STATUS, headers, answer
|
|
return client.MULTI_STATUS, headers, answer
|