Skip to content

Commit

Permalink
Merge pull request #954 from girder/delete-folder-annotations
Browse files Browse the repository at this point in the history
Add an endpoint to delete all annotations in a folder
  • Loading branch information
manthey authored Sep 1, 2022
2 parents 12d3151 + 2c80d68 commit cf4c175
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 1.16.3

### Improvements
- Reduce rest calls to get settings ([953](../../pull/953))
- Add an endpoint to delete all annotations in a folder ([954](../../pull/954))

## 1.16.2

### Improvements
Expand Down
22 changes: 22 additions & 0 deletions girder_annotation/girder_large_image_annotation/rest/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def __init__(self):
self.route('GET', ('folder', ':id', 'present'), self.existFolderAnnotations)
self.route('GET', ('folder', ':id', 'create'), self.canCreateFolderAnnotations)
self.route('PUT', ('folder', ':id', 'access'), self.setFolderAnnotationAccess)
self.route('DELETE', ('folder', ':id'), self.deleteFolderAnnotations)
self.route('GET', ('old',), self.getOldAnnotations)
self.route('DELETE', ('old',), self.deleteOldAnnotations)
self.route('GET', ('counts',), self.getItemListAnnotationCounts)
Expand Down Expand Up @@ -725,6 +726,27 @@ def setFolderAnnotationAccess(self, id, params):

return {'updated': count}

@autoDescribeRoute(
Description('Delete all user-owned annotations from the items in a folder')
.param('id', 'The ID of the folder', required=True, paramType='path')
.param('recurse', 'Whether or not to retrieve all '
'annotations from subfolders', required=False, default=False, dataType='boolean')
.errorResponse('ID was invalid.')
)
@access.user
def deleteFolderAnnotations(self, id, params):
setResponseTimeLimit(86400)
user = self.getCurrentUser()
if not user:
return []
count = 0
for annotation in self.getFolderAnnotations(id, params['recurse'], user):
annot = Annotation().load(annotation['_id'], user=user, getElements=False)
Annotation().remove(annot)
count += 1

return {'deleted': count}

@autoDescribeRoute(
Description('Report on old annotations.')
.param('age', 'The minimum age in days.', required=False,
Expand Down

0 comments on commit cf4c175

Please sign in to comment.