Skip to content

Commit 3b6581a

Browse files
committed
storage: add a user-provided human name to OAuth 2.0 sessions
1 parent 7c0eeec commit 3b6581a

File tree

7 files changed

+32
-4
lines changed

7 files changed

+32
-4
lines changed

crates/data-model/src/oauth2/session.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ pub struct Session {
8383
pub user_agent: Option<String>,
8484
pub last_active_at: Option<DateTime<Utc>>,
8585
pub last_active_ip: Option<IpAddr>,
86+
pub human_name: Option<String>,
8687
}
8788

8889
impl std::ops::Deref for Session {

crates/storage-pg/.sqlx/query-5a2e9b5002c1927c0035c22e393172b36ab46a4377b46618205151ea041886d5.json renamed to crates/storage-pg/.sqlx/query-6b8d28b76d7ab33178b46dbb28c11e41d86f22b3fa899a952cad00129e59bee6.json

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

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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Copyright 2025 New Vector Ltd.
2+
--
3+
-- SPDX-License-Identifier: AGPL-3.0-only
4+
-- Please see LICENSE in the repository root for full details.
5+
6+
-- Add a user-provided human name to OAuth 2.0 sessions
7+
ALTER TABLE oauth2_sessions
8+
ADD COLUMN human_name TEXT;

crates/storage-pg/src/app_session.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ impl TryFrom<AppSessionLookup> for AppSession {
192192
user_agent,
193193
last_active_at,
194194
last_active_ip,
195+
human_name,
195196
};
196197

197198
Ok(AppSession::OAuth2(Box::new(session)))
@@ -299,7 +300,10 @@ impl AppSessionRepository for PgAppSessionRepository<'_> {
299300
AppSessionLookupIden::ScopeList,
300301
)
301302
.expr_as(Expr::cust("NULL"), AppSessionLookupIden::DeviceId)
302-
.expr_as(Expr::cust("NULL"), AppSessionLookupIden::HumanName)
303+
.expr_as(
304+
Expr::col((OAuth2Sessions::Table, OAuth2Sessions::HumanName)),
305+
AppSessionLookupIden::HumanName,
306+
)
303307
.expr_as(
304308
Expr::col((OAuth2Sessions::Table, OAuth2Sessions::CreatedAt)),
305309
AppSessionLookupIden::CreatedAt,

crates/storage-pg/src/iden.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ pub enum OAuth2Sessions {
8383
UserAgent,
8484
LastActiveAt,
8585
LastActiveIp,
86+
HumanName,
8687
}
8788

8889
#[derive(sea_query::Iden)]

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct OAuthSessionLookup {
5555
user_agent: Option<String>,
5656
last_active_at: Option<DateTime<Utc>>,
5757
last_active_ip: Option<IpAddr>,
58+
human_name: Option<String>,
5859
}
5960

6061
impl TryFrom<OAuthSessionLookup> for Session {
@@ -90,6 +91,7 @@ impl TryFrom<OAuthSessionLookup> for Session {
9091
user_agent: value.user_agent,
9192
last_active_at: value.last_active_at,
9293
last_active_ip: value.last_active_ip,
94+
human_name: value.human_name,
9395
})
9496
}
9597
}
@@ -195,6 +197,7 @@ impl OAuth2SessionRepository for PgOAuth2SessionRepository<'_> {
195197
, user_agent
196198
, last_active_at
197199
, last_active_ip as "last_active_ip: IpAddr"
200+
, human_name
198201
FROM oauth2_sessions
199202
200203
WHERE oauth2_session_id = $1
@@ -270,6 +273,7 @@ impl OAuth2SessionRepository for PgOAuth2SessionRepository<'_> {
270273
user_agent: None,
271274
last_active_at: None,
272275
last_active_ip: None,
276+
human_name: None,
273277
})
274278
}
275279

@@ -392,6 +396,10 @@ impl OAuth2SessionRepository for PgOAuth2SessionRepository<'_> {
392396
Expr::col((OAuth2Sessions::Table, OAuth2Sessions::LastActiveIp)),
393397
OAuthSessionLookupIden::LastActiveIp,
394398
)
399+
.expr_as(
400+
Expr::col((OAuth2Sessions::Table, OAuth2Sessions::HumanName)),
401+
OAuthSessionLookupIden::HumanName,
402+
)
395403
.from(OAuth2Sessions::Table)
396404
.apply_filter(filter)
397405
.generate_pagination(

0 commit comments

Comments
 (0)