Files
codeocean/app/policies/comment_policy.rb
Maximilian Grundke 57b773698b Fix comment policy
2016-04-26 17:42:53 +02:00

29 lines
468 B
Ruby

class CommentPolicy < ApplicationPolicy
def author?
if @record.is_a?(ActiveRecord::Relation)
flag = true
@record.all {|item| flag = (flag and item.author == @user)}
flag
else
@user == @record.author
end
end
private :author?
def create?
everyone
end
[:new?, :show?, :destroy?].each do |action|
define_method(action) { admin? || author? }
end
def edit?
admin?
end
def index?
everyone
end
end