Files
AIclinicalresearch/backend/compare_pkb_aia_rvw.ts
HaHafeng 66255368b7 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
2026-01-16 13:42:10 +08:00

75 lines
2.2 KiB
TypeScript

import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
async function getTableColumns(schema: string, tableName: string): Promise<any[]> {
return prisma.$queryRawUnsafe(`
SELECT column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_schema = '${schema}' AND table_name = '${tableName}'
ORDER BY ordinal_position
`);
}
async function main() {
console.log('🔍 PKB、AIA、RVW 模块表结构\n');
console.log('=' .repeat(70));
// PKB 模块的表
console.log('\n📋 PKB 模块 (pkb_schema):\n');
const pkbTables = ['batch_results', 'batch_tasks', 'documents', 'knowledge_bases', 'task_templates'];
for (const table of pkbTables) {
console.log(`\n--- pkb_schema.${table} ---`);
const cols = await getTableColumns('pkb_schema', table);
if (cols.length === 0) {
console.log(' ❌ 表不存在');
} else {
cols.forEach((c: any) => console.log(` ${c.column_name}: ${c.data_type} ${c.is_nullable === 'NO' ? 'NOT NULL' : ''}`));
}
}
// AIA 模块的表
console.log('\n\n📋 AIA 模块 (aia_schema):\n');
const aiaTables = ['conversations', 'general_conversations', 'general_messages', 'messages', 'projects'];
for (const table of aiaTables) {
console.log(`\n--- aia_schema.${table} ---`);
const cols = await getTableColumns('aia_schema', table);
if (cols.length === 0) {
console.log(' ❌ 表不存在');
} else {
cols.forEach((c: any) => console.log(` ${c.column_name}: ${c.data_type} ${c.is_nullable === 'NO' ? 'NOT NULL' : ''}`));
}
}
// RVW 模块的表
console.log('\n\n📋 RVW 模块 (rvw_schema):\n');
const rvwTables = ['review_tasks'];
for (const table of rvwTables) {
console.log(`\n--- rvw_schema.${table} ---`);
const cols = await getTableColumns('rvw_schema', table);
if (cols.length === 0) {
console.log(' ❌ 表不存在');
} else {
cols.forEach((c: any) => console.log(` ${c.column_name}: ${c.data_type} ${c.is_nullable === 'NO' ? 'NOT NULL' : ''}`));
}
}
console.log('\n' + '=' .repeat(70));
}
main()
.catch(console.error)
.finally(() => prisma.$disconnect());