Skip to main content

when

Function when 

Source
pub fn when<F>(predicate: F) -> When<F>
where F: Fn(&Cx) -> bool + Send + Sync + 'static,
Expand description

Allows every ability while predicate holds for the request.

fn editor(cx: &Cx) -> bool {
    auth::user::<Staff>(cx).is_some_and(|staff| staff.editor)
}

fn post_policy() -> impl Policy<Post> {
    ReadOnly.or(when(editor))
}