storage: allow setting the human_name when creating compat sessions
This commit is contained in:
@@ -305,7 +305,7 @@ impl Options {
|
||||
|
||||
let compat_session = repo
|
||||
.compat_session()
|
||||
.add(&mut rng, &clock, &user, device, None, admin)
|
||||
.add(&mut rng, &clock, &user, device, None, admin, None)
|
||||
.await?;
|
||||
|
||||
let token = TokenType::CompatAccessToken.generate(&mut rng);
|
||||
|
||||
@@ -107,7 +107,7 @@ mod tests {
|
||||
let device = Device::generate(&mut rng);
|
||||
let session = repo
|
||||
.compat_session()
|
||||
.add(&mut rng, &state.clock, &user, device, None, false)
|
||||
.add(&mut rng, &state.clock, &user, device, None, false, None)
|
||||
.await
|
||||
.unwrap();
|
||||
repo.save().await.unwrap();
|
||||
|
||||
@@ -251,7 +251,7 @@ mod tests {
|
||||
|
||||
let device = Device::generate(&mut rng);
|
||||
repo.compat_session()
|
||||
.add(&mut rng, &state.clock, &alice, device, None, false)
|
||||
.add(&mut rng, &state.clock, &alice, device, None, false, None)
|
||||
.await
|
||||
.unwrap();
|
||||
let device = Device::generate(&mut rng);
|
||||
@@ -260,7 +260,7 @@ mod tests {
|
||||
|
||||
let session = repo
|
||||
.compat_session()
|
||||
.add(&mut rng, &state.clock, &bob, device, None, false)
|
||||
.add(&mut rng, &state.clock, &bob, device, None, false, None)
|
||||
.await
|
||||
.unwrap();
|
||||
state.clock.advance(Duration::minutes(1));
|
||||
|
||||
@@ -484,6 +484,7 @@ async fn token_login(
|
||||
device,
|
||||
Some(&browser_session),
|
||||
false,
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -576,7 +577,7 @@ async fn user_password_login(
|
||||
|
||||
let session = repo
|
||||
.compat_session()
|
||||
.add(&mut rng, clock, &user, device, None, false)
|
||||
.add(&mut rng, clock, &user, device, None, false, None)
|
||||
.await?;
|
||||
|
||||
Ok((session, user))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n INSERT INTO compat_sessions\n (compat_session_id, user_id, device_id,\n user_session_id, created_at, is_synapse_admin)\n VALUES ($1, $2, $3, $4, $5, $6)\n ",
|
||||
"query": "\n INSERT INTO compat_sessions\n (compat_session_id, user_id, device_id,\n user_session_id, created_at, is_synapse_admin,\n human_name)\n VALUES ($1, $2, $3, $4, $5, $6, $7)\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
@@ -10,10 +10,11 @@
|
||||
"Text",
|
||||
"Uuid",
|
||||
"Timestamptz",
|
||||
"Bool"
|
||||
"Bool",
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "cf1273b8aaaccedeb212a971d5e8e0dd23bfddab0ec08ee192783e103a1c4766"
|
||||
"hash": "e99ab37ab3e03ad9c48792772b09bac77b09f67e623d5371ab4dadbe2d41fa1c"
|
||||
}
|
||||
@@ -571,7 +571,7 @@ mod tests {
|
||||
let device = Device::generate(&mut rng);
|
||||
let compat_session = repo
|
||||
.compat_session()
|
||||
.add(&mut rng, &clock, &user, device.clone(), None, false)
|
||||
.add(&mut rng, &clock, &user, device.clone(), None, false, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ mod tests {
|
||||
let device_str = device.as_str().to_owned();
|
||||
let session = repo
|
||||
.compat_session()
|
||||
.add(&mut rng, &clock, &user, device.clone(), None, false)
|
||||
.add(&mut rng, &clock, &user, device.clone(), None, false, None)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(session.user_id, user.id);
|
||||
@@ -227,6 +227,7 @@ mod tests {
|
||||
device,
|
||||
Some(&browser_session),
|
||||
false,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -331,7 +332,7 @@ mod tests {
|
||||
let device = Device::generate(&mut rng);
|
||||
let session = repo
|
||||
.compat_session()
|
||||
.add(&mut rng, &clock, &user, device, None, false)
|
||||
.add(&mut rng, &clock, &user, device, None, false, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -452,7 +453,7 @@ mod tests {
|
||||
let device = Device::generate(&mut rng);
|
||||
let session = repo
|
||||
.compat_session()
|
||||
.add(&mut rng, &clock, &user, device, None, false)
|
||||
.add(&mut rng, &clock, &user, device, None, false, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -618,7 +619,7 @@ mod tests {
|
||||
let device = Device::generate(&mut rng);
|
||||
let compat_session = repo
|
||||
.compat_session()
|
||||
.add(&mut rng, &clock, &user, device, None, false)
|
||||
.add(&mut rng, &clock, &user, device, None, false, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -305,6 +305,7 @@ impl CompatSessionRepository for PgCompatSessionRepository<'_> {
|
||||
device: Device,
|
||||
browser_session: Option<&BrowserSession>,
|
||||
is_synapse_admin: bool,
|
||||
human_name: Option<String>,
|
||||
) -> Result<CompatSession, Self::Error> {
|
||||
let created_at = clock.now();
|
||||
let id = Ulid::from_datetime_with_source(created_at.into(), rng);
|
||||
@@ -314,8 +315,9 @@ impl CompatSessionRepository for PgCompatSessionRepository<'_> {
|
||||
r#"
|
||||
INSERT INTO compat_sessions
|
||||
(compat_session_id, user_id, device_id,
|
||||
user_session_id, created_at, is_synapse_admin)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
user_session_id, created_at, is_synapse_admin,
|
||||
human_name)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
"#,
|
||||
Uuid::from(id),
|
||||
Uuid::from(user.id),
|
||||
@@ -323,6 +325,7 @@ impl CompatSessionRepository for PgCompatSessionRepository<'_> {
|
||||
browser_session.map(|s| Uuid::from(s.id)),
|
||||
created_at,
|
||||
is_synapse_admin,
|
||||
human_name.as_deref(),
|
||||
)
|
||||
.traced()
|
||||
.execute(&mut *self.conn)
|
||||
@@ -333,7 +336,7 @@ impl CompatSessionRepository for PgCompatSessionRepository<'_> {
|
||||
state: CompatSessionState::default(),
|
||||
user_id: user.id,
|
||||
device: Some(device),
|
||||
human_name: None,
|
||||
human_name,
|
||||
user_session_id: browser_session.map(|s| s.id),
|
||||
created_at,
|
||||
is_synapse_admin,
|
||||
|
||||
@@ -215,10 +215,13 @@ pub trait CompatSessionRepository: Send + Sync {
|
||||
/// * `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
|
||||
/// * `human_name`: The human-readable name of the session provided by the
|
||||
/// client or the user
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`Self::Error`] if the underlying repository fails
|
||||
#[expect(clippy::too_many_arguments)]
|
||||
async fn add(
|
||||
&mut self,
|
||||
rng: &mut (dyn RngCore + Send),
|
||||
@@ -227,6 +230,7 @@ pub trait CompatSessionRepository: Send + Sync {
|
||||
device: Device,
|
||||
browser_session: Option<&BrowserSession>,
|
||||
is_synapse_admin: bool,
|
||||
human_name: Option<String>,
|
||||
) -> Result<CompatSession, Self::Error>;
|
||||
|
||||
/// End a compat session
|
||||
@@ -337,6 +341,7 @@ repository_impl!(CompatSessionRepository:
|
||||
device: Device,
|
||||
browser_session: Option<&BrowserSession>,
|
||||
is_synapse_admin: bool,
|
||||
human_name: Option<String>,
|
||||
) -> Result<CompatSession, Self::Error>;
|
||||
|
||||
async fn finish(
|
||||
|
||||
Reference in New Issue
Block a user