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§
Sourcetype Input: FormInput
type Input: FormInput
What the settings page asks for: the app’s own
#[derive(FormInput)] struct.
Sourcetype User: PanelUser
type User: PanelUser
The user who edits the tenant: the type the panel’s
Authenticator loads, which mounting checks.
Required Methods§
Sourcefn fill(
&self,
cx: &Cx,
user: &Self::User,
tenant: &Membership,
) -> impl Future<Output = Result<Self::Input>> + Send
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.
Provided Methods§
Sourcefn may_edit(&self, _cx: &Cx, _user: &Self::User, _tenant: &Membership) -> bool
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.
Sourcefn validate(
&self,
_cx: &Cx,
_user: &Self::User,
_tenant: &Membership,
_input: &Self::Input,
_ex: &mut dyn Executor,
) -> impl Future<Output = Result<FieldErrors>> + Send
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".