feat: 新用户默认分组可设置 (DefaultUserGroup) - #6599
Conversation
新增 DefaultUserGroup 配置项,允许管理员设置新注册用户的默认分组, 替代原有写死的 'default' 值。 后端: - common/constants.go: DefaultUserGroup 变量(默认 'default') - model/option.go: OptionMap 注册 + UpdateOption switch case - model/user.go: Insert/InsertWithTx 在 Group 为空时自动赋值 前端: - 管理端 Quota Settings 新增「Default User Group」输入框 - types/billing/index/section-registry 补字段传递 - en/zh i18n 补文案 AI-assisted by Claude Code.
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
WalkthroughThe PR adds a configurable default group for newly registered users. The backend validates and applies the setting during user creation. The frontend exposes the setting in quota settings with English and Chinese translations. Git ignores two custom archive files. ChangesDefault user group
Custom archive ignore rules
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
model/option.go (1)
219-236: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winReject non-existent
DefaultUserGroupvalues.
validateOptionValueaccepts anyDefaultUserGroupvalue beforeUpdateOptionsaves it, and new users are created withcommon.DefaultUserGroup. Add a group-existence validation for this option key so admins cannot set an invalid default group.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@model/option.go` around lines 219 - 236, Update UpdateOption to validate DefaultUserGroup values against existing groups before persisting the option, rejecting unknown group names with an error. Add this check alongside validateOptionValue and reuse the existing group lookup or model symbols rather than saving the invalid value or updating OptionMap.
🧹 Nitpick comments (1)
web/src/features/system-settings/general/quota-settings-section.tsx (1)
287-303: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueWrap the placeholder text in
t()for i18n consistency.The
Inputplaceholder uses the bare string'default'. Other placeholders in this file, such as theTopUpLinkfield'st('https://example.com/topup'), wrap literal example text int(...).Wrap this placeholder the same way for consistency with the rest of the form.
♻️ Proposed fix
- <Input placeholder='default' {...field} /> + <Input placeholder={t('default')} {...field} />As per path instructions,
web/**/*.{tsx,ts}: "面向用户的文案必须使用 i18n;React 组件使用useTranslation()的t()".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@web/src/features/system-settings/general/quota-settings-section.tsx` around lines 287 - 303, Update the Input for the DefaultUserGroup field in the quota settings section to pass the placeholder text through the existing translation function t(), matching the i18n handling used by other user-facing placeholders in the form.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@web/src/features/system-settings/general/quota-settings-section.tsx`:
- Line 59: Update the DefaultUserGroup field in the settings validation schema
to require at least one character, preventing an empty value from being saved.
Preserve its existing string validation while adding the minimum-length
constraint.
---
Outside diff comments:
In `@model/option.go`:
- Around line 219-236: Update UpdateOption to validate DefaultUserGroup values
against existing groups before persisting the option, rejecting unknown group
names with an error. Add this check alongside validateOptionValue and reuse the
existing group lookup or model symbols rather than saving the invalid value or
updating OptionMap.
---
Nitpick comments:
In `@web/src/features/system-settings/general/quota-settings-section.tsx`:
- Around line 287-303: Update the Input for the DefaultUserGroup field in the
quota settings section to pass the placeholder text through the existing
translation function t(), matching the i18n handling used by other user-facing
placeholders in the form.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 2ac9e28a-298d-4cb6-8a45-03501488442b
📒 Files selected for processing (10)
.gitignorecommon/constants.gomodel/option.gomodel/user.goweb/src/features/system-settings/billing/index.tsxweb/src/features/system-settings/billing/section-registry.tsxweb/src/features/system-settings/general/quota-settings-section.tsxweb/src/features/system-settings/types.tsweb/src/i18n/locales/en.jsonweb/src/i18n/locales/zh.json
根据 CodeRabbit review 建议修复:
- model/option.go: validateOptionValue 校验 DefaultUserGroup 非空且必须存在于分组比例设置(Group Ratio)中,防止管理员设置不存在的默认分组导致新用户路由失败
- quota-settings-section.tsx: DefaultUserGroup schema 加 min(1) 防止空值保存;placeholder 改用 t('default') 与同文件其他字段 i18n 一致
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
model/option.go (1)
542-543: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy liftSynchronize reads and writes to
common.DefaultUserGroup.
updateOptionMapwritescommon.DefaultUserGroupundercommon.OptionMapRWMutex, butUser.InsertandUser.InsertWithTxcan read it concurrently without the same lock. Put these writes and reads on the same synchronized getter/setter path, or use another atomic configuration mechanism.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@model/option.go` around lines 542 - 543, Synchronize access to common.DefaultUserGroup across the updateOptionMap case and the User.Insert and User.InsertWithTx readers. Route both writes and reads through the same locked getter/setter path, or apply an equivalent atomic configuration mechanism, ensuring no direct unsynchronized access remains.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@model/option.go`:
- Around line 217-224: Update UpdateGroupRatioByJSONString so it validates the
configured common.DefaultUserGroup against the incoming group-ratio map before
replacing groupRatioMap, rejecting changes that remove the default group;
preserve the existing map update only after validation succeeds.
---
Outside diff comments:
In `@model/option.go`:
- Around line 542-543: Synchronize access to common.DefaultUserGroup across the
updateOptionMap case and the User.Insert and User.InsertWithTx readers. Route
both writes and reads through the same locked getter/setter path, or apply an
equivalent atomic configuration mechanism, ensuring no direct unsynchronized
access remains.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 042a919e-da90-4528-aa2c-d661b5e81bbd
📒 Files selected for processing (2)
model/option.goweb/src/features/system-settings/general/quota-settings-section.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
- web/src/features/system-settings/general/quota-settings-section.tsx
- common/constants.go: 新增 GetDefaultUserGroup() 加锁读取(OptionMapRWMutex.RLock),与 updateOptionMap 的写锁配对,避免 User.Insert/InsertWithTx 并发读取竞态 - model/user.go: Insert/InsertWithTx 改用 common.GetDefaultUserGroup() 读取 - setting/ratio_setting/group_ratio.go: UpdateGroupRatioByJSONString 拒绝移除当前默认分组(DefaultUserGroup),防止新用户被分配到不存在的分组
概述
新增 DefaultUserGroup 配置项,允许管理员通过后台设置新注册用户的默认分组。
改动 (10 files, +37 lines)
后端: constants.go / option.go / user.go
前端: quota-settings-section + types + billing + section-registry
i18n: en/zh 补文案
兼容性
默认值 'default' 与原版行为完全一致,仅对新注册用户生效。
Summary by CodeRabbit
New Features
Configuration
defaultand can be updated through quota settings.