pundit: convert forum topics / forum posts to pundit.

Fix it being possible for users to delete or undelete their own forum
posts and topics, even if they were deleted by a mod.
This commit is contained in:
evazion
2020-03-16 02:42:54 -05:00
parent b3ff08fedf
commit db63b6d44f
18 changed files with 262 additions and 170 deletions

View File

@@ -0,0 +1,33 @@
class ForumPostPolicy < ApplicationPolicy
def show?
user.level >= record.topic.min_level
end
def create?
unbanned? && policy(record.topic).reply?
end
def update?
unbanned? && show? && (user.is_moderator? || (record.creator_id == user.id && !record.topic.is_locked?))
end
def destroy?
unbanned? && show? && user.is_moderator?
end
def undelete?
unbanned? && show? && user.is_moderator?
end
def show_deleted?
!record.is_deleted? || user.is_moderator?
end
def permitted_attributes_for_create
[:body, :topic_id]
end
def permitted_attributes_for_update
[:body]
end
end