girder-large-image-annotation 1.36.2.dev2__tar.gz → 1.36.2.dev4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. {girder_large_image_annotation-1.36.2.dev2/girder_large_image_annotation.egg-info → girder_large_image_annotation-1.36.2.dev4}/PKG-INFO +3 -3
  2. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/rest/annotation.py +1 -1
  3. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4/girder_large_image_annotation.egg-info}/PKG-INFO +3 -3
  4. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation.egg-info/requires.txt +2 -2
  5. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/test_annotation/test_annotations_rest.py +265 -0
  6. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/LICENSE +0 -0
  7. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/README.rst +0 -0
  8. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/docs/annotations.rst +0 -0
  9. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/docs/plottable.rst +0 -0
  10. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/__init__.py +0 -0
  11. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/constants.py +0 -0
  12. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/handlers.py +0 -0
  13. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/models/__init__.py +0 -0
  14. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/models/annotation.py +0 -0
  15. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/models/annotationelement.py +0 -0
  16. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/rest/__init__.py +0 -0
  17. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/utils/__init__.py +0 -0
  18. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/convert.js +0 -0
  19. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/convertFeatures.js +0 -0
  20. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/defaults/circle.js +0 -0
  21. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/defaults/ellipse.js +0 -0
  22. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/defaults/index.js +0 -0
  23. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/defaults/point.js +0 -0
  24. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/defaults/polyline.js +0 -0
  25. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/defaults/rectangle.js +0 -0
  26. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/geojs/common.js +0 -0
  27. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/geojs/convert.js +0 -0
  28. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/geojs/coordinates/array.js +0 -0
  29. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/geojs/coordinates/index.js +0 -0
  30. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/geojs/coordinates/point.js +0 -0
  31. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/geojs/index.js +0 -0
  32. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/geojs/types/circle.js +0 -0
  33. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/geojs/types/ellipse.js +0 -0
  34. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/geojs/types/index.js +0 -0
  35. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/geojs/types/line.js +0 -0
  36. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/geojs/types/point.js +0 -0
  37. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/geojs/types/polygon.js +0 -0
  38. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/geojs/types/rectangle.js +0 -0
  39. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/geometry/circle.js +0 -0
  40. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/geometry/ellipse.js +0 -0
  41. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/geometry/index.js +0 -0
  42. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/geometry/point.js +0 -0
  43. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/geometry/polyline.js +0 -0
  44. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/geometry/rectangle.js +0 -0
  45. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/index.js +0 -0
  46. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/rotate.js +0 -0
  47. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/annotations/style.js +0 -0
  48. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/collections/AnnotationCollection.js +0 -0
  49. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/collections/ElementCollection.js +0 -0
  50. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/collections/index.js +0 -0
  51. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/index.js +0 -0
  52. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/main.js +0 -0
  53. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/models/AnnotationModel.js +0 -0
  54. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/models/ElementModel.js +0 -0
  55. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/models/index.js +0 -0
  56. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/package.json +0 -0
  57. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/routes.js +0 -0
  58. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/stylesheets/annotationListWidget.styl +0 -0
  59. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/stylesheets/itemList.styl +0 -0
  60. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/templates/annotationListWidget.pug +0 -0
  61. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/templates/imageViewerAnnotationList.pug +0 -0
  62. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/templates/largeImageAnnotationConfig.pug +0 -0
  63. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/views/annotationListWidget.js +0 -0
  64. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/views/configView.js +0 -0
  65. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/views/hierarchyWidget.js +0 -0
  66. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/views/imageViewerSelectWidget.js +0 -0
  67. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/views/imageViewerWidget/base.js +0 -0
  68. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/views/imageViewerWidget/geojs.js +0 -0
  69. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/views/imageViewerWidget/index.js +0 -0
  70. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/views/index.js +0 -0
  71. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation/web_client/views/itemList.js +0 -0
  72. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation.egg-info/SOURCES.txt +0 -0
  73. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation.egg-info/dependency_links.txt +0 -0
  74. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation.egg-info/entry_points.txt +0 -0
  75. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation.egg-info/not-zip-safe +0 -0
  76. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation.egg-info/scm_file_list.json +0 -0
  77. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/girder_large_image_annotation.egg-info/top_level.txt +0 -0
  78. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/pyproject.toml +0 -0
  79. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/setup.cfg +0 -0
  80. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/setup.py +0 -0
  81. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/test_annotation/__init__.py +0 -0
  82. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/test_annotation/conftest.py +0 -0
  83. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/test_annotation/girder_utilities.py +0 -0
  84. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/test_annotation/test_annotations.py +0 -0
  85. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/test_annotation/test_web_client.py +0 -0
  86. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/test_annotation/web_client_specs/.eslintrc +0 -0
  87. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/test_annotation/web_client_specs/annotationListSpec.js +0 -0
  88. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/test_annotation/web_client_specs/annotationSpec.js +0 -0
  89. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/test_annotation/web_client_specs/geojsAnnotationSpec.js +0 -0
  90. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/test_annotation/web_client_specs/geojsSpec.js +0 -0
  91. {girder_large_image_annotation-1.36.2.dev2 → girder_large_image_annotation-1.36.2.dev4}/test_annotation/web_client_specs/sample_annotation.json +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: girder-large-image-annotation
3
- Version: 1.36.2.dev2
3
+ Version: 1.36.2.dev4
4
4
  Summary: A Girder plugin to store and display annotations on large, multiresolution images.
5
5
  Home-page: https://github.com/girder/large_image
6
6
  Author: Kitware, Inc.
@@ -19,7 +19,7 @@ Requires-Python: >=3.10
19
19
  Description-Content-Type: text/x-rst
20
20
  License-File: LICENSE
21
21
  Requires-Dist: jsonschema>=2.5.1
22
- Requires-Dist: girder-large-image>=1.36.2.dev2
22
+ Requires-Dist: girder-large-image>=1.36.2.dev4
23
23
  Requires-Dist: orjson
24
24
  Provides-Extra: compute
25
25
  Requires-Dist: openpyxl; extra == "compute"
@@ -27,7 +27,7 @@ Requires-Dist: pandas>=2.2; extra == "compute"
27
27
  Requires-Dist: python-calamine; extra == "compute"
28
28
  Requires-Dist: umap-learn; extra == "compute"
29
29
  Provides-Extra: tasks
30
- Requires-Dist: girder-large-image[tasks]>=1.36.2.dev2; extra == "tasks"
30
+ Requires-Dist: girder-large-image[tasks]>=1.36.2.dev4; extra == "tasks"
31
31
  Dynamic: author
32
32
  Dynamic: author-email
33
33
  Dynamic: classifier
@@ -1027,7 +1027,7 @@ class AnnotationResource(Resource):
1027
1027
  if not user:
1028
1028
  return []
1029
1029
  access = json.loads(params['access'])
1030
- public = self.boolParam('public', params, False)
1030
+ public = bool(params.get('public'))
1031
1031
  count = 0
1032
1032
  for annotation in self.getFolderAnnotations(id, params['recurse'], user):
1033
1033
  annot = Annotation().load(annotation['_id'], user=user, getElements=False)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: girder-large-image-annotation
3
- Version: 1.36.2.dev2
3
+ Version: 1.36.2.dev4
4
4
  Summary: A Girder plugin to store and display annotations on large, multiresolution images.
5
5
  Home-page: https://github.com/girder/large_image
6
6
  Author: Kitware, Inc.
@@ -19,7 +19,7 @@ Requires-Python: >=3.10
19
19
  Description-Content-Type: text/x-rst
20
20
  License-File: LICENSE
21
21
  Requires-Dist: jsonschema>=2.5.1
22
- Requires-Dist: girder-large-image>=1.36.2.dev2
22
+ Requires-Dist: girder-large-image>=1.36.2.dev4
23
23
  Requires-Dist: orjson
24
24
  Provides-Extra: compute
25
25
  Requires-Dist: openpyxl; extra == "compute"
@@ -27,7 +27,7 @@ Requires-Dist: pandas>=2.2; extra == "compute"
27
27
  Requires-Dist: python-calamine; extra == "compute"
28
28
  Requires-Dist: umap-learn; extra == "compute"
29
29
  Provides-Extra: tasks
30
- Requires-Dist: girder-large-image[tasks]>=1.36.2.dev2; extra == "tasks"
30
+ Requires-Dist: girder-large-image[tasks]>=1.36.2.dev4; extra == "tasks"
31
31
  Dynamic: author
32
32
  Dynamic: author-email
33
33
  Dynamic: classifier
@@ -1,5 +1,5 @@
1
1
  jsonschema>=2.5.1
2
- girder-large-image>=1.36.2.dev2
2
+ girder-large-image>=1.36.2.dev4
3
3
  orjson
4
4
 
5
5
  [compute]
@@ -9,4 +9,4 @@ python-calamine
9
9
  umap-learn
10
10
 
11
11
  [tasks]
12
- girder-large-image[tasks]>=1.36.2.dev2
12
+ girder-large-image[tasks]>=1.36.2.dev4
@@ -15,6 +15,7 @@ pytestmark = pytest.mark.girder
15
15
 
16
16
  try:
17
17
  from girder_large_image import constants
18
+ from girder_large_image_annotation.constants import ANNOTATION_ACCESS_FLAG
18
19
  from girder_large_image_annotation.models.annotation import Annotation
19
20
 
20
21
  from girder.constants import AccessType
@@ -1115,3 +1116,267 @@ def testFolderEndpoints(server, admin, user):
1115
1116
  params={'recurse': True})
1116
1117
  assert utilities.respStatus(resp) == 200
1117
1118
  assert len(resp.json) == 2
1119
+
1120
+
1121
+ def _folderAccessSetup(admin, user):
1122
+ """
1123
+ Create a private folder with a subfolder, with annotations in each made by
1124
+ a user and by an admin. The user has admin access to the folders and to
1125
+ the annotations they made. The admin's annotations have empty access
1126
+ control lists. A second user is given read access to the folders after
1127
+ the annotations are created, so has no access to any of the annotations.
1128
+
1129
+ :param admin: an admin user.
1130
+ :param user: a non-admin user.
1131
+ :returns: a dictionary with other (the second user), folderA, folderB (a
1132
+ subfolder of folderA), userInA (a list of the user's annotations in
1133
+ folderA), userInB (the same for folderB), and adminInA and adminInB (the
1134
+ same for the admin).
1135
+ """
1136
+ other = User().createUser(
1137
+ 'other', 'password', 'Other', 'User', 'other@girder.test')
1138
+ collection = Collection().createCollection('collection A', user, public=False)
1139
+ folderA = Folder().createFolder(
1140
+ collection, 'folder A', parentType='collection', creator=user, public=False)
1141
+ folderB = Folder().createFolder(folderA, 'folder B', creator=user, public=False)
1142
+ itemA1 = Item().createItem('sample A1', user, folderA)
1143
+ itemA2 = Item().createItem('sample A2', user, folderA)
1144
+ itemB1 = Item().createItem('sample B1', user, folderB)
1145
+ result = {'other': other, 'userInA': [], 'userInB': [], 'adminInA': [], 'adminInB': []}
1146
+ for item, key in ((itemA1, 'A'), (itemA2, 'A'), (itemB1, 'B')):
1147
+ result['userIn' + key].append(
1148
+ Annotation().createAnnotation(item, user, sampleAnnotation))
1149
+ for item, key in ((itemA1, 'A'), (itemB1, 'B')):
1150
+ annot = Annotation().createAnnotation(item, admin, sampleAnnotation, public=False)
1151
+ Annotation().setAccessList(annot, access={'users': [], 'groups': []}, save=True)
1152
+ result['adminIn' + key].append(annot)
1153
+ Collection().setUserAccess(collection, other, AccessType.READ, save=True)
1154
+ result['folderA'] = Folder().setUserAccess(folderA, other, AccessType.READ, save=True)
1155
+ result['folderB'] = Folder().setUserAccess(folderB, other, AccessType.READ, save=True)
1156
+ return result
1157
+
1158
+
1159
+ def _annotationAccessLevels(annot):
1160
+ """
1161
+ Get the current access of an annotation from the database.
1162
+
1163
+ :param annot: the annotation to check.
1164
+ :returns: a dictionary of user id to access level for the users in the
1165
+ annotation's access control list, and the annotation's public flag.
1166
+ """
1167
+ annot = Annotation().load(annot['_id'], force=True, getElements=False)
1168
+ return {entry['id']: entry['level'] for entry in annot['access']['users']}, annot['public']
1169
+
1170
+
1171
+ @pytest.mark.usefixtures('unbindLargeImage', 'unbindAnnotation')
1172
+ @pytest.mark.plugin('large_image_annotation')
1173
+ def testFolderAnnotationAccess(server, admin, user):
1174
+ setup = _folderAccessSetup(admin, user)
1175
+ other = setup['other']
1176
+ path = '/annotation/folder/%s/access' % setup['folderA']['_id']
1177
+ userAnnots = setup['userInA'] + setup['userInB']
1178
+ adminAnnots = setup['adminInA'] + setup['adminInB']
1179
+
1180
+ def accessList(*entries):
1181
+ return json.dumps({'groups': [], 'users': [{
1182
+ 'id': str(entry['_id']), 'level': level, 'flags': [],
1183
+ } for entry, level in entries]})
1184
+
1185
+ # The second user starts with no access to any annotation
1186
+ for annot in userAnnots + adminAnnots:
1187
+ resp = server.request('/annotation/%s' % annot['_id'], user=other)
1188
+ assert utilities.respStatus(resp) == 403
1189
+
1190
+ # This requires a logged in user
1191
+ resp = server.request(path, method='PUT', params={
1192
+ 'access': accessList((user, AccessType.ADMIN))})
1193
+ assert utilities.respStatus(resp) == 401
1194
+
1195
+ # A user without admin access to any annotations changes nothing
1196
+ resp = server.request(path, method='PUT', user=other, params={
1197
+ 'access': accessList((other, AccessType.ADMIN)), 'recurse': True})
1198
+ assert utilities.respStatus(resp) == 200
1199
+ assert resp.json == {'updated': 0}
1200
+ for annot in userAnnots:
1201
+ assert _annotationAccessLevels(annot) == ({user['_id']: AccessType.ADMIN}, False)
1202
+
1203
+ # Without recurse, only the user's annotations in the folder itself are
1204
+ # changed
1205
+ resp = server.request(path, method='PUT', user=user, params={
1206
+ 'access': accessList((user, AccessType.ADMIN), (other, AccessType.READ)),
1207
+ 'public': True})
1208
+ assert utilities.respStatus(resp) == 200
1209
+ assert resp.json == {'updated': 2}
1210
+ for annot in setup['userInA']:
1211
+ assert _annotationAccessLevels(annot) == (
1212
+ {user['_id']: AccessType.ADMIN, other['_id']: AccessType.READ}, True)
1213
+ resp = server.request('/annotation/%s' % annot['_id'], user=other)
1214
+ assert utilities.respStatus(resp) == 200
1215
+ assert resp.json['_accessLevel'] == AccessType.READ
1216
+ for annot in setup['userInB']:
1217
+ assert _annotationAccessLevels(annot) == ({user['_id']: AccessType.ADMIN}, False)
1218
+ resp = server.request('/annotation/%s' % annot['_id'], user=other)
1219
+ assert utilities.respStatus(resp) == 403
1220
+ # Annotations the user does not have admin access to are not changed
1221
+ for annot in adminAnnots:
1222
+ assert _annotationAccessLevels(annot) == ({}, False)
1223
+
1224
+ # With recurse, annotations in subfolders are changed. The access control
1225
+ # list is replaced, not merged, and public defaults to false.
1226
+ resp = server.request(path, method='PUT', user=user, params={
1227
+ 'access': accessList((user, AccessType.ADMIN)), 'recurse': True})
1228
+ assert utilities.respStatus(resp) == 200
1229
+ assert resp.json == {'updated': 3}
1230
+ for annot in userAnnots:
1231
+ assert _annotationAccessLevels(annot) == ({user['_id']: AccessType.ADMIN}, False)
1232
+ resp = server.request('/annotation/%s' % annot['_id'], user=other)
1233
+ assert utilities.respStatus(resp) == 403
1234
+ for annot in adminAnnots:
1235
+ assert _annotationAccessLevels(annot) == ({}, False)
1236
+
1237
+ # A user can remove their own access, after which they can no longer
1238
+ # change the annotations
1239
+ resp = server.request(path, method='PUT', user=user, params={
1240
+ 'access': accessList((other, AccessType.ADMIN)), 'recurse': True})
1241
+ assert utilities.respStatus(resp) == 200
1242
+ assert resp.json == {'updated': 3}
1243
+ for annot in userAnnots:
1244
+ assert _annotationAccessLevels(annot) == ({other['_id']: AccessType.ADMIN}, False)
1245
+ resp = server.request(path, method='PUT', user=user, params={
1246
+ 'access': accessList((user, AccessType.ADMIN)), 'recurse': True})
1247
+ assert utilities.respStatus(resp) == 200
1248
+ assert resp.json == {'updated': 0}
1249
+ for annot in userAnnots:
1250
+ assert _annotationAccessLevels(annot) == ({other['_id']: AccessType.ADMIN}, False)
1251
+
1252
+ # A site admin changes all annotations, regardless of their access
1253
+ resp = server.request(path, method='PUT', user=admin, params={
1254
+ 'access': accessList((user, AccessType.WRITE)), 'recurse': True})
1255
+ assert utilities.respStatus(resp) == 200
1256
+ assert resp.json == {'updated': 5}
1257
+ for annot in userAnnots + adminAnnots:
1258
+ assert _annotationAccessLevels(annot) == ({user['_id']: AccessType.WRITE}, False)
1259
+
1260
+ # The annotation elements are not affected by changing access
1261
+ resp = server.request('/annotation/%s' % userAnnots[0]['_id'], user=user)
1262
+ assert utilities.respStatus(resp) == 200
1263
+ assert resp.json['_accessLevel'] == AccessType.WRITE
1264
+ assert len(resp.json['annotation']['elements']) == len(sampleAnnotation['elements'])
1265
+
1266
+
1267
+ @pytest.mark.usefixtures('unbindLargeImage', 'unbindAnnotation')
1268
+ @pytest.mark.plugin('large_image_annotation')
1269
+ def testFolderAnnotationPresent(server, admin, user):
1270
+ setup = _folderAccessSetup(admin, user)
1271
+ other = setup['other']
1272
+ pathA = '/annotation/folder/%s/present' % setup['folderA']['_id']
1273
+ pathB = '/annotation/folder/%s/present' % setup['folderB']['_id']
1274
+
1275
+ def present(path, checkUser, **params):
1276
+ resp = server.request(path, user=checkUser, params=params)
1277
+ assert utilities.respStatus(resp) == 200
1278
+ return resp.json
1279
+
1280
+ assert present(pathA, user) is True
1281
+ assert present(pathA, user, recurse=False) is True
1282
+ assert present(pathB, user) is True
1283
+ assert present(pathA, admin) is True
1284
+ # Read access to the folder is not enough; the user must have admin access
1285
+ # to an annotation
1286
+ assert present(pathA, other) is False
1287
+ assert present(pathB, other) is False
1288
+ assert not present(pathA, None)
1289
+
1290
+ # Subfolders are checked by default, but not if recurse is false
1291
+ Annotation().setUserAccess(setup['userInB'][0], other, AccessType.WRITE, save=True)
1292
+ assert present(pathA, other) is False
1293
+ Annotation().setUserAccess(setup['userInB'][0], other, AccessType.ADMIN, save=True)
1294
+ assert present(pathA, other) is True
1295
+ assert present(pathA, other, recurse=False) is False
1296
+ assert present(pathB, other, recurse=False) is True
1297
+
1298
+ # Deleted annotations are not counted
1299
+ emptyFolder = Folder().createFolder(setup['folderA'], 'empty', creator=user)
1300
+ emptyPath = '/annotation/folder/%s/present' % emptyFolder['_id']
1301
+ assert present(emptyPath, user) is False
1302
+ item = Item().createItem('sample', user, emptyFolder)
1303
+ annot = Annotation().createAnnotation(item, user, sampleAnnotation)
1304
+ assert present(emptyPath, user) is True
1305
+ resp = server.request('/annotation/%s' % annot['_id'], method='DELETE', user=user)
1306
+ assert utilities.respStatus(resp) == 200
1307
+ assert present(emptyPath, user) is False
1308
+
1309
+
1310
+ @pytest.mark.usefixtures('unbindLargeImage', 'unbindAnnotation')
1311
+ @pytest.mark.plugin('large_image_annotation')
1312
+ def testFolderAnnotationCreate(server, admin, user):
1313
+ setup = _folderAccessSetup(admin, user)
1314
+ other = setup['other']
1315
+ folder = setup['folderA']
1316
+ path = '/annotation/folder/%s/create' % folder['_id']
1317
+
1318
+ resp = server.request(path)
1319
+ assert utilities.respStatus(resp) == 401
1320
+ for checkUser in (user, admin):
1321
+ resp = server.request(path, user=checkUser)
1322
+ assert utilities.respStatus(resp) == 200
1323
+ assert resp.json is True
1324
+ # Read access is not enough to create annotations
1325
+ resp = server.request(path, user=other)
1326
+ assert utilities.respStatus(resp) == 200
1327
+ assert resp.json is False
1328
+ # Read access with the create annotations flag is enough
1329
+ Folder().setUserAccess(
1330
+ folder, other, AccessType.READ, save=True, flags=[ANNOTATION_ACCESS_FLAG])
1331
+ resp = server.request(path, user=other)
1332
+ assert utilities.respStatus(resp) == 200
1333
+ assert resp.json is True
1334
+ # As is write access without the flag
1335
+ Folder().setUserAccess(folder, other, AccessType.WRITE, save=True)
1336
+ resp = server.request(path, user=other)
1337
+ assert utilities.respStatus(resp) == 200
1338
+ assert resp.json is True
1339
+ # Without read access, the folder cannot be checked
1340
+ Folder().setUserAccess(folder, other, None, save=True)
1341
+ resp = server.request(path, user=other)
1342
+ assert utilities.respStatus(resp) == 403
1343
+
1344
+
1345
+ @pytest.mark.usefixtures('unbindLargeImage', 'unbindAnnotation')
1346
+ @pytest.mark.plugin('large_image_annotation')
1347
+ def testFolderAnnotationDelete(server, admin, user):
1348
+ setup = _folderAccessSetup(admin, user)
1349
+ other = setup['other']
1350
+ path = '/annotation/folder/%s' % setup['folderA']['_id']
1351
+
1352
+ def remaining():
1353
+ resp = server.request(path, user=admin, params={'recurse': True})
1354
+ assert utilities.respStatus(resp) == 200
1355
+ return {entry['_id'] for entry in resp.json}
1356
+
1357
+ def ids(*keys):
1358
+ return {str(annot['_id']) for key in keys for annot in setup[key]}
1359
+
1360
+ assert remaining() == ids('userInA', 'userInB', 'adminInA', 'adminInB')
1361
+ resp = server.request(path, method='DELETE', params={'recurse': True})
1362
+ assert utilities.respStatus(resp) == 401
1363
+ # A user without admin access to any annotations deletes nothing
1364
+ resp = server.request(path, method='DELETE', user=other, params={'recurse': True})
1365
+ assert utilities.respStatus(resp) == 200
1366
+ assert resp.json == {'deleted': 0}
1367
+ assert remaining() == ids('userInA', 'userInB', 'adminInA', 'adminInB')
1368
+ # Without recurse, only the user's annotations in the folder itself are
1369
+ # deleted
1370
+ resp = server.request(path, method='DELETE', user=user)
1371
+ assert utilities.respStatus(resp) == 200
1372
+ assert resp.json == {'deleted': 2}
1373
+ assert remaining() == ids('userInB', 'adminInA', 'adminInB')
1374
+ resp = server.request(path, method='DELETE', user=user, params={'recurse': True})
1375
+ assert utilities.respStatus(resp) == 200
1376
+ assert resp.json == {'deleted': 1}
1377
+ assert remaining() == ids('adminInA', 'adminInB')
1378
+ # A site admin deletes all annotations
1379
+ resp = server.request(path, method='DELETE', user=admin, params={'recurse': True})
1380
+ assert utilities.respStatus(resp) == 200
1381
+ assert resp.json == {'deleted': 2}
1382
+ assert remaining() == set()