Skip to main content

Scopable

Derive Macro Scopable 

Source
#[derive(Scopable)]
{
    // Attributes available to this derive:
    #[secure]
}
Expand description

Derive macro for implementing ScopableEntity.

Place this on your SeaORM Model struct along with #[secure(...)] attributes.

§Attributes

All four scope dimensions must be explicitly specified:

  • tenant_col = "column_name" OR no_tenant - Tenant isolation column
  • resource_col = "column_name" OR no_resource - Primary resource ID column
  • owner_col = "column_name" OR no_owner - Owner-based filtering column
  • type_col = "column_name" OR no_type - Type-based filtering column
  • unrestricted - Mark as global entity (forbids all other attributes)

§Example

#[derive(DeriveEntityModel, Scopable)]
#[sea_orm(table_name = "users")]
#[secure(
    tenant_col = "tenant_id",
    resource_col = "id",
    no_owner,
    no_type
)]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: Uuid,
    pub tenant_id: Uuid,
    pub email: String,
}

§Global Entities

For entities that are not tenant-scoped (global lookup tables, system config, etc.), use the unrestricted flag:

#[derive(DeriveEntityModel, Scopable)]
#[sea_orm(table_name = "system_config")]
#[secure(unrestricted)]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: Uuid,
    pub key: String,
    pub value: String,
}