Rethink permissions in CodeOcean for usage in schools and adopt views

This commit is contained in:
Sebastian Serth
2018-11-27 17:05:38 +01:00
parent 7a63a9c1c1
commit d3f67ab4c7
17 changed files with 47 additions and 76 deletions

View File

@@ -9,22 +9,28 @@ class ApplicationPolicy
end
private :teacher?
def author?
@user == @record.author
end
private :author?
def everyone
# As the ApplicationController forces to have any authorization, `everyone` here means `every user logged in`
true
end
private :everyone
def no_one
false
end
private :no_one
def initialize(user, record)
@user = user
@record = record
require_user!
end
def no_one
false
end
private :no_one
def require_user!
fail Pundit::NotAuthorizedError unless @user
end

View File

@@ -1,9 +1,4 @@
class CommentPolicy < ApplicationPolicy
def author?
@user == @record.author
end
private :author?
def create?
everyone
end

View File

@@ -1,5 +1,3 @@
class ConsumerPolicy < AdminOnlyPolicy
def show?
super || @user.consumer == @record
end
end

View File

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

View File

@@ -1,9 +1,4 @@
class ExercisePolicy < AdminOrAuthorPolicy
def author?
@user == @record.author
end
private :author?
def batch_update?
admin?
end

View File

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

View File

@@ -1,10 +1,5 @@
class FileTypePolicy < AdminOnlyPolicy
def author?
@user == @record.author
end
private :author?
[:create?, :index?, :new?].each do |action|
[:index?, :show?].each do |action|
define_method(action) { admin? || teacher? }
end

View File

@@ -1,9 +1,4 @@
class InterventionPolicy < AdminOrAuthorPolicy
def author?
@user == @record.author
end
private :author?
def batch_update?
admin?
end

View File

@@ -1,9 +1,4 @@
class ProxyExercisePolicy < AdminOrAuthorPolicy
def author?
@user == @record.author
end
private :author?
def batch_update?
admin?
end

View File

@@ -1,9 +1,4 @@
class RequestForCommentPolicy < ApplicationPolicy
def author?
@user == @record.author
end
private :author?
def create?
everyone
end

View File

@@ -1,9 +1,4 @@
class SearchPolicy < AdminOrAuthorPolicy
def author?
@user == @record.author
end
private :author?
def batch_update?
admin?
end

View File

@@ -1,9 +1,4 @@
class SubmissionPolicy < ApplicationPolicy
def author?
@user == @record.author
end
private :author?
def create?
everyone
end
@@ -16,4 +11,15 @@ class SubmissionPolicy < ApplicationPolicy
def index?
admin?
end
def everyone_in_study_group
users_in_same_study_group = @record.study_groups.users
users_in_same_study_group.include? @user
end
private :everyone_in_study_group
def teacher_in_study_group
teacher? && everyone_in_study_group
end
private :teacher_in_study_group
end

View File

@@ -1,9 +1,4 @@
class TagPolicy < AdminOrAuthorPolicy
def author?
@user == @record.author
end
private :author?
def batch_update?
admin?
end