graphs renamed to web

This commit is contained in:
Priec
2026-08-03 12:23:50 +02:00
parent f77e23a986
commit 35d85de556
47 changed files with 19 additions and 19 deletions

View File

@@ -0,0 +1,52 @@
use axum::http::HeaderMap;
use crate::{
AppState,
auth::GetAuthorizationRequest,
definitions::common::Empty,
services::authenticated_request,
};
use super::state::{AddTablePageState, CreateTableForm};
pub(crate) async fn load_page(
state: AppState,
headers: &HeaderMap,
form: CreateTableForm,
error: Option<String>,
) -> Result<AddTablePageState, LoadError> {
let authorization_request =
authenticated_request(headers, GetAuthorizationRequest {}).map_err(|_| LoadError::Unauthenticated)?;
let mut auth = state.auth;
let authorization = auth
.get_authorization(authorization_request)
.await
.map_err(|error| match error.code() {
tonic::Code::Unauthenticated => LoadError::Unauthenticated,
_ => LoadError::Backend(error.message().to_string()),
})?
.into_inner();
if authorization.role != "admin" {
return Err(LoadError::Forbidden);
}
let mut definitions = state.definitions;
let tree = definitions
.get_profile_tree(
authenticated_request(headers, Empty {}).map_err(|_| LoadError::Unauthenticated)?,
)
.await
.map_err(|error| LoadError::Backend(error.message().to_string()))?
.into_inner();
Ok(AddTablePageState {
profiles: tree.profiles.into_iter().map(|profile| profile.name).collect(),
form,
error,
})
}
pub(crate) enum LoadError {
Unauthenticated,
Forbidden,
Backend(String),
}