Merge pull request #248 from openHPI/improve_groups

Improve groups with a view and always create a group
This commit is contained in:
rteusner
2018-12-19 13:57:41 +01:00
committed by GitHub
14 changed files with 173 additions and 11 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