You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-07-31 09:24:31 +03:00
Save which user session created a compat session
This also exposes the user session in the GraphQL API, and allow filtering on browser session ID on the app session list.
This commit is contained in:
@ -15,7 +15,7 @@
|
||||
//! Repositories to interact with all kinds of sessions
|
||||
|
||||
use async_trait::async_trait;
|
||||
use mas_data_model::{CompatSession, Device, Session, User};
|
||||
use mas_data_model::{BrowserSession, CompatSession, Device, Session, User};
|
||||
|
||||
use crate::{repository_impl, Page, Pagination};
|
||||
|
||||
@ -56,6 +56,7 @@ pub enum AppSession {
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
|
||||
pub struct AppSessionFilter<'a> {
|
||||
user: Option<&'a User>,
|
||||
browser_session: Option<&'a BrowserSession>,
|
||||
state: Option<AppSessionState>,
|
||||
device_id: Option<&'a Device>,
|
||||
}
|
||||
@ -67,7 +68,7 @@ impl<'a> AppSessionFilter<'a> {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Set the user who owns the compatibility sessions
|
||||
/// Set the user who owns the sessions
|
||||
#[must_use]
|
||||
pub fn for_user(mut self, user: &'a User) -> Self {
|
||||
self.user = Some(user);
|
||||
@ -80,6 +81,19 @@ impl<'a> AppSessionFilter<'a> {
|
||||
self.user
|
||||
}
|
||||
|
||||
/// Set the browser session filter
|
||||
#[must_use]
|
||||
pub fn for_browser_session(mut self, browser_session: &'a BrowserSession) -> Self {
|
||||
self.browser_session = Some(browser_session);
|
||||
self
|
||||
}
|
||||
|
||||
/// Get the browser session filter
|
||||
#[must_use]
|
||||
pub fn browser_session(&self) -> Option<&BrowserSession> {
|
||||
self.browser_session
|
||||
}
|
||||
|
||||
/// Set the device ID filter
|
||||
#[must_use]
|
||||
pub fn for_device(mut self, device_id: &'a Device) -> Self {
|
||||
|
@ -16,7 +16,7 @@ use std::net::IpAddr;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use chrono::{DateTime, Utc};
|
||||
use mas_data_model::{CompatSession, CompatSsoLogin, Device, User};
|
||||
use mas_data_model::{BrowserSession, CompatSession, CompatSsoLogin, Device, User};
|
||||
use rand_core::RngCore;
|
||||
use ulid::Ulid;
|
||||
|
||||
@ -175,6 +175,7 @@ pub trait CompatSessionRepository: Send + Sync {
|
||||
/// * `clock`: The clock used to generate timestamps
|
||||
/// * `user`: The user to create the compat session for
|
||||
/// * `device`: The device ID of this session
|
||||
/// * `browser_session`: The browser session which created this session
|
||||
/// * `is_synapse_admin`: Whether the session is a synapse admin session
|
||||
///
|
||||
/// # Errors
|
||||
@ -186,6 +187,7 @@ pub trait CompatSessionRepository: Send + Sync {
|
||||
clock: &dyn Clock,
|
||||
user: &User,
|
||||
device: Device,
|
||||
browser_session: Option<&BrowserSession>,
|
||||
is_synapse_admin: bool,
|
||||
) -> Result<CompatSession, Self::Error>;
|
||||
|
||||
@ -261,6 +263,7 @@ repository_impl!(CompatSessionRepository:
|
||||
clock: &dyn Clock,
|
||||
user: &User,
|
||||
device: Device,
|
||||
browser_session: Option<&BrowserSession>,
|
||||
is_synapse_admin: bool,
|
||||
) -> Result<CompatSession, Self::Error>;
|
||||
|
||||
|
Reference in New Issue
Block a user