FIX: do not show confirmation modal (#31304)

Currently when using the shortcuts to delete a post the UI would show
you the confirmation modal even if you don't have the right to do it.
This commit fixes the issue at the root in the
`deletePostWithConfirmation` function.
This commit is contained in:
Joffrey JAFFEUX 2025-02-12 17:04:08 +01:00 committed by GitHub
parent f5c2a4dbbd
commit 963675c32e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 0 deletions

View File

@ -824,6 +824,10 @@ export default class TopicController extends Controller.extend(
@action
deletePostWithConfirmation(post, opts) {
if (!post.can_delete) {
return;
}
this.dialog.yesNoConfirm({
message: i18n("post.confirm_delete"),
didConfirm: () => this.send("deletePost", post, opts),

View File

@ -30,6 +30,26 @@ RSpec.describe "Keyboard shortcuts", type: :system do
expect(page).to have_no_css(".keyboard-shortcuts-modal")
end
describe "<d>" do
fab!(:post)
let(:current_user) { Fabricate(:user) }
let(:topic_page) { PageObjects::Pages::Topic.new }
let(:dialog) { PageObjects::Components::Dialog.new }
before { sign_in(current_user) }
context "when user can't delete the post" do
it "doesnt show the confirmation modal" do
topic_page.visit_topic(post.topic)
send_keys("j d")
expect(dialog).to be_closed
end
end
end
describe "<a>" do
let(:current_user) { topic.user }
let(:topic_page) { PageObjects::Pages::Topic.new }