Skip to content

Add secondary development phase one foundation - #5685

Closed
binshiz wants to merge 1 commit into
QuantumNous:mainfrom
binshiz:codex/secondary-development-phase1
Closed

Add secondary development phase one foundation#5685
binshiz wants to merge 1 commit into
QuantumNous:mainfrom
binshiz:codex/secondary-development-phase1

Conversation

@binshiz

@binshiz binshiz commented Jun 23, 2026

Copy link
Copy Markdown

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。
  • AI-assisted: 当前本地 git 用户 binshiz <binshiz@binshizdeMacBook-Air.local> 不在仓库历史高频核心作者列表中,本 PR 由 Codex 协助生成并整理。

📝 变更描述 / Description

实现二次开发第一阶段的数据和后台底座:在保留现有 role 门槛的基础上扩展 RBAC 权限点,新增角色/权限/用户绑定模型、提供商资料与钱包/结算配置、模型广场模型/API 配置/Key/价格/审核记录基础表,并通过 GORM 自动迁移和初始化内置权限。

新增权限中间件和 RBAC、Provider、Marketplace Model API;模型 Key 使用 MODEL_KEY_ENCRYPTION_SECRET 加密存储,响应只返回脱敏信息。管理写操作、角色绑定和模型/Key/价格/提供商变更会写入操作审计。

Default 前端新增模型广场、提供商控制台、财务底座、角色权限、审计日志入口,并按后端返回的权限点做菜单和路由隔离;普通用户仅可进入公开模型广场,提供商仅管理自身资源,财务/运营/超级管理员按矩阵访问对应模块。

🚀 变更类型 / 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

已通过本地验证:

go test ./...
cd web/default && bun run typecheck
cd web/default && bun run i18n:sync
cd web/default && bun run build

说明:本 PR 刻意未包含既有无关工作树改动 web/bun.lockweb/classic/rsbuild.config.ts

Summary by CodeRabbit

Release Notes

  • New Features

    • Added marketplace model management system for creating, listing, and managing models with API configurations and pricing.
    • Introduced provider profile and financial management (wallet, settlement configuration).
    • Implemented role-based access control (RBAC) with customizable roles and permissions for fine-grained authorization.
    • Added secure model key encryption with automatic masking of sensitive values.
    • Introduced audit logging system for tracking administrative actions and compliance.
    • Added dedicated finance and provider management consoles.
  • Tests

    • Added comprehensive tests for marketplace RBAC behavior and data isolation.
    • Added tests for model key encryption and security validation.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d082cc51-d9c1-4210-82d4-6e26d0b6a644

📥 Commits

Reviewing files that changed from the base of the PR and between 9fc9c8f and bdae092.

📒 Files selected for processing (40)
  • common/secret_box.go
  • controller/marketplace.go
  • controller/marketplace_test.go
  • controller/rbac.go
  • controller/user.go
  • middleware/rbac.go
  • model/main.go
  • model/marketplace.go
  • model/rbac.go
  • model/rbac_marketplace_test.go
  • model/task_cas_test.go
  • router/api-router.go
  • web/default/src/features/secondary-development/api.ts
  • web/default/src/features/secondary-development/index.tsx
  • web/default/src/features/secondary-development/types.ts
  • web/default/src/features/usage-logs/components/common-logs-filter-bar.tsx
  • web/default/src/features/usage-logs/components/common-logs-stats.tsx
  • web/default/src/features/usage-logs/components/usage-logs-table.tsx
  • web/default/src/features/usage-logs/constants.ts
  • web/default/src/features/usage-logs/index.tsx
  • web/default/src/features/usage-logs/lib/utils.ts
  • web/default/src/features/usage-logs/section-registry.tsx
  • web/default/src/features/usage-logs/types.ts
  • web/default/src/hooks/use-sidebar-config.ts
  • web/default/src/hooks/use-sidebar-data.ts
  • web/default/src/hooks/use-sidebar-view.ts
  • web/default/src/i18n/locales/en.json
  • web/default/src/i18n/locales/fr.json
  • web/default/src/i18n/locales/ja.json
  • web/default/src/i18n/locales/ru.json
  • web/default/src/i18n/locales/vi.json
  • web/default/src/i18n/locales/zh.json
  • web/default/src/lib/rbac.ts
  • web/default/src/routeTree.gen.ts
  • web/default/src/routes/_authenticated/finance/index.tsx
  • web/default/src/routes/_authenticated/marketplace/index.tsx
  • web/default/src/routes/_authenticated/provider-console/index.tsx
  • web/default/src/routes/_authenticated/rbac/index.tsx
  • web/default/src/routes/_authenticated/usage-logs/$section.tsx
  • web/default/src/stores/auth-store.ts

Walkthrough

This PR introduces a full marketplace management platform. It adds AES-GCM model-key encryption, GORM-backed RBAC and marketplace data models with lifecycle hooks, HTTP controllers with fine-grained permission gating and audit logging, a PermissionAuth middleware, new API route groups, and a React frontend with consoles for marketplace, provider, finance, and RBAC management—plus audit log support and RBAC-filtered sidebar navigation.

Changes

Marketplace, RBAC & Audit Platform

Layer / File(s) Summary
AES-GCM model key encryption & masking
common/secret_box.go
Adds EncryptModelKey/DecryptModelKey via SHA-256-derived AES-GCM key from env, and MaskSecret that keeps first/last 4 runes.
RBAC & marketplace data models + DB migration
model/rbac.go, model/marketplace.go, model/main.go, model/rbac_marketplace_test.go, model/task_cas_test.go
Defines GORM-backed role/permission/user-role structs with constants, EnsureBuiltinRBAC, UserHasPermission helpers, marketplace/provider/model/key/pricing/review structs with lifecycle hooks and SetModelKeyPlaintext, expands AutoMigrate in both migration paths, and adds tests covering permission matrix, data isolation, and key encryption.
RBAC middleware, controllers & router wiring
middleware/rbac.go, controller/rbac.go, controller/marketplace.go, controller/user.go, controller/marketplace_test.go, router/api-router.go
Adds PermissionAuth middleware, RBAC handlers for listing roles/permissions and replacing user roles, marketplace handlers for provider/model/key/pricing/review CRUD with ownership checks and audit logging, extends GetSelf with role_codes/permission_codes, and wires /api/rbac, /api/provider, and /api/marketplace-models route groups.
Frontend RBAC library & auth store
web/default/src/lib/rbac.ts, web/default/src/stores/auth-store.ts
Adds PERMISSION constants, getPermissionCodes, hasPermission, hasAnyPermission helpers; extends UserPermissions with role_codes and permission_codes.
Secondary development console UI
web/default/src/features/secondary-development/types.ts, web/default/src/features/secondary-development/api.ts, web/default/src/features/secondary-development/index.tsx
Introduces domain types, typed API client wrappers, and the SecondaryDevelopment component with MarketplaceConsole, ProviderConsole, FinanceConsole, and RBACConsole sections using React Query and RBAC-gated actions.
Audit log category support
web/default/src/features/usage-logs/types.ts, web/default/src/features/usage-logs/section-registry.tsx, web/default/src/features/usage-logs/constants.ts, web/default/src/features/usage-logs/index.tsx, web/default/src/features/usage-logs/lib/utils.ts, web/default/src/features/usage-logs/components/...
Extends LogCategory with 'audit', adds audit section metadata, propagates adminOverride through table/filter-bar/stats components, and sets type=MANAGE in audit fetch requests.
Authenticated routes, sidebar nav & route tree
web/default/src/routes/_authenticated/..., web/default/src/routeTree.gen.ts, web/default/src/hooks/use-sidebar-data.ts, web/default/src/hooks/use-sidebar-config.ts, web/default/src/hooks/use-sidebar-view.ts
Registers /marketplace, /provider-console, /finance, /rbac routes with beforeLoad RBAC guards; adds sidebar nav items; filters nav items per-user permission; gates /usage-logs/audit with AUDIT_VIEW.
Multilingual translations
web/default/src/i18n/locales/en.json, ...fr.json, ...ja.json, ...ru.json, ...vi.json, ...zh.json
Adds ~40 new translation keys per locale for marketplace, provider, RBAC, finance, settlement, wallet, model-key, pricing, and audit UI strings.

Sequence Diagram(s)

sequenceDiagram
  participant Browser as Browser (React)
  participant RouteGuard as beforeLoad (RBAC guard)
  participant AuthStore as useAuthStore
  participant SecDev as SecondaryDevelopment
  participant APIClient as api.ts
  participant PermissionAuth as PermissionAuth middleware
  participant Controller as marketplace/rbac controller
  participant ModelLayer as model/rbac + model/marketplace
  participant DB

  Browser->>RouteGuard: navigate to /marketplace
  RouteGuard->>AuthStore: read user
  AuthStore-->>RouteGuard: user + permission_codes
  RouteGuard-->>Browser: redirect /403 OR render component

  Browser->>SecDev: render MarketplaceConsole
  SecDev->>APIClient: getMarketplaceModels()
  APIClient->>PermissionAuth: GET /api/marketplace-models + JWT
  PermissionAuth->>ModelLayer: UserHasAnyPermission(id, role, perms)
  ModelLayer->>DB: query role_permissions
  DB-->>ModelLayer: codes
  ModelLayer-->>PermissionAuth: allowed
  PermissionAuth->>Controller: c.Next()
  Controller->>ModelLayer: ListMarketplaceModels(...)
  ModelLayer->>DB: SELECT marketplace_models + providers
  DB-->>ModelLayer: rows
  ModelLayer-->>Controller: []MarketplaceModel
  Controller-->>APIClient: ApiSuccess{items, total}
  APIClient-->>SecDev: PageData<MarketplaceModel>
  SecDev-->>Browser: render model table
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Possibly related PRs

  • QuantumNous/new-api#1701: Modifies controller/user.go's GetSelf response, overlapping directly with this PR's addition of role_codes and permission_codes to the permissions map returned by GetSelf.

Poem

🐇 A rabbit built a marketplace today,
With AES keys locked safely away.
Providers and models lined up in a row,
Permissions checked before letting you go.
Audit logs flowing, the sidebar looks neat—
****masked**** secrets make the picture complete! 🔑

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@binshiz

binshiz commented Jun 23, 2026

Copy link
Copy Markdown
Author

Closing per requester instruction: this draft PR should not target QuantumNous/new-api.

@binshiz binshiz closed this Jun 23, 2026
@binshiz
binshiz deleted the codex/secondary-development-phase1 branch June 23, 2026 13:32
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