Skip to content

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

FIX: Don't show edit indicator when only hidden tags changed (#36870)

Régis Hanol567996673331
diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb
index 6de65d017d1..8dc4e63cea4 100644
--- a/lib/post_revisor.rb
+++ b/lib/post_revisor.rb
@@ -465,7 +465,10 @@ class PostRevisor
def revise_and_create_new_version
@version_changed = true
@post.version += 1
- @post.public_version += 1
+
+ @hidden_revision = only_hidden_tags_changed?
+ @post.public_version += 1 unless @hidden_revision
+
@post.last_version_at = @revised_at
revise
@@ -616,8 +619,8 @@ class PostRevisor
user_id: @post.last_editor_id,
post_id: @post.id,
number: @post.version,
- modifications: modifications,
- hidden: only_hidden_tags_changed?,
+ modifications:,
+ hidden: @hidden_revision,
)
end
@@ -697,16 +700,19 @@ class PostRevisor
end
def only_hidden_tags_changed?
- return false if (hidden_tag_names = DiscourseTagging.hidden_tag_names).blank?
+ return false if post_changed?
- modifications = post_changes.merge(topic_diff)
- if modifications.keys.size == 1 && (tags_diff = modifications["tags"]).present?
- a, b = tags_diff[0] || [], tags_diff[1] || []
- changed_tags = ((a + b) - (a & b)).map(&:presence).compact
- return true if (changed_tags - hidden_tag_names).empty?
- end
+ changed_topic_fields = PostRevisor.tracked_topic_fields.keys.select { |f| @fields.key?(f) }
+ return false if changed_topic_fields != [:tags]
- false
+ hidden_tag_names = DiscourseTagging.hidden_tag_names
+ return false if hidden_tag_names.blank?
+
+ new_tags = @fields[:tags] || []
+ current_tags = @topic.tags.map(&:name)
+ added_or_removed = (new_tags - current_tags) | (current_tags - new_tags)
+
+ (added_or_removed - hidden_tag_names).empty?
end
def plugin_callbacks
diff --git a/spec/lib/post_revisor_spec.rb b/spec/lib/post_revisor_spec.rb
index 82a35583f96..16d51f705b8 100644
--- a/spec/lib/post_revisor_spec.rb
+++ b/spec/lib/post_revisor_spec.rb
@@ -1408,6 +1408,25 @@ describe PostRevisor do
expect(post.reload.revisions.first.hidden).to eq(true)
end
+ it "doesn't increment public_version for hidden revisions" do
+ post_revisor.revise!(admin, raw: post.raw, tags: topic.tags.map(&:name) + ["secret"])
+ post.reload
+ expect(post.version).to eq(2)
+ expect(post.public_version).to eq(1)
+ end
+
+ it "increments public_version when hidden tag added with other visible changes" do
+ post_revisor.revise!(
+ admin,
+ raw: "#{post.raw} with additional content",
+ tags: topic.tags.map(&:name) + ["secret"],
+ )
+ post.reload
+ expect(post.version).to eq(2)
+ expect(post.public_version).to eq(2)
+ expect(post.revisions.first.hidden).to eq(false)
+ end
+
it "doesn't notify topic owner about hidden tags" do
PostActionNotifier.enable
Jobs.run_immediately!