Fix tests and slightly refactor some policies
This commit is contained in:
@@ -63,7 +63,7 @@ module Lti
|
||||
else # 'learner'
|
||||
next
|
||||
end
|
||||
end
|
||||
end unless provider.roles.blank?
|
||||
result
|
||||
end
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -1,13 +1,5 @@
|
||||
class FileTemplatePolicy < AdminOnlyPolicy
|
||||
|
||||
def index?
|
||||
admin? || teacher?
|
||||
end
|
||||
|
||||
def show?
|
||||
admin? || teacher?
|
||||
end
|
||||
|
||||
def by_file_type?
|
||||
everyone
|
||||
end
|
||||
|
@@ -1,6 +1,3 @@
|
||||
class FileTypePolicy < AdminOnlyPolicy
|
||||
[:index?, :show?].each do |action|
|
||||
define_method(action) { admin? || teacher? }
|
||||
end
|
||||
|
||||
end
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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?
|
||||
|
@@ -7,10 +7,6 @@ class SubscriptionPolicy < ApplicationPolicy
|
||||
author? || admin?
|
||||
end
|
||||
|
||||
def show_error?
|
||||
everyone
|
||||
end
|
||||
|
||||
def author?
|
||||
@user == @record.user
|
||||
end
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user