mirror of
https://github.com/discourse/discourse.git
synced 2026-08-08 17:53:55 +08:00
The `can_permanently_delete` site setting was hidden and could only be enabled via the Rails console. There was no indication in the admin UI that this capability existed, leading to confusion and wasted time for admins trying to permanently delete content. This commit unhides the setting and adds layered safeguards at every level of the permanent deletion flow: **Site setting visibility:** - Remove `hidden: true` so the setting appears in the admin UI - Add a `requires_confirmation` dialog when enabling (not when disabling) via a new `simple_on_enable` confirmation type - Add a proper setting description since it was missing **Type-to-confirm on all permanent delete actions:** - Replace the weak yes/no dialogs on post and revision permanent deletion with a type-to-confirm pattern (type "permanently delete") - Show context-aware titles and messages (post vs topic, with post count for topics) - Reusable `PermanentlyDeleteConfirm` dialog body component following the `SecondFactorConfirmPhrase` pattern **Server-side pre-check endpoint:** - Add `GET /posts/:id/permanently_delete_check` (admin-only via `AdminConstraint`) that uses the guardian to validate whether permanent deletion is allowed before showing the confirmation dialog - Returns the reason when denied (cooldown timer, undeleted posts) so the admin gets immediate feedback instead of going through the full confirmation flow only to be rejected - Returns accurate `post_count` for topic deletion messages **Refactors:** - Extract `Topic#deletable_posts_count` to share the post counting query between the guardian, `cannot_permanently_delete_reason`, and the new endpoint - Use exclusion (`NOT small_action`) instead of inclusion for post type filtering, so plugin-added post types are counted correctly Ref - t/181345 --------- Co-authored-by: Martin Brennan <martin@discourse.org>
65 lines
1.4 KiB
Ruby
Vendored
65 lines
1.4 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module PageObjects
|
|
module Modals
|
|
class PostHistory < PageObjects::Modals::Base
|
|
MODAL_SELECTOR = ".history-modal"
|
|
|
|
def click_previous_revision
|
|
footer.find("button.previous-revision").click
|
|
self
|
|
end
|
|
|
|
def previous_locale
|
|
body.find(".revision__locale .revision-content.--previous")
|
|
end
|
|
|
|
def current_locale
|
|
body.find(".revision__locale .revision-content.--current")
|
|
end
|
|
|
|
def current_revision
|
|
revision_numbers.find("strong:nth-child(3)")
|
|
end
|
|
|
|
def hide_revision
|
|
footer.find("button.hide-revision").click
|
|
self
|
|
end
|
|
|
|
def destroy_revisions
|
|
footer.find("button.destroy-revision").click
|
|
end
|
|
|
|
def has_destroy_revisions_button?
|
|
footer.has_css?("button.destroy-revision")
|
|
end
|
|
|
|
def has_tag_changes?
|
|
body.has_css?(".-tag-revisions")
|
|
end
|
|
|
|
def previous_tags
|
|
body.find(".-tag-revisions .tag-revision__wrapper:first-child")
|
|
end
|
|
|
|
def current_tags
|
|
body.find(".-tag-revisions .tag-revision__wrapper:last-child")
|
|
end
|
|
|
|
def deleted_tags
|
|
body.all(".-tag-revisions .discourse-tag.diff-del").map(&:text)
|
|
end
|
|
|
|
def inserted_tags
|
|
body.all(".-tag-revisions .discourse-tag.diff-ins").map(&:text)
|
|
end
|
|
|
|
private
|
|
|
|
def revision_numbers
|
|
footer.find("#revision-numbers")
|
|
end
|
|
end
|
|
end
|
|
end
|