Fix rights type "None"

This commit is contained in:
Guillaume Ayoub 2013-08-14 11:58:08 +02:00
parent 15ef75301f
commit f7f26afd6b
2 changed files with 9 additions and 11 deletions

View File

@ -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

View File

@ -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))