sharing: map_list code improvement
This commit is contained in:
@@ -55,8 +55,8 @@ class ApplicationPartMkcalendar(ApplicationBase):
|
|||||||
"Bad MKCALENDAR request on %r: %s", path, e, exc_info=True)
|
"Bad MKCALENDAR request on %r: %s", path, e, exc_info=True)
|
||||||
return httputils.BAD_REQUEST
|
return httputils.BAD_REQUEST
|
||||||
if self._sharing._enabled:
|
if self._sharing._enabled:
|
||||||
# check for shared collections (all users / active or inactive)
|
# check for shared collections (all)
|
||||||
collections_share_map = self._sharing.sharing_collection_map_list(user=None, active=False)
|
collections_share_map = self._sharing.sharing_collection_map_list()
|
||||||
if collections_share_map:
|
if collections_share_map:
|
||||||
for share in collections_share_map:
|
for share in collections_share_map:
|
||||||
if share['PathOrToken'] == path:
|
if share['PathOrToken'] == path:
|
||||||
|
|||||||
@@ -62,8 +62,8 @@ class ApplicationPartMkcol(ApplicationBase):
|
|||||||
logger.warning("MKCOL request %r (type:%s): %s", path, collection_type, "rejected because of missing rights 'W'")
|
logger.warning("MKCOL request %r (type:%s): %s", path, collection_type, "rejected because of missing rights 'W'")
|
||||||
return httputils.NOT_ALLOWED
|
return httputils.NOT_ALLOWED
|
||||||
if self._sharing._enabled:
|
if self._sharing._enabled:
|
||||||
# check for shared collections (all users, active or inactive)
|
# check for shared collections (all)
|
||||||
collections_share_map = self._sharing.sharing_collection_map_list(user=None, active=False)
|
collections_share_map = self._sharing.sharing_collection_map_list()
|
||||||
if collections_share_map:
|
if collections_share_map:
|
||||||
for share in collections_share_map:
|
for share in collections_share_map:
|
||||||
if share['PathOrToken'] == path:
|
if share['PathOrToken'] == path:
|
||||||
|
|||||||
@@ -466,8 +466,8 @@ class ApplicationPartPropfind(ApplicationBase):
|
|||||||
if http_depth == "1":
|
if http_depth == "1":
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
if logger.isEnabledFor(logging.DEBUG):
|
||||||
logger.debug("TRACE/PROPFIND: get shared collections")
|
logger.debug("TRACE/PROPFIND: get shared collections")
|
||||||
# check for shared collections
|
# check for shared collections related to user, Enabled and not Hidden
|
||||||
collections_share_map = self._sharing.sharing_collection_map_list(user)
|
collections_share_map = self._sharing.sharing_collection_map_list(User=user, Enabled=True, Hidden=False)
|
||||||
if collections_share_map:
|
if collections_share_map:
|
||||||
for share in collections_share_map:
|
for share in collections_share_map:
|
||||||
c_share = share['PathOrToken']
|
c_share = share['PathOrToken']
|
||||||
|
|||||||
@@ -290,29 +290,22 @@ class BaseSharing:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
# list sharings of type "map"
|
# list sharings of type "map"
|
||||||
def sharing_collection_map_list(self, user: Union[str, None], active: bool = True) -> list[dict]:
|
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 (active==True: enabled and unhidden) or None if not found"""
|
""" returning dict with shared collections by filter(User/Enabled/Hidden) or None if not found"""
|
||||||
if not self.sharing_collection_by_map:
|
if not self.sharing_collection_by_map:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
if logger.isEnabledFor(logging.DEBUG):
|
||||||
logger.debug("TRACE/sharing/map: not active")
|
logger.debug("TRACE/sharing/map: not active")
|
||||||
return [{}]
|
return [{}]
|
||||||
|
|
||||||
# retrieve collections which are enabled and not hidden by owner+user
|
# retrieve collections depending on filter
|
||||||
if active:
|
shared_collection_list = self.database_list_sharing(
|
||||||
shared_collection_list = self.database_list_sharing(
|
ShareType="map",
|
||||||
ShareType="map",
|
OwnerOrUser=User,
|
||||||
OwnerOrUser=user,
|
User=User,
|
||||||
User=user,
|
EnabledByOwner=Enabled,
|
||||||
EnabledByOwner=True,
|
EnabledByUser=Enabled,
|
||||||
EnabledByUser=True,
|
HiddenByOwner=Hidden,
|
||||||
HiddenByOwner=False,
|
HiddenByUser=Hidden)
|
||||||
HiddenByUser=False)
|
|
||||||
else:
|
|
||||||
# unconditional
|
|
||||||
shared_collection_list = self.database_list_sharing(
|
|
||||||
ShareType="map",
|
|
||||||
OwnerOrUser=user,
|
|
||||||
User=user)
|
|
||||||
|
|
||||||
# final
|
# final
|
||||||
return shared_collection_list
|
return shared_collection_list
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ class Sharing(sharing.BaseSharing):
|
|||||||
result = []
|
result = []
|
||||||
|
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
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:
|
for row in self._sharing_cache:
|
||||||
if index == 0:
|
if index == 0:
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ class Sharing(sharing.BaseSharing):
|
|||||||
result = []
|
result = []
|
||||||
|
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
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:
|
for _ShareType in sharing.SHARE_TYPES_V1:
|
||||||
if ShareType is not None and _ShareType != ShareType:
|
if ShareType is not None and _ShareType != ShareType:
|
||||||
|
|||||||
Reference in New Issue
Block a user