Skip to content

feat: 敏感配置 + JSONC 支持#241

Open
animacaeli wants to merge 1 commit into
dotnetcore:masterfrom
animacaeli:feat/sensitive-config-and-jsonc
Open

feat: 敏感配置 + JSONC 支持#241
animacaeli wants to merge 1 commit into
dotnetcore:masterfrom
animacaeli:feat/sensitive-config-and-jsonc

Conversation

@animacaeli

@animacaeli animacaeli commented Jul 19, 2026

Copy link
Copy Markdown

概述

本 PR 新增两个功能:敏感配置JSONC 编辑支持

⚠️ 声明:此 PR 的所有代码由 AI(Claude Code)编写,人工审核通过后提交。

AI 参与方式:

  • 需求分析和架构规划由 AI 完成(含完整项目代码阅读)
  • 所有后端 C# 代码、前端 TypeScript/React 代码由 AI 生成
  • 单元测试由 AI 生成
  • 人工负责:需求确认、方案审批、代码审查、最终审核

一、敏感配置

功能描述

  • 新建/编辑配置时可勾选"敏感配置"
  • 敏感配置的值在管理界面中需 CONFIG_VIEW_SENSITIVE 权限才能查看明文
  • 无权限用户看到的值显示为 ******
  • 客户端 SDK 接口不受影响(始终返回真实值)

后端变更

文件 变更
Data.Entity/Config.cs 新增 Sensitive 字段
Data.Entity/PublishDetail.cs 新增 Sensitive 字段
Apisite/Models/ConfigVM.cs ViewModel 新增 Sensitive
Apisite/Controllers/api/Models/ApiConfigVM.cs API ViewModel 新增 Sensitive
Apisite/Models/Mapping/ModelMappingExtension.cs ToApiConfigVM() 映射 Sensitive 和 Description
IService/IPermissionService.cs 新增 Config_ViewSensitive 权限
Controllers/ConfigController.cs 所有读接口调用 MaskSensitiveConfigs() 掩码;Add/Edit 保存 Sensitive
Service/ConfigService.cs Publish 写入 PublishDetail.Sensitive;EnvSync 同步敏感标记

安全设计

  1. 掩码在后端强制执行,不依赖前端
  2. 客户端 API(api/ConfigController)不做掩码
  3. 新增独立权限 Config_ViewSensitive,不耦合编辑权限
  4. 掩码方法同时支持 JWT Claim 和 Basic Auth

前端变更

文件 变更
pages/Configs/data.d.ts ConfigListItem 新增 sensitive
pages/Configs/index.tsx 新建表单增加 ProFormSwitch;表格新增敏感列(🔒)
pages/Configs/comps/updateForm.tsx 编辑表单增加 ProFormSwitch
models/functionKeys.ts 新增 Config_ViewSensitive
locales/zh-CN/pages.ts, locales/en-US/pages.ts 中英文新增 4 个 i18n key

二、JSONC(JSON with Comments)支持

功能描述

  • 编辑 JSON 配置时,描述字段以 // 注释形式渲染
  • 支持双向转换:表数据 ↔ JSONC(注释 ↔ 描述)
  • 参照 VS Code settings.json 体验

新增文件

文件 说明
Common/DictionaryConvertToJsonC.cs JSONC 序列化器
Common/JsonCConfigurationFileParser.cs JSONC 反序列化器(基于 Newtonsoft.Json)

修改文件

文件 变更
Controllers/ConfigController.cs GetJson 输出 JSONC;SaveJson 改用 SaveJsonCAsync
Service/ConfigService.cs 新增 SaveJsonCAsync;SaveFromDictAsync 扩展支持描述
IService/IConfigService.cs 接口新增 SaveJsonCAsync
pages/Configs/comps/JsonEditor.tsx Monaco 语言从 json 改为 jsonc

双向转换示例

// 保存的 JSONC:
{
"oss": {
"custom_domain": "xxx.com" // 自定义域名
}
}

// 转为表数据:
// group="oss", key="custom_domain", value="xxx.com", description="自定义域名"

附带修复

SaveFromDictAsync 之前新建配置从不设置 Description,现通过 descriptions 可选参数修复,标准 JSON 路径向后兼容。


三、测试

新增 2 个测试文件,共 17 个用例:

  • DictionaryConvertToJsonCTests.cs — 7 个(基本、嵌套、空字典、敏感字符转义、数组等)
  • JsonCConfigurationFileParserTests.cs — 10 个(含往返测试:values+descriptions → JSONC → values+descriptions)

四、文件统计

类型 数量
新增文件 4
修改文件 16
总计 20(+808 行 / -18 行)

Co-Authored-By: Claude noreply@anthropic.com
🤖 Generated with Claude Code

- Add sensitive configuration: new Sensitive field on Config/PublishDetail entities,
  Config_ViewSensitive permission for controlling access to sensitive values,
  and mask logic (******) in admin API when user lacks the permission.
- Add JSONC (JSON with Comments) support: DictionaryConvertToJsonC serializer
  outputs descriptions as inline // comments, JsonCConfigurationFileParser
  extracts comments back to descriptions using Newtonsoft.Json JsonTextReader.
- Fix SaveFromDictAsync to set Description for newly created configs from JSONC.
- EnvSync now propagates Sensitive and Description changes across environments.
- Frontend: sensitive switch in add/edit forms, lock icon column, jsonc language
  in Monaco editor, i18n for zh-CN and en-US.
- Unit tests for JSONC serializer, parser, and round-trip conversion.

Co-Authored-By: Claude <noreply@anthropic.com>
@animacaeli animacaeli closed this Jul 19, 2026
@animacaeli animacaeli reopened this Jul 19, 2026
@kklldog

kklldog commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Cool.
@animacaeli 这个只是配置值在前端显示的时候显示 ****** ?数据库里存的还是原始值吗?

@animacaeli

Copy link
Copy Markdown
Author

Cool. @animacaeli 这个只是配置值在前端显示的时候显示 ****** ?数据库里存的还是原始值吗?

数据库和客户端都是原始值,在前端受到权限控制显示掩码

@animacaeli

Copy link
Copy Markdown
Author

@kklldog 这个 PR 需要你那边注意看下,我只是针对我们架构的痛点进行补充,不会 C#,全部是都是Claude Code 写的。麻烦您审核一下,如果有其他问题,辛苦反馈。

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.

3 participants