pub struct TenantScopePlugin { /* private fields */ }Implementations§
Source§impl TenantScopePlugin
impl TenantScopePlugin
pub fn new() -> Self
Sourcepub fn from_manifest(manifest: &AppManifest) -> Self
pub fn from_manifest(manifest: &AppManifest) -> Self
Auto-configure from a manifest: any entity that declares a tenantId
(or tenant_id) field is marked tenant-scoped using that field.
This is how the server registers the plugin by default. Adding a
tenantId field to an entity is the signal — no separate config
step required. Apps that use a different field name (e.g. orgId)
can still call [scope_with_field] after this to customize.
Sourcepub fn scope(&mut self, entity: impl Into<String>) -> &mut Self
pub fn scope(&mut self, entity: impl Into<String>) -> &mut Self
Mark entity as tenant-scoped using the default tenantId field.
Sourcepub fn scope_with_field(
&mut self,
entity: impl Into<String>,
field: impl Into<String>,
) -> &mut Self
pub fn scope_with_field( &mut self, entity: impl Into<String>, field: impl Into<String>, ) -> &mut Self
Mark entity as tenant-scoped using a custom field name.
pub fn is_scoped(&self, entity: &str) -> bool
pub fn field_for(&self, entity: &str) -> Option<&str>
Sourcepub fn stamp_insert(
&self,
entity: &str,
data: &mut Value,
auth: &AuthContext,
) -> Result<(), TenantError>
pub fn stamp_insert( &self, entity: &str, data: &mut Value, auth: &AuthContext, ) -> Result<(), TenantError>
Stamp tenantId onto a row that’s about to be inserted.
Returns Err if the entity is scoped but the caller has no tenant.
Sourcepub fn check_write(
&self,
entity: &str,
existing: &Value,
auth: &AuthContext,
) -> Result<(), TenantError>
pub fn check_write( &self, entity: &str, existing: &Value, auth: &AuthContext, ) -> Result<(), TenantError>
Verify that an existing row belongs to the caller’s tenant before allowing a mutation.
Trait Implementations§
Source§impl Default for TenantScopePlugin
impl Default for TenantScopePlugin
Source§impl Plugin for TenantScopePlugin
impl Plugin for TenantScopePlugin
Source§fn on_init(&self, _ctx: &PluginContext)
fn on_init(&self, _ctx: &PluginContext)
Called once when the plugin is registered.
Source§fn routes(&self) -> Vec<PluginRoute>
fn routes(&self) -> Vec<PluginRoute>
Custom API routes this plugin handles.
Source§fn before_insert(
&self,
_entity: &str,
_data: &mut Value,
_auth: &AuthContext,
) -> Result<(), PluginError>
fn before_insert( &self, _entity: &str, _data: &mut Value, _auth: &AuthContext, ) -> Result<(), PluginError>
Called before an entity insert. Return Err to reject.
Source§fn after_insert(
&self,
_entity: &str,
_id: &str,
_data: &Value,
_auth: &AuthContext,
)
fn after_insert( &self, _entity: &str, _id: &str, _data: &Value, _auth: &AuthContext, )
Called after a successful insert.
Source§fn before_update(
&self,
_entity: &str,
_id: &str,
_data: &mut Value,
_auth: &AuthContext,
) -> Result<(), PluginError>
fn before_update( &self, _entity: &str, _id: &str, _data: &mut Value, _auth: &AuthContext, ) -> Result<(), PluginError>
Called before an entity update. Return Err to reject.
Source§fn after_update(
&self,
_entity: &str,
_id: &str,
_data: &Value,
_auth: &AuthContext,
)
fn after_update( &self, _entity: &str, _id: &str, _data: &Value, _auth: &AuthContext, )
Called after a successful update.
Source§fn before_delete(
&self,
_entity: &str,
_id: &str,
_auth: &AuthContext,
) -> Result<(), PluginError>
fn before_delete( &self, _entity: &str, _id: &str, _auth: &AuthContext, ) -> Result<(), PluginError>
Called before an entity delete. Return Err to reject.
Source§fn after_delete(&self, _entity: &str, _id: &str, _auth: &AuthContext)
fn after_delete(&self, _entity: &str, _id: &str, _auth: &AuthContext)
Called after a successful delete.
Source§fn on_request(
&self,
_method: &str,
_path: &str,
_auth: &AuthContext,
) -> Result<(), PluginError>
fn on_request( &self, _method: &str, _path: &str, _auth: &AuthContext, ) -> Result<(), PluginError>
Called on every incoming request (middleware).
Source§fn on_request_with_meta(
&self,
method: &str,
path: &str,
auth: &AuthContext,
_meta: &RequestMeta<'_>,
) -> Result<(), PluginError>
fn on_request_with_meta( &self, method: &str, path: &str, auth: &AuthContext, _meta: &RequestMeta<'_>, ) -> Result<(), PluginError>
Richer variant of [
on_request] that also receives per-request
metadata (peer IP today; more fields may be added later). The
default implementation delegates to on_request so existing
plugins keep working without changes. Plugins that care about
IP — notably rate limiting — override this hook.Source§fn on_session_create(&self, _user_id: &str, _token: &str)
fn on_session_create(&self, _user_id: &str, _token: &str)
Called when a new session is created.
Source§fn entities(&self) -> Vec<ManifestEntity>
fn entities(&self) -> Vec<ManifestEntity>
Additional manifest entities this plugin contributes.
Auto Trait Implementations§
impl Freeze for TenantScopePlugin
impl RefUnwindSafe for TenantScopePlugin
impl Send for TenantScopePlugin
impl Sync for TenantScopePlugin
impl Unpin for TenantScopePlugin
impl UnsafeUnpin for TenantScopePlugin
impl UnwindSafe for TenantScopePlugin
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