From 847235f6e706253f6109a345fbdfeed9ce2ba409 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Wed, 22 May 2013 18:49:30 +0200 Subject: [PATCH] Read the configuration file for rights each time We now re-parse the file each time we need to get the rights. It's definitely too much, but it's not the slowest part of Radicale. --- radicale/rights/from_file.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/radicale/rights/from_file.py b/radicale/rights/from_file.py index a480532d..8ba954fd 100644 --- a/radicale/rights/from_file.py +++ b/radicale/rights/from_file.py @@ -60,16 +60,19 @@ except ImportError: # pylint: enable=F0401 -FILENAME = os.path.expanduser(config.get("rights", "file")) -if FILENAME: +FILENAME = ( + os.path.expanduser(config.get("rights", "file")) or + log.LOGGER.error("No file name configured for rights type 'from_file'")) + + +def _read_rights(): + """Update the rights according to the configuration file.""" log.LOGGER.debug("Reading rights from file %s" % FILENAME) - RIGHTS = ConfigParser() - if not RIGHTS.read(FILENAME): + rights = ConfigParser() + if not rights.read(FILENAME): log.LOGGER.error( "File '%s' not found for rights management" % FILENAME) -else: - log.LOGGER.error("No file name configured for rights type 'from_file'") - RIGHTS = None + return rights def read_authorized(user, collection): @@ -80,7 +83,8 @@ def read_authorized(user, collection): return True else: try: - return "r" in RIGHTS.get(collection.url.rstrip("/") or "/", user) + return "r" in _read_rights().get( + collection.url.rstrip("/") or "/", user) except (NoSectionError, NoOptionError): return False @@ -93,6 +97,7 @@ def write_authorized(user, collection): return True else: try: - return "w" in RIGHTS.get(collection.url.rstrip("/") or "/", user) + return "w" in _read_rights().get( + collection.url.rstrip("/") or "/", user) except (NoSectionError, NoOptionError): return False