From 6c7e9c5ef5c63ae29b393cf8fa9654d0ff36e56c Mon Sep 17 00:00:00 2001 From: Peter Bieringer Date: Fri, 6 Mar 2026 06:08:44 +0100 Subject: [PATCH] sharing: map_list code improvement --- radicale/app/mkcalendar.py | 4 ++-- radicale/app/mkcol.py | 4 ++-- radicale/app/propfind.py | 4 ++-- radicale/sharing/__init__.py | 29 +++++++++++------------------ radicale/sharing/csv.py | 2 +- radicale/sharing/files.py | 2 +- 6 files changed, 19 insertions(+), 26 deletions(-) diff --git a/radicale/app/mkcalendar.py b/radicale/app/mkcalendar.py index b2825075..02a821e1 100644 --- a/radicale/app/mkcalendar.py +++ b/radicale/app/mkcalendar.py @@ -55,8 +55,8 @@ class ApplicationPartMkcalendar(ApplicationBase): "Bad MKCALENDAR request on %r: %s", path, e, exc_info=True) return httputils.BAD_REQUEST if self._sharing._enabled: - # check for shared collections (all users / active or inactive) - collections_share_map = self._sharing.sharing_collection_map_list(user=None, active=False) + # check for shared collections (all) + collections_share_map = self._sharing.sharing_collection_map_list() if collections_share_map: for share in collections_share_map: if share['PathOrToken'] == path: diff --git a/radicale/app/mkcol.py b/radicale/app/mkcol.py index d3bef110..66b0fd15 100644 --- a/radicale/app/mkcol.py +++ b/radicale/app/mkcol.py @@ -62,8 +62,8 @@ class ApplicationPartMkcol(ApplicationBase): logger.warning("MKCOL request %r (type:%s): %s", path, collection_type, "rejected because of missing rights 'W'") return httputils.NOT_ALLOWED if self._sharing._enabled: - # check for shared collections (all users, active or inactive) - collections_share_map = self._sharing.sharing_collection_map_list(user=None, active=False) + # check for shared collections (all) + collections_share_map = self._sharing.sharing_collection_map_list() if collections_share_map: for share in collections_share_map: if share['PathOrToken'] == path: diff --git a/radicale/app/propfind.py b/radicale/app/propfind.py index 16db8f3c..da6106a4 100644 --- a/radicale/app/propfind.py +++ b/radicale/app/propfind.py @@ -466,8 +466,8 @@ class ApplicationPartPropfind(ApplicationBase): if http_depth == "1": if logger.isEnabledFor(logging.DEBUG): logger.debug("TRACE/PROPFIND: get shared collections") - # check for shared collections - collections_share_map = self._sharing.sharing_collection_map_list(user) + # check for shared collections related to user, Enabled and not Hidden + collections_share_map = self._sharing.sharing_collection_map_list(User=user, Enabled=True, Hidden=False) if collections_share_map: for share in collections_share_map: c_share = share['PathOrToken'] diff --git a/radicale/sharing/__init__.py b/radicale/sharing/__init__.py index dfabeab9..322bf46d 100644 --- a/radicale/sharing/__init__.py +++ b/radicale/sharing/__init__.py @@ -290,29 +290,22 @@ class BaseSharing: return None # list sharings of type "map" - def sharing_collection_map_list(self, user: Union[str, None], active: bool = True) -> list[dict]: - """ returning dict with shared collections (active==True: enabled and unhidden) or None if not found""" + def sharing_collection_map_list(self, User: Union[str, None] = None, Enabled: Union[bool, None] = None, Hidden: Union[bool, None] = None) -> list[dict]: + """ returning dict with shared collections by filter(User/Enabled/Hidden) or None if not found""" if not self.sharing_collection_by_map: if logger.isEnabledFor(logging.DEBUG): logger.debug("TRACE/sharing/map: not active") return [{}] - # retrieve collections which are enabled and not hidden by owner+user - if active: - shared_collection_list = self.database_list_sharing( - ShareType="map", - OwnerOrUser=user, - User=user, - EnabledByOwner=True, - EnabledByUser=True, - HiddenByOwner=False, - HiddenByUser=False) - else: - # unconditional - shared_collection_list = self.database_list_sharing( - ShareType="map", - OwnerOrUser=user, - User=user) + # retrieve collections depending on filter + shared_collection_list = self.database_list_sharing( + ShareType="map", + OwnerOrUser=User, + User=User, + EnabledByOwner=Enabled, + EnabledByUser=Enabled, + HiddenByOwner=Hidden, + HiddenByUser=Hidden) # final return shared_collection_list diff --git a/radicale/sharing/csv.py b/radicale/sharing/csv.py index cf761923..5dfc45a4 100644 --- a/radicale/sharing/csv.py +++ b/radicale/sharing/csv.py @@ -159,7 +159,7 @@ class Sharing(sharing.BaseSharing): result = [] if logger.isEnabledFor(logging.DEBUG): - logger.debug("TRACE/sharing/list/called: ShareType=%r OwnerOrUser=%r User=%r PathOrToken=%r PathMapped=%r HiddenByOwner=%s HiddenByUser=%s", ShareType, OwnerOrUser, User, PathOrToken, PathMapped, HiddenByOwner, HiddenByUser) + logger.debug("TRACE/sharing/list/called: ShareType=%r OwnerOrUser=%r User=%r PathOrToken=%r PathMapped=%r EnabledByOwner=%s EnabledByUser=%s HiddenByOwner=%s HiddenByUser=%s", ShareType, OwnerOrUser, User, PathOrToken, PathMapped, EnabledByOwner, EnabledByUser, HiddenByOwner, HiddenByUser) for row in self._sharing_cache: if index == 0: diff --git a/radicale/sharing/files.py b/radicale/sharing/files.py index 3a79730f..fba8bdd6 100644 --- a/radicale/sharing/files.py +++ b/radicale/sharing/files.py @@ -155,7 +155,7 @@ class Sharing(sharing.BaseSharing): result = [] if logger.isEnabledFor(logging.DEBUG): - logger.debug("TRACE/sharing/list/called: ShareType=%r OwnerOrUser=%r User=%r PathOrToken=%r PathMapped=%r HiddenByOwner=%s HiddenByUser=%s", ShareType, OwnerOrUser, User, PathOrToken, PathMapped, HiddenByOwner, HiddenByUser) + logger.debug("TRACE/sharing/list/called: ShareType=%r OwnerOrUser=%r User=%r PathOrToken=%r PathMapped=%r EnabledByOwner=%s EnabledByUser=%s HiddenByOwner=%s HiddenByUser=%s", ShareType, OwnerOrUser, User, PathOrToken, PathMapped, EnabledByOwner, EnabledByUser, HiddenByOwner, HiddenByUser) for _ShareType in sharing.SHARE_TYPES_V1: if ShareType is not None and _ShareType != ShareType: