# 嵌入式媒体帖子允许的群组与帖子审核工作流程冲突：取消隐藏！因 ActiveRecord::RecordInvalid 失败

**URL:** https://meta.discourse.org/t/embedded-media-post-allowed-groups-conflicts-with-post-moderation-workflow-unhide-fails-with-activerecord-recordinvalid/390575
**Category:** Bug
**Created:** [2025年十二月6日 11:30 UTC](https://meta.discourse.org/t/embedded-media-post-allowed-groups-conflicts-with-post-moderation-workflow-unhide-fails-with-activerecord-recordinvalid/390575 "2025-12-06T11:30:31Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![copymonopoly](https://avatars.discourse-cdn.com/v4/letter/c/4491bb/32.png) [@copymonopoly](https://meta.discourse.org/u/copymonopoly)
#### Post date: [2025年十二月6日 11:30 UTC](https://meta.discourse.org/t/embedded-media-post-allowed-groups-conflicts-with-post-moderation-workflow-unhide-fails-with-activerecord-recordinvalid/390575/1 "2025-12-06T11:30:31Z")

</div>

**“允许嵌入媒体帖子的群组”与帖子取消隐藏工作流程** 之间存在冲突。

如果一个帖子是由_不_在允许的媒体群组中的用户创建，随后被隐藏（通过标记），当版主编辑该隐藏帖子并添加媒体时，尝试 **取消隐藏** 该帖子将失败并出现以下错误：

```plaintext
ActiveRecord::RecordInvalid
Validation failed: 抱歉，您不能在帖子中嵌入媒体项。

```

取消隐藏过程使用 **原始作者的权限** 重新运行媒体验证，而不是版主的权限，从而导致取消隐藏失败。

* * *

# **重现步骤**

1. 配置 **允许嵌入媒体帖子的群组** ，排除低信任度的用户。
2. 使用_不_在允许群组中的用户创建帖子。
3. 让帖子被系统标记隐藏。（我不太确定这一点——似乎帖子只能通过标记隐藏，而不能由工作人员手动隐藏？工作人员可以隐藏主题，但不能隐藏单个帖子。如果我错了，请纠正我。）
4. 版主编辑隐藏的帖子并插入媒体（图片/视频）。
5. 尝试取消隐藏帖子（通过用户界面或在 Rails 控制台中执行 `post.unhide!`）。
6. 操作失败并出现以下错误：

`ActiveRecord::RecordInvalid Validation failed: 抱歉，您不能在帖子中嵌入媒体项。`

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2025年十二月8日 01:01 UTC](https://meta.discourse.org/t/embedded-media-post-allowed-groups-conflicts-with-post-moderation-workflow-unhide-fails-with-activerecord-recordinvalid/390575/2 "2025-12-08T01:01:48Z")

</div>

@kris.kotlarek 你对以下内容有何看法：

> <https://github.com/discourse/discourse/pull/36512>
>
> We were not skipping validations on unhide making it impossible for modertators
> …to unhide posts that violated a posts validation rules
> 
> (eg: too many links, not allowed to have embedding, etc)
> 
> Note: this still leaves the post "uneditable" by the actual user, but at least
> give the moderator a way of allowing something banned by the rules.

我认为它是安全的，特别是由于有一个调用点仍然需要验证：`PostRevisor#remove_flags_and_unhide_post`，所以额外的参数可以让我们提供更多的安全性。

话虽如此，这些代码路径非常复杂……所以值得仔细审查。

---

<div class="post-metadata">

### Author: ![kris.kotlarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kris.kotlarek/32/176919_2.png) [@kris.kotlarek](https://meta.discourse.org/u/kris.kotlarek)
#### Post date: [2025年十二月9日 01:26 UTC](https://meta.discourse.org/t/embedded-media-post-allowed-groups-conflicts-with-post-moderation-workflow-unhide-fails-with-activerecord-recordinvalid/390575/3 "2025-12-09T01:26:36Z")

</div>

感谢您报告此错误。此问题已在此拉取请求中修复：

> <https://github.com/discourse/discourse/pull/36512>
>
> We were not acting as moderators when unhide, making it impossible for moderator…s
> to unhide posts that violated a post's validation rules.
> 
> (eg: too many links, not allowed to have embedding, etc)
> 
> Note: this still leaves the post "uneditable" by the actual user, but at least
> give the moderator a way of allowing something banned by the rules.
> 
> https://meta.discourse.org/t/embedded-media-post-allowed-groups-conflicts-with-post-moderation-workflow-unhide-fails-with-activerecord-recordinvalid/390575

---

<div class="post-metadata">

### Author: ![kris.kotlarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kris.kotlarek/32/176919_2.png) [@kris.kotlarek](https://meta.discourse.org/u/kris.kotlarek)
#### Post date: [2025年十二月12日 21:00 UTC](https://meta.discourse.org/t/embedded-media-post-allowed-groups-conflicts-with-post-moderation-workflow-unhide-fails-with-activerecord-recordinvalid/390575/4 "2025-12-12T21:00:32Z")

</div>

此主题在 3 天后自动关闭。不再允许回复。
