@@ -480,10 +480,12 @@ def get_recordings(
480480 count = queryset .count ()
481481 offset = (q .page - 1 ) * q .limit
482482
483- # One query for page of recordings + owner ; prefetch file annotations + species (no N+1)
483+ # One query for page of recordings; prefetch current user's file annotations only (no N+1)
484484 file_annotations_prefetch = Prefetch (
485485 'recordingannotation_set' ,
486- queryset = RecordingAnnotation .objects .prefetch_related ('species' ).order_by ('confidence' ),
486+ queryset = RecordingAnnotation .objects .filter (owner = request .user )
487+ .prefetch_related ('species' )
488+ .order_by ('confidence' ),
487489 )
488490 page_recordings = list (
489491 queryset .select_related ('owner' ).prefetch_related (file_annotations_prefetch )[
@@ -634,9 +636,10 @@ def get_recording(request: HttpRequest, id: int):
634636 ).exists ()
635637 )
636638 recording ['userMadeAnnotations' ] = user_has_annotations
637- fileAnnotations = RecordingAnnotation .objects .filter (recording = id ).order_by (
638- 'confidence'
639- )
639+ # Only expose file-level annotations owned by the current user
640+ fileAnnotations = RecordingAnnotation .objects .filter (
641+ recording = id , owner = request .user
642+ ).order_by ('confidence' )
640643 recording ['fileAnnotations' ] = [
641644 RecordingAnnotationSchema .from_orm (fileAnnotation ).dict ()
642645 for fileAnnotation in fileAnnotations
@@ -650,9 +653,16 @@ def get_recording(request: HttpRequest, id: int):
650653
651654@router .get ('/{recording_id}/recording-annotations' )
652655def get_recording_annotations (request : HttpRequest , recording_id : int ):
653- fileAnnotations = RecordingAnnotation .objects .filter (recording = recording_id ).order_by (
654- 'confidence'
655- )
656+ try :
657+ recording = Recording .objects .get (pk = recording_id )
658+ except Recording .DoesNotExist :
659+ return {'error' : 'Recording not found' }
660+ if recording .owner != request .user and not recording .public :
661+ return {'error' : 'Permission denied. You do not own this recording, and it is not public.' }
662+ # Only return file-level annotations owned by the current user (same as pulse annotations)
663+ fileAnnotations = RecordingAnnotation .objects .filter (
664+ recording = recording_id , owner = request .user
665+ ).order_by ('confidence' )
656666 output = [
657667 RecordingAnnotationSchema .from_orm (fileAnnotation ).dict ()
658668 for fileAnnotation in fileAnnotations
0 commit comments