You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-07-29 22:01:14 +03:00
frontend: Show all compatibilities sessions, not just SSO logins
Also cleans up a bunch of things in the frontend
This commit is contained in:
@ -24,7 +24,10 @@ use crate::state::ContextExt;
|
||||
/// A compat session represents a client session which used the legacy Matrix
|
||||
/// login API.
|
||||
#[derive(Description)]
|
||||
pub struct CompatSession(pub mas_data_model::CompatSession);
|
||||
pub struct CompatSession(
|
||||
pub mas_data_model::CompatSession,
|
||||
pub Option<mas_data_model::CompatSsoLogin>,
|
||||
);
|
||||
|
||||
#[Object(use_type_description)]
|
||||
impl CompatSession {
|
||||
@ -61,6 +64,11 @@ impl CompatSession {
|
||||
pub async fn finished_at(&self) -> Option<DateTime<Utc>> {
|
||||
self.0.finished_at()
|
||||
}
|
||||
|
||||
/// The associated SSO login, if any.
|
||||
pub async fn sso_login(&self) -> Option<CompatSsoLogin> {
|
||||
self.1.as_ref().map(|l| CompatSsoLogin(l.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
/// A compat SSO login represents a login done through the legacy Matrix login
|
||||
@ -114,6 +122,6 @@ impl CompatSsoLogin {
|
||||
.context("Could not load compat session")?;
|
||||
repo.cancel().await?;
|
||||
|
||||
Ok(Some(CompatSession(session)))
|
||||
Ok(Some(CompatSession(session, Some(self.0.clone()))))
|
||||
}
|
||||
}
|
||||
|
@ -22,14 +22,17 @@ use mas_storage::{
|
||||
oauth2::OAuth2SessionRepository,
|
||||
upstream_oauth2::UpstreamOAuthLinkRepository,
|
||||
user::{BrowserSessionRepository, UserEmailRepository},
|
||||
Pagination,
|
||||
Pagination, RepositoryAccess,
|
||||
};
|
||||
|
||||
use super::{
|
||||
compat_sessions::CompatSsoLogin, BrowserSession, Cursor, NodeCursor, NodeType, OAuth2Session,
|
||||
UpstreamOAuth2Link,
|
||||
};
|
||||
use crate::{model::matrix::MatrixUser, state::ContextExt};
|
||||
use crate::{
|
||||
model::{matrix::MatrixUser, CompatSession},
|
||||
state::ContextExt,
|
||||
};
|
||||
|
||||
#[derive(Description)]
|
||||
/// A user is an individual's account.
|
||||
@ -129,6 +132,58 @@ impl User {
|
||||
.await
|
||||
}
|
||||
|
||||
/// Get the list of compatibility sessions, chronologically sorted
|
||||
async fn compat_sessions(
|
||||
&self,
|
||||
ctx: &Context<'_>,
|
||||
|
||||
#[graphql(desc = "Returns the elements in the list that come after the cursor.")]
|
||||
after: Option<String>,
|
||||
#[graphql(desc = "Returns the elements in the list that come before the cursor.")]
|
||||
before: Option<String>,
|
||||
#[graphql(desc = "Returns the first *n* elements from the list.")] first: Option<i32>,
|
||||
#[graphql(desc = "Returns the last *n* elements from the list.")] last: Option<i32>,
|
||||
) -> Result<Connection<Cursor, CompatSession>, async_graphql::Error> {
|
||||
let state = ctx.state();
|
||||
let mut repo = state.repository().await?;
|
||||
|
||||
query(
|
||||
after,
|
||||
before,
|
||||
first,
|
||||
last,
|
||||
|after, before, first, last| async move {
|
||||
let after_id = after
|
||||
.map(|x: OpaqueCursor<NodeCursor>| x.extract_for_type(NodeType::CompatSsoLogin))
|
||||
.transpose()?;
|
||||
let before_id = before
|
||||
.map(|x: OpaqueCursor<NodeCursor>| x.extract_for_type(NodeType::CompatSsoLogin))
|
||||
.transpose()?;
|
||||
let pagination = Pagination::try_new(before_id, after_id, first, last)?;
|
||||
|
||||
let page = repo
|
||||
.compat_session()
|
||||
.list_paginated(&self.0, pagination)
|
||||
.await?;
|
||||
|
||||
repo.cancel().await?;
|
||||
|
||||
let mut connection = Connection::new(page.has_previous_page, page.has_next_page);
|
||||
connection
|
||||
.edges
|
||||
.extend(page.edges.into_iter().map(|(session, sso_login)| {
|
||||
Edge::new(
|
||||
OpaqueCursor(NodeCursor(NodeType::CompatSession, session.id)),
|
||||
CompatSession(session, sso_login),
|
||||
)
|
||||
}));
|
||||
|
||||
Ok::<_, async_graphql::Error>(connection)
|
||||
},
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Get the list of active browser sessions, chronologically sorted
|
||||
async fn browser_sessions(
|
||||
&self,
|
||||
|
@ -66,7 +66,8 @@ impl EndCompatSessionPayload {
|
||||
/// Returns the ended session.
|
||||
async fn compat_session(&self) -> Option<CompatSession> {
|
||||
match self {
|
||||
Self::Ended(session) => Some(CompatSession(session.clone())),
|
||||
// XXX: the SSO login is not returned here.
|
||||
Self::Ended(session) => Some(CompatSession(session.clone(), None)),
|
||||
Self::NotFound => None,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user