Allow attach custom rights backend, small fix in default config file

This commit is contained in:
Sergey Fursov 2013-12-29 15:13:35 +04:00
parent 017df0ddcf
commit 1d0418594d
3 changed files with 14 additions and 5 deletions

7
config
View File

@ -105,12 +105,15 @@ committer = Firstname Lastname <Radicale@Radicale.org>
[rights] [rights]
# Rights backend # Rights backend
# Value: regex # Value: regex
backend = "regex" backend = regex
# Rights management method # Rights management method
# Value: None | owner_only | owner_write | from_file # Value: None | owner_only | owner_write | from_file | custom
type = None type = None
# Rights custom handler
custom_handler =
# File for rights management from_file # File for rights management from_file
file = ~/.config/radicale/rights file = ~/.config/radicale/rights

View File

@ -78,6 +78,7 @@ INITIAL_CONFIG = {
"rights": { "rights": {
"backend": "regex", "backend": "regex",
"type": "None", "type": "None",
"custom_handler": "",
"file": "~/.config/radicale/rights"}, "file": "~/.config/radicale/rights"},
"storage": { "storage": {
"type": "filesystem", "type": "filesystem",

View File

@ -31,9 +31,14 @@ from .. import config
def load(): def load():
"""Load list of available storage managers.""" """Load list of available storage managers."""
storage_type = config.get("rights", "backend") storage_type = config.get("rights", "backend")
root_module = __import__( if storage_type == 'custom':
"rights.%s" % storage_type, globals=globals(), level=2) rights_module = config.get("rights", "custom_handler")
module = getattr(root_module, storage_type) __import__(rights_module)
module = sys.modules[rights_module]
else:
root_module = __import__(
"rights.%s" % storage_type, globals=globals(), level=2)
module = getattr(root_module, storage_type)
sys.modules[__name__].authorized = module.authorized sys.modules[__name__].authorized = module.authorized
return module return module