mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-07 15:53:29 +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>
45 lines
1,000 B
Ruby
45 lines
1,000 B
Ruby
# frozen_string_literal: true
|
|
|
|
module PageObjects
|
|
module Components
|
|
class Dialog < PageObjects::Components::Base
|
|
def closed?
|
|
has_no_css?(".dialog-container")
|
|
end
|
|
|
|
def open?
|
|
has_css?(".dialog-container")
|
|
end
|
|
|
|
def has_content?(content)
|
|
find(".dialog-container").has_content?(content)
|
|
end
|
|
|
|
def click_yes
|
|
find(".dialog-footer .btn-primary").click
|
|
end
|
|
|
|
def click_danger
|
|
find(".dialog-footer .btn-danger").click
|
|
end
|
|
|
|
alias click_ok click_yes
|
|
|
|
def click_no
|
|
find(".dialog-footer .btn-default").click
|
|
end
|
|
|
|
def has_confirm_button_disabled?
|
|
has_css?(".dialog-footer .btn-danger[disabled]")
|
|
end
|
|
|
|
def has_no_confirm_button_disabled?
|
|
has_no_css?(".dialog-footer .btn-danger[disabled]")
|
|
end
|
|
|
|
def fill_in_confirmation_phrase(phrase)
|
|
find(".dialog-body input.confirmation-phrase").fill_in(with: phrase)
|
|
end
|
|
end
|
|
end
|
|
end
|