pub struct Gate<A>where
A: Actor,{ /* private fields */ }Expand description
A registry of authorization abilities.
Checks are synchronous. An authorization decision that needs a database round-trip is a sign the subject should have been loaded already — the controller has the record in hand by the time it authorizes, and re-fetching it inside the check would double every query.
Implementations§
Source§impl<A> Gate<A>where
A: Actor,
impl<A> Gate<A>where
A: Actor,
Sourcepub fn define<S, F>(self, ability: impl Into<String>, check: F) -> Gate<A>
pub fn define<S, F>(self, ability: impl Into<String>, check: F) -> Gate<A>
Define an ability taking the actor and an optional subject.
Sourcepub fn define_simple<F>(self, ability: impl Into<String>, check: F) -> Gate<A>
pub fn define_simple<F>(self, ability: impl Into<String>, check: F) -> Gate<A>
Define an ability that ignores its subject.
Sourcepub fn before<F>(self, check: F) -> Gate<A>
pub fn before<F>(self, check: F) -> Gate<A>
Register a check that runs before every ability.
Returning Some(true) grants regardless of the ability — the “an admin
may do anything” rule, in one place instead of at the top of every
check. None defers.
Sourcepub fn allows<S>(&self, ability: &str, actor: &A, subject: Option<&S>) -> boolwhere
S: 'static,
pub fn allows<S>(&self, ability: &str, actor: &A, subject: Option<&S>) -> boolwhere
S: 'static,
Whether actor may perform ability on subject.
An undefined ability is denied. Defaulting to “allow” would mean a typo in an ability name silently opens a hole.
Sourcepub fn denies<S>(&self, ability: &str, actor: &A, subject: Option<&S>) -> boolwhere
S: 'static,
pub fn denies<S>(&self, ability: &str, actor: &A, subject: Option<&S>) -> boolwhere
S: 'static,
The inverse of allows.
Sourcepub fn allows_any(&self, ability: &str, actor: &A) -> bool
pub fn allows_any(&self, ability: &str, actor: &A) -> bool
Whether actor may perform ability, with no subject.
Grant, or fail with a 403.
Trait Implementations§
Auto Trait Implementations§
impl<A> !RefUnwindSafe for Gate<A>
impl<A> !UnwindSafe for Gate<A>
impl<A> Freeze for Gate<A>
impl<A> Send for Gate<A>
impl<A> Sync for Gate<A>
impl<A> Unpin for Gate<A>
impl<A> UnsafeUnpin for Gate<A>
Blanket Implementations§
impl<T> Actor for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Event for T
impl<T> Event for T
Source§fn event_name() -> &'static strwhere
Self: Sized,
fn event_name() -> &'static strwhere
Self: Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more