fn auth_met(required: &Option<String>, auth: &mut Auth, conn: &r2d2::PooledConnection<r2d2_postgres::PostgresConnectionManager>) -> Result<bool, status::Custom<Json>> {
    auth.validate(conn)?;

    match required {
        None => Err(not_authed()),
        Some(req) => match req.as_ref() {
            "public" => Ok(true),
            "admin" => {
                if auth.uid.is_none() || auth.access.is_none() {
                    return Err(not_authed());
                } else if auth.access == Some(String::from("admin")) {
                    return Ok(true);
                } else {
                    return Err(not_authed());
                }
            },
            "user" => {
                if auth.uid.is_some() {
                    return Ok(true);
                } else {
                    return Err(not_authed());
                }
            },
            "self" => {
                //Note: This ensures the user is validated,
                //it is up to the parent caller to ensure
                //the UID of 'self' matches the requested resource

                if auth.uid.is_some() {
                    return Ok(true);
                } else {
                    return Err(not_authed());
                }
            },
            _ => Err(not_authed())
        }
    }
}
///
/// Determines whether the current auth state meets or exceeds the
/// requirements of an endpoint
///
Determines whether the current auth state meets or exceeds the
requirements of an endpoint
Determines whether the current auth state meets or exceeds the requirements of an endpoint
fn auth_met(required: &Option<String>, auth: &mut Auth, conn: &r2d2::PooledConnection<r2d2_postgres::PostgresConnectionManager>) -> Result<bool, status::Custom<Json>> {
    auth.validate(conn)?;
    match required {
        None => Err(not_authed()),
        Some(req) => match req.as_ref() {
            "public" => Ok(true),
            "admin" => {
                if auth.uid.is_none() || auth.access.is_none() {
                    return Err(not_authed());
                } else if auth.access == Some(String::from("admin")) {
                    return Ok(true);
                } else {
                    return Err(not_authed());
                }
            },
            "user" => {
                if auth.uid.is_some() {
                    return Ok(true);
                } else {
                    return Err(not_authed());
                }
            },
            "self" => {
                //Note: This ensures the user is validated,
                //it is up to the parent caller to ensure
                //the UID of 'self' matches the requested resource
                if auth.uid.is_some() {
                    return Ok(true);
                } else {
                    return Err(not_authed());
                }
            },
            _ => Err(not_authed())
        }
    }
}
fn auth_met ( required : & Option < String > , auth : & mut Auth , conn : & r2d2 :: PooledConnection < r2d2_postgres :: PostgresConnectionManager > ) -> Result < bool , status :: Custom < Json > > { auth . validate ( conn ) ? ; match required { None => Err ( not_authed ( ) ) , Some ( req ) => match req . as_ref ( ) { " " => Ok ( true ) , " " => { if auth . uid . is_none ( ) || auth . access . is_none ( ) { return Err ( not_authed ( ) ) ; } else if auth . access == Some ( String :: from ( " " ) ) { return Ok ( true ) ; } else { return Err ( not_authed ( ) ) ; } } , " " => { if auth . uid . is_some ( ) { return Ok ( true ) ; } else { return Err ( not_authed ( ) ) ; } } , " " => { //Note: This ensures the user is validated, //it is up to the parent caller to ensure //the UID of 'self' matches the requested resource if auth . uid . is_some ( ) { return Ok ( true ) ; } else { return Err ( not_authed ( ) ) ; } } , _ => Err ( not_authed ( ) ) } } }
Determines whether the current auth state meets or exceeds the
requirements of an endpoint
Determines whether the current auth state meets or exceeds the requirements of an endpoint
required
&Option<String>
auth
&mut Auth
conn
&r2d2::PooledConnection<r2d2_postgres::PostgresConnectionManager>
required
&Option<String>
auth
&mut Auth
conn
&r2d2::PooledConnection<r2d2_postgres::PostgresConnectionManager>