Files
codeocean/app/policies/study_group_policy.rb
Sebastian Serth d63700c7db Add live dashboard for teachers in the context of an exercise
This commit also adds the fundamentals for ActionCable
2019-03-06 14:00:59 +01:00

22 lines
548 B
Ruby

class StudyGroupPolicy < AdminOnlyPolicy
def index?
admin? || teacher?
end
[:show?, :destroy?, :edit?, :update?, :stream_la?].each do |action|
define_method(action) { admin? || @user.teacher? && @record.present? && @record.users.include?(@user) }
end
class Scope < Scope
def resolve
if @user.admin?
@scope.all
elsif @user.teacher?
@scope.joins(:study_group_memberships).where('user_id = ? AND user_type = ?', @user.id, @user.class.name)
else
@scope.none
end
end
end
end