From 08d35d97f250d9cf795d4af034829e0b554348fe Mon Sep 17 00:00:00 2001 From: Max Berger Date: Tue, 3 Mar 2026 22:54:42 +0100 Subject: [PATCH] Add actual state of PermittedCreateCollectionByMap and PermittedCreateCollectionByToken in info response --- radicale/sharing/__init__.py | 4 ++-- radicale/tests/test_sharing.py | 28 +++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/radicale/sharing/__init__.py b/radicale/sharing/__init__.py index 45e05ed1..8dba8314 100644 --- a/radicale/sharing/__init__.py +++ b/radicale/sharing/__init__.py @@ -963,10 +963,10 @@ class BaseSharing: answer['Status'] = "success" if ShareType in ["all", "map"]: answer['FeatureEnabledCollectionByMap'] = self.sharing_collection_by_map - answer['PermittedCreateCollectionByMap'] = True # TODO toggle per permission, default? + answer['PermittedCreateCollectionByMap'] = self.permit_create_map if ShareType in ["all", "token"]: answer['FeatureEnabledCollectionByToken'] = self.sharing_collection_by_token - answer['PermittedCreateCollectionByToken'] = True # TODO toggle per permission, default? + answer['PermittedCreateCollectionByToken'] = self.permit_create_token # action: TOGGLE elif action in API_SHARE_TOGGLES_V1: diff --git a/radicale/tests/test_sharing.py b/radicale/tests/test_sharing.py index d61d1b2c..aef27c29 100644 --- a/radicale/tests/test_sharing.py +++ b/radicale/tests/test_sharing.py @@ -220,7 +220,9 @@ class TestSharingApiSanity(BaseTest): # path with valid API and hook but not enabled "token" self.configure({"sharing": { "collection_by_map": "True", - "collection_by_token": "False"} + "collection_by_token": "False", + "permit_create_map": "False", + "permit_create_token": "False"} }) sharetype = "token" for action in sharing.API_HOOKS_V1: @@ -233,10 +235,10 @@ class TestSharingApiSanity(BaseTest): json_dict = {} _, headers, answer = self._sharing_api_json("all", "info", check=200, login="owner:ownerpw", json_dict=json_dict) answer_dict = json.loads(answer) - assert answer_dict['FeatureEnabledCollectionByMap'] is True - assert answer_dict['FeatureEnabledCollectionByToken'] is False - assert answer_dict['PermittedCreateCollectionByMap'] is True - assert answer_dict['PermittedCreateCollectionByToken'] is True + assert answer_dict['FeatureEnabledCollectionByMap'] is True, f'FeatureEnabledCollectionByMap {db_type}' + assert answer_dict['FeatureEnabledCollectionByToken'] is False, f'FeatureEnabledCollectionByToken {db_type}' + assert answer_dict['PermittedCreateCollectionByMap'] is False, f'PermittedCreateCollectionByMap {db_type}' + assert answer_dict['PermittedCreateCollectionByToken'] is False, f'PermittedCreateCollectionByToken {db_type}' logging.info("\n*** check API hook: info/map") json_dict = {} @@ -270,6 +272,22 @@ class TestSharingApiSanity(BaseTest): assert 'FeatureEnabledCollectionByMap' not in answer_dict assert 'PermittedCreateCollectionByMap' not in answer_dict + # When turning on permission to create + self.configure({"sharing": { + "collection_by_map": "True", + "collection_by_token": "True", + "permit_create_map": "True", + "permit_create_token": "True"} + }) + logging.info("\n*** check API hook: info/all") + json_dict = {} + _, headers, answer = self._sharing_api_json("all", "info", check=200, login="owner:ownerpw", json_dict=json_dict) + answer_dict = json.loads(answer) + assert answer_dict['FeatureEnabledCollectionByMap'] is True, f'FeatureEnabledCollectionByMap {db_type}' + assert answer_dict['FeatureEnabledCollectionByToken'] is True, f'FeatureEnabledCollectionByToken {db_type}' + assert answer_dict['PermittedCreateCollectionByMap'] is True, f'PermittedCreateCollectionByMap {db_type}' + assert answer_dict['PermittedCreateCollectionByToken'] is True, f'PermittedCreateCollectionByToken {db_type}' + def test_sharing_api_list_with_auth(self) -> None: """POST/list with authentication.""" self.configure({"auth": {"type": "htpasswd",