V0: Annotation API - Annotation App Token Support #2514
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.