Files
zlwuandCursor 2905dc3d5f feat(bx): 报销模块接入数据权限过滤
新增 bx_data_scope 与 BxUserContext.to_user_info,列表/我的单据 AND scope,待办审批不加 scope,审批操作 skip_scope。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-28 21:00:18 +08:00

51 lines
1.4 KiB
Python

"""报销模块认证适配:门户 JWT 用户 → bx 业务上下文。"""
from __future__ import annotations
from dataclasses import dataclass
from typing import Any, Dict
from fastapi import Depends
from app.core.menu_guard import require_admin_or_super_admin
@dataclass
class BxUserContext:
"""bx Service/Router 使用的当前用户上下文(sys_user.id 为 UUID 字符串)。"""
id: str
name: str
dept_id: str
role: str
tenant_no: str
def to_tenant_user_dict(self) -> Dict[str, Any]:
"""供 get_tenant_no 等门户工具使用。"""
return {
"user_id": self.id,
"role": self.role,
"tenant_no": self.tenant_no,
}
def to_user_info(self) -> Dict[str, Any]:
"""与门户 JWT / apply_data_scope 所需的 user_info 字段对齐。"""
return {
"user_id": self.id,
"role": self.role,
"tenant_no": self.tenant_no,
"dept_id": self.dept_id,
"region_id": self.dept_id,
}
def get_bx_current_user(
user: dict = Depends(require_admin_or_super_admin),
) -> BxUserContext:
return BxUserContext(
id=(user.get("user_id") or "").strip(),
name=(user.get("real_name") or user.get("username") or "").strip(),
dept_id=(user.get("region_id") or "").strip(),
role=(user.get("role") or "").strip(),
tenant_no=(user.get("tenant_no") or "").strip(),
)