# 当解析值为 false 时，\`user\_in\_X\` 主题设置支持的后备机制失败

**URL:** <https://meta.discourse.org/t/fallback-for-user-in-x-theme-setting-support-fails-when-resolved-value-is-false/408524>\
**Category:** Bug\
**Tags:** copy-post\
**Created:** [2026年七月26日 00:08 UTC](https://meta.discourse.org/t/fallback-for-user-in-x-theme-setting-support-fails-when-resolved-value-is-false/408524 "2026-07-26T00:08:58Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)\
**Post date:** [2026年七月26日 00:08 UTC](https://meta.discourse.org/t/fallback-for-user-in-x-theme-setting-support-fails-when-resolved-value-is-false/408524/1 "2026-07-26T00:08:58Z")

</div>

> [@martin](#):
>
> 我已经通过 [DEV: Use resolve\_group\_membership core theme functionality - Pull Request #37 - discourse/discourse-copy-post - GitHub](https://github.com/discourse/discourse-copy-post/pull/37) 修复了 discourse-copy-post，现在我正在检查我们的其他官方插件，看看是否有其他插件也需要同样的处理（例如，你已经指出了 [GitHub - discourse/discourse-unanswered-filter · GitHub](https://github.com/discourse/discourse-unanswered-filter) ）
> 
> 对于你自己的 [Filter Favorites](https://meta.discourse.org/t/filter-favorites/386594) ，你可以参考我所做的 copy-post 示例

我刚才试了一下，但我在测试时似乎发现了一个问题：  
如果用户不属于任何允许的组，新的 `user_in_copy_button_allowed_groups` 检查不会返回结果。因此，针对尚无法处理 `user_in_setting` 的论坛的后备代码会被执行，但会失败：

```plaintext
[THEME 254 'Copy post button'] TypeError: Cannot read properties of undefined (reading 'split')

```

复现步骤：

1. 安装该组件并将其添加到你的主题中
2. 将 allowed\_groups 限制为管理员
3. 模拟一个非管理员测试用户，并查看浏览器控制台

我认为问题出在这里：

```js
if (Object.hasOwn(settings, "user_in_copy_button_allowed_groups")) {
    if (settings.user_in_copy_button_allowed_groups) {
      return true;
    }
  }

```

这仅在值为 `true` 时提前返回。当值为 `false` 时，会执行下面的后备代码，该代码期望设置值仍然以字符串形式存在——但在我使用我复制自 copy-post 的后备模式的 \[1\] 组件进行的测试中，一旦启用 `user_in_X` 支持，它就变成了 `undefined`。我猜测修复方法是在这种情况下也返回 `false`，这样只有当 `user_in_X` 键根本不存在时（旧版核心），才会使用后备代码，而不是在解析后的值恰好为 `false` 时。

我的假设正确吗，还是说该设置仍然期望以字符串形式提供组？

* * *

1. prefilled composer link

---

_[View the full topic](https://meta.discourse.org/t/fallback-for-user-in-x-theme-setting-support-fails-when-resolved-value-is-false/408524)._
