pub struct TenantContext { /* private fields */ }Expand description
Extracted from every authenticated request. Cannot be constructed outside the auth module (fields are private). All repository methods require this — the type system prevents cross-tenant data access.
Implementations§
Source§impl TenantContext
impl TenantContext
Sourcepub fn new(
tenant_id: TenantId,
user_id: UserId,
role: UserRole,
tier: SubscriptionTier,
) -> Self
pub fn new( tenant_id: TenantId, user_id: UserId, role: UserRole, tier: SubscriptionTier, ) -> Self
Construct from a verified auth token. In production, this is called only by the auth middleware after JWT verification.
pub fn tenant_id(&self) -> &TenantId
pub fn user_id(&self) -> &UserId
pub fn role(&self) -> &UserRole
pub fn tier(&self) -> &SubscriptionTier
Sourcepub fn can(&self, action: Action, resource: Resource) -> bool
pub fn can(&self, action: Action, resource: Resource) -> bool
Check if the user can perform an action on a resource.
Sourcepub fn tier_includes(&self, required_tier: &SubscriptionTier) -> bool
pub fn tier_includes(&self, required_tier: &SubscriptionTier) -> bool
Check if the tenant’s tier includes a feature at required_tier.
Trait Implementations§
Source§impl Clone for TenantContext
impl Clone for TenantContext
Source§fn clone(&self) -> TenantContext
fn clone(&self) -> TenantContext
Returns a duplicate of the value. Read more
1.0.0 · 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 TenantContext
impl Debug for TenantContext
Source§impl<'de> Deserialize<'de> for TenantContext
impl<'de> Deserialize<'de> for TenantContext
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for TenantContext
impl RefUnwindSafe for TenantContext
impl Send for TenantContext
impl Sync for TenantContext
impl Unpin for TenantContext
impl UnsafeUnpin for TenantContext
impl UnwindSafe for TenantContext
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