背景: - 开发计划 A1 批次要求登录/刷新/登出、用户生命周期、路由与按钮权限、 权限三态用例;视觉已选定方案 B(主从分栏 + 分屏登录)。 改动: - packages/shared:新增 identity 契约(User/Me/Login/Refresh/Department/Role) 与 user:view 权限点;写接口 strict 校验。 - apps/api:新增 identity 模块与 Prisma expand 迁移(departments/users/roles/ user_roles/role_permissions/refresh_tokens);Argon2id、JWT access+refresh 旋转与 jti 吊销、登录失败锁定、首登强改、守卫链、/me、@Audit 上下文、幂等种子。 - apps/web:按方案 B 落地 /users、/users/new、/users/:id、分屏登录与 403; usePermission/<Can>、路由守卫、401 单飞刷新、停用会话兜底、Semi + token。 - e2e:新增 A1-QA-01 六类端到端用例(A1_E2E 门控)。 - openapi 与前端生成类型同步;.env.example 登记认证变量;实施报告入库。 影响面: - 新增运行时依赖 @nestjs/jwt、argon2(计划 A1-BE-02 已批准,版本精确锁定)。 - 迁移为 expand,不改既有表;本地需 prisma migrate 后重新 seed。 - 平台导航「用户与组织」由 /platform/users 调整为 /users。 回滚方式: - 代码整体回滚本提交;迁移为 expand,回滚代码不需删表; - 本地如需彻底回退按实施报告 §6 处理。 验证证据: - pnpm format:check / lint / typecheck 通过; - pnpm test:shared 95 / api 60 / web 55; - pnpm test:int:7 个(真实 PG/Redis); - A1_E2E=1 playwright test e2e/a1-identity.spec.ts:6/6; - 报告:docs/开发计划/灵犀_A1身份认证与用户管理_实施报告_V0.1.md
This commit is contained in:
1 parent
f0d218bd99
commit
4d9eb980af
120 files changed
+13112
-314
No files matched your search
@@ -0,0 +1,25 @@
|
||||
import type { BreadcrumbEntry } from './nav-config';
|
||||
|
||||
/**
|
||||
* /users 下的子路由(新建 / 详情)不在 nav-config 的菜单项里,
|
||||
* 这里补齐面包屑:工作台 / 平台 / 用户与组织 / 当前页。
|
||||
*/
|
||||
export function getUserSectionTrail(pathname: string): BreadcrumbEntry[] | null {
|
||||
if (pathname === '/users/new') {
|
||||
return [
|
||||
{ key: 'home', label: '工作台', path: '/' },
|
||||
{ key: 'platform', label: '平台' },
|
||||
{ key: 'users', label: '用户与组织', path: '/users' },
|
||||
{ key: 'user-new', label: '新建用户' },
|
||||
];
|
||||
}
|
||||
if (/^\/users\/[^/]+$/.test(pathname)) {
|
||||
return [
|
||||
{ key: 'home', label: '工作台', path: '/' },
|
||||
{ key: 'platform', label: '平台' },
|
||||
{ key: 'users', label: '用户与组织', path: '/users' },
|
||||
{ key: 'user-detail', label: '成员详情' },
|
||||
];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -26,6 +26,13 @@ describe('导航配置', () => {
|
||||
expect(modules.map((module) => module.key)).toEqual(['dashboard']);
|
||||
});
|
||||
|
||||
it('子路由(/users/new、/users/:id)也归属用户与组织', () => {
|
||||
expect(findActiveNav(NAV_MODULES, '/users/new')?.item?.label).toBe('用户与组织');
|
||||
expect(findActiveNav(NAV_MODULES, '/users/01HZZZZZZZZZZZZZZZZZZZZZZZ')?.module.key).toBe(
|
||||
'platform',
|
||||
);
|
||||
});
|
||||
|
||||
it('按路径定位当前模块与菜单', () => {
|
||||
const active = findActiveNav(NAV_MODULES, '/material/quick-review');
|
||||
expect(active?.module.key).toBe('material');
|
||||
@@ -35,7 +42,7 @@ describe('导航配置', () => {
|
||||
|
||||
it('面包屑从导航配置派生', () => {
|
||||
expect(getBreadcrumbs(NAV_MODULES, '/')).toEqual([{ key: 'home', label: '工作台', path: '/' }]);
|
||||
const breadcrumbs = getBreadcrumbs(NAV_MODULES, '/platform/users');
|
||||
const breadcrumbs = getBreadcrumbs(NAV_MODULES, '/users');
|
||||
expect(breadcrumbs.map((entry) => entry.label)).toEqual(['工作台', '平台', '用户与组织']);
|
||||
});
|
||||
});
|
||||
@@ -242,16 +242,16 @@ export const NAV_MODULES: readonly NavModule[] = [
|
||||
{
|
||||
key: 'platform',
|
||||
label: '平台',
|
||||
path: '/platform/users',
|
||||
path: '/users',
|
||||
icon: IconSettings,
|
||||
permission: Permission.USER_MANAGE,
|
||||
permission: Permission.USER_VIEW,
|
||||
items: [
|
||||
{
|
||||
key: 'users',
|
||||
label: '用户与组织',
|
||||
path: '/platform/users',
|
||||
path: '/users',
|
||||
icon: IconUser,
|
||||
permission: Permission.USER_MANAGE,
|
||||
permission: Permission.USER_VIEW,
|
||||
description: '账号、组织与登录状态',
|
||||
},
|
||||
{
|
||||
@@ -378,7 +378,11 @@ export interface ActiveNav {
|
||||
export function findActiveNav(modules: readonly NavModule[], pathname: string): ActiveNav | null {
|
||||
const normalized = pathname !== '/' ? pathname.replace(/\/+$/, '') : pathname;
|
||||
for (const module of modules) {
|
||||
const item = module.items.find((candidate) => candidate.path === normalized);
|
||||
const item = module.items.find(
|
||||
(candidate) =>
|
||||
candidate.path === normalized ||
|
||||
(candidate.path !== '/' && normalized.startsWith(`${candidate.path}/`)),
|
||||
);
|
||||
if (item) {
|
||||
return { module, item };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user