Include hidden exercises for other teachers of the same study group

This commit is contained in:
Sebastian Serth
2022-04-13 20:55:44 +02:00
parent 66d4f90b4a
commit 3cd2be01de

View File

@ -38,7 +38,13 @@ class ExercisePolicy < AdminOrAuthorPolicy
if @user.admin?
@scope.all
elsif @user.teacher?
@scope.where('user_id = ? OR public = TRUE', @user.id)
@scope.where(
'user_id IN (SELECT user_id FROM study_group_memberships WHERE study_group_id IN (?))
OR (user_id = ? AND user_type = ?)
OR public = TRUE',
@user.study_groups.pluck(:id),
@user.id, @user.class.name
)
else
@scope.none
end