Refactor exercise_controller and move more checks to policy

* We introduce a custom handler for Pundit::NotAuthorizedError
This commit is contained in:
Sebastian Serth
2022-09-04 00:05:13 +02:00
parent 0de213b8c7
commit 49f4f0e6c5
4 changed files with 78 additions and 7 deletions

View File

@ -30,7 +30,11 @@ class ExercisePolicy < AdminOrAuthorPolicy
end
%i[implement? working_times? intervention? search? reload?].each do |action|
define_method(action) { everyone }
define_method(action) do
return no_one unless @record.files.visible.exists?
admin? || teacher_in_study_group? || author? || (everyone && !@record.unpublished?)
end
end
def submit?