From 49b753eee06d5f709b552927d17fa0a878bb46df Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 11 Jan 2021 14:56:08 -0500 Subject: [PATCH] FIX: Hiding a post should not trigger the duplicate check (#11680) If for some reason a post was allowed to be duplicated (probably via staff edit) hiding it should be permitted. --- app/models/post.rb | 1 + spec/models/post_spec.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/models/post.rb b/app/models/post.rb index 5da11450f0e..afaf6e11dae 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -529,6 +529,7 @@ class Post < ActiveRecord::Base self.hidden = true self.hidden_at = Time.zone.now self.hidden_reason_id = reason + self.skip_unique_check = true save! Topic.where( diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index edf5859bda4..5fa6c13a049 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -1301,6 +1301,21 @@ describe Post do end end + describe ".hide!" do + after do + Discourse.redis.flushdb + end + + it "should ignore the duplicate check" do + p1 = Fabricate(:post) + p2 = Fabricate(:post, user: p1.user) + SiteSetting.unique_posts_mins = 10 + p1.store_unique_post_key + p2.reload.hide!(PostActionType.types[:off_topic]) + expect(p2).to be_hidden + end + end + describe ".unhide!" do before { SiteSetting.unique_posts_mins = 5 }