Skip to main content

sift_query_core/query/scope/
policy.rs

1use super::super::plan::ServerScope;
2use crate::{ParamError, SearchEntity};
3
4/// Builds a server-owned authorization scope from a trusted request context.
5///
6/// The context is supplied by the application after authentication. It is never
7/// parsed from `RawParams`, and the resulting scope is still validated by the
8/// normal query planner before any SQL is rendered.
9pub trait ScopeProvider<C, E: SearchEntity>: Send + Sync {
10    fn scope(&self, context: &C) -> Result<ServerScope<E>, ParamError>;
11}
12
13impl<C, E, F> ScopeProvider<C, E> for F
14where
15    E: SearchEntity,
16    F: Fn(&C) -> Result<ServerScope<E>, ParamError> + Send + Sync,
17{
18    fn scope(&self, context: &C) -> Result<ServerScope<E>, ParamError> {
19        self(context)
20    }
21}