Skip to content

Dev - #5267

Closed
coyer wants to merge 10 commits into
QuantumNous:mainfrom
coyer:dev
Closed

Dev#5267
coyer wants to merge 10 commits into
QuantumNous:mainfrom
coyer:dev

Conversation

@coyer

@coyer coyer commented Jun 3, 2026

Copy link
Copy Markdown

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

  • Closes # (如有)

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

(请在此粘贴截图、关键日志或测试报告,以证明变更生效)

Summary by CodeRabbit

  • New Features

    • User invitation feature—admins can enable users to invite new users
    • Security audit logging with flexible storage options (local files or remote endpoint)
    • Enhanced group management and ratio configuration
  • Documentation

    • Added comprehensive build and setup instructions
    • Documented system architecture and key workflows
  • Localization

    • Full UI translations added for English, French, Japanese, Russian, Vietnamese, and Chinese

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

This PR introduces a security audit feature that captures and logs API requests/responses with configurable local or remote storage, adds a user invitation flag, and includes comprehensive documentation, frontend UI controls, and multi-language support.

Changes

Security Audit & User Invite Features

Layer / File(s) Summary
Feature Architecture Documentation
desc/1.md, desc/2.md, desc/3.md
Technical documentation of API gateway forwarding flow, subscription management workflow, and security audit end-to-end architecture including middleware capture, local/remote storage modes, and retention policies.
Audit Configuration Model & Option Handling
setting/operation_setting/audit_setting.go, model/option.go
Defines AuditSetting struct with mode constants and default values; integrates audit config reloading via handleConfigUpdate for dynamic runtime updates.
Audit Service Architecture: Data Models & Storage Backends
service/audit/service.go
Implements AuditRecord/AuditFile data structures, AuditStorage interface, LocalStorage (JSONL with rotation and file decoding), and RemoteStorage (multipart HTTP POST) with singleton AuditLogger, lazy initialization, and retention cleanup.
Audit Middleware: Request Capture & Response Wrapping
middleware/audit.go
Implements AuditMiddleware that extracts request body/multipart files/embedded JSON images, masks token secrets, wraps response writer for status capture, and asynchronously logs audit records via goroutine pool with helpers for relay format resolution and MIME-to-filename inference.
Audit Router Registration & Config Plumbing
router/relay-router.go, model/log.go
Registers AuditMiddleware across /pg, /v1, /suno, /v1beta, and Midjourney routes; comments out verbose consume log statement to reduce log noise.
Audit Settings Frontend UI & Component Integration
web/classic/src/pages/Setting/Operation/SettingsAudit.jsx, web/classic/src/components/settings/OperationSetting.jsx, web/classic/package.json
Implements SettingsAudit React form component with mode selector, local/remote conditional fields, and async batch updates; integrates into OperationSetting card; adds baseline-browser-mapping and caniuse-lite dependencies.
User Invite Backend: Flag Definition & API Response
common/constants.go, controller/misc.go
Introduces UserInviteEnabled global boolean flag; exposes it in GetStatus API response alongside _qn discriminator field.
User Invite Frontend: System Settings & Conditional Rendering
web/classic/src/components/settings/SystemSetting.jsx, web/classic/src/components/topup/index.jsx
Adds UserInviteEnabled checkbox to login/registration settings; conditionally renders InvitationCard only when flag is enabled in TopUp component.
Internationalization, Build Documentation & Dependencies
README.zh_CN.md, web/classic/src/i18n/locales/*, web/classic/src/pages/Setting/Ratio/GroupRatioSettings.jsx
Adds build command documentation (Makefile/manual/PowerShell); translates audit settings/user invite/group management UI across 6 locales; implements JSON parsing helper for group ratio configuration.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant AuditMiddleware
  participant AuditLogger
  participant LocalStorage
  participant RemoteStorage

  Client->>AuditMiddleware: HTTP Request
  AuditMiddleware->>AuditMiddleware: Extract body/files/metadata
  AuditMiddleware->>AuditMiddleware: Wrap response writer
  AuditMiddleware->>Client: Process (c.Next())
  AuditMiddleware->>AuditLogger: Log(AuditRecord) async
  AuditLogger->>LocalStorage: Save (JSONL + files)
  AuditLogger->>RemoteStorage: Save (multipart POST)
  LocalStorage->>LocalStorage: Rotate by size
  RemoteStorage->>RemoteStorage: HTTP POST with auth
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • QuantumNous/new-api#2565: Modifies controller/misc.go's GetStatus to add a feature flag field to response payload, similar pattern to user_invite_enabled.
  • QuantumNous/new-api#1701: Also updates controller/misc.go's GetStatus response structure with additional status fields.

Suggested reviewers

  • Calcium-Ion
  • seefs001
  • creamlike1024

Poem

🐰 A rabbit builds an audit trail so grand,
Captures each request with a careful hand.
Invites now flow, with flags so neat,
Ten thousand translations, complete!
New-API hops toward audit's feat. 🐇✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 2.94% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title "Dev" is vague and generic; it does not convey any meaningful information about the changeset's primary purpose. Provide a descriptive title that summarizes the main change, such as "Add security audit feature and user invite toggle" or "Implement audit logging and group management enhancements".
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch dev

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coyer coyer closed this Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant