pundit: convert comments to pundit.

This commit is contained in:
evazion
2020-03-15 15:37:34 -05:00
parent d8e4a26906
commit a0c4617057
7 changed files with 58 additions and 45 deletions

View 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