pub struct Abilities<M> { /* private fields */ }Expand description
A policy that answers each Ability from the check declared for it, and denies every
ability it declares none for.
A closure policy that ends in _ => true allows whatever it does not name, such as the
restore a soft delete adds or an action declared later. Abilities allows only what it
names:
let policy = Abilities::<Post>::new()
.view_any(is_editor)
.view(|_cx, _post| true)
.create(is_editor)
.update(|cx, post| is_editor(cx) && !post.locked);
// No delete, restore or action: each is refused until the policy declares it.A write’s record check also allows the write at all: delete allows
DeleteAny, restore allows
RestoreAny, force_delete allows
ForceDeleteAny, and run allows
RunAny for its action, since the panel asks the record’s check before
each of these writes. The _any methods narrow it; declared alone, they allow no record.
view does not allow ViewAny: the list asks ViewAny
alone and shows every row the resource’s query returns, so view_any is
declared on its own.
Declaring an ability twice replaces its earlier check; combine the checks in one closure.
The model’s type is named on new, Abilities::<Post>::new(): a closure is checked before
the chain learns the model from where the policy goes.
Implementations§
Source§impl<M> Abilities<M>
impl<M> Abilities<M>
Sourcepub fn view(
self,
check: impl Fn(&Cx, &M) -> bool + Send + Sync + 'static,
) -> Self
pub fn view( self, check: impl Fn(&Cx, &M) -> bool + Send + Sync + 'static, ) -> Self
Who may see a record: View, asked by its detail page, its edit form,
each write to it, the export and relationship options. The list shows a row without it,
and asks it only to offer the row’s actions.
Sourcepub fn create(self, check: impl Fn(&Cx) -> bool + Send + Sync + 'static) -> Self
pub fn create(self, check: impl Fn(&Cx) -> bool + Send + Sync + 'static) -> Self
Who may create a record: Create.
Sourcepub fn update(
self,
check: impl Fn(&Cx, &M) -> bool + Send + Sync + 'static,
) -> Self
pub fn update( self, check: impl Fn(&Cx, &M) -> bool + Send + Sync + 'static, ) -> Self
Who may edit a record: Update.
Sourcepub fn delete(
self,
check: impl Fn(&Cx, &M) -> bool + Send + Sync + 'static,
) -> Self
pub fn delete( self, check: impl Fn(&Cx, &M) -> bool + Send + Sync + 'static, ) -> Self
Who may delete a record: Delete.
Sourcepub fn restore_any(
self,
check: impl Fn(&Cx) -> bool + Send + Sync + 'static,
) -> Self
pub fn restore_any( self, check: impl Fn(&Cx) -> bool + Send + Sync + 'static, ) -> Self
Who may restore trashed records at all: RestoreAny. Defaults to
whether restore is declared.
Sourcepub fn restore(
self,
check: impl Fn(&Cx, &M) -> bool + Send + Sync + 'static,
) -> Self
pub fn restore( self, check: impl Fn(&Cx, &M) -> bool + Send + Sync + 'static, ) -> Self
Who may restore a trashed record: Restore.
Sourcepub fn force_delete_any(
self,
check: impl Fn(&Cx) -> bool + Send + Sync + 'static,
) -> Self
pub fn force_delete_any( self, check: impl Fn(&Cx) -> bool + Send + Sync + 'static, ) -> Self
Who may delete trashed records for good at all:
ForceDeleteAny, which the panel also asks DeleteAny of.
Defaults to whether force_delete is declared.
Sourcepub fn force_delete(
self,
check: impl Fn(&Cx, &M) -> bool + Send + Sync + 'static,
) -> Self
pub fn force_delete( self, check: impl Fn(&Cx, &M) -> bool + Send + Sync + 'static, ) -> Self
Who may delete a trashed record for good: ForceDelete, which
the panel also asks Delete of.