feat(admin): Add user management and upgrade to module permission system
Features - User Management (Phase 4.1): - Database: Add user_modules table for fine-grained module permissions - Database: Add 4 user permissions (view/create/edit/delete) to role_permissions - Backend: UserService (780 lines) - CRUD with tenant isolation - Backend: UserController + UserRoutes (648 lines) - 13 API endpoints - Backend: Batch import users from Excel - Frontend: UserListPage (412 lines) - list/filter/search/pagination - Frontend: UserFormPage (341 lines) - create/edit with module config - Frontend: UserDetailPage (393 lines) - details/tenant/module management - Frontend: 3 modal components (592 lines) - import/assign/configure - API: GET/POST/PUT/DELETE /api/admin/users/* endpoints Architecture Upgrade - Module Permission System: - Backend: Add getUserModules() method in auth.service - Backend: Login API returns modules array in user object - Frontend: AuthContext adds hasModule() method - Frontend: Navigation filters modules based on user.modules - Frontend: RouteGuard checks requiredModule instead of requiredVersion - Frontend: Remove deprecated version-based permission system - UX: Only show accessible modules in navigation (clean UI) - UX: Smart redirect after login (avoid 403 for regular users) Fixes: - Fix UTF-8 encoding corruption in ~100 docs files - Fix pageSize type conversion in userService (String to Number) - Fix authUser undefined error in TopNavigation - Fix login redirect logic with role-based access check - Update Git commit guidelines v1.2 with UTF-8 safety rules Database Changes: - CREATE TABLE user_modules (user_id, tenant_id, module_code, is_enabled) - ADD UNIQUE CONSTRAINT (user_id, tenant_id, module_code) - INSERT 4 permissions + role assignments - UPDATE PUBLIC tenant with 8 module subscriptions Technical: - Backend: 5 new files (~2400 lines) - Frontend: 10 new files (~2500 lines) - Docs: 1 development record + 2 status updates + 1 guideline update - Total: ~4900 lines of code Status: User management 100% complete, module permission system operational
This commit is contained in:
@@ -1,26 +1,26 @@
|
||||
# 敹恍<EFBFBD>笔<EFBFBD><EFBFBD>賣<EFBFBD>霂閙𥁒<EFBFBD>?- Schema餈<61>宏<EFBFBD>𡡞<EFBFBD>霂?
|
||||
# 快速功能测试报告 - Schema迁移后验证
|
||||
|
||||
> **瘚贝<EFBFBD><EFBFBD>園𡢿嚗?* 2025-11-12 10:45
|
||||
> **测试时间:** 2025-11-12 10:45
|
||||
> **测试人:** AI助手
|
||||
> **瘚贝<EFBFBD><EFBFBD>桃<EFBFBD>嚗?* 撉諹<E69289>Schema餈<EFBFBD>宏<EFBFBD>釶risma憭锭chema<EFBFBD>滨蔭<EFBFBD>𡒊頂蝏<EFBFBD>糓<EFBFBD>行迤撣詨極雿?
|
||||
> **瘚贝<EFBFBD>蝏𤘪<EFBFBD>嚗?* <20>?**<2A>券<EFBFBD><E588B8>朞<EFBFBD>** <EFBFBD><EFBFBD>
|
||||
> **测试目的:** 验证Schema迁移和Prisma多Schema配置后系统是否正常工作
|
||||
> **测试结果:** ✅ **全部通过** 🎉
|
||||
|
||||
---
|
||||
|
||||
## <EFBFBD>?瘚贝<E7989A>璁<EFBFBD><E79281>
|
||||
## ✅ 测试概况
|
||||
|
||||
### 测试范围
|
||||
- <EFBFBD>?<3F>𡒊垢<F0A1928A>滚𦛚<E6BB9A>亙熒璉<E78692><E79289>?
|
||||
- <EFBFBD>?<3F>唳旿摨栞<E691A8><E6A09E>亦𠶖<E4BAA6>?
|
||||
- <EFBFBD>?Platform Schema嚗<EFBFBD>鍂<EFBFBD>瑟芋<EFBFBD>梹<EFBFBD>
|
||||
- <EFBFBD>?AIA Schema嚗㇁I<EFBFBD>箄<EFBFBD><EFBFBD>桃<EFBFBD>璅∪<EFBFBD>嚗?
|
||||
- <EFBFBD>?PKB Schema嚗<EFBFBD>葵鈭箇䰻霂<EFBFBD><EFBFBD>璅∪<EFBFBD>嚗?
|
||||
- <EFBFBD>?頝沒chema憭㚚睸撘閧鍂
|
||||
- ✅ 后端服务健康检查
|
||||
- ✅ 数据库连接状态
|
||||
- ✅ Platform Schema(用户模块)
|
||||
- ✅ AIA Schema(AI智能问答模块)
|
||||
- ✅ PKB Schema(个人知识库模块)
|
||||
- ✅ 跨Schema外键引用
|
||||
|
||||
### 测试方法
|
||||
使用curl命令测试后端API接口,验证:
|
||||
1. 服务是否运行
|
||||
2. <EFBFBD>唳旿摨𤘪糓<EFBFBD>西<EFBFBD><EFBFBD>?
|
||||
2. 数据库是否连接
|
||||
3. 各Schema的数据是否能正常读取
|
||||
4. Prisma Client是否正确路由到新Schema
|
||||
|
||||
@@ -28,11 +28,11 @@
|
||||
|
||||
## 📋 测试详细结果
|
||||
|
||||
### 瘚贝<EFBFBD>1嚗𡁜<EFBFBD>摨瑟<EFBFBD><EFBFBD>?<3F>?
|
||||
### 测试1:健康检查 ✅
|
||||
|
||||
**<EFBFBD>亙藁嚗?* `GET http://localhost:3001/health`
|
||||
**接口:** `GET http://localhost:3001/health`
|
||||
|
||||
**<EFBFBD>滚<EFBFBD>嚗?*
|
||||
**响应:**
|
||||
```json
|
||||
{
|
||||
"status": "ok",
|
||||
@@ -42,15 +42,15 @@
|
||||
}
|
||||
```
|
||||
|
||||
**蝏栞捏嚗?* <20>?<3F>𡒊垢<F0A1928A>滚𦛚<E6BB9A>峕㺭<E5B395>桀<EFBFBD>餈墧𦻖甇<F0A6BB96>虜
|
||||
**结论:** ✅ 后端服务和数据库连接正常
|
||||
|
||||
---
|
||||
|
||||
### 瘚贝<EFBFBD>2嚗鋫PI<EFBFBD>亙藁 <20>?
|
||||
### 测试2:API入口 ✅
|
||||
|
||||
**<EFBFBD>亙藁嚗?* `GET http://localhost:3001/api/v1`
|
||||
**接口:** `GET http://localhost:3001/api/v1`
|
||||
|
||||
**<EFBFBD>滚<EFBFBD>嚗?*
|
||||
**响应:**
|
||||
```json
|
||||
{
|
||||
"message": "AI Clinical Research Platform API",
|
||||
@@ -59,15 +59,15 @@
|
||||
}
|
||||
```
|
||||
|
||||
**蝏栞捏嚗?* <20>?API<50>滚𦛚甇<F0A69B9A>虜餈鞱<E9A488>
|
||||
**结论:** ✅ API服务正常运行
|
||||
|
||||
---
|
||||
|
||||
### 瘚贝<EFBFBD>3嚗鋫IA Schema - 憿寧𤌍<EFBFBD>𡑒” <20>?
|
||||
### 测试3:AIA Schema - 项目列表 ✅
|
||||
|
||||
**<EFBFBD>亙藁嚗?* `GET http://localhost:3001/api/v1/projects`
|
||||
**接口:** `GET http://localhost:3001/api/v1/projects`
|
||||
|
||||
**<EFBFBD>滚<EFBFBD>嚗?*
|
||||
**响应:**
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
@@ -75,8 +75,8 @@
|
||||
{
|
||||
"id": "a6ce8b46-bac6-4284-a9ae-031d636086bc",
|
||||
"userId": "user-mock-001",
|
||||
"name": "<EFBFBD>X<EFBFBD>扳<EFBFBD>撌渡<EFBFBD><EFBFBD>䂿蒾銵<EFBFBD><EFBFBD>?,
|
||||
"background": "<EFBFBD>X<EFBFBD>扳<EFBFBD>撌渡<EFBFBD><EFBFBD>䂿蒾銵<EFBFBD><EFBFBD>?,
|
||||
"name": "慢性淋巴细胞白血病",
|
||||
"background": "慢性淋巴细胞白血病",
|
||||
"researchType": "observational",
|
||||
"conversationCount": 0,
|
||||
"createdAt": "2025-11-05T07:38:55.147Z",
|
||||
@@ -86,17 +86,17 @@
|
||||
}
|
||||
```
|
||||
|
||||
**StatusCode嚗?* 200 OK
|
||||
**<EFBFBD>唳旿<EFBFBD>交<EFBFBD>嚗?* `aia_schema.projects`
|
||||
**蝏栞捏嚗?* <20>?<3F>賢<EFBFBD>甇<EFBFBD>&隞垾IA Schema霂餃<E99C82>憿寧𤌍<E5AFA7>唳旿
|
||||
**StatusCode:** 200 OK
|
||||
**数据来源:** `aia_schema.projects`
|
||||
**结论:** ✅ 能够正确从AIA Schema读取项目数据
|
||||
|
||||
---
|
||||
|
||||
### 瘚贝<EFBFBD>4嚗鋫IA Schema - 撖寡<EFBFBD><EFBFBD>𡑒” <20>?
|
||||
### 测试4:AIA Schema - 对话列表 ✅
|
||||
|
||||
**<EFBFBD>亙藁嚗?* `GET http://localhost:3001/api/v1/chat/conversations`
|
||||
**接口:** `GET http://localhost:3001/api/v1/chat/conversations`
|
||||
|
||||
**<EFBFBD>滚<EFBFBD>嚗?*
|
||||
**响应:**
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
@@ -114,17 +114,17 @@
|
||||
}
|
||||
```
|
||||
|
||||
**StatusCode嚗?* 200 OK
|
||||
**<EFBFBD>唳旿<EFBFBD>交<EFBFBD>嚗?* `aia_schema.general_conversations`
|
||||
**蝏栞捏嚗?* <20>?<3F>賢<EFBFBD>甇<EFBFBD>&隞垾IA Schema霂餃<E99C82>撖寡<E69296><E5AFA1>唳旿
|
||||
**StatusCode:** 200 OK
|
||||
**数据来源:** `aia_schema.general_conversations`
|
||||
**结论:** ✅ 能够正确从AIA Schema读取对话数据
|
||||
|
||||
---
|
||||
|
||||
### 瘚贝<EFBFBD>5嚗䥪KB Schema - <EFBFBD>亥<EFBFBD>摨枏<EFBFBD>銵?<3F>?
|
||||
### 测试5:PKB Schema - 知识库列表 ✅
|
||||
|
||||
**<EFBFBD>亙藁嚗?* `GET http://localhost:3001/api/v1/knowledge-bases`
|
||||
**接口:** `GET http://localhost:3001/api/v1/knowledge-bases`
|
||||
|
||||
**<EFBFBD>滚<EFBFBD>嚗?*
|
||||
**响应:**
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
@@ -132,8 +132,8 @@
|
||||
{
|
||||
"id": "b42a116b-a22c-41ba-95fd-4d56a6974e7e",
|
||||
"userId": "user-mock-001",
|
||||
"name": "CLL<EFBFBD>詨<EFBFBD><EFBFBD>亥<EFBFBD>摨?,
|
||||
"description": "CLL<EFBFBD>詨<EFBFBD><EFBFBD>亥<EFBFBD>摨?,
|
||||
"name": "CLL相关知识库",
|
||||
"description": "CLL相关知识库",
|
||||
"difyDatasetId": "a5e231bc-428e-4462-bc2e-6f94a83d3b6f",
|
||||
"fileCount": 48,
|
||||
"characterCount": 0,
|
||||
@@ -144,41 +144,41 @@
|
||||
}
|
||||
```
|
||||
|
||||
**StatusCode嚗?* 200 OK
|
||||
**<EFBFBD>唳旿<EFBFBD>交<EFBFBD>嚗?* `pkb_schema.knowledge_bases`
|
||||
**蝏栞捏嚗?* <20>?<3F>賢<EFBFBD>甇<EFBFBD>&隞窰KB Schema霂餃<E99C82><E9A483>亥<EFBFBD>摨𤘪㺭<F0A498AA>?
|
||||
**StatusCode:** 200 OK
|
||||
**数据来源:** `pkb_schema.knowledge_bases`
|
||||
**结论:** ✅ 能够正确从PKB Schema读取知识库数据
|
||||
|
||||
---
|
||||
|
||||
## 🔍 验证结论
|
||||
|
||||
### <EFBFBD>詨<EFBFBD><EFBFBD>𤑳緵 潃?
|
||||
### 核心发现 ⭐
|
||||
|
||||
**Prisma Client<EFBFBD>芸𢆡憭<EFBFBD><EFBFBD>Schema頝舐眏嚗?*
|
||||
**Prisma Client自动处理Schema路由!**
|
||||
|
||||
1. <EFBFBD>?**<2A>𣳇<EFBFBD>靽格㺿隞<E3BABF><E99A9E>** - <EFBFBD>唳<EFBFBD>隞<EFBFBD><EFBFBD>蝏抒賒甇<EFBFBD>虜撌乩<EFBFBD>
|
||||
2. <EFBFBD>?**<2A>芸𢆡Schema頝舐眏** - Prisma<EFBFBD>寞旿@@schema()<EFBFBD><EFBFBD>倌<EFBFBD>芸𢆡<EFBFBD>亥砭甇<EFBFBD>&<EFBFBD><EFBFBD>chema
|
||||
3. <EFBFBD>?**頝沒chema撘閧鍂<E996A7>㗇<EFBFBD>** - 憭㚚睸<EFBFBD>喟頂甇<EFBFBD>虜撌乩<EFBFBD>
|
||||
4. <EFBFBD>?**<2A>扯<EFBFBD><E689AF>惩蔣<E683A9>?* - <20>亥砭<E4BAA5>笔漲甇<E6BCB2>虜
|
||||
1. ✅ **无需修改代码** - 现有代码继续正常工作
|
||||
2. ✅ **自动Schema路由** - Prisma根据@@schema()标签自动查询正确的schema
|
||||
3. ✅ **跨Schema引用有效** - 外键关系正常工作
|
||||
4. ✅ **性能无影响** - 查询速度正常
|
||||
|
||||
### 测试覆盖
|
||||
|
||||
| Schema | 瘚贝<EFBFBD>銵?| <20>嗆<EFBFBD>?| <20>唳旿<E594B3>?|
|
||||
| Schema | 测试表 | 状态 | 数据量 |
|
||||
|--------|--------|------|--------|
|
||||
| platform_schema | users | <EFBFBD>?<3F>湔𦻖撉諹<E69289> | - |
|
||||
| aia_schema | projects | <EFBFBD>?<3F>朞<EFBFBD> | 1+ |
|
||||
| aia_schema | general_conversations | <EFBFBD>?<3F>朞<EFBFBD> | 1+ |
|
||||
| pkb_schema | knowledge_bases | <EFBFBD>?<3F>朞<EFBFBD> | 1+ |
|
||||
| platform_schema | users | ✅ 间接验证 | - |
|
||||
| aia_schema | projects | ✅ 通过 | 1+ |
|
||||
| aia_schema | general_conversations | ✅ 通过 | 1+ |
|
||||
| pkb_schema | knowledge_bases | ✅ 通过 | 1+ |
|
||||
|
||||
**<EFBFBD>餉恣嚗?* 3銝杵chema嚗?銝芣瓲敹<E793B2>”嚗<E2809D><E59A97><EFBFBD>冽<EFBFBD>霂閖<E99C82>朞<EFBFBD> <20>?
|
||||
**总计:** 3个Schema,3个核心表,全部测试通过 ✅
|
||||
|
||||
---
|
||||
|
||||
## 💡 重要结论
|
||||
|
||||
### <EFBFBD>?<3F>𣂼<EFBFBD>撉諹<E69289>
|
||||
### ✅ 成功验证
|
||||
|
||||
1. **Schema餈<EFBFBD>宏<EFBFBD>𣂼<EFBFBD>** - <EFBFBD><EFBFBD><EFBFBD>㗇㺭<EFBFBD>桀<EFBFBD><EFBFBD>渲<EFBFBD>蝘?
|
||||
1. **Schema迁移成功** - 所有数据完整迁移
|
||||
2. **Prisma配置正确** - 多Schema支持工作正常
|
||||
3. **代码无需修改** - 现有代码自动适配
|
||||
4. **外键关系有效** - 跨Schema引用正常
|
||||
@@ -188,54 +188,54 @@
|
||||
**为什么代码不需要修改?**
|
||||
|
||||
```typescript
|
||||
// <EFBFBD>唳<EFBFBD>隞<EFBFBD><EFBFBD>嚗<EFBFBD><EFBFBD><EFBFBD><EFBFBD>靽格㺿嚗?
|
||||
// 现有代码(无需修改)
|
||||
const projects = await prisma.project.findMany();
|
||||
|
||||
// Prisma自动翻译为:
|
||||
// SELECT * FROM aia_schema.projects;
|
||||
```
|
||||
|
||||
Prisma Client<EFBFBD>函<EFBFBD><EFBFBD>鞉𧒄撌脩<EFBFBD>霂餃<EFBFBD>鈭<EFBFBD><EFBFBD>銝沸odel<EFBFBD><EFBFBD>@@schema()`<EFBFBD><EFBFBD>倌嚗?
|
||||
隡朞䌊<EFBFBD>典銁SQL<EFBFBD>亥砭銝凋蝙<EFBFBD>冽迤蝖桃<EFBFBD>schema<EFBFBD>滨<EFBFBD><EFBFBD>?
|
||||
Prisma Client在生成时已经读取了每个model的`@@schema()`标签,
|
||||
会自动在SQL查询中使用正确的schema前缀。
|
||||
|
||||
**撘<EFBFBD><EFBFBD>𤏸<EFBFBD><EFBFBD><EFBFBD><EFBFBD>毺䰻嚗<EFBFBD><EFBFBD><EFBFBD>券<EFBFBD>𤩺<EFBFBD>嚗?* <20><>
|
||||
**开发者无感知,完全透明!** 🎉
|
||||
|
||||
---
|
||||
|
||||
## 📊 测试时间统计
|
||||
|
||||
- <EFBFBD>交𪄳API頝臬<EFBFBD>嚗?<3F><><EFBFBD>
|
||||
- <EFBFBD>扯<EFBFBD>瘚贝<EFBFBD>嚗?<3F><><EFBFBD>
|
||||
- 蝻硋<EFBFBD><EFBFBD>亙<EFBFBD>嚗?0<><30><EFBFBD>
|
||||
- **<EFBFBD>餉恣嚗?* 15<31><35><EFBFBD> <20>?
|
||||
- 查找API路径:3分钟
|
||||
- 执行测试:2分钟
|
||||
- 编写报告:10分钟
|
||||
- **总计:** 15分钟 ⚡
|
||||
|
||||
---
|
||||
|
||||
## 🎯 后续建议
|
||||
|
||||
### 已确认可跳过
|
||||
- <EFBFBD>?**隞餃𦛚12嚗帋誨<E5B88B><E8AAA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>訕chema** - 銝漤<EFBFBD>閬<EFBFBD><EFBFBD>Prisma<EFBFBD>芸𢆡憭<EFBFBD><EFBFBD>
|
||||
- ❌ **任务12:代码适配新Schema** - 不需要!Prisma自动处理
|
||||
|
||||
### 建议继续
|
||||
- <EFBFBD>?**隞餃𦛚10-11嚗𡁜<E59A97>撱箸<E692B1>獢?* - AIA<49>釶KB<4B>唳旿摨栞挽霈⊥<E99C88>獢?
|
||||
- <EFBFBD>?**Week 2嚗𡁜<EFBFBD>蝡舀沲<EFBFBD><EFBFBD>挽霈?* - <20>喲睸頝臬<E9A09D>隞餃𦛚
|
||||
- ✅ **任务10-11:创建文档** - AIA和PKB数据库设计文档
|
||||
- ✅ **Week 2:前端架构设计** - 关键路径任务
|
||||
|
||||
---
|
||||
|
||||
## 📚 相关文档
|
||||
|
||||
- [Schema<EFBFBD>𠉛氖<EFBFBD>嗆<EFBFBD>霈曇恣](./01-Schema<EFBFBD>𠉛氖<EFBFBD>嗆<EFBFBD>霈曇恣嚗?0銝迎<E98A9D>.md)
|
||||
- [Schema隔离架构设计](./01-Schema隔离架构设计(10个).md)
|
||||
- [Schema迁移完成报告](./Schema迁移完成报告.md)
|
||||
- [Prisma配置完成报告](./Prisma配置完成报告.md)
|
||||
- [数据库验证通过报告](./数据库验证通过.md)
|
||||
|
||||
---
|
||||
|
||||
**瘚贝<EFBFBD>摰峕<EFBFBD><EFBFBD>園𡢿嚗?* 2025-11-12 10:45
|
||||
**銝衤<EFBFBD>甇伐<EFBFBD>** <20>𥕦遣AIA<49>釶KB<4B>唳旿摨栞挽霈⊥<E99C88>獢?
|
||||
**瘚贝<EFBFBD><EFBFBD>嗆<EFBFBD><EFBFBD><EFBFBD>** <20>?<3F>券<EFBFBD><E588B8>朞<EFBFBD>嚗峕<E59A97><E5B395><EFBFBD>靽桀<E99DBD>
|
||||
**测试完成时间:** 2025-11-12 10:45
|
||||
**下一步:** 创建AIA和PKB数据库设计文档
|
||||
**测试状态:** ✅ 全部通过,无需修复
|
||||
|
||||
**<EFBFBD><EFBFBD> Schema餈<EFBFBD>宏<EFBFBD>釶risma<EFBFBD>滨蔭撉諹<EFBFBD><EFBFBD>𣂼<EFBFBD>嚗?* 潃鐥<E6BD83>潃?
|
||||
**🎉 Schema迁移和Prisma配置验证成功!** ⭐⭐⭐
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user