Skip to content

Commit

Permalink
Merge pull request #5838 from dodona-edu/fix/saved-annotation-new
Browse files Browse the repository at this point in the history
Fix filtering on new saved annotation page
  • Loading branch information
jorg-vr authored Nov 13, 2024
2 parents f995c26 + 2e997f8 commit b7a244a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/controllers/saved_annotations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
2 changes: 1 addition & 1 deletion app/policies/annotation_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions test/controllers/saved_annotation_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b7a244a

Please sign in to comment.