use crate::authorities::{AuthDetails, AuthoritiesCheck};
use actix_web::guard::{Guard, GuardContext};
use std::hash::Hash;
pub struct AuthorityGuard<Type> {
allow_authority: Type,
}
impl<Type: Eq + Hash + 'static> AuthorityGuard<Type> {
pub fn new(allow_authority: Type) -> AuthorityGuard<Type> {
AuthorityGuard { allow_authority }
}
}
impl<Type: Eq + Hash + 'static> Guard for AuthorityGuard<Type> {
fn check(&self, request: &GuardContext) -> bool {
request
.req_data()
.get::<AuthDetails<Type>>()
.filter(|details| details.has_authority(&self.allow_authority))
.is_some()
}
}