Skip to content

Commit

Permalink
Merge branch 'main' into chore/simplify-search
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Nov 13, 2024
2 parents 4c0adbc + b7a244a commit 52025b1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/controllers/saved_annotations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def new
@annotations = AnnotationPolicy::Scope.new(current_user, Annotation.all).resolve
@annotations = @annotations.where(saved_annotation_id: nil).where(user_id: current_user.id)
@filters = filters(@annotations)

Check warning on line 46 in app/controllers/saved_annotations_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/saved_annotations_controller.rb#L46

Added line #L46 was not covered by tests
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 52025b1

Please sign in to comment.