pub struct PermissionContext {
pub user_id: Option<i64>,
pub tenant_id: Option<i64>,
pub dept_id: Option<i64>,
pub roles: Vec<String>,
pub permissions: Vec<String>,
pub extras: HashMap<String, String>,
}Expand description
权限上下文 — 当前请求的用户/租户/部门信息
由调用方(通常是中间件)在请求开始时构建,并传递给 DataPermissionInterceptor。
Fields§
§user_id: Option<i64>当前用户 ID
tenant_id: Option<i64>当前租户 ID
dept_id: Option<i64>当前部门 ID
roles: Vec<String>用户角色列表(用于角色级别的权限规则)
permissions: Vec<String>用户权限列表(细粒度权限码)
extras: HashMap<String, String>扩展数据(如自定义字段值)
Implementations§
Source§impl PermissionContext
impl PermissionContext
Sourcepub fn with_user_id(self, user_id: i64) -> Self
pub fn with_user_id(self, user_id: i64) -> Self
设置用户 ID
Sourcepub fn with_tenant_id(self, tenant_id: i64) -> Self
pub fn with_tenant_id(self, tenant_id: i64) -> Self
设置租户 ID
Sourcepub fn with_dept_id(self, dept_id: i64) -> Self
pub fn with_dept_id(self, dept_id: i64) -> Self
设置部门 ID
Sourcepub fn with_roles(self, roles: Vec<String>) -> Self
pub fn with_roles(self, roles: Vec<String>) -> Self
设置角色列表
Sourcepub fn with_permissions(self, perms: Vec<String>) -> Self
pub fn with_permissions(self, perms: Vec<String>) -> Self
设置权限列表
Sourcepub fn has_permission(&self, perm: &str) -> bool
pub fn has_permission(&self, perm: &str) -> bool
检查是否拥有指定权限
Trait Implementations§
Source§impl Clone for PermissionContext
impl Clone for PermissionContext
Source§fn clone(&self) -> PermissionContext
fn clone(&self) -> PermissionContext
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PermissionContext
impl Debug for PermissionContext
Source§impl Default for PermissionContext
impl Default for PermissionContext
Source§fn default() -> PermissionContext
fn default() -> PermissionContext
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for PermissionContext
impl RefUnwindSafe for PermissionContext
impl Send for PermissionContext
impl Sync for PermissionContext
impl Unpin for PermissionContext
impl UnsafeUnpin for PermissionContext
impl UnwindSafe for PermissionContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more