From 3cd2be01de15268bfd55c10ac3e2436438009f2f Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Wed, 13 Apr 2022 20:55:44 +0200 Subject: [PATCH] Include hidden exercises for other teachers of the same study group --- app/policies/exercise_policy.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/policies/exercise_policy.rb b/app/policies/exercise_policy.rb index 2c36b47e..993fe67c 100644 --- a/app/policies/exercise_policy.rb +++ b/app/policies/exercise_policy.rb @@ -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