Fix it so that when a forum topic is deleted, all posts in the topic are deleted too. Also make it so that when a forum topic is undeleted, all posts in it are undeleted too. Before when a topic was deleted, only the topic itself was marked as deleted, not the posts inside the topic. This meant that when a spam topic was deleted, the OP wouldn't be marked as deleted, so any modreports against it wouldn't be marked as handled. Also change it so that it's not possible to undelete a post in a deleted topic, or to delete the OP of a topic without deleting the topic itself. Finally, add a fix script to delete all active posts in deleted topics, and to undelete all deleted OPs in active topics.
56 lines
1.2 KiB
Ruby
56 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class ForumPostPolicy < ApplicationPolicy
|
|
def index?
|
|
true
|
|
end
|
|
|
|
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? && !record.is_deleted? && user.is_moderator?
|
|
end
|
|
|
|
def undelete?
|
|
unbanned? && show? && record.is_deleted? && !record.topic.is_deleted? && user.is_moderator?
|
|
end
|
|
|
|
def reply?
|
|
policy(record.topic).reply?
|
|
end
|
|
|
|
def votable?
|
|
unbanned? && show? && record.bulk_update_request.present? && record.bulk_update_request.is_pending? && record.bulk_update_request.user_id != user.id
|
|
end
|
|
|
|
def reportable?
|
|
unbanned? && show? && record.creator_id != user.id && !record.creator.is_moderator? && record.created_at.after?(1.year.ago)
|
|
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
|
|
|
|
def html_data_attributes
|
|
super + [[:topic, :is_deleted?]]
|
|
end
|
|
end
|