pub enum Ability<'a, M> {
ViewAny,
View(&'a M),
Create,
Update(&'a M),
DeleteAny,
Delete(&'a M),
RunAny {
action: &'static str,
},
Run {
action: &'static str,
record: &'a M,
},
RunHeader {
action: &'static str,
},
}Expand description
One thing a policy is asked to allow; record abilities are asked once per loaded row, and a record that cannot be viewed cannot be written by guessing its key.
Variants§
ViewAny
Open the list, export it, and offer the records as relationship options.
View(&'a M)
See one record.
Create
Open the create form and submit it.
Update(&'a M)
Edit one record.
DeleteAny
Delete at all.
Delete(&'a M)
Delete one record.
RunAny
Run
RunHeader
Run the HeaderAction whose NAME is action from the list’s
header. It acts on no record, so nothing else of the policy is asked but ViewAny.
Implementations§
Source§impl<M> Ability<'_, M>
impl<M> Ability<'_, M>
Sourcepub fn is_action<A, R>(self) -> bool
pub fn is_action<A, R>(self) -> bool
Whether the ability is RunAny or Run for the action
A.
It compares against A::NAME, so renaming the action keeps the policy matching it, and a
type that is not an action of the resource does not compile. R is inferred when A is an
action of one resource.
fn post_policy(cx: &Cx, ability: Ability<'_, Post>) -> bool {
match ability {
Ability::Run { record, .. } if ability.is_action::<Publish, _>() => !record.published,
Ability::ViewAny | Ability::View(_) => true,
_ => is_editor(cx),
}
}Source§impl<M> Ability<'_, M>
impl<M> Ability<'_, M>
Sourcepub fn is_header_action<A: HeaderAction>(self) -> bool
pub fn is_header_action<A: HeaderAction>(self) -> bool
Whether the ability is RunHeader for the header action A, which
a resource’s policy answers to let the request run it.
fn post_policy(cx: &Cx, ability: Ability<'_, Post>) -> bool {
match ability {
_ if ability.is_header_action::<RecountTags>() => is_admin(cx),
Ability::ViewAny | Ability::View(_) => true,
_ => false,
}
}