use async_trait::async_trait;
use crate::models::{Graphic, RendererInfo};
#[async_trait]
pub trait AccessControl: Send + Sync {
async fn authorize_connect(&self, query: &str) -> bool;
async fn on_renderer_connected(&self, name: &str, query: &str);
async fn filter_visible(
&self,
api_key: &str,
renderers: Vec<RendererInfo>,
) -> Vec<RendererInfo>;
async fn filter_graphics(&self, _api_key: &str, graphics: Vec<Graphic>) -> Vec<Graphic> {
graphics
}
async fn can_target(&self, api_key: &str, renderer_name: &str) -> bool;
async fn can_load_graphic(
&self,
_api_key: &str,
_renderer_name: &str,
_graphic_id: &str,
) -> bool {
true
}
}
pub struct AllowAllAccessControl;
#[async_trait]
impl AccessControl for AllowAllAccessControl {
async fn authorize_connect(&self, _query: &str) -> bool {
true
}
async fn on_renderer_connected(&self, _name: &str, _query: &str) {}
async fn filter_visible(
&self,
_api_key: &str,
renderers: Vec<RendererInfo>,
) -> Vec<RendererInfo> {
renderers
}
async fn can_target(&self, _api_key: &str, _renderer_name: &str) -> bool {
true
}
}