pub trait PanelUser:
Any
+ Send
+ Sync {
// Required methods
fn user_id(&self) -> String;
fn display_name(&self) -> &str;
// Provided methods
fn subtitle(&self) -> Option<&str> { ... }
fn email(&self) -> Option<&str> { ... }
fn can_access_panel(&self) -> bool { ... }
fn tenants(&self) -> &[Membership] { ... }
fn default_tenant(&self) -> Option<TenantId> { ... }
fn time_zone(&self) -> Option<TimeZone> { ... }
fn locale(&self) -> Option<Locale> { ... }
}Expand description
A signed-in user, as the panel knows it (ADR-0013).
Implement it for the app’s own user type and return that type from an
Authenticator; the shipped AdminUser implements it too. App code
reads the user back with its own type through user.
impl PanelUser for Staff {
fn user_id(&self) -> String {
self.id.to_string()
}
fn display_name(&self) -> &str {
&self.name
}
fn can_access_panel(&self) -> bool {
self.active
}
fn tenants(&self) -> &[Membership] {
&self.memberships
}
}Required Methods§
Sourcefn user_id(&self) -> String
fn user_id(&self) -> String
The stable key the session stores and
Authenticator::find_by_id receives. Any string fits.
Sourcefn display_name(&self) -> &str
fn display_name(&self) -> &str
The name the user menu shows.
Provided Methods§
Sourcefn subtitle(&self) -> Option<&str>
fn subtitle(&self) -> Option<&str>
The muted line under the name in the user menu, such as an email or a role. Defaults to none.
Sourcefn email(&self) -> Option<&str>
fn email(&self) -> Option<&str>
The address the account stores, which mail meant for the account goes to: a reset link, a verification link, a sign-in code. Defaults to none: the account gets no mail.
Sourcefn can_access_panel(&self) -> bool
fn can_access_panel(&self) -> bool
Whether the user may enter the panel. A user who may not answers 403,
indistinguishable from bad credentials at login. Defaults to true.
Sourcefn tenants(&self) -> &[Membership]
fn tenants(&self) -> &[Membership]
The tenants the user may act for, in the order the tenant switcher
lists them. A session acts for the default_tenant
until the user selects another. Defaults to none: the user has no tenant.
With two or more, a tenant menu sits atop the sidebar. It posts to {prefix}/tenant, which
stores the choice on the session and returns to the panel’s home page. A tenant the user
is not a member of answers 403, and a stored choice applies only while the membership
lasts. One browser acts for one tenant at a time, in every tab.
Sourcefn default_tenant(&self) -> Option<TenantId>
fn default_tenant(&self) -> Option<TenantId>
The tenant a session acts for until the user selects another, while it is one of
tenants, such as one the user picks on their profile page and the app
stores. Defaults to none: the first of tenants.
Sourcefn time_zone(&self) -> Option<TimeZone>
fn time_zone(&self) -> Option<TimeZone>
The time zone the user reads and enters wall-clock times in: a timestamp’s control, its
DateColumn day and its DateFilter days.
Defaults to none: the panel’s time_zone.
Sourcefn locale(&self) -> Option<Locale>
fn locale(&self) -> Option<Locale>
The locale the user reads the panel and their mails in, such as fr. Defaults to none: the
browser’s best match among the panel’s locales, else its
default. A locale matches the closest the panel offers, as fr-CA reads fr; one with no
match counts as none.
A user who stores their locale as text parses it:
fn locale(&self) -> Option<Locale> {
self.locale.as_deref()?.parse().ok()
}Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".