Skip to main content

TenantEditor

Trait TenantEditor 

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

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

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

How a panel lets the signed-in user edit the tenant they act for on its settings page, installed with Auth::tenant_profile.

It mirrors a ProfileEditor, for the request’s Membership: may_edit says who may open the page, fill loads the form from the tenant, validate refuses a submission field by field, and save writes it. validate and save run in one transaction the framework opens.

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

struct Teams;

impl TenantEditor for Teams {
    type Input = TeamSettings;
    type User = Staff;

    fn may_edit(&self, _cx: &Cx, staff: &Staff, _team: &Membership) -> bool {
        staff.owner
    }

    async fn fill(
        &self,
        _cx: &Cx,
        _staff: &Staff,
        team: &Membership,
    ) -> topcoat::Result<TeamSettings> {
        Ok(TeamSettings {
            name: team.name.clone(),
        })
    }

    async fn save(
        &self,
        _cx: &Cx,
        _staff: &Staff,
        team: &Membership,
        settings: TeamSettings,
        ex: &mut dyn toasty::Executor,
    ) -> topcoat::Result<()> {
        Team::filter_by_id(team.tenant.get())
            .update()
            .name(settings.name)
            .exec(ex)
            .await?;
        Ok(())
    }
}

Required Associated Types§

Source

type Input: FormInput

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

Source

type User: PanelUser

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

Required Methods§

Source

fn fill( &self, cx: &Cx, user: &Self::User, tenant: &Membership, ) -> impl Future<Output = Result<Self::Input>> + Send

The form as the page first shows it, loaded for tenant. The page renders what FormInput::write writes.

Source

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

Write a validated input to tenant through the transaction ex, which commits when it returns Ok.

Provided Methods§

Source

fn may_edit(&self, _cx: &Cx, _user: &Self::User, _tenant: &Membership) -> bool

Whether user may edit tenant, one of their memberships. Defaults to every member. A user who may not gets no link to the page, and the page answers them 403.

Source

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

Refuse a submission save should not receive: 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 save’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§