1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-31 09:24:31 +03:00

Remove the unique constraint on device IDs on compatibility sessions

In OAuth 2.0 sessions, we can have multiple sessions for the same device
anyway, so this constraint doesn't exactly make sense.

Fixes #2033
Fixes #2312
This commit is contained in:
Quentin Gliech
2024-02-20 15:28:34 +01:00
parent e45e707afc
commit 03b6ad7138
6 changed files with 70 additions and 147 deletions

View File

@ -68,6 +68,7 @@ pub struct CompatSessionFilter<'a> {
user: Option<&'a User>,
state: Option<CompatSessionState>,
auth_type: Option<CompatSessionType>,
device: Option<&'a Device>,
}
impl<'a> CompatSessionFilter<'a> {
@ -90,6 +91,19 @@ impl<'a> CompatSessionFilter<'a> {
self.user
}
/// Set the device filter
#[must_use]
pub fn for_device(mut self, device: &'a Device) -> Self {
self.device = Some(device);
self
}
/// Get the device filter
#[must_use]
pub fn device(&self) -> Option<&Device> {
self.device
}
/// Only return active compatibility sessions
#[must_use]
pub fn active_only(mut self) -> Self {
@ -151,24 +165,6 @@ pub trait CompatSessionRepository: Send + Sync {
/// Returns [`Self::Error`] if the underlying repository fails
async fn lookup(&mut self, id: Ulid) -> Result<Option<CompatSession>, Self::Error>;
/// Find a compatibility session by its device ID
///
/// Returns the compat session if it exists, `None` otherwise
///
/// # Parameters
///
/// * `user`: The user to lookup the compat session for
/// * `device`: The device ID of the compat session to lookup
///
/// # Errors
///
/// Returns [`Self::Error`] if the underlying repository fails
async fn find_by_device(
&mut self,
user: &User,
device: &Device,
) -> Result<Option<CompatSession>, Self::Error>;
/// Start a new compat session
///
/// Returns the newly created compat session
@ -259,12 +255,6 @@ pub trait CompatSessionRepository: Send + Sync {
repository_impl!(CompatSessionRepository:
async fn lookup(&mut self, id: Ulid) -> Result<Option<CompatSession>, Self::Error>;
async fn find_by_device(
&mut self,
user: &User,
device: &Device,
) -> Result<Option<CompatSession>, Self::Error>;
async fn add(
&mut self,
rng: &mut (dyn RngCore + Send),