Don't use the environ user variable, pass user to all the methods functions

This commit is contained in:
Guillaume Ayoub 2011-06-30 18:22:47 +02:00
parent 3d7f07dc0c
commit d17e8fa990

View File

@ -176,7 +176,7 @@ class Application(object):
# Check rights # Check rights
if not items 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, items, content) status, headers, answer = function(environ, items, content, None)
else: else:
# Ask authentication backend to check rights # Ask authentication backend to check rights
authorization = environ.get("HTTP_AUTHORIZATION", None) authorization = environ.get("HTTP_AUTHORIZATION", None)
@ -185,7 +185,6 @@ class Application(object):
auth = authorization.lstrip("Basic").strip().encode("ascii") auth = authorization.lstrip("Basic").strip().encode("ascii")
user, password = self.decode( user, password = self.decode(
base64.b64decode(auth), environ).split(":") base64.b64decode(auth), environ).split(":")
environ['USER'] = user
else: else:
user = password = None user = password = None
@ -216,7 +215,8 @@ class Application(object):
last_allowed = False last_allowed = False
if calendars: if calendars:
status, headers, answer = function(environ, calendars, content) status, headers, answer = function(
environ, calendars, content, user)
else: else:
status = client.UNAUTHORIZED status = client.UNAUTHORIZED
headers = { headers = {
@ -240,7 +240,7 @@ 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 delete(self, environ, calendars, content): def delete(self, environ, calendars, content, user):
"""Manage DELETE request.""" """Manage DELETE request."""
calendar = calendars[0] calendar = calendars[0]
item = calendar.get_item( item = calendar.get_item(
@ -255,7 +255,7 @@ class Application(object):
status = client.PRECONDITION_FAILED status = client.PRECONDITION_FAILED
return status, {}, answer return status, {}, answer
def get(self, environ, calendars, content): def get(self, environ, calendars, content, user):
"""Manage GET request.""" """Manage GET request."""
calendar = calendars[0] calendar = calendars[0]
item_name = xmlutils.name_from_path(environ["PATH_INFO"], calendar) item_name = xmlutils.name_from_path(environ["PATH_INFO"], calendar)
@ -282,12 +282,12 @@ 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, calendars, content): def head(self, environ, calendars, content, user):
"""Manage HEAD request.""" """Manage HEAD request."""
status, headers, answer = self.get(environ, calendars, content) status, headers, answer = self.get(environ, calendars, content)
return status, headers, None return status, headers, None
def mkcalendar(self, environ, calendars, content): def mkcalendar(self, environ, calendars, content, user):
"""Manage MKCALENDAR request.""" """Manage MKCALENDAR request."""
calendar = calendars[0] calendar = calendars[0]
props = xmlutils.props_from_request(content) props = xmlutils.props_from_request(content)
@ -301,7 +301,7 @@ class Application(object):
calendar.write() calendar.write()
return client.CREATED, {}, None return client.CREATED, {}, None
def move(self, environ, calendars, content): def move(self, environ, calendars, content, user):
"""Manage MOVE request.""" """Manage MOVE request."""
from_calendar = calendars[0] from_calendar = calendars[0]
from_name = xmlutils.name_from_path(environ["PATH_INFO"], from_calendar) from_name = xmlutils.name_from_path(environ["PATH_INFO"], from_calendar)
@ -327,7 +327,7 @@ class Application(object):
return client.FORBIDDEN, {}, None return client.FORBIDDEN, {}, None
def options(self, environ, calendars, content): def options(self, environ, calendars, content, user):
"""Manage OPTIONS request.""" """Manage OPTIONS request."""
headers = { headers = {
"Allow": "DELETE, HEAD, GET, MKCALENDAR, MOVE, " \ "Allow": "DELETE, HEAD, GET, MKCALENDAR, MOVE, " \
@ -335,16 +335,16 @@ 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, calendars, content): def propfind(self, environ, calendars, content, user):
"""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, calendars, environ.get("USER")) environ["PATH_INFO"], content, calendars, user)
return client.MULTI_STATUS, headers, answer return client.MULTI_STATUS, headers, answer
def proppatch(self, environ, calendars, content): def proppatch(self, environ, calendars, content, user):
"""Manage PROPPATCH request.""" """Manage PROPPATCH request."""
calendar = calendars[0] calendar = calendars[0]
answer = xmlutils.proppatch(environ["PATH_INFO"], content, calendar) answer = xmlutils.proppatch(environ["PATH_INFO"], content, calendar)
@ -353,7 +353,7 @@ class Application(object):
"Content-Type": "text/xml"} "Content-Type": "text/xml"}
return client.MULTI_STATUS, headers, answer return client.MULTI_STATUS, headers, answer
def put(self, environ, calendars, content): def put(self, environ, calendars, content, user):
"""Manage PUT request.""" """Manage PUT request."""
calendar = calendars[0] calendar = calendars[0]
headers = {} headers = {}
@ -373,7 +373,7 @@ class Application(object):
status = client.PRECONDITION_FAILED status = client.PRECONDITION_FAILED
return status, headers, None return status, headers, None
def report(self, environ, calendars, content): def report(self, environ, calendars, content, user):
"""Manage REPORT request.""" """Manage REPORT request."""
# TODO: support multiple calendars here # TODO: support multiple calendars here
calendar = calendars[0] calendar = calendars[0]