Use admin? or teacher? for permission check instead of internal_user?

This commit is contained in:
Sebastian Serth
2018-11-22 18:55:54 +01:00
parent 71fd3b9b07
commit 4b251599ff
11 changed files with 22 additions and 22 deletions

View File

@@ -1,6 +1,6 @@
class AdminOrAuthorPolicy < ApplicationPolicy
[:create?, :index?, :new?].each do |action|
define_method(action) { @user.internal_user? }
define_method(action) { admin? || teacher? }
end
[:destroy?, :edit?, :show?, :update?].each do |action|

View File

@@ -9,7 +9,7 @@ class ExercisePolicy < AdminOrAuthorPolicy
end
def show?
@user.internal_user?
admin? || teacher?
end
[:clone?, :destroy?, :edit?, :statistics?, :update?, :feedback?].each do |action|
@@ -24,7 +24,7 @@ class ExercisePolicy < AdminOrAuthorPolicy
def resolve
if @user.admin?
@scope.all
elsif @user.internal_user?
elsif @user.teacher?
@scope.where('user_id = ? OR public = TRUE', @user.id)
else
@scope.none

View File

@@ -9,7 +9,7 @@ class InterventionPolicy < AdminOrAuthorPolicy
end
def show?
@user.internal_user?
admin? || teacher?
end
[:clone?, :destroy?, :edit?, :update?].each do |action|
@@ -24,7 +24,7 @@ class InterventionPolicy < AdminOrAuthorPolicy
def resolve
if @user.admin?
@scope.all
elsif @user.internal_user?
elsif @user.teacher?
@scope.where('user_id = ? OR public = TRUE', @user.id)
else
@scope.none

View File

@@ -9,7 +9,7 @@ class ProxyExercisePolicy < AdminOrAuthorPolicy
end
def show?
@user.internal_user?
admin? || teacher?
end
[:clone?, :destroy?, :edit?, :update?].each do |action|
@@ -24,8 +24,8 @@ class ProxyExercisePolicy < AdminOrAuthorPolicy
def resolve
if @user.admin?
@scope.all
elsif @user.internal_user?
@scope.where('user_id = ? OR public = TRUE', @user.id)
elsif @user.teacher?
@scope.where('user_id = ?', @user.id)
else
@scope.none
end

View File

@@ -9,7 +9,7 @@ class SearchPolicy < AdminOrAuthorPolicy
end
def show?
@user.internal_user?
admin? || teacher?
end
[:clone?, :destroy?, :edit?, :update?].each do |action|
@@ -24,7 +24,7 @@ class SearchPolicy < AdminOrAuthorPolicy
def resolve
if @user.admin?
@scope.all
elsif @user.internal_user?
elsif @user.teacher?
@scope.where('user_id = ? OR public = TRUE', @user.id)
else
@scope.none

View File

@@ -9,7 +9,7 @@ class TagPolicy < AdminOrAuthorPolicy
end
def show?
@user.internal_user?
admin? || teacher?
end
[:clone?, :destroy?, :edit?, :update?].each do |action|
@@ -24,7 +24,7 @@ class TagPolicy < AdminOrAuthorPolicy
def resolve
if @user.admin?
@scope.all
elsif @user.internal_user?
elsif @user.teacher?
@scope.where('user_id = ? OR public = TRUE', @user.id)
else
@scope.none