mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 01:56:58 +08:00
FEATURE: Allow admins to permanently delete posts and topics (#14406)
Sometimes administrators want to permanently delete posts and topics from the database. To make sure that this is done for a good reasons, administrators can do this only after one minute has passed since the post was deleted or immediately if another administrator does it.
This commit is contained in:
@ -606,11 +606,21 @@ class TopicsController < ApplicationController
|
||||
end
|
||||
|
||||
def destroy
|
||||
topic = Topic.find_by(id: params[:id])
|
||||
guardian.ensure_can_delete!(topic)
|
||||
topic = Topic.with_deleted.find_by(id: params[:id])
|
||||
|
||||
first_post = topic.ordered_posts.first
|
||||
PostDestroyer.new(current_user, first_post, context: params[:context]).destroy
|
||||
force_destroy = false
|
||||
if params[:force_destroy].present?
|
||||
if !guardian.can_permanently_delete?(topic)
|
||||
return render_json_error topic.cannot_permanently_delete_reason(current_user), status: 403
|
||||
end
|
||||
|
||||
force_destroy = true
|
||||
else
|
||||
guardian.ensure_can_delete!(topic)
|
||||
end
|
||||
|
||||
first_post = topic.posts.with_deleted.order(:post_number).first
|
||||
PostDestroyer.new(current_user, first_post, context: params[:context], force_destroy: force_destroy).destroy
|
||||
|
||||
render body: nil
|
||||
rescue Discourse::InvalidAccess
|
||||
|
Reference in New Issue
Block a user