the settings page says whether the feed is alive: a read-only Connection card under the profile panel names the issuer and the client id straight from the config, shows the directory stream as a green Connected dot while /directory/live is open and amber Reconnecting from the moment it ends or fails, and ages the last roster event honestly off the sync task's atomics — the client secret is never read on any path that reaches the render, every signed-in reader may see it because nothing here is per-user data, and both wordings ride the Key enum in English and Turkish
Browse files at this commit72751ff99e27672f90e7680e6596df6ed9b681ddParent: 3134bfa6 changed files +205 -4
- crates/in-web/src/i18n.rs +21 -0
- crates/in-web/src/main.rs +27 -3
- crates/in-web/src/server.rs +64 -0
- crates/in-web/src/settings.rs +39 -1
- crates/in-web/tests/http.rs +53 -0
- style/main.scss +1 -0
crates/in-web/src/i18n.rsmodified+21 -0
| @@ -164,6 +164,13 @@ pub enum Key { | ||
| 164 | 164 | // Settings. |
| 165 | 165 | Settings, |
| 166 | 166 | Profile, |
| 167 | + Connection, | |
| 168 | + ConnectionIssuer, | |
| 169 | + ConnectionClientId, | |
| 170 | + ConnectionStream, | |
| 171 | + ConnectionConnected, | |
| 172 | + ConnectionReconnecting, | |
| 173 | + ConnectionLastEvent, | |
| 167 | 174 | DisplayName, |
| 168 | 175 | EmailAddress, |
| 169 | 176 | QuotaUsage, |
| @@ -335,6 +342,13 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | ||
| 335 | 342 | Profile => "Profile", |
| 336 | 343 | DisplayName => "Name", |
| 337 | 344 | EmailAddress => "Address", |
| 345 | + Connection => "Connection", | |
| 346 | + ConnectionIssuer => "Issuer", | |
| 347 | + ConnectionClientId => "Client ID", | |
| 348 | + ConnectionStream => "Directory stream", | |
| 349 | + ConnectionConnected => "Connected", | |
| 350 | + ConnectionReconnecting => "Reconnecting…", | |
| 351 | + ConnectionLastEvent => "Last event", | |
| 338 | 352 | QuotaUsage => "Storage used", |
| 339 | 353 | QuotaOf => "of", |
| 340 | 354 | AdminPanel => "Everyone", |
| @@ -499,6 +513,13 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | ||
| 499 | 513 | EmailAddress => "Adres", |
| 500 | 514 | QuotaUsage => "Kullanılan alan", |
| 501 | 515 | QuotaOf => "/", |
| 516 | + Connection => "Bağlantı", | |
| 517 | + ConnectionIssuer => "Sağlayıcı", | |
| 518 | + ConnectionClientId => "İstemci kimliği", | |
| 519 | + ConnectionStream => "Dizin akışı", | |
| 520 | + ConnectionConnected => "Bağlı", | |
| 521 | + ConnectionReconnecting => "Yeniden bağlanıyor…", | |
| 522 | + ConnectionLastEvent => "Son etkinlik", | |
| 502 | 523 | AdminPanel => "Herkes", |
| 503 | 524 | AllUsers => "Herkes", |
| 504 | 525 | SetQuota => "Kotayı ayarla", |
crates/in-web/src/main.rsmodified+27 -3
| @@ -222,7 +222,13 @@ async fn main() { | ||
| 222 | 222 | config.oidc.client_secret.clone(), |
| 223 | 223 | ); |
| 224 | 224 | let default_quota_bytes = config.default_quota_bytes; |
| 225 | - tokio::spawn(identity_sync(store.clone(), directory.clone(), default_quota_bytes)); | |
| 225 | + let health = in_web::server::DirectoryHealth::new(); | |
| 226 | + tokio::spawn(identity_sync( | |
| 227 | + store.clone(), | |
| 228 | + directory.clone(), | |
| 229 | + default_quota_bytes, | |
| 230 | + health.clone(), | |
| 231 | + )); | |
| 226 | 232 | |
| 227 | 233 | // The suite the switcher's wordmarks link to is im's to keep: im's |
| 228 | 234 | // admin panel owns the list and `/family` serves it to registered |
| @@ -272,6 +278,7 @@ async fn main() { | ||
| 272 | 278 | shutdown: in_web::live::Shutdown(stopping), |
| 273 | 279 | link_key: cookie_key, |
| 274 | 280 | directory, |
| 281 | + health, | |
| 275 | 282 | }) |
| 276 | 283 | .app_context(in_client::LogoutBack(Arc::new(|cx: &Cx| { |
| 277 | 284 | Box::pin(async move { Some(in_web::server::share_origin(cx).await) }) |
| @@ -392,6 +399,7 @@ async fn identity_sync( | ||
| 392 | 399 | store: Arc<dyn in_core::store::Store>, |
| 393 | 400 | client: im_client::directory::DirectoryClient, |
| 394 | 401 | default_quota_bytes: u64, |
| 402 | + health: in_web::server::DirectoryHealth, | |
| 395 | 403 | ) { |
| 396 | 404 | let mut backoff = std::time::Duration::from_secs(1); |
| 397 | 405 | loop { |
| @@ -403,29 +411,45 @@ async fn identity_sync( | ||
| 403 | 411 | } |
| 404 | 412 | match client.open_stream().await { |
| 405 | 413 | Ok(mut stream) => { |
| 414 | + health.connected(); | |
| 406 | 415 | while let Some(event) = stream.next().await { |
| 407 | 416 | match event { |
| 408 | 417 | Ok(im_client::directory::DirectoryEvent::Profile(member)) => { |
| 409 | 418 | mirror_member(&store, &member, default_quota_bytes).await; |
| 419 | + // Every event is proof the feed is alive; | |
| 420 | + // the card's age line reads this. | |
| 421 | + health.note_event(); | |
| 410 | 422 | } |
| 411 | 423 | // A network failure ends the stream; the full |
| 412 | 424 | // pass below re-lists before the redial. |
| 413 | 425 | Err(problem) => { |
| 426 | + health.reconnecting(); | |
| 414 | 427 | eprintln!("in: directory stream failed: {problem}"); |
| 415 | 428 | break; |
| 416 | 429 | } |
| 417 | 430 | } |
| 418 | 431 | } |
| 432 | + // The stream closed cleanly — im restarting or its | |
| 433 | + // window running out. The card goes amber until the | |
| 434 | + // redial below opens the next one. | |
| 435 | + health.reconnecting(); | |
| 436 | + } | |
| 437 | + Err(problem) => { | |
| 438 | + health.reconnecting(); | |
| 439 | + eprintln!("in: directory stream refused: {problem}") | |
| 419 | 440 | } |
| 420 | - Err(problem) => eprintln!("in: directory stream refused: {problem}"), | |
| 421 | 441 | } |
| 422 | 442 | } |
| 423 | - Err(problem) => eprintln!("in: directory pass failed: {problem}"), | |
| 443 | + Err(problem) => { | |
| 444 | + health.reconnecting(); | |
| 445 | + eprintln!("in: directory pass failed: {problem}") | |
| 446 | + } | |
| 424 | 447 | } |
| 425 | 448 | tokio::time::sleep(backoff).await; |
| 426 | 449 | backoff = (backoff * 2).min(IDENTITY_BACKOFF_CAP); |
| 427 | 450 | } |
| 428 | 451 | } |
| 452 | + | |
| 429 | 453 | /// How often the suite list is re-fetched from im. Short enough that a |
| 430 | 454 | /// service the admin adds over there shows up here before anyone goes |
| 431 | 455 | /// looking for its wordmark, long enough that the two are not talking |
crates/in-web/src/server.rsmodified+64 -0
| @@ -45,6 +45,70 @@ pub struct App { | ||
| 45 | 45 | /// change feed — authenticated with the same client pair the OIDC side |
| 46 | 46 | /// holds. Built once at boot; cheap to clone. |
| 47 | 47 | pub directory: im_client::directory::DirectoryClient, |
| 48 | + /// Whether the directory's live stream is up, read by the settings | |
| 49 | + /// page's Connection card. Atomics, not locks: the sync task writes | |
| 50 | + /// from its own loop, every settings render reads, neither ever blocks. | |
| 51 | + pub health: DirectoryHealth, | |
| 52 | +} | |
| 53 | + | |
| 54 | +/// The live state of the identity-directory connection, as the Connection | |
| 55 | +/// card displays it. Cloned freely; every clone sees the same atomics. | |
| 56 | +#[derive(Clone, Debug)] | |
| 57 | +pub struct DirectoryHealth { | |
| 58 | + /// 1 while `/directory/live` is open, 0 while connecting or | |
| 59 | + /// re-connecting — the boot default is 0, and every stream end or | |
| 60 | + /// error returns it there until the next open. | |
| 61 | + stream: Arc<std::sync::atomic::AtomicU8>, | |
| 62 | + /// Unix seconds of the last roster event the stream delivered; 0 is | |
| 63 | + /// never. The age a card shows is derived at read time, so a stale | |
| 64 | + /// moment ages honestly without a ticking task behind it. | |
| 65 | + last_event: Arc<std::sync::atomic::AtomicI64>, | |
| 66 | +} | |
| 67 | + | |
| 68 | +impl DirectoryHealth { | |
| 69 | + pub fn new() -> Self { | |
| 70 | + Self { | |
| 71 | + stream: Arc::new(std::sync::atomic::AtomicU8::new(0)), | |
| 72 | + last_event: Arc::new(std::sync::atomic::AtomicI64::new(0)), | |
| 73 | + } | |
| 74 | + } | |
| 75 | + | |
| 76 | + /// The stream opened. | |
| 77 | + pub fn connected(&self) { | |
| 78 | + use std::sync::atomic::Ordering::Relaxed; | |
| 79 | + self.stream.store(1, Relaxed); | |
| 80 | + } | |
| 81 | + | |
| 82 | + /// The stream ended or failed; the task will dial again. | |
| 83 | + pub fn reconnecting(&self) { | |
| 84 | + use std::sync::atomic::Ordering::Relaxed; | |
| 85 | + self.stream.store(0, Relaxed); | |
| 86 | + } | |
| 87 | + | |
| 88 | + /// A roster event came through the live stream: it is connected, and | |
| 89 | + /// this is the moment it last said anything. | |
| 90 | + pub fn note_event(&self) { | |
| 91 | + use std::sync::atomic::Ordering::Relaxed; | |
| 92 | + self.stream.store(1, Relaxed); | |
| 93 | + self.last_event.store(now_unix(), Relaxed); | |
| 94 | + } | |
| 95 | + | |
| 96 | + /// Whether the card shows the green dot. | |
| 97 | + pub fn stream_connected(&self) -> bool { | |
| 98 | + use std::sync::atomic::Ordering::Relaxed; | |
| 99 | + self.stream.load(Relaxed) == 1 | |
| 100 | + } | |
| 101 | + | |
| 102 | + /// Seconds since the last roster event, or `None` before the first one. | |
| 103 | + pub fn last_event_age_secs(&self) -> Option<i64> { | |
| 104 | + use std::sync::atomic::Ordering::Relaxed; | |
| 105 | + let at = self.last_event.load(Relaxed); | |
| 106 | + (at > 0).then(|| (now_unix() - at).max(0)) | |
| 107 | + } | |
| 108 | +} | |
| 109 | + | |
| 110 | +fn now_unix() -> i64 { | |
| 111 | + time::OffsetDateTime::now_utc().unix_timestamp() | |
| 48 | 112 | } |
| 49 | 113 | |
| 50 | 114 | /// The application context this request runs under. |
crates/in-web/src/settings.rsmodified+39 -1
| @@ -301,7 +301,13 @@ async fn settings(cx: &Cx) -> Result { | ||
| 301 | 301 | } |
| 302 | 302 | }; |
| 303 | 303 | let language = lang(cx).await; |
| 304 | - let store = app(cx).store; | |
| 304 | + let app = app(cx); | |
| 305 | + let store = app.store; | |
| 306 | + // The Connection card reads only what the config already carries and | |
| 307 | + // the sync task's own atomics — the client secret is never touched on | |
| 308 | + // any path that reaches this render. | |
| 309 | + let connected = app.health.stream_connected(); | |
| 310 | + let last_event = app.health.last_event_age_secs(); | |
| 305 | 311 | // Re-read the row so the quota bar never shows a stale number. |
| 306 | 312 | let fresh = store.user(&user.id).await?.unwrap_or_else(|| user.clone()); |
| 307 | 313 | let administers = fresh.admin; |
| @@ -438,6 +444,38 @@ async fn settings(cx: &Cx) -> Result { | ||
| 438 | 444 | </form> |
| 439 | 445 | </div> |
| 440 | 446 | </section> |
| 447 | + // The Connection card: who this app talks to, and whether | |
| 448 | + // the live feed is up right now. Read-only, every | |
| 449 | + // signed-in reader — nothing here is per-user data. | |
| 450 | + <section class="panel"> | |
| 451 | + <div class="panel-head"> | |
| 452 | + <h2 class="panel-title">(t(language, Key::Connection))</h2> | |
| 453 | + </div> | |
| 454 | + <div class="panel-body"> | |
| 455 | + <div class="field"> | |
| 456 | + <span class="field-label">(t(language, Key::ConnectionIssuer))</span> | |
| 457 | + <span class="field-static">(app.config.oidc.issuer.clone())</span> | |
| 458 | + </div> | |
| 459 | + <div class="field"> | |
| 460 | + <span class="field-label">(t(language, Key::ConnectionClientId))</span> | |
| 461 | + <span class="field-static">(app.config.oidc.client_id.clone())</span> | |
| 462 | + </div> | |
| 463 | + <div class="field"> | |
| 464 | + <span class="field-label">(t(language, Key::ConnectionStream))</span> | |
| 465 | + <span class="field-static"> | |
| 466 | + <span class=(if connected { "status-dot status-dot-done" } else { "status-dot status-dot-warn" })></span> | |
| 467 | + if connected { | |
| 468 | + (t(language, Key::ConnectionConnected)) | |
| 469 | + } else { | |
| 470 | + (t(language, Key::ConnectionReconnecting)) | |
| 471 | + } | |
| 472 | + if let Some(age) = last_event { | |
| 473 | + <span class="field-note">(format!("{} · {}s", t(language, Key::ConnectionLastEvent), age))</span> | |
| 474 | + } | |
| 475 | + </span> | |
| 476 | + </div> | |
| 477 | + </div> | |
| 478 | + </section> | |
| 441 | 479 | } |
| 442 | 480 | if section == Section::Links { |
| 443 | 481 | if let Some(token) = created { |
crates/in-web/tests/http.rsmodified+53 -0
| @@ -312,6 +312,7 @@ struct TestApp { | ||
| 312 | 312 | config: Config, |
| 313 | 313 | client: in_client::Config, |
| 314 | 314 | fake: FakeIm, |
| 315 | + health: in_web::server::DirectoryHealth, | |
| 315 | 316 | stop: tokio::sync::watch::Sender<bool>, |
| 316 | 317 | } |
| 317 | 318 | |
| @@ -378,6 +379,7 @@ impl TestApp { | ||
| 378 | 379 | defaulted: false, |
| 379 | 380 | }; |
| 380 | 381 | let (stop, stopping) = tokio::sync::watch::channel(false); |
| 382 | + let health = in_web::server::DirectoryHealth::new(); | |
| 381 | 383 | let router = in_client::mount( |
| 382 | 384 | Router::builder() |
| 383 | 385 | .discover() |
| @@ -402,6 +404,7 @@ impl TestApp { | ||
| 402 | 404 | "in-test".to_string(), |
| 403 | 405 | "s3cr3t".to_string(), |
| 404 | 406 | ), |
| 407 | + health: health.clone(), | |
| 405 | 408 | }) |
| 406 | 409 | .app_context(in_client::LogoutBack(Arc::new(|cx: &Cx| { |
| 407 | 410 | Box::pin(async move { Some(in_web::server::share_origin(cx).await) }) |
| @@ -414,6 +417,7 @@ impl TestApp { | ||
| 414 | 417 | config, |
| 415 | 418 | client, |
| 416 | 419 | fake, |
| 420 | + health, | |
| 417 | 421 | stop, |
| 418 | 422 | } |
| 419 | 423 | } |
| @@ -5293,3 +5297,52 @@ async fn an_empty_folder_says_how_to_fill_it() { | ||
| 5293 | 5297 | assert!(body.contains("id=\"upload-form\""), "{body}"); |
| 5294 | 5298 | assert!(body.contains("__inDrop"), "{body}"); |
| 5295 | 5299 | } |
| 5300 | + | |
| 5301 | +/// The settings Connection card reads the shared health the sync task | |
| 5302 | +/// writes: the issuer and the client id straight from the config, the | |
| 5303 | +/// stream wording from the state atomics, and never the client secret — | |
| 5304 | +/// the one value the card must not carry onto any page. | |
| 5305 | +#[tokio::test] | |
| 5306 | +async fn connection_card_shows_issuer_client_id_and_stream_state() { | |
| 5307 | + let app = TestApp::build().await; | |
| 5308 | + let cookie = app.sign_in("sub-conn", "conn@in.test", "Conn").await; | |
| 5309 | + | |
| 5310 | + // A fresh process has never opened the stream: the card is amber. | |
| 5311 | + let page = app.get("/settings", Some(&cookie)).await; | |
| 5312 | + assert_eq!(page.status, StatusCode::OK); | |
| 5313 | + let body = page.text(); | |
| 5314 | + assert!(body.contains("Connection"), "no card title: {body}"); | |
| 5315 | + assert!( | |
| 5316 | + body.contains(app.config.oidc.issuer.as_str()), | |
| 5317 | + "no issuer: {body}" | |
| 5318 | + ); | |
| 5319 | + assert!( | |
| 5320 | + body.contains("in-test"), | |
| 5321 | + "no client id: {body}" | |
| 5322 | + ); | |
| 5323 | + assert!(body.contains("Reconnecting"), "no amber wording: {body}"); | |
| 5324 | + assert!(body.contains("status-dot-warn"), "no amber dot: {body}"); | |
| 5325 | + assert!( | |
| 5326 | + !body.contains("s3cr3t"), | |
| 5327 | + "the client secret reached the page: {body}" | |
| 5328 | + ); | |
| 5329 | + | |
| 5330 | + // The sync task opens the stream: green, and the age line appears once | |
| 5331 | + // an event has come through. | |
| 5332 | + app.health.connected(); | |
| 5333 | + app.health.note_event(); | |
| 5334 | + let page = app.get("/settings", Some(&cookie)).await; | |
| 5335 | + let body = page.text(); | |
| 5336 | + assert!(body.contains("Connected"), "no green wording: {body}"); | |
| 5337 | + assert!(body.contains("status-dot-done"), "no green dot: {body}"); | |
| 5338 | + assert!(!body.contains("Reconnecting"), "amber lingered: {body}"); | |
| 5339 | + assert!(body.contains("Last event"), "no age line: {body}"); | |
| 5340 | + | |
| 5341 | + // The stream ends: amber again, no event line retraction needed — the | |
| 5342 | + // last event stays but the wording names the truth. | |
| 5343 | + app.health.reconnecting(); | |
| 5344 | + let page = app.get("/settings", Some(&cookie)).await; | |
| 5345 | + let body = page.text(); | |
| 5346 | + assert!(body.contains("Reconnecting"), "no amber return: {body}"); | |
| 5347 | + assert!(!body.contains("status-dot-done"), "green lingered: {body}"); | |
| 5348 | +} |
style/main.scssmodified+1 -0
| @@ -2305,6 +2305,7 @@ img.avatar { | ||
| 2305 | 2305 | } |
| 2306 | 2306 | |
| 2307 | 2307 | .status-dot-done { background: var(--positive); } |
| 2308 | +.status-dot-warn { background: var(--warn-ink); } | |
| 2308 | 2309 | |
| 2309 | 2310 | // The select carries no chrome of its own: the box around it is the control. |
| 2310 | 2311 | .status-select { |