pundit: convert forum post votes to pundit.

This commit is contained in:
evazion
2020-03-18 02:43:45 -05:00
parent be59e85d25
commit cc2b4abd09
8 changed files with 54 additions and 27 deletions

View File

@@ -19,6 +19,10 @@ class ForumPostPolicy < ApplicationPolicy
unbanned? && show? && user.is_moderator?
end
def votable?
unbanned? && show? && record.bulk_update_request.present? && record.bulk_update_request.is_pending?
end
def reportable?
unbanned? && show? && record.creator_id != user.id && !record.creator.is_moderator?
end

View File

@@ -0,0 +1,13 @@
class ForumPostVotePolicy < ApplicationPolicy
def create?
unbanned? && policy(record.forum_post).votable?
end
def destroy?
unbanned? && record.creator_id == user.id
end
def permitted_attributes
[:score]
end
end