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> Impersonation<U>where
U: PanelUser,
impl<U> Impersonation<U>where
U: PanelUser,
Sourcepub fn new(
allows: impl Fn(&Cx, &U, &U) -> bool + Send + Sync + 'static,
) -> Impersonation<U>
pub fn new( allows: impl Fn(&Cx, &U, &U) -> bool + Send + Sync + 'static, ) -> Impersonation<U>
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) -> Impersonation<U>
pub fn lifetime(self, lifetime: Duration) -> Impersonation<U>
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) -> Impersonation<U>
pub fn across_tenants(self) -> Impersonation<U>
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.
Sourcepub fn writable(self) -> Impersonation<U>
pub fn writable(self) -> Impersonation<U>
Let the actor write as the target: create, edit and delete records, run actions and header actions, and clear the target’s notifications, as far as the policies allow the target.
Off by default: acting as someone reads the panel as they read it, and writes nothing. Every
resource answers as if mounted ReadOnly, so its buttons are gone and
its write routes answer 403, can included; no header action runs, on a
resource or a page; and the notification bell offers nothing to mark or remove. A route
of the app’s own, outside the panel’s resources and pages, asks
impersonator itself.
Writable or not, the actor never reaches the target’s credentials: see
Auth::impersonation.