Skip to content

Commit 08a4c79

Browse files
committed
add option for global permit of delete of collection (default: True to avoid breaking change)
1 parent ab28d65 commit 08a4c79

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

config

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
# File for rights management from_file
8080
#file = /etc/radicale/rights
8181

82+
# Permit delete of a collection (global)
83+
#permit_delete_collection = True
84+
8285

8386
[storage]
8487

radicale/app/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class Application(ApplicationPartDelete, ApplicationPartHead,
6868
_max_content_length: int
6969
_auth_realm: str
7070
_extra_headers: Mapping[str, str]
71+
_permit_delete_collection: bool
7172

7273
def __init__(self, configuration: config.Configuration) -> None:
7374
"""Initialize Application.
@@ -84,6 +85,8 @@ def __init__(self, configuration: config.Configuration) -> None:
8485
self._max_content_length = configuration.get(
8586
"server", "max_content_length")
8687
self._auth_realm = configuration.get("auth", "realm")
88+
self._permit_delete_collection = configuration.get("rights", "permit_delete_collection")
89+
logger.info("permit delete of collection: %s", self._permit_delete_collection)
8790
self._extra_headers = dict()
8891
for key in self.configuration.options("headers"):
8992
self._extra_headers[key] = configuration.get("headers", key)

radicale/app/delete.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,18 @@ def do_DELETE(self, environ: types.WSGIEnviron, base_prefix: str,
7070
return httputils.PRECONDITION_FAILED
7171
hook_notification_item_list = []
7272
if isinstance(item, storage.BaseCollection):
73-
for i in item.get_all():
74-
hook_notification_item_list.append(
75-
HookNotificationItem(
76-
HookNotificationItemTypes.DELETE,
77-
access.path,
78-
i.uid
73+
if self._permit_delete_collection:
74+
for i in item.get_all():
75+
hook_notification_item_list.append(
76+
HookNotificationItem(
77+
HookNotificationItemTypes.DELETE,
78+
access.path,
79+
i.uid
80+
)
7981
)
80-
)
81-
xml_answer = xml_delete(base_prefix, path, item)
82+
xml_answer = xml_delete(base_prefix, path, item)
83+
else:
84+
return httputils.NOT_ALLOWED
8285
else:
8386
assert item.collection is not None
8487
assert item.href is not None

radicale/config.py

+4
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ def _convert_to_bool(value: Any) -> bool:
184184
"help": "rights backend",
185185
"type": str_or_callable,
186186
"internal": rights.INTERNAL_TYPES}),
187+
("permit_delete_collection", {
188+
"value": "True",
189+
"help": "permit delete of a collection",
190+
"type": bool}),
187191
("file", {
188192
"value": "/etc/radicale/rights",
189193
"help": "file for rights management from_file",

0 commit comments

Comments
 (0)