pub struct Impersonation<U> { /* private fields */ }Expand description
Who a panel’s users may act as, and for how long, set by Auth::impersonation.
let auth = Auth::password().impersonation(
// Support acts as customers, never as another member of support.
Impersonation::new(|_cx, actor: &AdminUser, target: &AdminUser| {
is_support(actor) && !is_support(target)
})
.lifetime(std::time::Duration::from_secs(30 * 60)),
);Implementations§
Source§impl<U: PanelUser> Impersonation<U>
impl<U: PanelUser> Impersonation<U>
Sourcepub fn new(allows: impl Fn(&Cx, &U, &U) -> bool + Send + Sync + 'static) -> Self
pub fn new(allows: impl Fn(&Cx, &U, &U) -> bool + Send + Sync + 'static) -> Self
Lets a user act as another when allows(cx, actor, target) answers true, for an hour.
It is asked again on every request while the actor acts as the target, so a change to
either user, or to the rule, ends it at once. A user never acts as themselves, nor as a
user who may not enter the panel, whatever it answers; on a panel that acts for tenants,
nor as a user who belongs to a tenant the actor does not, unless
across_tenants says otherwise.
Decide from actor and target alone: cx carries the request, but whom
auth::user names inside it depends on when the rule is asked.
Sourcepub fn lifetime(self, lifetime: Duration) -> Self
pub fn lifetime(self, lifetime: Duration) -> Self
How long acting as a user lasts before the actor is themselves again; defaults to an hour, and never exceeds a day.
Sourcepub fn across_tenants(self) -> Self
pub fn across_tenants(self) -> Self
Let the actor act as a user of tenants they are no member of, such as a platform’s own staff acting as any customer. Off by default: on a panel that acts for tenants, every tenant the target belongs to must be one of the actor’s, so acting as them reaches no tenant the actor could not already.