V0: Annotation API - Annotation App Token Support - #2514
Open
emmyxth wants to merge 1 commit into
Open
Conversation
tompollard
reviewed
Nov 10, 2025
| AnnotationCollectionCreateAPIView.as_view(), | ||
| name="annotation-collection-create", | ||
| ), | ||
| path( |
Member
There was a problem hiding this comment.
Not directly related to this PR, but would it be clearer to go with one of collections or collection for the endpoint? Currently we use both.
Member
|
@emmyxth please could you rebase this PR on the dev branch? |
tompollard
force-pushed
the
et/token-perm
branch
from
March 24, 2026 15:36
23fe17a to
538c8e1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As per conversation #1047 (comment), we want to add fine-grained token authorization. This PR introduces granular OAuth token scopes for the Annotations API, replacing the broad
annotations:viewandannotations:editscopes with resource-specific permissions.Changes
1. Fine-Grained OAuth Scopes (
physionet/settings/base.py)Replaced broad scopes with granular permissions:
annotations:collections:readandannotations:collections:writeannotations:types:readandannotations:types:writeannotations:annotations:readandannotations:annotations:write2. New Permission Classes (
annotation/views.py)AnnotationsCollectionsScopefor collection endpointsAnnotationsTypesScopefor type endpointsAnnotationsScope3. New Collection Read Endpoint (
annotation/views.py,annotation/urls.py)Added
AnnotationCollectionReadAPIViewwith:/annotations/collection/<slug>/prefetch_related()to reduce database queriesannotations:collections:read)4. Serializer Improvements (
annotation/serializers.py)AnnotationCollectionSerializerto end of file (afterAnnotationSerializerdefinition)annotationsfield toAnnotationCollectionSerializerto include related annotations in collection responsesAnnotationSerializer.to_representation()to properly access child location models:instance.location.textspanlocationinstead ofinstance.locationinstance.location.timeseriesintervallocationinstead ofinstance.locationinstance.location.imagebboxlocationinstead ofinstance.location5. Updated Tests (
annotation/tests.py)_read_annotation_collection()helper methodtest_read_annotation_collection_correct_scope()to verify collection read endpoint with proper scope handlingAll existing tests updated and passing with new scope requirements. New test added for collection read endpoint.