Files
codeocean/app/policies/exercise_policy.rb
Thomas Hille b05bb27ed9 search is now saved asynchron and without a form which caused some redirection through searches_controller
added asynchronous save of search, removed searches_controller,
2017-03-21 14:37:32 +01:00

35 lines
695 B
Ruby

class ExercisePolicy < AdminOrAuthorPolicy
def author?
@user == @record.author
end
private :author?
def batch_update?
admin?
end
def show?
@user.internal_user?
end
[:clone?, :destroy?, :edit?, :statistics?, :update?].each do |action|
define_method(action) { admin? || 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.internal_user?
@scope.where('user_id = ? OR public = TRUE', @user.id)
else
@scope.none
end
end
end
end