liuyun
6618137da5
feat(auth): 平台超管租户切换(super 标志 + switch-tenant)
...
- JWT 加 super 标志,sub 保持超管真实 userId,tenantCode 随切换
- isSuper 解析/checkUserActive/PermissionsGuard 支持跨租户超管
- POST /auth/switch-tenant
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-12 00:00:38 +08:00
liuyun
477f35293e
fix(security): 若干越权/健壮性修复
...
- assignOrgs 校验 orgCodes 存在性(对齐 assignResources)
- lock/kick 保护保留角色账号(super_admin/tenant_super_admin)
- BatchDeleteDto 加 @ArrayMaxSize(100)
- 待改密门禁显式放行 /auth/logout
- 分配部门改用独立权限码 role:assign-org
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-11 22:56:12 +08:00
liuyun
8eefa7fa44
feat(error): 业务错误码注册表(业务域+错误序)+ BusinessException
...
- error-codes 单一注册表 + BusinessException + 过滤器识别
- 迁移登录/锁定/待改密/用户名冲突/租户/会话等关键错误
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-11 22:42:12 +08:00
liuyun
bad8639175
feat(notice): 站内通知(公告 + 已读追踪)
...
- Notice/NoticeRead 实体;管理侧 CRUD + 用户侧 mine/unread-count/read/read-all
- 资源注册 notice 菜单 + 接口
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-11 22:25:19 +08:00
liuyun
9869974d4c
feat(auth): 首登强制改密 + 待改密门禁
...
- User 新增 must_change_password;创建(默认强制)/重置/createTenant 置 true
- 登录响应返回 mustChangePassword,改密成功清除
- JwtAuthGuard 待改密门禁:仅放行 PATCH /auth/me/password
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-11 21:54:38 +08:00
liuyun
86832ce32d
feat(session): 在线会话强踢 + 账号锁定/解锁
...
- JWT 引入 sid,单会话精确强退(sid 黑名单)与按用户踢全部(tokenVersion)
- User 新增 lockedAt/lockReason,登录/刷新/守卫统一拒绝锁定
- sessions 模块:活跃会话列表 + 单会话强退;users 新增 lock/unlock/kick-sessions
- 资源注册 + syncTenantResources 存量租户补齐脚本
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-11 21:35:43 +08:00
liuyun
127707ffde
feat(rbac): 批量删除 + 数据权限自定义闭环 + 若干修复
...
- users/orgs/resources 新增 POST /batch-delete(事务 + 失败汇总 + 用户踢下线)
- 角色数据权限自定义:GET/PUT /roles/:roleCode/orgs(roleOrg 写入路径)
- assignResources 校验 resourceCodes 存在性;角色 :id 语义改 :roleCode
- createTenant 补 createdBy;登录锁定双层阈值(IP+用户名 / 用户名全局)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-11 17:42:05 +08:00
liuyun
6937f9ece0
test: 修复 e2e + 补单元测试
...
- e2e 改为登录链路(成功返回 token / 密码错误 401)
- 补 maskSensitive、resolveDataScope 单测
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-11 17:01:30 +08:00
liuyun
ba1ae43e39
feat(security): helmet + CORS 白名单 + 限流 + 定时清理 + 时间契约 Unix 毫秒
...
- helmet 安全头 + CORS_ORIGIN 白名单 + Swagger 仅非生产
- @nestjs/throttler 全局限流(60s/100 次)
- @nestjs/schedule 定时清理过期 token 与旧日志
- API 时间统一 Unix 毫秒(TransformInterceptor 递归转换)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-11 16:54:08 +08:00
liuyun
5c1f2992b5
fix: created_by 注入 + 登出审计记录真实 username
...
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-11 16:43:31 +08:00
liuyun
13510ee216
feat(tenant): 租户 onboarding 模板 + 级联删除
...
- 抽取 seed 资源/字典到 tenant-template.ts,initTenant 幂等初始化租户
- 创建租户自动初始化管理员/根组织/角色/资源/字典
- 删除租户级联清理全部业务数据
- 修复 BaseCrudService 对 Tenant 模型的 tenantCode 大小写注入 bug
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-11 16:32:46 +08:00
liuyun
78e537fa73
feat(rbac): 用户-角色分配 + 权限码下发接口
...
- users: GET/PUT /users/:id/roles(事务化替换 + 过滤无效角色 + 清权限缓存)
- auth: GET /auth/permissions 返回 {super, permissions}
- permissions/seed: 新增 user:assign-role 权限码与资源
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-11 16:19:11 +08:00
liuyun
513688a5e6
fix(security): P0 安全越权堵漏(C1/H1-H6/H10/H11/H13/M1/M4/M6/M8-M11/M22)
...
- 平台管理员模型:super_admin=平台超管、tenant_super_admin=租户顶层(保留码),tenant:* 仅平台可授予
- 软删改名回收唯一键 + P2002→409
- 删除角色级联清理关联 + 聚合过滤已删/停用角色资源
- tokenVersion 会话吊销(重置密码/停用/删除即时踢下线)
- data_scope self 按 userId 过滤 + 详情数据权限校验
- 组织树防环、seed 不重置密码、日志脱敏补 phone/email
- JWT 密钥强校验、pageSize 上限、DTO 枚举校验、Prisma 错误映射、授权事务化
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-11 16:10:00 +08:00
liuyun
7340658305
feat: enforce RBAC, audit/login logging, and seed script
...
收口 Phase 0 三处「声明未生效」:
- 三级鉴权落地:权限集存 Redis(key 前缀隔离多项目),@RequirePermissions 挂到全部受控接口,super_admin 角色绕过权限码与 data_scope
- 审计/登录日志自动落库:@AuditLog 装饰器 + 拦截器异步写入(写操作+登录登出),登录成功/失败均记 login_log(脱敏)
- seed 脚本:一键初始化租户 touyun/用户 touyun/超管 super_admin/全量资源树(48 资源全量授权)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-10 23:19:41 +08:00
liuyun
24790e8985
feat: add Swagger API docs (/docs) with DTO schemas
...
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-10 21:39:37 +08:00
liuyun
bbc06ae775
feat: add pino structured logging (stdout + optional file via env)
...
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-10 21:31:05 +08:00
liuyun
d8d3055c73
feat: backend foundation (Prisma 6 + MySQL, auth, tenant/soft-delete/data-scope filters, core CRUD)
...
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-10 21:13:35 +08:00