sharing: fixes, doc update, alignment

This commit is contained in:
Peter Bieringer
2026-03-05 22:22:46 +01:00
parent 6070fe67da
commit 46780a48b0
3 changed files with 148 additions and 49 deletions

View File

@@ -290,7 +290,7 @@ class BaseSharing:
return None
# list sharings of type "map"
def sharing_collection_map_list(self, user: str, active: bool = True) -> list[dict]:
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"""
if not self.sharing_collection_by_map:
if logger.isEnabledFor(logging.DEBUG):
@@ -488,6 +488,7 @@ class BaseSharing:
# parse body according to content-type
content_type = environ.get("CONTENT_TYPE", "")
if 'application/json' in content_type:
output_format = "json" # default
try:
request_data = json.loads(request_body)
except json.JSONDecodeError:
@@ -501,6 +502,7 @@ class BaseSharing:
if logger.isEnabledFor(logging.DEBUG):
logger.debug("TRACE/" + api_info + " (json): %r", f"{request_data}")
elif 'application/x-www-form-urlencoded' in content_type:
output_format = "txt" # default
request_parsed = parse_qs(request_body)
# convert arrays into single value
request_data = {}
@@ -539,8 +541,11 @@ class BaseSharing:
output_format = "json"
elif 'text/csv' in accept:
output_format = "csv"
else:
elif 'text/plain' in accept:
output_format = "txt"
else:
# default from input type
pass
if output_format == "csv":
if not action == "list":
@@ -555,7 +560,6 @@ class BaseSharing:
# parameters default
PathOrToken: Union[str, None] = None
PathMapped: Union[str, None] = None
Owner: str = user
User: Union[str, None] = None
Permissions: Union[str, None] = None # no permissions by default
Enabled: Union[bool, None] = None
@@ -685,7 +689,7 @@ class BaseSharing:
logger.error(api_info + ": missing PathMapped")
return httputils.bad_request("Missing PathMapped")
## check whether collection exists
# check whether collection exists
with self._storage.acquire_lock("r", user, path=PathMapped):
item = next(iter(self._storage.discover(PathMapped)), None)
if not item:
@@ -741,7 +745,6 @@ class BaseSharing:
else:
User = user
# v1: create uuid token with 2x 32 bytes = 256 bit
token = "v1/" + str(base64.urlsafe_b64encode(uuid.uuid4().bytes + uuid.uuid4().bytes), 'utf-8')
@@ -784,9 +787,9 @@ class BaseSharing:
User = str(User)
# check access Permissions
access = Access(self._rights, Owner, PathMapped, None) # PathMapped is mandatory
access = Access(self._rights, user, PathMapped, None) # PathMapped is mandatory
if not access.check("r") and "i" not in access.permissions:
logger.info("Add sharing-by-map: access to path(mapped) %r not allowed for owner %r", PathMapped, Owner)
logger.info("Add sharing-by-map: access to path(mapped) %r not allowed for owner %r", PathMapped, user)
return httputils.NOT_ALLOWED
if self.permit_create_map is False:

View File

@@ -306,6 +306,9 @@ class TestSharingApiSanity(BaseTest):
form_array: Sequence[str]
json_dict: dict
self.mkcalendar("/owner/collectionL1/", login="owner:ownerpw")
self.mkcalendar("/owner/collectionL2/", login="owner:ownerpw")
for db_type in list(filter(lambda item: item != "none", sharing.INTERNAL_TYPES)):
logging.info("\n*** test: %s", db_type)
self.configure({"sharing": {"type": db_type}})
@@ -605,6 +608,8 @@ class TestSharingApiSanity(BaseTest):
path = path_base + "/event1.ics"
self.put(path, event, login="owner:ownerpw")
self.mkcalendar(path_base2, login="owner:ownerpw")
for db_type in list(filter(lambda item: item != "none", sharing.INTERNAL_TYPES)):
logging.info("\n*** test: %s", db_type)
self.configure({"sharing": {"type": db_type}})