FIX: don't send post edit notification when hidden tags are changed

FIX: don’t send post edit notification when hidden tags are changed

Create a hidden revision so staff can see the changed, but don’t send notifications to non-staff.

diff --git a/app/jobs/regular/notify_post_revision.rb b/app/jobs/regular/notify_post_revision.rb
index b7e5c18..2331c66 100644
--- a/app/jobs/regular/notify_post_revision.rb
+++ b/app/jobs/regular/notify_post_revision.rb
@@ -10,6 +10,8 @@ module Jobs
 
       ActiveRecord::Base.transaction do
         User.where(id: args[:user_ids]).find_each do |user|
+          next if post_revision.hidden && !user.staff?
+
           PostActionNotifier.alerter.create_notification(
             user,
             Notification.types[:edited],
diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb
index 01447f4..2ba4453 100644
--- a/lib/post_revisor.rb
+++ b/lib/post_revisor.rb
@@ -462,7 +462,8 @@ class PostRevisor
       user_id: @post.last_editor_id,
       post_id: @post.id,
       number: @post.version,
-      modifications: modifications
+      modifications: modifications,
+      hidden: only_hidden_tags_changed?
     )
   end
 
diff --git a/spec/components/post_revisor_spec.rb b/spec/components/post_revisor_spec.rb
index 5231efd..95bd120 100644
--- a/spec/components/post_revisor_spec.rb
+++ b/spec/components/post_revisor_spec.rb
@@ -753,6 +753,27 @@ describe PostRevisor do
                 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 and there are no tags left" do
+              topic.tags = Tag.where(name: ['important', 'secret']).to_a
+              expect {
+                result = subject.revise!(Fabricate(:admin), raw: post.raw, tags: [])
+                expect(result).to eq(true)
+              }.to_not change { topic.reload.bumped_at }
+            end
+
+            it "creates a hidden revision" do
+              subject.revise!(Fabricate(:admin), raw: post.raw, tags: topic.tags.map(&:name) + ['secret'])
+              expect(post.reload.revisions.first.hidden).to eq(true)
+            end
+
+            it "doesn't notify topic owner about hidden tags" do
+              PostActionNotifier.enable
+              Jobs.run_immediately!
+              expect {
+                subject.revise!(Fabricate(:admin), raw: post.raw, tags: topic.tags.map(&:name) + ['secret'])
+              }.not_to change { Notification.where(notification_type: Notification.types[:edited]).count }
+            end
           end
 
         end

GitHub sha: 1cf0b549

1 Like