Skip to content

Commit f2d87e1

Browse files
authored
Remote annotation lists (#1262)
* wip remote annotation lists. * Update readme, add test and fix annotation list
1 parent 5c02c35 commit f2d87e1

File tree

6 files changed

+142
-6
lines changed

6 files changed

+142
-6
lines changed

webknossos/Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ For upgrade instructions, please check the respective _Breaking Changes_ section
1515
### Breaking Changes
1616

1717
### Added
18+
- Added `get_remote_annotations()` to AnnotationInfo class to get a list of all remote Annotations of the current user. [#1262](https://github.com/scalableminds/webknossos-libs/pull/1262)
1819

1920
### Changed
2021

webknossos/tests/cassettes/test_annotation/test_remote_annotation_list.yml

Lines changed: 94 additions & 0 deletions
Large diffs are not rendered by default.

webknossos/tests/test_annotation.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,19 @@ def test_annotation_from_file_with_multi_volume() -> None:
148148
pass
149149

150150

151+
@pytest.mark.use_proxay
152+
def test_remote_annotation_list() -> None:
153+
path = TESTDATA_DIR / "annotations" / "l4_sample__explorational__suser__94b271.zip"
154+
annotation_from_file = wk.Annotation.load(path)
155+
annotation_from_file.organization_id = "Organization_X"
156+
test_token = os.getenv("WK_TOKEN")
157+
with wk.webknossos_context("http://localhost:9000", test_token):
158+
annotation_from_file.upload()
159+
annotations = wk.AnnotationInfo.get_remote_annotations()
160+
161+
assert annotation_from_file.name in [a.name for a in annotations]
162+
163+
151164
@pytest.mark.use_proxay
152165
def test_annotation_upload_download_roundtrip() -> None:
153166
path = TESTDATA_DIR / "annotations" / "l4_sample__explorational__suser__94b271.zip"

webknossos/webknossos/annotation/annotation_info.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional
1+
from typing import List, Optional
22

33
import attr
44

@@ -38,3 +38,21 @@ def _from_api_annotation(cls, api_annotation: ApiAnnotation) -> "AnnotationInfo"
3838
else None,
3939
modified=api_annotation.modified,
4040
)
41+
42+
@classmethod
43+
def get_remote_annotations(
44+
cls, is_finished: Optional[bool] = False, owner: Optional[str] = None
45+
) -> List["AnnotationInfo"]:
46+
"""Returns a list of AnnotationInfo objects for all annotations that belong to the current user (if owner is None).
47+
If owner is not None, only annotations of the specified owner are returned."""
48+
from ..client.context import _get_api_client
49+
50+
client = _get_api_client(True)
51+
if owner is None:
52+
owner = client.user_current().id
53+
54+
return [
55+
cls._from_api_annotation(api_annotation)
56+
for api_annotation in client.annotation_list(is_finished)
57+
if api_annotation.owner.id == owner
58+
]

webknossos/webknossos/client/api_client/models.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,11 @@ class ApiUser:
261261
@attr.s(auto_attribs=True)
262262
class ApiUserCompact:
263263
id: str
264-
email: str
265264
first_name: str
266265
last_name: str
267-
is_admin: bool
268-
is_dataset_manager: bool
266+
email: Optional[str] = None
267+
is_admin: Optional[bool] = None
268+
is_dataset_manager: Optional[bool] = None
269269

270270

271271
@attr.s(auto_attribs=True)
@@ -296,9 +296,9 @@ class ApiProject:
296296
name: str
297297
team: str
298298
team_name: str
299-
owner: Optional[ApiUserCompact] # None in case you have no read access on the owner
300299
priority: int
301300
paused: bool
301+
owner: Optional[ApiUserCompact] # None in case you have no read access on the owner
302302
expected_time: Optional[int] = None
303303

304304

@@ -311,7 +311,7 @@ class ApiAnnotation:
311311
description: str
312312
state: str
313313
modified: int
314-
data_store: ApiDataStore
314+
data_store: Optional[ApiDataStore] = None
315315
tracing_time: Optional[int] = None # millis
316316

317317

webknossos/webknossos/client/api_client/wk_api_client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ def dataset_explore_and_add_remote(
122122
dataset,
123123
)
124124

125+
def annotation_list(self, is_finished: Optional[bool]) -> List[ApiAnnotation]:
126+
route = "/annotations/readable"
127+
return self._get_json(
128+
route,
129+
List[ApiAnnotation],
130+
query={
131+
"isFinished": is_finished,
132+
},
133+
)
134+
125135
def datastore_list(self) -> List[ApiDataStore]:
126136
route = "/datastores"
127137
return self._get_json(route, List[ApiDataStore])

0 commit comments

Comments
 (0)