FIX: don't bump topics when hidden tags are added or removed

FIX: don’t bump topics when hidden tags are added or removed

diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb
index acba036..9e8842f 100644
--- a/lib/post_revisor.rb
+++ b/lib/post_revisor.rb
@@ -522,7 +522,23 @@ class PostRevisor
   end
 
   def bypass_bump?
-    !@post_successfully_saved || @topic_changes.errored? || @opts[:bypass_bump] == true || @post.whisper?
+    !@post_successfully_saved ||
+      @topic_changes.errored? ||
+      @opts[:bypass_bump] == true ||
+      @post.whisper? ||
+      only_hidden_tags_changed?
+  end
+
+  def only_hidden_tags_changed?
+    modifications = post_changes.merge(@topic_changes.diff)
+    if modifications.keys.size == 1 && tags_diff = modifications["tags"]
+      a, b = tags_diff[0] || [], tags_diff[1] || []
+      changed_tags = (a + b) - (a & b)
+      if (changed_tags - DiscourseTagging.hidden_tag_names(nil)).empty?
+        return true
+      end
+    end
+    false
   end
 
   def is_last_post?
diff --git a/spec/components/post_revisor_spec.rb b/spec/components/post_revisor_spec.rb
index 8f4cdb5..26ad1b7 100644
--- a/spec/components/post_revisor_spec.rb
+++ b/spec/components/post_revisor_spec.rb
@@ -740,6 +740,31 @@ describe PostRevisor do
             end
           end
 
+          context "hidden tags" do
+            let(:bumped_at) { 1.day.ago }
+
+            before do
+              topic.update_attributes!(bumped_at: bumped_at)
+              create_hidden_tags(['important', 'secret'])
+              topic = post.topic
+              topic.tags = [Fabricate(:tag, name: "super"), Tag.where(name: "important").first, Fabricate(:tag, name: "stuff")]
+            end
+
+            it "doesn't bump topic if only staff-only tags are added" do
+              expect {
+                result = subject.revise!(Fabricate(:admin), raw: post.raw, tags: topic.tags.map(&:name) + ['secret'])
+                expect(result).to eq(true)
+              }.to_not change { topic.reload.bumped_at }
+            end
+
+            it "doesn't bump topic if only staff-only tags are removed" do
+              expect {
+                result = subject.revise!(Fabricate(:admin), raw: post.raw, tags: topic.tags.map(&:name) - ['important', 'secret'])
+                expect(result).to eq(true)
+              }.to_not change { topic.reload.bumped_at }
+            end
+          end
+
         end
 
         context "cannot create tags" do
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index cb6a496..6b9910e 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -110,6 +110,16 @@ module Helpers
     end
   end
 
+  def create_hidden_tags(tag_names)
+    tag_group = Fabricate(:tag_group,
+      name: 'Hidden Tags',
+      permissions: { staff: :full }
+    )
+    tag_names.each do |name|
+      tag_group.tags << (Tag.where(name: name).first || Fabricate(:tag, name: name))
+    end
+  end
+
   def capture_stdout
     old_stdout = $stdout
     io = StringIO.new

GitHub sha: 5de750d3

2 Likes