From 62f17d13ad02a8515658a5a48fd6c64e7a3c0d0b Mon Sep 17 00:00:00 2001 From: iven Date: Fri, 17 Apr 2026 10:33:28 +0800 Subject: [PATCH] =?UTF-8?q?feat(core):=20TenantContext=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20department=5Fids=20=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为行级数据权限做准备,TenantContext 新增 department_ids 字段 存储用户所属部门 ID 列表。当前阶段 JWT 中间件填充为空列表, 待 user_positions 关联表建立后补充查询逻辑。 --- crates/erp-auth/src/middleware/jwt_auth.rs | 1 + crates/erp-core/src/rbac.rs | 1 + crates/erp-core/src/types.rs | 3 +++ 3 files changed, 5 insertions(+) diff --git a/crates/erp-auth/src/middleware/jwt_auth.rs b/crates/erp-auth/src/middleware/jwt_auth.rs index 20f2b3b..ddd07cd 100644 --- a/crates/erp-auth/src/middleware/jwt_auth.rs +++ b/crates/erp-auth/src/middleware/jwt_auth.rs @@ -52,6 +52,7 @@ pub async fn jwt_auth_middleware_fn( user_id: claims.sub, roles: claims.roles, permissions: claims.permissions, + department_ids: vec![], }; // Reconstruct the request with the TenantContext injected into extensions. diff --git a/crates/erp-core/src/rbac.rs b/crates/erp-core/src/rbac.rs index 9b25068..4fce2f0 100644 --- a/crates/erp-core/src/rbac.rs +++ b/crates/erp-core/src/rbac.rs @@ -49,6 +49,7 @@ mod tests { user_id: Uuid::now_v7(), roles: roles.into_iter().map(String::from).collect(), permissions: permissions.into_iter().map(String::from).collect(), + department_ids: vec![], } } diff --git a/crates/erp-core/src/types.rs b/crates/erp-core/src/types.rs index 6a29350..338962e 100644 --- a/crates/erp-core/src/types.rs +++ b/crates/erp-core/src/types.rs @@ -113,6 +113,7 @@ mod tests { user_id: Uuid::now_v7(), roles: vec!["admin".to_string()], permissions: vec!["user.read".to_string()], + department_ids: vec![], }; assert_eq!(ctx.roles.len(), 1); assert_eq!(ctx.permissions.len(), 1); @@ -154,4 +155,6 @@ pub struct TenantContext { pub user_id: Uuid, pub roles: Vec, pub permissions: Vec, + /// 用户所属部门 ID 列表(行级数据权限使用) + pub department_ids: Vec, }