Skip to content

Commit fcfacb7

Browse files
committed
Expose token in Share objects
Some use cases require passing the token to external applications that access NextCloud shares via WebDAV.
1 parent c834931 commit fcfacb7

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

nc_py_api/files/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,12 @@ def path(self) -> str:
442442
"""Share path relative to the user's root directory."""
443443
return self._raw_data.get("path", "").lstrip("/")
444444

445+
@property
446+
def token(self) -> str:
447+
"""Token for the Shared object."""
448+
# Nextcloud pre-initializes token to null and overwrites it for types that have it.
449+
return self._raw_data.get("token") or ""
450+
445451
@property
446452
def label(self) -> str:
447453
"""Label for the Shared object."""

tests/actual_tests/files_sharing_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def _test_share_fields(new_share: Share, get_by_id: Share, shared_file: FsNode):
4646
assert new_share.permissions & FilePermissions.PERMISSION_READ
4747
assert new_share.url
4848
assert new_share.path == shared_file.user_path
49+
assert new_share.token
50+
assert get_by_id.token == new_share.token
4951
assert get_by_id.share_id == new_share.share_id
5052
assert get_by_id.path == new_share.path
5153
assert get_by_id.mimetype == new_share.mimetype

0 commit comments

Comments
 (0)