diff --git a/app/controllers/saved_annotations_controller.rb b/app/controllers/saved_annotations_controller.rb index 06a6551648..d74155918b 100644 --- a/app/controllers/saved_annotations_controller.rb +++ b/app/controllers/saved_annotations_controller.rb @@ -42,8 +42,9 @@ def new authorize SavedAnnotation @annotations = AnnotationPolicy::Scope.new(current_user, Annotation.all).resolve @annotations = @annotations.where(saved_annotation_id: nil).where(user_id: current_user.id) - @courses = Course.where(id: @annotations.joins(:submission).pluck('submissions.course_id').uniq) - @exercises = Activity.where(id: @annotations.joins(:submission).pluck('submissions.exercise_id').uniq) + submissions = Submission.where(id: @annotations.pluck(:submission_id).uniq) + @courses = Course.where(id: submissions.pluck(:course_id).uniq) + @exercises = Activity.where(id: submissions.pluck(:exercise_id).uniq) @annotations = apply_scopes(@annotations.order_by_created_at(:DESC)) .includes(:course).includes(:user).includes(:submission) .paginate(page: parse_pagination_param(params[:page]), per_page: parse_pagination_param(params[:per_page])) diff --git a/app/policies/annotation_policy.rb b/app/policies/annotation_policy.rb index 6fa65d1c96..1045da391d 100644 --- a/app/policies/annotation_policy.rb +++ b/app/policies/annotation_policy.rb @@ -5,7 +5,7 @@ def resolve scope.all elsif user common = scope.joins(:submission) - common.released.where(submissions: { user: user }).or(common.where(submissions: { course_id: user.administrating_courses.map(&:id) })) + common.released.where(submission: { user: user }).or(common.where(submission: { course_id: user.administrating_courses.map(&:id) })) else scope.none end diff --git a/test/controllers/saved_annotation_controller_test.rb b/test/controllers/saved_annotation_controller_test.rb index 5132a21100..a99b186b1b 100644 --- a/test/controllers/saved_annotation_controller_test.rb +++ b/test/controllers/saved_annotation_controller_test.rb @@ -49,4 +49,25 @@ def setup assert_response :forbidden end + + test 'staff should be able to filter existing annotations on new page' do + get new_saved_annotation_path + + assert_response :success + + get new_saved_annotation_path, params: { exercise_id: 1 } + + assert_response :success + end + + test 'zeus should be able to filter existing annotations on new page' do + sign_in users(:zeus) + get new_saved_annotation_path + + assert_response :success + + get new_saved_annotation_path, params: { exercise_id: 1 } + + assert_response :success + end end