Skip to main content

Impersonation

Struct Impersonation 

Source
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>

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<U> !RefUnwindSafe for Impersonation<U>

§

impl<U> !UnwindSafe for Impersonation<U>

§

impl<U> Forget for Impersonation<U>

§

impl<U> Freeze for Impersonation<U>
where Arc<dyn Fn(&Cx, &U, &U) -> bool + Send + Sync>: Freeze,

§

impl<U> Send for Impersonation<U>
where Arc<dyn Fn(&Cx, &U, &U) -> bool + Send + Sync>: Send,

§

impl<U> Sync for Impersonation<U>
where Arc<dyn Fn(&Cx, &U, &U) -> bool + Send + Sync>: Sync,

§

impl<U> Unpin for Impersonation<U>
where Arc<dyn Fn(&Cx, &U, &U) -> bool + Send + Sync>: Unpin,

§

impl<U> UnsafeUnpin for Impersonation<U>
where Arc<dyn Fn(&Cx, &U, &U) -> bool + Send + Sync>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more