# 为匿名和登录用户设置基于组的细粒度权限

**URL:** <https://meta.discourse.org/t/granular-group-based-permissions-for-anonymous-and-logged-in-users/402273>\
**Category:** Announcements\
**Tags:** groups\
**Created:** [2026年五月13日 01:18 UTC](https://meta.discourse.org/t/granular-group-based-permissions-for-anonymous-and-logged-in-users/402273 "2026-05-13T01:18:57Z")\
**Posts on this page:** 1\
**Showing post:** 30

<div class="post-metadata">

**Author:** ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)\
**Post date:** [2026年八月6日 02:52 UTC](https://meta.discourse.org/t/granular-group-based-permissions-for-anonymous-and-logged-in-users/402273/30 "2026-08-06T02:52:25Z")

</div>

嘿，马丁 👋

我开了一个快速的 PR 来添加这两个类（`anonymous_users` 和 `logged_in_users`）。

> <https://github.com/discourse/discourse-groups-css-classes-in-body/pull/37>
>
> There are new granular groups for \`logged\_in\_users\` and \`anonymous\_users\` in cor…e now as seen here:
> 
> https://github.com/discourse/discourse/blob/2f70686a3fe4d183d6c643489ec2140a75103cbe/app/models/group.rb#L107-L119
> 
> This PR adds a check to see if the user exists (is logged in) or not (anonymous) and adds classes to the body tag for either. 
> 
> Files touched:
> 
> \`javascripts/discourse/api-initializers/init-theme.js\`
> 
> \*\*\* 
> 
> worth noting that this component isn't necessary to achieve group class css code changes for anonymous and logged in users:
> 
> https://meta.discourse.org/t/granular-group-based-permissions-for-anonymous-and-logged-in-users/402273/30

我还没怎么测试过（哈哈），但我觉得这挺直观的。代码只是检查当前用户是否存在，如果存在，则属于 `logged_in_users`，否则就是 `anonymous_users`。😁

**注意：** 我几乎可以肯定 Discourse 会自动添加 `.anon`，所以无需该组件也能实现匿名与已登录用户的 CSS 区分，但这只是简单地使用了新的群组约定。

---

_[View the full topic](https://meta.discourse.org/t/granular-group-based-permissions-for-anonymous-and-logged-in-users/402273)._
