Skip to content

Commit 9a660b2

Browse files
committed
storage: methods to set the sessions human name
1 parent 0b47355 commit 9a660b2

File tree

6 files changed

+138
-0
lines changed

6 files changed

+138
-0
lines changed

crates/storage-pg/.sqlx/query-8afada5220fefb0d01ed6f87d3d0ee8fca86b5cdce9320e190e3d3b8fd9f63bc.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/storage-pg/.sqlx/query-eb095f64bec5ac885683a8c6708320760971317c4519fae7af9d44e2be50985d.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/storage-pg/src/compat/session.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,4 +622,38 @@ impl CompatSessionRepository for PgCompatSessionRepository<'_> {
622622

623623
Ok(compat_session)
624624
}
625+
626+
#[tracing::instrument(
627+
name = "repository.compat_session.set_human_name",
628+
skip(self),
629+
fields(
630+
compat_session.id = %compat_session.id,
631+
compat_session.human_name = ?human_name,
632+
),
633+
err,
634+
)]
635+
async fn set_human_name(
636+
&mut self,
637+
mut compat_session: CompatSession,
638+
human_name: Option<String>,
639+
) -> Result<CompatSession, Self::Error> {
640+
let res = sqlx::query!(
641+
r#"
642+
UPDATE compat_sessions
643+
SET human_name = $2
644+
WHERE compat_session_id = $1
645+
"#,
646+
Uuid::from(compat_session.id),
647+
human_name.as_deref(),
648+
)
649+
.traced()
650+
.execute(&mut *self.conn)
651+
.await?;
652+
653+
compat_session.human_name = human_name;
654+
655+
DatabaseError::ensure_affected_rows(&res, 1)?;
656+
657+
Ok(compat_session)
658+
}
625659
}

crates/storage-pg/src/oauth2/session.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,4 +526,38 @@ impl OAuth2SessionRepository for PgOAuth2SessionRepository<'_> {
526526

527527
Ok(session)
528528
}
529+
530+
#[tracing::instrument(
531+
name = "repository.oauth2_session.set_human_name",
532+
skip(self),
533+
fields(
534+
client.id = %session.client_id,
535+
session.human_name = ?human_name,
536+
),
537+
err,
538+
)]
539+
async fn set_human_name(
540+
&mut self,
541+
mut session: Session,
542+
human_name: Option<String>,
543+
) -> Result<Session, Self::Error> {
544+
let res = sqlx::query!(
545+
r#"
546+
UPDATE oauth2_sessions
547+
SET human_name = $2
548+
WHERE oauth2_session_id = $1
549+
"#,
550+
Uuid::from(session.id),
551+
human_name.as_deref(),
552+
)
553+
.traced()
554+
.execute(&mut *self.conn)
555+
.await?;
556+
557+
session.human_name = human_name;
558+
559+
DatabaseError::ensure_affected_rows(&res, 1)?;
560+
561+
Ok(session)
562+
}
529563
}

crates/storage/src/compat/session.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,22 @@ pub trait CompatSessionRepository: Send + Sync {
328328
compat_session: CompatSession,
329329
user_agent: String,
330330
) -> Result<CompatSession, Self::Error>;
331+
332+
/// Set the human name of a compat session
333+
///
334+
/// # Parameters
335+
///
336+
/// * `compat_session`: The compat session to set the human name for
337+
/// * `human_name`: The human name to set
338+
///
339+
/// # Errors
340+
///
341+
/// Returns [`Self::Error`] if the underlying repository fails
342+
async fn set_human_name(
343+
&mut self,
344+
compat_session: CompatSession,
345+
human_name: Option<String>,
346+
) -> Result<CompatSession, Self::Error>;
331347
}
332348

333349
repository_impl!(CompatSessionRepository:
@@ -374,4 +390,10 @@ repository_impl!(CompatSessionRepository:
374390
compat_session: CompatSession,
375391
user_agent: String,
376392
) -> Result<CompatSession, Self::Error>;
393+
394+
async fn set_human_name(
395+
&mut self,
396+
compat_session: CompatSession,
397+
human_name: Option<String>,
398+
) -> Result<CompatSession, Self::Error>;
377399
);

crates/storage/src/oauth2/session.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,18 @@ pub trait OAuth2SessionRepository: Send + Sync {
430430
session: Session,
431431
user_agent: String,
432432
) -> Result<Session, Self::Error>;
433+
434+
/// Set the human name of a [`Session`]
435+
///
436+
/// # Parameters
437+
///
438+
/// * `session`: The [`Session`] to set the human name for
439+
/// * `human_name`: The human name to set
440+
async fn set_human_name(
441+
&mut self,
442+
session: Session,
443+
human_name: Option<String>,
444+
) -> Result<Session, Self::Error>;
433445
}
434446

435447
repository_impl!(OAuth2SessionRepository:
@@ -489,4 +501,10 @@ repository_impl!(OAuth2SessionRepository:
489501
session: Session,
490502
user_agent: String,
491503
) -> Result<Session, Self::Error>;
504+
505+
async fn set_human_name(
506+
&mut self,
507+
session: Session,
508+
human_name: Option<String>,
509+
) -> Result<Session, Self::Error>;
492510
);

0 commit comments

Comments
 (0)