1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-11-20 12:02:22 +03:00

Simple list of compat sessions

This commit is contained in:
Quentin Gliech
2022-11-14 17:44:03 +01:00
parent 02c47cab34
commit 2064c11d9b
19 changed files with 771 additions and 98 deletions

View File

@@ -22,8 +22,9 @@
#![warn(clippy::pedantic)]
#![allow(clippy::module_name_repetitions, clippy::missing_errors_doc)]
use async_graphql::{Context, Description, EmptyMutation, EmptySubscription};
use async_graphql::{Context, Description, EmptyMutation, EmptySubscription, ID};
use mas_axum_utils::SessionInfo;
use model::NodeType;
use sqlx::PgPool;
use self::model::{BrowserSession, Node, User};
@@ -78,4 +79,34 @@ impl RootQuery {
Ok(session.map(User::from))
}
/// Fetches an object given its ID.
async fn node(&self, ctx: &Context<'_>, id: ID) -> Result<Option<Node>, async_graphql::Error> {
let (node_type, id) = NodeType::from_id(&id)?;
let database = ctx.data::<PgPool>()?;
let session_info = ctx.data::<SessionInfo>()?;
let mut conn = database.acquire().await?;
let session = session_info.load_session(&mut conn).await?;
let Some(session) = session else { return Ok(None) };
match node_type {
// TODO
NodeType::Authentication
| NodeType::BrowserSession
| NodeType::CompatSession
| NodeType::CompatSsoLogin
| NodeType::OAuth2Client
| NodeType::UserEmail
| NodeType::OAuth2Session => Ok(None),
NodeType::User => {
if session.user.data == id {
Ok(Some(Box::new(User(session.user)).into()))
} else {
Ok(None)
}
}
}
}
}