Make auth-info endpoint machine readable

This commit is contained in:
Simon Goller 2024-06-05 22:30:09 +02:00
parent e2f5b04ff1
commit 506791fa6a
7 changed files with 112 additions and 36 deletions

View file

@ -2,7 +2,7 @@ use std::sync::Arc;
use async_trait::async_trait;
use service::permission::Authentication;
use service::ServiceError;
use service::{Privilege, ServiceError};
pub struct PermissionServiceImpl<PermissionDao, UserService>
where
@ -58,6 +58,27 @@ where
}
}
async fn get_privileges_for_current_user(
&self,
context: Authentication<Self::Context>,
) -> Result<Arc<[Privilege]>, ServiceError> {
match context {
Authentication::Full => Ok(Arc::new([Privilege {
name: "god-mode".into(),
}])),
Authentication::Context(context) => {
let current_user = self.user_service.current_user(context).await?;
Ok(self
.permission_dao
.privileges_for_user(current_user.as_ref())
.await?
.iter()
.map(service::Privilege::from)
.collect())
}
}
}
async fn create_user(
&self,
user: &str,