sz_rust_orm_facade/data_scope/context.rs
1//! 数据范围上下文 — 从 guard `UserContext` 转换而来的轻量级上下文
2//!
3//! orm-facade 不依赖 mvc-facade,因此定义独立上下文结构体。
4//! 业务层在调用 `data_scope()` 前从 `UserContext` 转换为 `DataScopeContext`。
5
6/// 数据范围上下文(从 guard `UserContext` 转换)
7#[derive(Debug, Clone)]
8pub struct DataScopeContext {
9 /// 用户 ID
10 pub user_id: i64,
11 /// 部门 ID
12 pub dept_id: i64,
13 /// 是否超级管理员(绕过数据范围)
14 pub is_super: bool,
15}
16
17impl DataScopeContext {
18 /// 创建上下文
19 pub fn new(user_id: i64, dept_id: i64, is_super: bool) -> Self {
20 Self {
21 user_id,
22 dept_id,
23 is_super,
24 }
25 }
26}
27
28impl Default for DataScopeContext {
29 fn default() -> Self {
30 Self::new(0, 0, false)
31 }
32}