pundit: convert comments to pundit.
This commit is contained in:
19
app/policies/comment_policy.rb
Normal file
19
app/policies/comment_policy.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
class CommentPolicy < ApplicationPolicy
|
||||
def update?
|
||||
unbanned? && (user.is_moderator? || record.updater_id == user.id)
|
||||
end
|
||||
|
||||
def can_sticky_comment?
|
||||
user.is_moderator?
|
||||
end
|
||||
|
||||
def permitted_attributes_for_create
|
||||
[:body, :post_id, :do_not_bump_post, (:is_sticky if can_sticky_comment?)].compact
|
||||
end
|
||||
|
||||
def permitted_attributes_for_update
|
||||
[:body, :is_deleted, (:is_sticky if can_sticky_comment?)].compact
|
||||
end
|
||||
|
||||
alias_method :undelete?, :update?
|
||||
end
|
||||
Reference in New Issue
Block a user