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.
This commit is contained in:
		| @@ -60,16 +60,19 @@ except ImportError: | |||||||
| # pylint: enable=F0401 | # pylint: enable=F0401 | ||||||
|  |  | ||||||
|  |  | ||||||
| FILENAME = os.path.expanduser(config.get("rights", "file")) | FILENAME = ( | ||||||
| if 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) |     log.LOGGER.debug("Reading rights from file %s" % FILENAME) | ||||||
|     RIGHTS = ConfigParser() |     rights = ConfigParser() | ||||||
|     if not RIGHTS.read(FILENAME): |     if not rights.read(FILENAME): | ||||||
|         log.LOGGER.error( |         log.LOGGER.error( | ||||||
|             "File '%s' not found for rights management" % FILENAME) |             "File '%s' not found for rights management" % FILENAME) | ||||||
| else: |     return rights | ||||||
|     log.LOGGER.error("No file name configured for rights type 'from_file'") |  | ||||||
|     RIGHTS = None |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def read_authorized(user, collection): | def read_authorized(user, collection): | ||||||
| @@ -80,7 +83,8 @@ def read_authorized(user, collection): | |||||||
|         return True |         return True | ||||||
|     else: |     else: | ||||||
|         try: |         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): |         except (NoSectionError, NoOptionError): | ||||||
|             return False |             return False | ||||||
|  |  | ||||||
| @@ -93,6 +97,7 @@ def write_authorized(user, collection): | |||||||
|         return True |         return True | ||||||
|     else: |     else: | ||||||
|         try: |         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): |         except (NoSectionError, NoOptionError): | ||||||
|             return False |             return False | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Guillaume Ayoub
					Guillaume Ayoub