Files
codeocean/app/policies/exercise_policy.rb
Sebastian Serth afafe0c218 Adjust teacher permissions:
* Hide non-public exercises and proxy exercises
* Hide average working time value on statistic page
* Add hint about filter to submission page for teachers
* Hide display name from feedback page
2020-09-07 19:04:34 +02:00

42 lines
1.0 KiB
Ruby

class ExercisePolicy < AdminOrAuthorPolicy
def batch_update?
admin?
end
[:show?, :feedback?, :requests_for_comments?, :statistics?].each do |action|
define_method(action) { admin? || teacher_in_study_group? || teacher? && @record.public? || author? }
end
def study_group_dashboard?
admin? || teacher_in_study_group?
end
def submission_statistics?
admin? || teacher_in_study_group?
end
def detailed_statistics?
admin?
end
[:clone?, :destroy?, :edit?, :update?, :export_external_check?, :export_external_confirm?].each do |action|
define_method(action) { admin? || teacher_in_study_group? || author? }
end
[:implement?, :working_times?, :intervention?, :search?, :submit?, :reload?].each do |action|
define_method(action) { everyone }
end
class Scope < Scope
def resolve
if @user.admin?
@scope.all
elsif @user.teacher?
@scope.where('user_id = ? OR public = TRUE', @user.id)
else
@scope.none
end
end
end
end