FIX: Respect the cooldown window when editing a flagged topic. (#16046)

When staff decides to hide a flagged post, and it's the first post on the topic, the post owner shouldn't be able to edit either of them until the cooldown finishes. Edit either of them automatically, unhides the post, and makes the topic visible when there's a flag involved.

Reported on meta: https://meta.discourse.org/t/users-can-edit-flagged-topic-title-when-they-should-not-be-able-to/217796
This commit is contained in:
Roman Rizzi
2022-02-25 11:09:31 -03:00
committed by GitHub
parent 770971a95e
commit 54ad50eda1
3 changed files with 24 additions and 9 deletions

View File

@ -1641,6 +1641,17 @@ describe Guardian do
expect(Guardian.new(coding_horror).can_edit?(topic)).to be_falsey
end
context 'first post is hidden' do
let!(:topic) { Fabricate(:topic, user: user) }
let!(:post) { Fabricate(:post, topic: topic, user: topic.user, hidden: true, hidden_at: Time.zone.now) }
it 'returns false for editing your own post while inside the cooldown window' do
SiteSetting.cooldown_minutes_after_hiding_posts = 30
expect(Guardian.new(topic.user).can_edit?(topic)).to eq(false)
end
end
context "locked" do
let(:post) { Fabricate(:post, locked_by_id: admin.id) }
let(:topic) { post.topic }