Selaa lähdekoodia

add option for global permit of delete of collection (default: True to avoid breaking change)

Peter Bieringer 1 vuosi sitten
vanhempi
sitoutus
0f355114ae
4 muutettua tiedostoa jossa 14 lisäystä ja 1 poistoa
  1. 3 0
      config
  2. 3 0
      radicale/app/__init__.py
  3. 4 1
      radicale/app/delete.py
  4. 4 0
      radicale/config.py

+ 3 - 0
config

@@ -79,6 +79,9 @@
 # File for rights management from_file
 #file = /etc/radicale/rights
 
+# Permit delete of a collection (global)
+#permit_delete_collection = True
+
 
 [storage]
 

+ 3 - 0
radicale/app/__init__.py

@@ -68,6 +68,7 @@ class Application(ApplicationPartDelete, ApplicationPartHead,
     _max_content_length: int
     _auth_realm: str
     _extra_headers: Mapping[str, str]
+    _permit_delete_collection: bool
 
     def __init__(self, configuration: config.Configuration) -> None:
         """Initialize Application.
@@ -84,6 +85,8 @@ class Application(ApplicationPartDelete, ApplicationPartHead,
         self._max_content_length = configuration.get(
             "server", "max_content_length")
         self._auth_realm = configuration.get("auth", "realm")
+        self._permit_delete_collection = configuration.get("rights", "permit_delete_collection")
+        logger.info("permit delete of collection: %s", self._permit_delete_collection)
         self._extra_headers = dict()
         for key in self.configuration.options("headers"):
             self._extra_headers[key] = configuration.get("headers", key)

+ 4 - 1
radicale/app/delete.py

@@ -68,7 +68,10 @@ class ApplicationPartDelete(ApplicationBase):
                 # ETag precondition not verified, do not delete item
                 return httputils.PRECONDITION_FAILED
             if isinstance(item, storage.BaseCollection):
-                xml_answer = xml_delete(base_prefix, path, item)
+                if self._permit_delete_collection:
+                    xml_answer = xml_delete(base_prefix, path, item)
+                else:
+                    return httputils.NOT_ALLOWED
             else:
                 assert item.collection is not None
                 assert item.href is not None

+ 4 - 0
radicale/config.py

@@ -184,6 +184,10 @@ DEFAULT_CONFIG_SCHEMA: types.CONFIG_SCHEMA = OrderedDict([
             "help": "rights backend",
             "type": str_or_callable,
             "internal": rights.INTERNAL_TYPES}),
+        ("permit_delete_collection", {
+            "value": "True",
+            "help": "permit delete of a collection",
+            "type": bool}),
         ("file", {
             "value": "/etc/radicale/rights",
             "help": "file for rights management from_file",