Skip to main content

impersonate

Function impersonate 

Source
pub async fn impersonate(
    cx: &Cx,
    ex: &mut dyn Executor,
    target: &dyn PanelUser,
) -> Result<()>
Expand description

Makes the request’s session act as target through ex, and records it through ex too, so a transaction commits both or neither; 403 when the signed-in user may not under the panel’s Impersonation rule, or acts as someone already.

It is what the Impersonate action runs, for an action of the app’s own where that one cannot go: a resource whose model is not the panel’s user type, such as the record a PanelUser wraps. The action loads the user it acts as, since target is what the rule reads.

async fn act_as(
    cx: &Cx,
    ex: &mut dyn toasty::Executor,
    target: &dyn PanelUser,
) -> topcoat::Result<()> {
    auth::impersonate(cx, ex, target).await
}