Skip to main content

Tenancy

Struct Tenancy 

Source
pub struct Tenancy<M> { /* private fields */ }
Expand description

How a resource’s rows belong to a tenant.

A resource declares one with ResourceDef::tenancy. A scoped tenancy names, by lens, the tenant UUID each row is filtered on:

ResourceDef::new().tenancy(Tenancy::column(Post::fields().tenant_id()))

ResourceDef::new().tenancy(Tenancy::via(Comment::fields().post().tenant_id()))

A scoped resource answers 403 to a request with no tenant, in every handler, instead of serving unscoped rows or writing rows with no tenant.

Implementations§

Source§

impl<M: Model + 'static> Tenancy<M>

Source

pub fn none() -> Self

Rows belong to no tenant: the resource is served as query states it, to every request. The default.

Source

pub fn column<T>(lens: impl Into<Path<M, T>>) -> Self
where T: Send + Sync + 'static, M: Send + Sync, Uuid: IntoExpr<T>,

Rows carry their tenant in one UUID column of their own model, Uuid or Option<Uuid>.

The framework filters every loader on it and stamps the request’s tenant into it on create, so the record form must not claim it. Mounting the panel refuses a lens that is not a single field of the model.

Source

pub fn via<T>(lens: impl Into<Path<M, T>>) -> Self
where T: Send + Sync + 'static, M: Send + Sync, Uuid: IntoExpr<T>,

Rows inherit their tenant through a relation: lens reaches the parent’s tenant column, as Comment::fields().post().tenant_id() does.

The framework filters every loader on it. It stamps nothing on create: a row’s tenant is its parent’s. The lens starts at a belongs_to relation, and mounting the panel requires the form to write that relation’s foreign key through a relationship field over a tenant-scoped resource, whose key the framework re-checks against that resource’s tenant-scoped query inside the write.

Source

pub fn is_scoped(&self) -> bool

Whether the rows belong to a tenant, so every handler requires one.

Trait Implementations§

Source§

impl<M: Model + 'static> Default for Tenancy<M>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<M> !RefUnwindSafe for Tenancy<M>

§

impl<M> !UnwindSafe for Tenancy<M>

§

impl<M> Freeze for Tenancy<M>
where PhantomData<fn() -> M>: Freeze,

§

impl<M> Send for Tenancy<M>
where PhantomData<fn() -> M>: Send,

§

impl<M> Sync for Tenancy<M>
where PhantomData<fn() -> M>: Sync,

§

impl<M> Unpin for Tenancy<M>
where PhantomData<fn() -> M>: Unpin,

§

impl<M> UnsafeUnpin for Tenancy<M>
where PhantomData<fn() -> M>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more