From 3fa592474b9d772f9d06db8719c2f14beb735862 Mon Sep 17 00:00:00 2001 From: jorg-vr Date: Wed, 16 Aug 2023 14:53:24 +0200 Subject: [PATCH] Avoid 403 errors when a user cannot access linked saved annotations --- app/assets/javascripts/state/SavedAnnotations.ts | 5 +++++ app/views/annotations/_annotation.json.jbuilder | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/state/SavedAnnotations.ts b/app/assets/javascripts/state/SavedAnnotations.ts index 9870c2d405..4489d76344 100644 --- a/app/assets/javascripts/state/SavedAnnotations.ts +++ b/app/assets/javascripts/state/SavedAnnotations.ts @@ -43,6 +43,11 @@ class SavedAnnotationState extends State { private async fetch(id: number): Promise { const url = `${URL}/${id}.json`; const response = await fetch(url); + + if (response.status === 403) { + return undefined; + } + this.byId.set(id, await response.json()); return this.byId.get(id); } diff --git a/app/views/annotations/_annotation.json.jbuilder b/app/views/annotations/_annotation.json.jbuilder index 9534645e44..04c539b066 100644 --- a/app/views/annotations/_annotation.json.jbuilder +++ b/app/views/annotations/_annotation.json.jbuilder @@ -1,4 +1,4 @@ -json.extract! annotation, :id, :line_nr, :annotation_text, :user_id, :submission_id, :saved_annotation_id, :created_at, :updated_at, :course_id, :column, :rows, :columns +json.extract! annotation, :id, :line_nr, :annotation_text, :user_id, :submission_id, :created_at, :updated_at, :course_id, :column, :rows, :columns json.row annotation.line_nr || 0 if annotation.is_a?(Question) json.extract! annotation, :question_state @@ -41,3 +41,5 @@ json.responses annotation.responses do |response| json.partial! response, as: :annotation end json.thread_root_id annotation.thread_root_id + +json.saved_annotation_id annotation.saved_annotation_id if annotation.saved_annotation.present? && SavedAnnotationPolicy.new(current_user, annotation.saved_annotation).show?