Allow all teachers of the same study group to edit their exercises
This commit is contained in:
@ -26,11 +26,16 @@ class ApplicationPolicy
|
|||||||
private :no_one
|
private :no_one
|
||||||
|
|
||||||
def everyone_in_study_group
|
def everyone_in_study_group
|
||||||
study_group = @record.study_group
|
if @record.respond_to? :study_group # e.g. submission
|
||||||
return false if study_group.blank?
|
study_group = @record.study_group
|
||||||
|
return false if study_group.blank?
|
||||||
|
|
||||||
users_in_same_study_group = study_group.users
|
users_in_same_study_group = study_group.users
|
||||||
return false if users_in_same_study_group.blank?
|
else # e.g. exercise
|
||||||
|
study_groups = @record.user.study_groups
|
||||||
|
users_in_same_study_group = study_groups.collect{ |study_group|
|
||||||
|
study_group.users}.flatten
|
||||||
|
end
|
||||||
|
|
||||||
users_in_same_study_group.include? @user
|
users_in_same_study_group.include? @user
|
||||||
end
|
end
|
||||||
|
@ -8,7 +8,7 @@ class ExercisePolicy < AdminOrAuthorPolicy
|
|||||||
end
|
end
|
||||||
|
|
||||||
[:clone?, :destroy?, :edit?, :update?].each do |action|
|
[:clone?, :destroy?, :edit?, :update?].each do |action|
|
||||||
define_method(action) { admin? || author? }
|
define_method(action) { admin? || teacher_in_study_group || author? }
|
||||||
end
|
end
|
||||||
|
|
||||||
[:implement?, :working_times?, :intervention?, :search?, :submit?, :reload?].each do |action|
|
[:implement?, :working_times?, :intervention?, :search?, :submit?, :reload?].each do |action|
|
||||||
|
Reference in New Issue
Block a user