Hiding a revision doesn’t remove the edit indicator when the post no longer passes validation

AI-generated summary

akjgklajg reports a bug where hiding a post revision fails to remove the “edited” indicator (the pencil icon) for non-staff users if the post no longer passes current validation rules.

Steps to Reproduce:

  1. Create a short post and edit it to generate revision history.
  2. Increase the min_post_length setting above the post’s current length.
  3. As staff, hide the latest revision.

Expected Behavior: The post should revert to its previous public version, hiding the edit indicator.
Actual Behavior: The revision is hidden, but the public_version remains unchanged. Non-staff users still see the edit indicator and an empty edit history.

Root Cause: In PostsController#hide_revision, the code attempts to decrement post.public_version and save the post using post.save. This triggers PostValidator, which rejects the update because the post now violates the stricter length constraints. Consequently, the save fails silently regarding the version update, though the revision itself is marked as hidden via update_column.

Proposed Fix: Use post.update_columns(public_version: post.public_version - 1) or post.save(validate: false) to bypass validation, mirroring the logic used in post_revision.hide!. The reporter notes that show_revision likely suffers from the same issue.

Steps:

  1. Create a post with a 20-character body and edit it once, so it has an edit history and the pencil shows.
  2. Raise min_post_length (or min_first_post_length for a first post) above the post’s length.
  3. As staff, open the edit history and hide revision 2.

Expected: non-staff users no longer see the pencil (public_version back to 1).

Actual: the revision is hidden, but public_version stays at 2, so non-staff still see the pencil and an edit history with nothing visible in it. The request returns 200.

Cause: in PostsController#hide_revision, post_revision.hide! uses update_column, but the version change is saved with a plain post.save, which runs PostValidator and isn’t checked:

post.public_version -= 1
post.save

Any post that fails validation today doesn’t save. That includes posts that predate a settings change, posts created with skip_validations (imports), posts containing a watched word added later, and posts by TL0 users over the newuser_max_* limits. show_revision probably has the same issue in the other direction.

Suggested fix: post.update_columns(public_version: post.public_version - 1), or post.save(validate: false), matching hide!.