Skip to content

Comments

feat: custom tenant supports#78

Merged
Jiakaic merged 1 commit intoLianjiaTech:developfrom
Jiakaic:feat/custom_tenants_supports
Nov 5, 2025
Merged

feat: custom tenant supports#78
Jiakaic merged 1 commit intoLianjiaTech:developfrom
Jiakaic:feat/custom_tenants_supports

Conversation

@Jiakaic
Copy link
Member

@Jiakaic Jiakaic commented Nov 4, 2025

Pull Request

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Fixes # (issue)

Type of Change

Please delete options that are not relevant.

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🧹 Code refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🔧 Configuration change

Component

Please check the components affected by this PR:

  • 🔧 API (Backend)
  • 🎨 Web (Frontend)
  • 🐳 Docker/Infrastructure
  • 📖 Documentation
  • 🧪 Tests
  • 📦 Dependencies

Testing

Please describe the tests that you ran to verify your changes:

  • Unit tests pass (npm test / mvn test)
  • Integration tests pass
  • Manual testing completed
  • Docker build successful

Test Configuration:

  • OS: [e.g. Ubuntu 20.04]
  • Node.js version: [e.g. 20.x]
  • Java version: [e.g. 8]

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Screenshots (if applicable)

Please add screenshots to help explain your changes.

Additional Notes

Add any additional notes, concerns, or questions here.

@Jiakaic
Copy link
Member Author

Jiakaic commented Nov 4, 2025

@claude 检查提交的代码,使用中文回复

@github-actions
Copy link

github-actions bot commented Nov 4, 2025

Claude encountered an error —— View job


I'll analyze this and get back to you.

@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Claude finished @Jiakaic's task —— View job


代码审查任务列表

  • 读取仓库配置文件 (CLAUDE.md)
  • 分析主要代码变更
  • 检查租户支持功能的实现
  • 审查潜在的代码质量和安全问题
  • 提供中文反馈意见

代码审查结果

🎯 功能概述

这个PR实现了多租户支持功能,主要将原有的单租户架构重构为支持多租户的架构。核心变更包括:

  1. 路由重构:从 /app/* 改为 /tenant/[tenantId]/app/*
  2. 租户管理:新增租户会话管理和配置中心
  3. 文件重组:大量文件从根目录移动到租户特定目录

✅ 优点

  1. 架构设计清晰:租户隔离设计合理,通过URL路径参数实现租户识别
  2. 向后兼容:保留了旧路由转换逻辑,确保平滑迁移
  3. 配置灵活:支持动态加载自定义租户配置,便于私有化部署
  4. 组件复用:大部分组件通过props传递tenantId,实现了良好的复用性

⚠️ 需要关注的问题

1. 安全风险

// web/utils/getQueryParams.ts:19
globalThis.localStorage?.setItem(tenantId, JSON.stringify(userInfo))
  • 风险:直接将用户信息存储在localStorage中,可能存在XSS攻击风险
  • 建议:考虑对敏感信息进行加密存储,或使用更安全的存储方式

2. 错误处理不够完善

// web/utils/tenant-session.ts:30
static clearTenant(): void {
  if (typeof window !== 'undefined')
    sessionStorage.removeItem(this.TENANT_KEY) // TENANT_KEY未定义
}
  • 问题TENANT_KEY常量未定义,会导致运行时错误
  • 建议:补充缺失的常量定义

3. 类型安全性问题

// web/utils/getQueryParams.ts:13
const userInfo: any = { // 使用了any类型
  ucid,
  userName,
  tenantId,
  spaceCode,
}
  • 建议:定义明确的UserInfo接口替代any类型

4. 硬编码值过多

// web/utils/tenant-session.ts:4
private static readonly DEFAULT_TENANT = 'test'
  • 建议:将默认租户ID移至配置文件中,便于不同环境的配置

5. 异常处理不足

// web/config/tenant.ts:75-84
try {
  const customConfig = require('./tenant-custom')
  // ...
} catch (error) {
  console.info('Custom tenant configuration not found, using base configuration only')
}
  • 建议:对require失败的具体原因进行更细致的处理

🔧 代码质量建议

1. 优化会话管理

// 建议增加会话过期处理
static isSessionValid(): boolean {
  // 检查会话是否过期
  const timestamp = sessionStorage.getItem('sessionTimestamp')
  const currentTime = Date.now()
  return currentTime - parseInt(timestamp || '0') < SESSION_TIMEOUT
}

2. 增强错误边界

建议在关键组件周围添加错误边界,特别是租户初始化相关的组件。

3. 优化路由处理

// web/utils/tenant-routes.ts:18-25
// 建议使用Map提高查询性能
const tenantMappings = new Map(Object.entries(TENANT_NAME_MAPPINGS))

📊 文件变更统计

  • 新增文件:2个(主要是租户相关工具类)
  • 重命名文件:95个(大部分是路径迁移)
  • 修改文件:3个(主要是布局和导航组件)

🎉 总体评价

这是一个架构层面的重大重构,整体设计合理,代码组织清晰。多租户支持的实现方式符合业界最佳实践,通过URL路径参数实现租户隔离既直观又便于扩展。

建议在合并前解决上述安全和代码质量问题,特别是会话管理的安全性和错误处理的完善性。


@Jiakaic Jiakaic merged commit 737187e into LianjiaTech:develop Nov 5, 2025
1 check passed
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