Add view for StudyGroups

This commit is contained in:
Sebastian Serth
2018-12-14 14:52:04 +01:00
parent 9061a07763
commit 7983c0797a
13 changed files with 168 additions and 9 deletions

View File

@@ -0,0 +1,21 @@
class StudyGroupPolicy < AdminOnlyPolicy
def index?
admin? || teacher?
end
[:show?, :destroy?, :edit?, :update?].each do |action|
define_method(action) { admin? || @user.teacher? && @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