Skip to main content

TenantRegistrar

Trait TenantRegistrar 

Source
pub trait TenantRegistrar:
    Send
    + Sync
    + 'static {
    type Input: FormInput;
    type User: PanelUser;

    // Required method
    fn register(
        &self,
        cx: &Cx,
        user: &Self::User,
        input: Self::Input,
        ex: &mut dyn Executor,
    ) -> impl Future<Output = Result<Membership>> + Send;

    // Provided method
    fn validate(
        &self,
        _cx: &Cx,
        _user: &Self::User,
        _input: &Self::Input,
        _ex: &mut dyn Executor,
    ) -> impl Future<Output = Result<FieldErrors>> + Send { ... }
}
Expand description

How a panel lets the signed-in user create a tenant to act for, installed with a TenantRegistration.

It mirrors a Registrar: Input is the form the page asks for, validate refuses a submission field by field, and register writes the tenant and the user’s membership of it. Both run in one transaction the framework opens. The next request reloads the user, whose tenants must then list the new one.

#[derive(tablo_core::FormInput)]
struct NewTeam {
    name: String,
}

struct Teams;

impl TenantRegistrar for Teams {
    type Input = NewTeam;
    type User = Staff;

    async fn register(
        &self,
        _cx: &Cx,
        staff: &Staff,
        team: NewTeam,
        ex: &mut dyn toasty::Executor,
    ) -> topcoat::Result<Membership> {
        let team = toasty::create!(Team { name: team.name })
            .exec(&mut *ex)
            .await?;
        toasty::create!(Seat {
            staff_id: staff.id,
            team_id: team.id,
        })
        .exec(ex)
        .await?;
        Ok(Membership::new(team.id.into(), team.name))
    }
}

Required Associated Types§

Source

type Input: FormInput

What the page asks for: the app’s own #[derive(FormInput)] struct.

Source

type User: PanelUser

The user who registers the tenant: the type the panel’s Authenticator loads, which mounting checks.

Required Methods§

Source

fn register( &self, cx: &Cx, user: &Self::User, input: Self::Input, ex: &mut dyn Executor, ) -> impl Future<Output = Result<Membership>> + Send

Create the tenant from a validated input, with user a member of it, through the transaction ex, which commits when it returns Ok; answer the membership the request’s session then acts under.

Provided Methods§

Source

fn validate( &self, _cx: &Cx, _user: &Self::User, _input: &Self::Input, _ex: &mut dyn Executor, ) -> impl Future<Output = Result<FieldErrors>> + Send

Refuse a submission register should not receive, such as a name another tenant holds: each error names an input field’s key and renders under its control. Defaults to none. A key no control renders is a declaration error: the page would show no message.

It runs inside the registration’s transaction ex, after the input parses and its controls’ own rules pass.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§