From 5ec9aaec07dd0b8b9b66239beb3072c2262bd448 Mon Sep 17 00:00:00 2001 From: MatthewHana Date: Tue, 12 Mar 2024 04:41:00 +1100 Subject: [PATCH 1/4] Add custom Radicale DAV property getcontentcount This adds a custom Radicale DAV property called 'getcontentcount' which returns the number of entries contained within that collection. --- radicale/app/propfind.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/radicale/app/propfind.py b/radicale/app/propfind.py index 8cbe4a06..1b8d8b7a 100644 --- a/radicale/app/propfind.py +++ b/radicale/app/propfind.py @@ -272,6 +272,12 @@ def xml_propfind_response( element.text = displayname else: is404 = True + elif tag == xmlutils.make_clark("RADICALE:getcontentcount"): + # Only for internal use by the web interface + if is_collection or is_leaf: + element.text = str(sum(1 for entry in item.get_all())) + else: + is404 = True elif tag == xmlutils.make_clark("D:displayname"): displayname = collection.get_meta("D:displayname") if not displayname and is_leaf: From ee2fc74bc097e4a7e2823d154291b1d3b420e8dd Mon Sep 17 00:00:00 2001 From: MatthewHana Date: Wed, 13 Mar 2024 01:52:45 +1100 Subject: [PATCH 2/4] Don't allow RADICALE:getcontentcount prop for collections Tests should pass now --- radicale/app/propfind.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radicale/app/propfind.py b/radicale/app/propfind.py index 1b8d8b7a..73c6206d 100644 --- a/radicale/app/propfind.py +++ b/radicale/app/propfind.py @@ -274,7 +274,7 @@ def xml_propfind_response( is404 = True elif tag == xmlutils.make_clark("RADICALE:getcontentcount"): # Only for internal use by the web interface - if is_collection or is_leaf: + if not is_collection or is_leaf: element.text = str(sum(1 for entry in item.get_all())) else: is404 = True From 2c13b8d2e03bfeaaf66e6f185b7e2c2f28ae6860 Mon Sep 17 00:00:00 2001 From: MatthewHana Date: Wed, 13 Mar 2024 02:02:23 +1100 Subject: [PATCH 3/4] Update propfind.py Don't return getcontentcount prop on leaf or principal collection. --- radicale/app/propfind.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radicale/app/propfind.py b/radicale/app/propfind.py index 73c6206d..47773481 100644 --- a/radicale/app/propfind.py +++ b/radicale/app/propfind.py @@ -274,7 +274,7 @@ def xml_propfind_response( is404 = True elif tag == xmlutils.make_clark("RADICALE:getcontentcount"): # Only for internal use by the web interface - if not is_collection or is_leaf: + if is_collection and not collection.is_principal: element.text = str(sum(1 for entry in item.get_all())) else: is404 = True From 825464f102bd53d263abeb73b294ac382ec12cb4 Mon Sep 17 00:00:00 2001 From: MatthewHana Date: Wed, 13 Mar 2024 02:16:16 +1100 Subject: [PATCH 4/4] Additional type checking for getcontentcount prop Tests keep failing due to static type checking for condition that won't occur due to earlier checking. Bringing checking into if statement. --- radicale/app/propfind.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/radicale/app/propfind.py b/radicale/app/propfind.py index 47773481..b1cfc197 100644 --- a/radicale/app/propfind.py +++ b/radicale/app/propfind.py @@ -274,8 +274,8 @@ def xml_propfind_response( is404 = True elif tag == xmlutils.make_clark("RADICALE:getcontentcount"): # Only for internal use by the web interface - if is_collection and not collection.is_principal: - element.text = str(sum(1 for entry in item.get_all())) + if isinstance(item, storage.BaseCollection) and not collection.is_principal: + element.text = str(sum(1 for x in item.get_all())) else: is404 = True elif tag == xmlutils.make_clark("D:displayname"):