Skip to content

Commit

Permalink
Avoid 403 errors when a user cannot access linked saved annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Aug 16, 2023
1 parent 188842b commit 3fa5924
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/assets/javascripts/state/SavedAnnotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class SavedAnnotationState extends State {
private async fetch(id: number): Promise<SavedAnnotation> {
const url = `${URL}/${id}.json`;
const response = await fetch(url);

if (response.status === 403) {
return undefined;

Check warning on line 48 in app/assets/javascripts/state/SavedAnnotations.ts

View check run for this annotation

Codecov / codecov/patch

app/assets/javascripts/state/SavedAnnotations.ts#L48

Added line #L48 was not covered by tests
}

this.byId.set(id, await response.json());
return this.byId.get(id);
}
Expand Down
4 changes: 3 additions & 1 deletion app/views/annotations/_annotation.json.jbuilder
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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?

0 comments on commit 3fa5924

Please sign in to comment.