storage: methods to set the sessions human name

This commit is contained in:
Quentin Gliech
2025-04-25 14:39:34 +02:00
parent c6075f5cc0
commit 3b9d580b17
6 changed files with 138 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
{
"db_name": "PostgreSQL",
"query": "\n UPDATE oauth2_sessions\n SET human_name = $2\n WHERE oauth2_session_id = $1\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Uuid",
"Text"
]
},
"nullable": []
},
"hash": "8afada5220fefb0d01ed6f87d3d0ee8fca86b5cdce9320e190e3d3b8fd9f63bc"
}

View File

@@ -0,0 +1,15 @@
{
"db_name": "PostgreSQL",
"query": "\n UPDATE compat_sessions\n SET human_name = $2\n WHERE compat_session_id = $1\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Uuid",
"Text"
]
},
"nullable": []
},
"hash": "eb095f64bec5ac885683a8c6708320760971317c4519fae7af9d44e2be50985d"
}

View File

@@ -622,4 +622,38 @@ impl CompatSessionRepository for PgCompatSessionRepository<'_> {
Ok(compat_session)
}
#[tracing::instrument(
name = "repository.compat_session.set_human_name",
skip(self),
fields(
compat_session.id = %compat_session.id,
compat_session.human_name = ?human_name,
),
err,
)]
async fn set_human_name(
&mut self,
mut compat_session: CompatSession,
human_name: Option<String>,
) -> Result<CompatSession, Self::Error> {
let res = sqlx::query!(
r#"
UPDATE compat_sessions
SET human_name = $2
WHERE compat_session_id = $1
"#,
Uuid::from(compat_session.id),
human_name.as_deref(),
)
.traced()
.execute(&mut *self.conn)
.await?;
compat_session.human_name = human_name;
DatabaseError::ensure_affected_rows(&res, 1)?;
Ok(compat_session)
}
}

View File

@@ -526,4 +526,38 @@ impl OAuth2SessionRepository for PgOAuth2SessionRepository<'_> {
Ok(session)
}
#[tracing::instrument(
name = "repository.oauth2_session.set_human_name",
skip(self),
fields(
client.id = %session.client_id,
session.human_name = ?human_name,
),
err,
)]
async fn set_human_name(
&mut self,
mut session: Session,
human_name: Option<String>,
) -> Result<Session, Self::Error> {
let res = sqlx::query!(
r#"
UPDATE oauth2_sessions
SET human_name = $2
WHERE oauth2_session_id = $1
"#,
Uuid::from(session.id),
human_name.as_deref(),
)
.traced()
.execute(&mut *self.conn)
.await?;
session.human_name = human_name;
DatabaseError::ensure_affected_rows(&res, 1)?;
Ok(session)
}
}

View File

@@ -328,6 +328,22 @@ pub trait CompatSessionRepository: Send + Sync {
compat_session: CompatSession,
user_agent: String,
) -> Result<CompatSession, Self::Error>;
/// Set the human name of a compat session
///
/// # Parameters
///
/// * `compat_session`: The compat session to set the human name for
/// * `human_name`: The human name to set
///
/// # Errors
///
/// Returns [`Self::Error`] if the underlying repository fails
async fn set_human_name(
&mut self,
compat_session: CompatSession,
human_name: Option<String>,
) -> Result<CompatSession, Self::Error>;
}
repository_impl!(CompatSessionRepository:
@@ -374,4 +390,10 @@ repository_impl!(CompatSessionRepository:
compat_session: CompatSession,
user_agent: String,
) -> Result<CompatSession, Self::Error>;
async fn set_human_name(
&mut self,
compat_session: CompatSession,
human_name: Option<String>,
) -> Result<CompatSession, Self::Error>;
);

View File

@@ -430,6 +430,18 @@ pub trait OAuth2SessionRepository: Send + Sync {
session: Session,
user_agent: String,
) -> Result<Session, Self::Error>;
/// Set the human name of a [`Session`]
///
/// # Parameters
///
/// * `session`: The [`Session`] to set the human name for
/// * `human_name`: The human name to set
async fn set_human_name(
&mut self,
session: Session,
human_name: Option<String>,
) -> Result<Session, Self::Error>;
}
repository_impl!(OAuth2SessionRepository:
@@ -489,4 +501,10 @@ repository_impl!(OAuth2SessionRepository:
session: Session,
user_agent: String,
) -> Result<Session, Self::Error>;
async fn set_human_name(
&mut self,
session: Session,
human_name: Option<String>,
) -> Result<Session, Self::Error>;
);