A platform for community discussion. Free, open, simple.
FIX: Don't decrement public_version when destroying hidden revision (#37704)
Sam84706bcef7bc
diff --git a/lib/post_revisor.rb b/lib/post_revisor.rbindex 11b97116989..4ef4b3258af 100644--- a/lib/post_revisor.rb+++ b/lib/post_revisor.rb@@ -386,7 +386,15 @@ class PostRevisorreturn false if @skip_revision# topic-only changes (without post content changes) should always create a new version# since the grace period concept doesn't apply to metadata changes like tags- return true if topic_changed? && !post_changed?+ if topic_changed? && !post_changed?+ # Allow hidden tag-only changes to update a previous hidden revision+ # so that reverting hidden tag changes collapses the revisions+ if only_hidden_tags_changed? &&+ PostRevision.where(post_id: @post.id, number: @post.version).pick(:hidden)+ return false+ end+ return true+ endedited_by_another_user? || flagged? || !grace_period_edit? || owner_changed? ||force_new_version? || edit_reason_specified?end@@ -648,11 +656,12 @@ class PostRevisorend# should probably do this before saving the post!if revision.modifications.empty?+ hidden = revision.hiddenrevision.destroy@post.last_editor_id =PostRevision.where(post_id: @post.id).order(number: :desc).pick(:user_id) || @post.user_id@post.version -= 1- @post.public_version -= 1+ @post.public_version -= 1 unless hidden@post.save(validate: @validate_post)elserevision.savediff --git a/spec/lib/post_revisor_spec.rb b/spec/lib/post_revisor_spec.rbindex 8f2095b063c..57c78eef9c9 100644--- a/spec/lib/post_revisor_spec.rb+++ b/spec/lib/post_revisor_spec.rb@@ -1459,6 +1459,21 @@ describe PostRevisor doexpect(post.public_version).to eq(1)end+ it "doesn't decrement public_version when hidden revision is destroyed" do+ original_tags = topic.tags.map(&:name)+ post_revisor.revise!(admin, raw: post.raw, tags: original_tags + ["secret"])+ post.reload+ expect(post.version).to eq(2)+ expect(post.public_version).to eq(1)+ expect(post.revisions.count).to eq(1)++ post_revisor.revise!(admin, raw: post.raw, tags: original_tags)+ post.reload+ expect(post.version).to eq(1)+ expect(post.public_version).to eq(1)+ expect(post.revisions.count).to eq(0)+ end+it "increments public_version when hidden tag added with other visible changes" dopost_revisor.revise!(admin,