Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Oct 8, 2024
1 parent 8bc4623 commit fb3f620
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/controllers/saved_annotations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ 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('INNER JOIN submissions AS submission ON submission.id = annotations.submission_id').pluck('submission.course_id').uniq)
@exercises = Activity.where(id: @annotations.joins('INNER JOIN submissions AS submission ON submission.id = annotations.submission_id').pluck('submission.exercise_id').uniq)
@courses = Course.where(id: @annotations.pluck('submission.course_id').uniq)
@exercises = Activity.where(id: @annotations.pluck('submission.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
7 changes: 4 additions & 3 deletions app/policies/annotation_policy.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
class AnnotationPolicy < ApplicationPolicy
class Scope < ApplicationPolicy::Scope
def resolve
annotations = scope.joins('INNER JOIN submissions AS submission ON submission.id = annotations.submission_id')
if user&.zeus?
scope.all
annotations.all
elsif user
scope.released.where(submission: { user: user }).or(scope.where(submission: { course_id: user.administrating_courses.map(&:id) }))
annotations.released.where(submission: { user: user }).or(annotations.where(submission: { course_id: user.administrating_courses.map(&:id) }))
else
scope.none
annotations.none
end
end
end
Expand Down

0 comments on commit fb3f620

Please sign in to comment.