admin: expose the sessions 'human_name'

This commit is contained in:
Quentin Gliech
2025-04-25 13:54:49 +02:00
parent 79868c3ca3
commit 5d4c371e53
6 changed files with 70 additions and 30 deletions

View File

@@ -184,6 +184,9 @@ pub struct CompatSession {
/// The time this session was finished
pub finished_at: Option<DateTime<Utc>>,
/// The user-provided name, if any
pub human_name: Option<String>,
}
impl
@@ -210,6 +213,7 @@ impl
last_active_at: session.last_active_at,
last_active_ip: session.last_active_ip,
finished_at,
human_name: session.human_name,
}
}
}
@@ -237,6 +241,7 @@ impl CompatSession {
last_active_at: Some(DateTime::default()),
last_active_ip: Some([1, 2, 3, 4].into()),
finished_at: None,
human_name: Some("Laptop".to_owned()),
},
Self {
id: Ulid::from_bytes([0x02; 16]),
@@ -249,6 +254,7 @@ impl CompatSession {
last_active_at: Some(DateTime::default()),
last_active_ip: Some([1, 2, 3, 4].into()),
finished_at: Some(DateTime::default()),
human_name: None,
},
Self {
id: Ulid::from_bytes([0x03; 16]),
@@ -261,6 +267,7 @@ impl CompatSession {
last_active_at: None,
last_active_ip: None,
finished_at: None,
human_name: None,
},
]
}
@@ -301,6 +308,9 @@ pub struct OAuth2Session {
/// The last IP address used by the session
last_active_ip: Option<IpAddr>,
/// The user-provided name, if any
human_name: Option<String>,
}
impl From<mas_data_model::Session> for OAuth2Session {
@@ -316,6 +326,7 @@ impl From<mas_data_model::Session> for OAuth2Session {
user_agent: session.user_agent,
last_active_at: session.last_active_at,
last_active_ip: session.last_active_ip,
human_name: session.human_name,
}
}
}
@@ -335,6 +346,7 @@ impl OAuth2Session {
user_agent: Some("Mozilla/5.0".to_owned()),
last_active_at: Some(DateTime::default()),
last_active_ip: Some("127.0.0.1".parse().unwrap()),
human_name: Some("Laptop".to_owned()),
},
Self {
id: Ulid::from_bytes([0x02; 16]),
@@ -347,6 +359,7 @@ impl OAuth2Session {
user_agent: None,
last_active_at: None,
last_active_ip: None,
human_name: None,
},
Self {
id: Ulid::from_bytes([0x03; 16]),
@@ -359,6 +372,7 @@ impl OAuth2Session {
user_agent: Some("Mozilla/5.0".to_owned()),
last_active_at: Some(DateTime::default()),
last_active_ip: Some("127.0.0.1".parse().unwrap()),
human_name: None,
},
]
}

View File

@@ -119,7 +119,7 @@ mod tests {
let response = state.request(request).await;
response.assert_status(StatusCode::OK);
let body: serde_json::Value = response.json();
assert_json_snapshot!(body, @r###"
assert_json_snapshot!(body, @r#"
{
"data": {
"type": "compat-session",
@@ -133,7 +133,8 @@ mod tests {
"user_agent": null,
"last_active_at": null,
"last_active_ip": null,
"finished_at": null
"finished_at": null,
"human_name": null
},
"links": {
"self": "/api/admin/v1/compat-sessions/01FSHN9AG0QHEHKX2JNQ2A2D07"
@@ -143,7 +144,7 @@ mod tests {
"self": "/api/admin/v1/compat-sessions/01FSHN9AG0QHEHKX2JNQ2A2D07"
}
}
"###);
"#);
}
#[sqlx::test(migrator = "mas_storage_pg::MIGRATOR")]

View File

@@ -276,7 +276,7 @@ mod tests {
let response = state.request(request).await;
response.assert_status(StatusCode::OK);
let body: serde_json::Value = response.json();
assert_json_snapshot!(body, @r###"
assert_json_snapshot!(body, @r#"
{
"meta": {
"count": 2
@@ -294,7 +294,8 @@ mod tests {
"user_agent": null,
"last_active_at": null,
"last_active_ip": null,
"finished_at": null
"finished_at": null,
"human_name": null
},
"links": {
"self": "/api/admin/v1/compat-sessions/01FSHNB530AAPR7PEV8KNBZD5Y"
@@ -312,7 +313,8 @@ mod tests {
"user_agent": null,
"last_active_at": null,
"last_active_ip": null,
"finished_at": "2022-01-16T14:43:00Z"
"finished_at": "2022-01-16T14:43:00Z",
"human_name": null
},
"links": {
"self": "/api/admin/v1/compat-sessions/01FSHNCZP0PPF7X0EVMJNECPZW"
@@ -325,7 +327,7 @@ mod tests {
"last": "/api/admin/v1/compat-sessions?page[last]=10"
}
}
"###);
"#);
// Filter by user
let request = Request::get(format!(
@@ -337,7 +339,7 @@ mod tests {
let response = state.request(request).await;
response.assert_status(StatusCode::OK);
let body: serde_json::Value = response.json();
assert_json_snapshot!(body, @r###"
assert_json_snapshot!(body, @r#"
{
"meta": {
"count": 1
@@ -355,7 +357,8 @@ mod tests {
"user_agent": null,
"last_active_at": null,
"last_active_ip": null,
"finished_at": null
"finished_at": null,
"human_name": null
},
"links": {
"self": "/api/admin/v1/compat-sessions/01FSHNB530AAPR7PEV8KNBZD5Y"
@@ -368,7 +371,7 @@ mod tests {
"last": "/api/admin/v1/compat-sessions?filter[user]=01FSHN9AG0MZAA6S4AF7CTV32E&page[last]=10"
}
}
"###);
"#);
// Filter by status (active)
let request = Request::get("/api/admin/v1/compat-sessions?filter[status]=active")
@@ -377,7 +380,7 @@ mod tests {
let response = state.request(request).await;
response.assert_status(StatusCode::OK);
let body: serde_json::Value = response.json();
assert_json_snapshot!(body, @r###"
assert_json_snapshot!(body, @r#"
{
"meta": {
"count": 1
@@ -395,7 +398,8 @@ mod tests {
"user_agent": null,
"last_active_at": null,
"last_active_ip": null,
"finished_at": null
"finished_at": null,
"human_name": null
},
"links": {
"self": "/api/admin/v1/compat-sessions/01FSHNB530AAPR7PEV8KNBZD5Y"
@@ -408,7 +412,7 @@ mod tests {
"last": "/api/admin/v1/compat-sessions?filter[status]=active&page[last]=10"
}
}
"###);
"#);
// Filter by status (finished)
let request = Request::get("/api/admin/v1/compat-sessions?filter[status]=finished")
@@ -417,7 +421,7 @@ mod tests {
let response = state.request(request).await;
response.assert_status(StatusCode::OK);
let body: serde_json::Value = response.json();
assert_json_snapshot!(body, @r###"
assert_json_snapshot!(body, @r#"
{
"meta": {
"count": 1
@@ -435,7 +439,8 @@ mod tests {
"user_agent": null,
"last_active_at": null,
"last_active_ip": null,
"finished_at": "2022-01-16T14:43:00Z"
"finished_at": "2022-01-16T14:43:00Z",
"human_name": null
},
"links": {
"self": "/api/admin/v1/compat-sessions/01FSHNCZP0PPF7X0EVMJNECPZW"
@@ -448,6 +453,6 @@ mod tests {
"last": "/api/admin/v1/compat-sessions?filter[status]=finished&page[last]=10"
}
}
"###);
"#);
}
}

View File

@@ -110,7 +110,7 @@ mod tests {
response.assert_status(StatusCode::OK);
let body: serde_json::Value = response.json();
assert_eq!(body["data"]["type"], "oauth2-session");
insta::assert_json_snapshot!(body, @r###"
insta::assert_json_snapshot!(body, @r#"
{
"data": {
"type": "oauth2-session",
@@ -124,7 +124,8 @@ mod tests {
"scope": "urn:mas:admin",
"user_agent": null,
"last_active_at": null,
"last_active_ip": null
"last_active_ip": null,
"human_name": null
},
"links": {
"self": "/api/admin/v1/oauth2-sessions/01FSHN9AG0MKGTBNZ16RDR3PVY"
@@ -134,7 +135,7 @@ mod tests {
"self": "/api/admin/v1/oauth2-sessions/01FSHN9AG0MKGTBNZ16RDR3PVY"
}
}
"###);
"#);
}
#[sqlx::test(migrator = "mas_storage_pg::MIGRATOR")]

View File

@@ -331,7 +331,7 @@ mod tests {
let response = state.request(request).await;
response.assert_status(StatusCode::OK);
let body: serde_json::Value = response.json();
insta::assert_json_snapshot!(body, @r###"
insta::assert_json_snapshot!(body, @r#"
{
"meta": {
"count": 1
@@ -349,7 +349,8 @@ mod tests {
"scope": "urn:mas:admin",
"user_agent": null,
"last_active_at": null,
"last_active_ip": null
"last_active_ip": null,
"human_name": null
},
"links": {
"self": "/api/admin/v1/oauth2-sessions/01FSHN9AG0MKGTBNZ16RDR3PVY"
@@ -362,6 +363,6 @@ mod tests {
"last": "/api/admin/v1/oauth2-sessions?page[last]=10"
}
}
"###);
"#);
}
}

View File

@@ -132,7 +132,8 @@
"user_agent": "Mozilla/5.0",
"last_active_at": "1970-01-01T00:00:00Z",
"last_active_ip": "1.2.3.4",
"finished_at": null
"finished_at": null,
"human_name": "Laptop"
},
"links": {
"self": "/api/admin/v1/compat-sessions/01040G2081040G2081040G2081"
@@ -150,7 +151,8 @@
"user_agent": "Mozilla/5.0",
"last_active_at": "1970-01-01T00:00:00Z",
"last_active_ip": "1.2.3.4",
"finished_at": "1970-01-01T00:00:00Z"
"finished_at": "1970-01-01T00:00:00Z",
"human_name": null
},
"links": {
"self": "/api/admin/v1/compat-sessions/02081040G2081040G2081040G2"
@@ -168,7 +170,8 @@
"user_agent": null,
"last_active_at": null,
"last_active_ip": null,
"finished_at": null
"finished_at": null,
"human_name": null
},
"links": {
"self": "/api/admin/v1/compat-sessions/030C1G60R30C1G60R30C1G60R3"
@@ -245,7 +248,8 @@
"user_agent": "Mozilla/5.0",
"last_active_at": "1970-01-01T00:00:00Z",
"last_active_ip": "1.2.3.4",
"finished_at": null
"finished_at": null,
"human_name": "Laptop"
},
"links": {
"self": "/api/admin/v1/compat-sessions/01040G2081040G2081040G2081"
@@ -430,7 +434,8 @@
"scope": "openid",
"user_agent": "Mozilla/5.0",
"last_active_at": "1970-01-01T00:00:00Z",
"last_active_ip": "127.0.0.1"
"last_active_ip": "127.0.0.1",
"human_name": "Laptop"
},
"links": {
"self": "/api/admin/v1/oauth2-sessions/01040G2081040G2081040G2081"
@@ -448,7 +453,8 @@
"scope": "urn:mas:admin",
"user_agent": null,
"last_active_at": null,
"last_active_ip": null
"last_active_ip": null,
"human_name": null
},
"links": {
"self": "/api/admin/v1/oauth2-sessions/02081040G2081040G2081040G2"
@@ -466,7 +472,8 @@
"scope": "urn:matrix:org.matrix.msc2967.client:api:*",
"user_agent": "Mozilla/5.0",
"last_active_at": "1970-01-01T00:00:00Z",
"last_active_ip": "127.0.0.1"
"last_active_ip": "127.0.0.1",
"human_name": null
},
"links": {
"self": "/api/admin/v1/oauth2-sessions/030C1G60R30C1G60R30C1G60R3"
@@ -560,7 +567,8 @@
"scope": "openid",
"user_agent": "Mozilla/5.0",
"last_active_at": "1970-01-01T00:00:00Z",
"last_active_ip": "127.0.0.1"
"last_active_ip": "127.0.0.1",
"human_name": "Laptop"
},
"links": {
"self": "/api/admin/v1/oauth2-sessions/01040G2081040G2081040G2081"
@@ -2726,6 +2734,11 @@
"type": "string",
"format": "date-time",
"nullable": true
},
"human_name": {
"description": "The user-provided name, if any",
"type": "string",
"nullable": true
}
}
},
@@ -3001,6 +3014,11 @@
"type": "string",
"format": "ip",
"nullable": true
},
"human_name": {
"description": "The user-provided name, if any",
"type": "string",
"nullable": true
}
}
},