Преглед изворни кода

move check predefined_collections props to config.py

IM пре 1 година
родитељ
комит
515afb52ed
2 измењених фајлова са 7 додато и 4 уклоњено
  1. 1 3
      radicale/app/__init__.py
  2. 6 1
      radicale/config.py

+ 1 - 3
radicale/app/__init__.py

@@ -48,7 +48,6 @@ from radicale.app.propfind import ApplicationPartPropfind
 from radicale.app.proppatch import ApplicationPartProppatch
 from radicale.app.proppatch import ApplicationPartProppatch
 from radicale.app.put import ApplicationPartPut
 from radicale.app.put import ApplicationPartPut
 from radicale.app.report import ApplicationPartReport
 from radicale.app.report import ApplicationPartReport
-from radicale.item import check_and_sanitize_props
 from radicale.log import logger
 from radicale.log import logger
 
 
 # Combination of types.WSGIStartResponse and WSGI application return value
 # Combination of types.WSGIStartResponse and WSGI application return value
@@ -274,8 +273,7 @@ class Application(ApplicationPartDelete, ApplicationPartHead,
                                 jsn_coll = self.configuration.get("storage", "predefined_collections")
                                 jsn_coll = self.configuration.get("storage", "predefined_collections")
                                 for (name_coll, props) in jsn_coll.items():
                                 for (name_coll, props) in jsn_coll.items():
                                     try:
                                     try:
-                                        checked_props = check_and_sanitize_props(props)
-                                        self._storage.create_collection(principal_path + name_coll, props=checked_props)
+                                        self._storage.create_collection(principal_path + name_coll, props=props)
                                     except ValueError as e:
                                     except ValueError as e:
                                         logger.warning("Failed to create predefined collection %r: %s", name_coll, e)
                                         logger.warning("Failed to create predefined collection %r: %s", name_coll, e)
                         except ValueError as e:
                         except ValueError as e:

+ 6 - 1
radicale/config.py

@@ -37,6 +37,7 @@ from typing import (Any, Callable, ClassVar, Iterable, List, Optional,
                     Sequence, Tuple, TypeVar, Union)
                     Sequence, Tuple, TypeVar, Union)
 
 
 from radicale import auth, hook, rights, storage, types, web
 from radicale import auth, hook, rights, storage, types, web
+from radicale.item import check_and_sanitize_props
 
 
 DEFAULT_CONFIG_PATH: str = os.pathsep.join([
 DEFAULT_CONFIG_PATH: str = os.pathsep.join([
     "?/etc/radicale/config",
     "?/etc/radicale/config",
@@ -105,7 +106,11 @@ def _convert_to_bool(value: Any) -> bool:
 def json_str(value: Any) -> dict:
 def json_str(value: Any) -> dict:
     if not value:
     if not value:
         return {}
         return {}
-    return json.loads(value)
+    ret = json.loads(value)
+    for (name_coll, props) in ret.items():
+        checked_props = check_and_sanitize_props(props)
+        ret[name_coll] = checked_props
+    return ret
 
 
 
 
 INTERNAL_OPTIONS: Sequence[str] = ("_allow_extra",)
 INTERNAL_OPTIONS: Sequence[str] = ("_allow_extra",)