pub struct RlsContext {
pub tenant_id: String,
pub agent_id: String,
/* private fields */
}Expand description
RLS context carrying tenant identity for data isolation.
Fields§
§tenant_id: StringThe unified tenant ID — the primary identity for data isolation. Empty string means no tenant scope.
agent_id: StringLegacy: The agent (reseller) this context is scoped to. Empty string means no agent scope.
Implementations§
Source§impl RlsContext
impl RlsContext
Sourcepub fn tenant(tenant_id: &str) -> RlsContext
pub fn tenant(tenant_id: &str) -> RlsContext
Create a context scoped to a specific tenant (the unified identity).
Sourcepub fn agent(agent_id: &str) -> RlsContext
pub fn agent(agent_id: &str) -> RlsContext
Create a context scoped to a specific agent (reseller).
Sourcepub fn tenant_and_agent(tenant_id: &str, agent_id: &str) -> RlsContext
pub fn tenant_and_agent(tenant_id: &str, agent_id: &str) -> RlsContext
Create a context scoped to both tenant and agent.
Sourcepub fn global() -> RlsContext
pub fn global() -> RlsContext
Create a global context scoped to platform rows (tenant_id IS NULL).
This is not a bypass: it applies explicit global scoping in AST injection
and exposes app.is_global=true for policy usage at the database layer.
Sourcepub fn super_admin(_token: SuperAdminToken) -> RlsContext
pub fn super_admin(_token: SuperAdminToken) -> RlsContext
Create a super admin context that bypasses tenant isolation.
Requires a SuperAdminToken — which can only be created via
named constructors (for_system_process, for_webhook, for_auth).
Uses nil UUID for all IDs to avoid ''::uuid cast errors
in PostgreSQL RLS policies (PostgreSQL doesn’t short-circuit OR).
Sourcepub fn empty() -> RlsContext
pub fn empty() -> RlsContext
Create an empty context (no tenant, no super admin).
Used for system-level operations that must not operate within any tenant scope (startup introspection, migrations, health checks).
Sourcepub fn user(user_id: &str) -> RlsContext
pub fn user(user_id: &str) -> RlsContext
Create a user-scoped context for authenticated end-user operations.
Sets app.current_user_id so that DB policies can enforce
row-level isolation by user (e.g. user_id = get_current_user_id()).
Does NOT bypass tenant isolation or grant super-admin.
Sourcepub fn has_tenant(&self) -> bool
pub fn has_tenant(&self) -> bool
Returns true if this context has a tenant scope.
Sourcepub fn bypasses_rls(&self) -> bool
pub fn bypasses_rls(&self) -> bool
Returns true if this context bypasses tenant isolation.
Trait Implementations§
Source§impl Clone for RlsContext
impl Clone for RlsContext
Source§fn clone(&self) -> RlsContext
fn clone(&self) -> RlsContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more