From f7f26afd6b3e3bf9c4a35eeb87c1eb55cd95374c Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Wed, 14 Aug 2013 11:58:08 +0200 Subject: [PATCH] Fix rights type "None" --- radicale/__init__.py | 3 +-- radicale/rights.py | 17 ++++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/radicale/__init__.py b/radicale/__init__.py index 2dd6401..ded212e 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -302,8 +302,7 @@ class Application(object): status, headers, answer = NOT_ALLOWED else: # Unknown or unauthorized user - log.LOGGER.info( - "%s refused" % (user or "Anonymous user")) + log.LOGGER.info("%s refused" % (user or "Anonymous user")) status, headers, answer = WRONG_CREDENTIALS # Set content length diff --git a/radicale/rights.py b/radicale/rights.py index 596b975..c848751 100644 --- a/radicale/rights.py +++ b/radicale/rights.py @@ -38,8 +38,8 @@ except ImportError: FILENAME = os.path.expanduser(config.get("rights", "file")) +TYPE = config.get("rights", "type").lower() DEFINED_RIGHTS = { - "none": "[rw]\nuser:.*\ncollection:.*\npermission:rw", "owner_write": "[r]\nuser:.*\ncollection:.*\npermission:r\n" "[w]\nuser:.*\ncollection:^%(login)s/.+$\npermission:w", "owner_only": "[rw]\nuser:.\ncollection: ^%(login)s/.+$\npermission:rw"} @@ -48,17 +48,16 @@ DEFINED_RIGHTS = { def _read_from_sections(user, collection, permission): """Get regex sections.""" regex = ConfigParser({"login": user, "path": collection}) - rights_type = config.get("rights", "type").lower() - if rights_type in DEFINED_RIGHTS: - log.LOGGER.debug("Rights type '%s'" % rights_type) - regex.read_string(DEFINED_RIGHTS[rights_type]) - elif rights_type == "from_file": + if TYPE in DEFINED_RIGHTS: + log.LOGGER.debug("Rights type '%s'" % TYPE) + regex.read_string(DEFINED_RIGHTS[TYPE]) + elif TYPE == "from_file": log.LOGGER.debug("Reading rights from file %s" % FILENAME) if not regex.read(FILENAME): log.LOGGER.error("File '%s' not found for rights" % FILENAME) return False else: - log.LOGGER.error("Unknown rights type '%s'" % rights_type) + log.LOGGER.error("Unknown rights type '%s'" % TYPE) return False for section in regex.sections(): @@ -80,5 +79,5 @@ def _read_from_sections(user, collection, permission): def authorized(user, collection, right): """Check if the user is allowed to read or write the collection.""" - return user and _read_from_sections( - user, collection.url.rstrip("/") or "/", right) + return TYPE == "none" or (user and _read_from_sections( + user, collection.url.rstrip("/") or "/", right))