Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option for global permit of delete of collection (default: True t… #1409

Merged
merged 3 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,12 @@ Default: `owner_only`
File for the rights backend `from_file`. See the
[Rights](#authentication-and-rights) section.

##### permit_delete_collection

(New since 3.1.9)

Global control of permission to delete complete collection (default: True)

#### storage

##### type
Expand Down
3 changes: 3 additions & 0 deletions config
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
3 changes: 3 additions & 0 deletions radicale/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -84,6 +85,8 @@ def __init__(self, configuration: config.Configuration) -> None:
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)
Expand Down
1 change: 1 addition & 0 deletions radicale/app/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ApplicationBase:
_rights: rights.BaseRights
_web: web.BaseWeb
_encoding: str
_permit_delete_collection: bool

def __init__(self, configuration: config.Configuration) -> None:
self.configuration = configuration
Expand Down
5 changes: 4 additions & 1 deletion radicale/app/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ def do_DELETE(self, environ: types.WSGIEnviron, base_prefix: str,
# 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
Expand Down
4 changes: 4 additions & 0 deletions radicale/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ def _convert_to_bool(value: Any) -> bool:
"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",
Expand Down
Loading