Embedded media post allowed groups conflicts with post moderation workflow: unhide! fails with ActiveRecord::RecordInvalid

There is a conflict between “Embedded media post allowed groups” and the post unhide workflow.

If a post is created by a user who is not in the allowed media groups and later gets hidden (via flags), when a moderator edits the hidden post and adds media, attempting to unhide the post will fail with:

ActiveRecord::RecordInvalid
Validation failed: Sorry, you can't embed media items in a post.

The unhide process re-runs media validation using the original author’s permissions, not the moderator’s, causing the unhide to fail.


Steps to Reproduce

  1. Configure Embedded media post allowed groups, excluding low-trust users.
  2. Use a user not included in the allowed groups to create a post.
  3. Have the post hidden by system flags.(I’m not fully sure here — it seems posts can only be hidden via flags, not manually by staff? Staff can hide topics but not individual posts. Please correct me if I’m wrong.)
  4. A moderator edits the hidden post and inserts media (images/videos).
  5. Attempt to unhide the post (either in the UI or via post.unhide! in Rails console).
  6. The operation fails with:

ActiveRecord::RecordInvalid Validation failed: Sorry, you can't embed media items in a post.