Fix tests and slightly refactor some policies

This commit is contained in:
Sebastian Serth
2018-11-30 15:44:45 +01:00
parent 2125fb1c1d
commit 3665058435
14 changed files with 19 additions and 64 deletions

View File

@@ -1,9 +1,9 @@
class ExecutionEnvironmentPolicy < AdminOnlyPolicy
[:execute_command?, :shell?, :statistics?].each do |action|
[:execute_command?, :shell?, :statistics?, :show?].each do |action|
define_method(action) { admin? || author? }
end
[:show?, :index?, :new?].each do |action|
[:index?].each do |action|
define_method(action) { admin? || teacher? }
end
end

View File

@@ -1,13 +1,5 @@
class FileTemplatePolicy < AdminOnlyPolicy
def index?
admin? || teacher?
end
def show?
admin? || teacher?
end
def by_file_type?
everyone
end

View File

@@ -1,6 +1,3 @@
class FileTypePolicy < AdminOnlyPolicy
[:index?, :show?].each do |action|
define_method(action) { admin? || teacher? }
end
end

View File

@@ -11,8 +11,8 @@ class InterventionPolicy < AdminOrAuthorPolicy
define_method(action) { admin? || author?}
end
[:reload?].each do |action|
define_method(action) { everyone }
def reload?
everyone
end
class Scope < Scope

View File

@@ -20,7 +20,7 @@ class ProxyExercisePolicy < AdminOrAuthorPolicy
if @user.admin?
@scope.all
elsif @user.teacher?
@scope.where('user_id = ?', @user.id)
@scope.where('user_id = ? OR public = TRUE', @user.id)
else
@scope.none
end

View File

@@ -11,8 +11,8 @@ class RequestForCommentPolicy < ApplicationPolicy
everyone
end
[:destroy?].each do |action|
define_method(action) { admin? }
def destroy?
admin?
end
def mark_as_solved?

View File

@@ -7,10 +7,6 @@ class SubscriptionPolicy < ApplicationPolicy
author? || admin?
end
def show_error?
everyone
end
def author?
@user == @record.user
end

View File

@@ -1,29 +1,13 @@
class TagPolicy < AdminOrAuthorPolicy
def batch_update?
admin?
end
def show?
admin? || teacher?
end
[:clone?, :destroy?, :edit?, :update?].each do |action|
define_method(action) { admin? || author?}
end
[:reload?].each do |action|
define_method(action) { everyone }
end
class TagPolicy < AdminOnlyPolicy
class Scope < Scope
def resolve
if @user.admin?
if @user.admin? || @user.teacher?
@scope.all
elsif @user.teacher?
@scope.where('user_id = ? OR public = TRUE', @user.id)
else
@scope.none
end
end
end
end