Clean the server's __call__ method, with comments and better variable names
This commit is contained in:
parent
9d193b6b30
commit
a7481a0546
@ -211,18 +211,23 @@ class Application(object):
|
|||||||
else:
|
else:
|
||||||
user = password = None
|
user = password = None
|
||||||
|
|
||||||
last_allowed = None
|
last_collection_allowed = None
|
||||||
collections = []
|
allowed_items = []
|
||||||
for collection in items:
|
for item in items:
|
||||||
if not isinstance(collection, ical.Collection):
|
if not isinstance(item, ical.Collection):
|
||||||
if last_allowed:
|
# item is not a colleciton, it's the child of the last
|
||||||
collections.append(collection)
|
# collection we've met in the loop. Only add this item if
|
||||||
|
# this last collection was allowed.
|
||||||
|
if last_collection_allowed:
|
||||||
|
allowed_items.append(item)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# item is a collection
|
||||||
|
collection = item
|
||||||
if collection.owner in acl.PUBLIC_USERS:
|
if collection.owner in acl.PUBLIC_USERS:
|
||||||
log.LOGGER.info("Public collection")
|
log.LOGGER.info("Public collection")
|
||||||
collections.append(collection)
|
allowed_items.append(collection)
|
||||||
last_allowed = True
|
last_collection_allowed = True
|
||||||
else:
|
else:
|
||||||
log.LOGGER.info(
|
log.LOGGER.info(
|
||||||
"Checking rights for collection owned by %s" % (
|
"Checking rights for collection owned by %s" % (
|
||||||
@ -230,18 +235,18 @@ class Application(object):
|
|||||||
if self.acl.has_right(collection.owner, user, password):
|
if self.acl.has_right(collection.owner, user, password):
|
||||||
log.LOGGER.info(
|
log.LOGGER.info(
|
||||||
"%s allowed" % (user or "Anonymous user"))
|
"%s allowed" % (user or "Anonymous user"))
|
||||||
collections.append(collection)
|
allowed_items.append(collection)
|
||||||
last_allowed = True
|
last_collection_allowed = True
|
||||||
else:
|
else:
|
||||||
log.LOGGER.info(
|
log.LOGGER.info(
|
||||||
"%s refused" % (user or "Anonymous user"))
|
"%s refused" % (user or "Anonymous user"))
|
||||||
last_allowed = False
|
last_collection_allowed = False
|
||||||
|
|
||||||
if collections:
|
if allowed_items:
|
||||||
# Collections found
|
# Collections and items found
|
||||||
status, headers, answer = function(
|
status, headers, answer = function(
|
||||||
environ, collections, content, user)
|
environ, allowed_items, content, user)
|
||||||
elif user and last_allowed is None:
|
elif user and last_collection_allowed is None:
|
||||||
# Good user and no collections found, redirect user to home
|
# Good user and no collections found, redirect user to home
|
||||||
location = "/%s/" % str(quote(user))
|
location = "/%s/" % str(quote(user))
|
||||||
log.LOGGER.info("redirecting to %s" % location)
|
log.LOGGER.info("redirecting to %s" % location)
|
||||||
|
Loading…
Reference in New Issue
Block a user