Skip to content

added files.get_tags function #260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

All notable changes to this project will be documented in this file.

## [0.14.0 - 2024-05-xx]
## [0.14.0 - 2024-05-31]

### Added

- NextcloudApp: `nc.ui.files_dropdown_menu.register_ex` to register new version of FileActions(AppAPI 2.6.0+)
- `LoginFlowV2` implementation by @blvdek #255
- NextcloudApp: `nc.ui.files_dropdown_menu.register_ex` to register new version of FileActions(AppAPI 2.6.0+) #252
- `files.get_tags` function to get all tags assigned to the file or directory. #260

## [0.13.0 - 2024-04-28]

Expand Down
2 changes: 1 addition & 1 deletion nc_py_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
NextcloudMissingCapabilities,
)
from ._version import __version__
from .files import FilePermissions, FsNode, LockType
from .files import FilePermissions, FsNode, LockType, SystemTag
from .files.sharing import ShareType
from .nextcloud import AsyncNextcloud, AsyncNextcloudApp, Nextcloud, NextcloudApp
12 changes: 12 additions & 0 deletions nc_py_api/files/_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ def build_list_tags_response(response: Response) -> list[SystemTag]:
return result


def build_tags_ids_for_object(url_to_fetch: str, response: Response) -> list[int]:
result = []
records = _webdav_response_to_records(response, "list_tags_ids")
for record in records:
prop_stat = record["d:propstat"]
if str(prop_stat.get("d:status", "")).find("200 OK") != -1:
href_suffix = str(record["d:href"]).removeprefix(url_to_fetch).strip("/")
if href_suffix:
result.append(int(href_suffix))
return result


def build_update_tag_req(
name: str | None, user_visible: bool | None, user_assignable: bool | None
) -> ElementTree.Element:
Expand Down
496 changes: 14 additions & 482 deletions nc_py_api/files/files.py

Large diffs are not rendered by default.

523 changes: 523 additions & 0 deletions nc_py_api/files/files_async.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion nc_py_api/nextcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
from .ex_app.occ_commands import AsyncOccCommandsAPI, OccCommandsAPI
from .ex_app.providers.providers import AsyncProvidersApi, ProvidersApi
from .ex_app.ui.ui import AsyncUiApi, UiApi
from .files.files import AsyncFilesAPI, FilesAPI
from .files.files import FilesAPI
from .files.files_async import AsyncFilesAPI
from .loginflow_v2 import _AsyncLoginFlowV2API, _LoginFlowV2API
from .notes import _AsyncNotesAPI, _NotesAPI
from .notifications import _AsyncNotificationsAPI, _NotificationsAPI
Expand Down
16 changes: 13 additions & 3 deletions tests/actual_tests/files_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@

import pytest

from nc_py_api import FsNode, LockType, NextcloudException, NextcloudExceptionNotFound
from nc_py_api import (
FsNode,
LockType,
NextcloudException,
NextcloudExceptionNotFound,
SystemTag,
)


class MyBytesIO(BytesIO):
Expand Down Expand Up @@ -1152,7 +1158,7 @@ async def test_create_update_delete_tag_async(anc_any):
await anc_any.files.update_tag(tag)


def test_assign_unassign_tag(nc_any):
def test_get_assign_unassign_tag(nc_any):
with contextlib.suppress(NextcloudExceptionNotFound):
nc_any.files.delete_tag(nc_any.files.tag_by_name("test_nc_py_api"))
with contextlib.suppress(NextcloudExceptionNotFound):
Expand All @@ -1167,8 +1173,10 @@ def test_assign_unassign_tag(nc_any):
assert tag2.user_assignable is False
new_file = nc_any.files.upload("/test_dir_tmp/tag_test.txt", content=b"")
new_file = nc_any.files.by_id(new_file)
assert nc_any.files.get_tags(new_file) == []
assert len(nc_any.files.list_by_criteria(tags=[tag1])) == 0
nc_any.files.assign_tag(new_file, tag1)
assert isinstance(nc_any.files.get_tags(new_file)[0], SystemTag)
assert len(nc_any.files.list_by_criteria(tags=[tag1])) == 1
assert len(nc_any.files.list_by_criteria(["favorite"], tags=[tag1])) == 0
assert len(nc_any.files.list_by_criteria(tags=[tag1, tag2.tag_id])) == 0
Expand All @@ -1182,7 +1190,7 @@ def test_assign_unassign_tag(nc_any):


@pytest.mark.asyncio(scope="session")
async def test_assign_unassign_tag_async(anc_any):
async def test_get_assign_unassign_tag_async(anc_any):
with contextlib.suppress(NextcloudExceptionNotFound):
await anc_any.files.delete_tag(await anc_any.files.tag_by_name("test_nc_py_api"))
with contextlib.suppress(NextcloudExceptionNotFound):
Expand All @@ -1197,8 +1205,10 @@ async def test_assign_unassign_tag_async(anc_any):
assert tag2.user_assignable is False
new_file = await anc_any.files.upload("/test_dir_tmp/tag_test.txt", content=b"")
new_file = await anc_any.files.by_id(new_file)
assert await anc_any.files.get_tags(new_file) == []
assert len(await anc_any.files.list_by_criteria(tags=[tag1])) == 0
await anc_any.files.assign_tag(new_file, tag1)
assert isinstance((await anc_any.files.get_tags(new_file))[0], SystemTag)
assert len(await anc_any.files.list_by_criteria(tags=[tag1])) == 1
assert len(await anc_any.files.list_by_criteria(["favorite"], tags=[tag1])) == 0
assert len(await anc_any.files.list_by_criteria(tags=[tag1, tag2.tag_id])) == 0
Expand Down