Skip to content

A platform for community discussion. Free, open, simple.

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

Neil Lalonde1cf0b549abc3
diff --git a/app/jobs/regular/notify_post_revision.rb b/app/jobs/regular/notify_post_revision.rb
index b7e5c184dc9..2331c6655a6 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 01447f4253d..2ba445324cc 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 5231efdf98c..95bd120208b 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