Skip to content

Commit e615c78

Browse files
committed
admin: expose the sessions 'human_name'
1 parent 2cc8c3a commit e615c78

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

crates/handlers/src/admin/model.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ pub struct CompatSession {
184184

185185
/// The time this session was finished
186186
pub finished_at: Option<DateTime<Utc>>,
187+
188+
/// The user-provided name, if any
189+
pub human_name: Option<String>,
187190
}
188191

189192
impl
@@ -210,6 +213,7 @@ impl
210213
last_active_at: session.last_active_at,
211214
last_active_ip: session.last_active_ip,
212215
finished_at,
216+
human_name: session.human_name,
213217
}
214218
}
215219
}
@@ -237,6 +241,7 @@ impl CompatSession {
237241
last_active_at: Some(DateTime::default()),
238242
last_active_ip: Some([1, 2, 3, 4].into()),
239243
finished_at: None,
244+
human_name: Some("Laptop".to_owned()),
240245
},
241246
Self {
242247
id: Ulid::from_bytes([0x02; 16]),
@@ -249,6 +254,7 @@ impl CompatSession {
249254
last_active_at: Some(DateTime::default()),
250255
last_active_ip: Some([1, 2, 3, 4].into()),
251256
finished_at: Some(DateTime::default()),
257+
human_name: None,
252258
},
253259
Self {
254260
id: Ulid::from_bytes([0x03; 16]),
@@ -261,6 +267,7 @@ impl CompatSession {
261267
last_active_at: None,
262268
last_active_ip: None,
263269
finished_at: None,
270+
human_name: None,
264271
},
265272
]
266273
}
@@ -301,6 +308,9 @@ pub struct OAuth2Session {
301308

302309
/// The last IP address used by the session
303310
last_active_ip: Option<IpAddr>,
311+
312+
/// The user-provided name, if any
313+
human_name: Option<String>,
304314
}
305315

306316
impl From<mas_data_model::Session> for OAuth2Session {
@@ -316,6 +326,7 @@ impl From<mas_data_model::Session> for OAuth2Session {
316326
user_agent: session.user_agent,
317327
last_active_at: session.last_active_at,
318328
last_active_ip: session.last_active_ip,
329+
human_name: session.human_name,
319330
}
320331
}
321332
}
@@ -335,6 +346,7 @@ impl OAuth2Session {
335346
user_agent: Some("Mozilla/5.0".to_owned()),
336347
last_active_at: Some(DateTime::default()),
337348
last_active_ip: Some("127.0.0.1".parse().unwrap()),
349+
human_name: Some("Laptop".to_owned()),
338350
},
339351
Self {
340352
id: Ulid::from_bytes([0x02; 16]),
@@ -347,6 +359,7 @@ impl OAuth2Session {
347359
user_agent: None,
348360
last_active_at: None,
349361
last_active_ip: None,
362+
human_name: None,
350363
},
351364
Self {
352365
id: Ulid::from_bytes([0x03; 16]),
@@ -359,6 +372,7 @@ impl OAuth2Session {
359372
user_agent: Some("Mozilla/5.0".to_owned()),
360373
last_active_at: Some(DateTime::default()),
361374
last_active_ip: Some("127.0.0.1".parse().unwrap()),
375+
human_name: None,
362376
},
363377
]
364378
}

docs/api/spec.json

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@
132132
"user_agent": "Mozilla/5.0",
133133
"last_active_at": "1970-01-01T00:00:00Z",
134134
"last_active_ip": "1.2.3.4",
135-
"finished_at": null
135+
"finished_at": null,
136+
"human_name": "Laptop"
136137
},
137138
"links": {
138139
"self": "/api/admin/v1/compat-sessions/01040G2081040G2081040G2081"
@@ -150,7 +151,8 @@
150151
"user_agent": "Mozilla/5.0",
151152
"last_active_at": "1970-01-01T00:00:00Z",
152153
"last_active_ip": "1.2.3.4",
153-
"finished_at": "1970-01-01T00:00:00Z"
154+
"finished_at": "1970-01-01T00:00:00Z",
155+
"human_name": null
154156
},
155157
"links": {
156158
"self": "/api/admin/v1/compat-sessions/02081040G2081040G2081040G2"
@@ -168,7 +170,8 @@
168170
"user_agent": null,
169171
"last_active_at": null,
170172
"last_active_ip": null,
171-
"finished_at": null
173+
"finished_at": null,
174+
"human_name": null
172175
},
173176
"links": {
174177
"self": "/api/admin/v1/compat-sessions/030C1G60R30C1G60R30C1G60R3"
@@ -245,7 +248,8 @@
245248
"user_agent": "Mozilla/5.0",
246249
"last_active_at": "1970-01-01T00:00:00Z",
247250
"last_active_ip": "1.2.3.4",
248-
"finished_at": null
251+
"finished_at": null,
252+
"human_name": "Laptop"
249253
},
250254
"links": {
251255
"self": "/api/admin/v1/compat-sessions/01040G2081040G2081040G2081"
@@ -430,7 +434,8 @@
430434
"scope": "openid",
431435
"user_agent": "Mozilla/5.0",
432436
"last_active_at": "1970-01-01T00:00:00Z",
433-
"last_active_ip": "127.0.0.1"
437+
"last_active_ip": "127.0.0.1",
438+
"human_name": "Laptop"
434439
},
435440
"links": {
436441
"self": "/api/admin/v1/oauth2-sessions/01040G2081040G2081040G2081"
@@ -448,7 +453,8 @@
448453
"scope": "urn:mas:admin",
449454
"user_agent": null,
450455
"last_active_at": null,
451-
"last_active_ip": null
456+
"last_active_ip": null,
457+
"human_name": null
452458
},
453459
"links": {
454460
"self": "/api/admin/v1/oauth2-sessions/02081040G2081040G2081040G2"
@@ -466,7 +472,8 @@
466472
"scope": "urn:matrix:org.matrix.msc2967.client:api:*",
467473
"user_agent": "Mozilla/5.0",
468474
"last_active_at": "1970-01-01T00:00:00Z",
469-
"last_active_ip": "127.0.0.1"
475+
"last_active_ip": "127.0.0.1",
476+
"human_name": null
470477
},
471478
"links": {
472479
"self": "/api/admin/v1/oauth2-sessions/030C1G60R30C1G60R30C1G60R3"
@@ -560,7 +567,8 @@
560567
"scope": "openid",
561568
"user_agent": "Mozilla/5.0",
562569
"last_active_at": "1970-01-01T00:00:00Z",
563-
"last_active_ip": "127.0.0.1"
570+
"last_active_ip": "127.0.0.1",
571+
"human_name": "Laptop"
564572
},
565573
"links": {
566574
"self": "/api/admin/v1/oauth2-sessions/01040G2081040G2081040G2081"
@@ -2726,6 +2734,11 @@
27262734
"type": "string",
27272735
"format": "date-time",
27282736
"nullable": true
2737+
},
2738+
"human_name": {
2739+
"description": "The user-provided name, if any",
2740+
"type": "string",
2741+
"nullable": true
27292742
}
27302743
}
27312744
},
@@ -3001,6 +3014,11 @@
30013014
"type": "string",
30023015
"format": "ip",
30033016
"nullable": true
3017+
},
3018+
"human_name": {
3019+
"description": "The user-provided name, if any",
3020+
"type": "string",
3021+
"nullable": true
30043022
}
30053023
}
30063024
},

0 commit comments

Comments
 (0)