forge
Explore
Log in

Don't you dare go Hollow

The suite in the topbar, and a logout that ends the central session

Browse files at this commit

dbbff0d7ba62697a425fd7d3501cdbce8a5430f5Ahmet Kaan GümüşParent: a311758
  • feat
    • the suite in the topbar, and a logout that ends the central session
Show full message
feat(web): the suite in the topbar, and a logout that ends the central session

[[services]] entries render as a switcher beside the page nav (the app
you are in marked like the nav marks itself); no entries, no switcher.
Clearing the local cookie now walks the browser on to im's /logout with
this app's public address as back, so the central session ends too.
in-client grows logout_back for that. Carries the dev values in
config/in.toml (loopback issuer, in-dev-capture client, dev secret,
resolved storage line) and the [storage.r2] doc block from the storage
slice.
config/in.tomlmodified+57 -3
@@ -20,16 +20,70 @@ base_url = ""
20 # created on boot. Not written here: it defaults to beside the database file,20 # created on boot. Not written here: it defaults to beside the database file,
21 # and the boot completes this file with the value it resolved.21 # and the boot completes this file with the value it resolved.
22 22
23+# The suite the signed-in chrome's switcher links to: one [[services]]
24+# table per app — `key` the word the switcher renders, `name` its hover
25+# label, `url` the address the link points at (scheme and host, no
26+# trailing slash). In names itself among them so the switcher can mark
27+# where the reader is. Production sets these on the deploy side as
28+# https://<key>.dizey.sh; this committed copy carries only the
29+# development addresses.
30+# Where drive files, thumbnails and staged upload chunks live as files, created on boot.
31+storage = "/home/tahinli/Documents/Code/Rust/in/storage"
32+
33+[[services]]
34+key = "in"
35+name = "Files"
36+url = "http://127.0.0.1:7655"
37+
38+[[services]]
39+key = "im"
40+name = "Account"
41+url = "http://127.0.0.1:7650"
42+
43+[[services]]
44+key = "iz"
45+name = "Board"
46+url = "http://127.0.0.1:7654"
47+
23 [oidc]48 [oidc]
24 # The provider that signs people in. Required: no default is guessed.49 # The provider that signs people in. Required: no default is guessed.
25-issuer = ""50+issuer = "http://127.0.0.1:7650"
26 # The client id In presents to the provider. Required.51 # The client id In presents to the provider. Required.
27-client_id = ""52+client_id = "in-dev-capture"
28 # The client secret In presents to the provider. Required. Filled in only on53 # The client secret In presents to the provider. Required. Filled in only on
29 # the machine that runs the server — the committed copy stays empty.54 # the machine that runs the server — the committed copy stays empty.
30-client_secret = ""55+client_secret = "in-dev-secret"
31 # Where the provider sends the browser back after sign-in. Not written here:56 # Where the provider sends the browser back after sign-in. Not written here:
32 # it defaults from `listen` on every boot, so moving the address never leaves57 # it defaults from `listen` on every boot, so moving the address never leaves
33 # a stale callback behind. Set it only when the public address differs from58 # a stale callback behind. Set it only when the public address differs from
34 # the bind address (a proxy in front, for instance).59 # the bind address (a proxy in front, for instance).
35 # redirect_uri = "http://127.0.0.1:7655/auth/callback"60 # redirect_uri = "http://127.0.0.1:7655/auth/callback"
61+
62+# Where the file bytes themselves live. With no [storage.r2] table, the
63+# bytes stay on local disk in the `storage` tree (files/ and thumbs/ beside
64+# the database) — the default, and the only shape every other key here
65+# describes.
66+#
67+# Setting [storage.r2] moves the file and thumbnail bytes into a Cloudflare
68+# R2 bucket. The database keeps every row, quota and piece of metadata —
69+# only the bytes move. `storage` still names the local tree either way:
70+# upload chunks stage there, then stream up to the bucket.
71+#
72+# [storage.r2]
73+# account_id — the R2 account id; the endpoint becomes
74+# https://<account_id>.r2.cloudflarestorage.com
75+# bucket — the bucket the blobs land in, under files/ and thumbs/ — the same
76+# layout the local tree uses, so an rclone maps one onto the other.
77+# key_file — a path (resolved against this config directory) to a file with
78+# two lines: the R2 access key id on the first, the secret on the second.
79+# Create it readable only by the user the server runs as (0600); it is
80+# read once at boot and never logged:
81+# (umask 077 && printf '%s\n%s\n' '<access key id>' '<secret>' > config/r2.keys)
82+#
83+# Absence is meaningful: no table, no bucket, local bytes. Nothing here is
84+# ever completed into the file for you.
85+#
86+# Migrating an existing deployment's bytes into the bucket — database and
87+# storage tree stay where they are; run once with the server stopped:
88+# rclone copy <storage>/files :r2,account=<id>,key=<id>:<bucket>/files
89+# rclone copy <storage>/thumbs :r2,account=<id>,key=<id>:<bucket>/thumbs
crates/in-client/examples/mint.rsmodified+1 -0
@@ -29,6 +29,7 @@ fn main() {
29 redirect_uri: String::new(),29 redirect_uri: String::new(),
30 cookie_name,30 cookie_name,
31 cookie_key: key,31 cookie_key: key,
32+ logout_back: String::new(),
32 };33 };
33 let exp = time::OffsetDateTime::now_utc() + time::Duration::days(1);34 let exp = time::OffsetDateTime::now_utc() + time::Duration::days(1);
34 println!("{}", in_client::mint_session_cookie(&config, &token, exp));35 println!("{}", in_client::mint_session_cookie(&config, &token, exp));
crates/in-client/src/lib.rsmodified+46 -4
@@ -44,6 +44,13 @@ pub struct Config {
44 pub cookie_name: String,44 pub cookie_name: String,
45 /// 32 bytes, generated once per app and kept out of the repository.45 /// 32 bytes, generated once per app and kept out of the repository.
46 pub cookie_key: [u8; 32],46 pub cookie_key: [u8; 32],
47+ /// The app's public origin — `base_url` when the file sets one, else
48+ /// the address bound, derived the way the app derives its public links.
49+ /// After clearing the local cookie, `/auth/logout` walks the browser on
50+ /// to im's `/logout?back={logout_back}/`, so the central session ends
51+ /// and the person lands back at this app's front door. Empty is legal —
52+ /// im catches a stray `back` on its own `/` — but a real app sets it.
53+ pub logout_back: String,
47 }54 }
48 55
49 /// The registered state: the config, one HTTP client, and the JWKS cache.56 /// The registered state: the config, one HTTP client, and the JWKS cache.
@@ -534,12 +541,24 @@ async fn in_callback(cx: &Cx) -> Result<Response, topcoat::Error> {
534 }541 }
535 }542 }
536 543
537-/// Signs out of the app only. To end the central session too, post to im's544+/// Signs out of the app, then out of im: the local cookie is cleared
538-/// `/logout` — a link there is a silent re-login, by design.545+/// first — this app forgets the person even if the central hop never
546+/// lands — and the browser is sent on to im's `/logout` with this app's
547+/// public address as `back`. im revokes the central session and returns
548+/// them here. The hop is a top-level navigation (the user menu's sign-out
549+/// link carries `data-hard`), never a fetch.
539 #[route(GET "/auth/logout")]550 #[route(GET "/auth/logout")]
540 async fn in_logout(cx: &Cx) -> Result<Response, topcoat::Error> {551 async fn in_logout(cx: &Cx) -> Result<Response, topcoat::Error> {
541- clear_cookie(cx, &client(cx).config.cookie_name);552+ let state = client(cx);
542- see(cx, "/")553+ clear_cookie(cx, &state.config.cookie_name);
554+ see(
555+ cx,
556+ &format!(
557+ "{}/logout?back={}",
558+ state.config.issuer,
559+ urlencoded(&format!("{}/", state.config.logout_back)),
560+ ),
561+ )
543 }562 }
544 563
545 fn urlencoded(raw: &str) -> String {564 fn urlencoded(raw: &str) -> String {
@@ -859,6 +878,7 @@ mod tests {
859 redirect_uri: "http://app.test/auth/callback".into(),878 redirect_uri: "http://app.test/auth/callback".into(),
860 cookie_name: "in_session".into(),879 cookie_name: "in_session".into(),
861 cookie_key: [7u8; 32],880 cookie_key: [7u8; 32],
881+ logout_back: String::new(),
862 };882 };
863 assert_eq!(introspect_path(), "/introspect");883 assert_eq!(introspect_path(), "/introspect");
864 let exp = OffsetDateTime::now_utc() + time::Duration::hours(1);884 let exp = OffsetDateTime::now_utc() + time::Duration::hours(1);
@@ -916,6 +936,27 @@ mod tests {
916 );936 );
917 }937 }
918 938
939+ #[tokio::test]
940+ async fn logout_clears_the_cookie_and_walks_to_the_issuer() {
941+ let router = test_router(test_config("http://im.test".into()));
942+ let res = TestResponse::of(
943+ router
944+ .handle(get("/auth/logout", Some(&session_cookie("tok-1"))))
945+ .await,
946+ )
947+ .await;
948+ assert_eq!(res.status, http::StatusCode::SEE_OTHER);
949+ assert_eq!(
950+ res.location.as_deref(),
951+ Some("http://im.test/logout?back=http%3A%2F%2Fapp.test%2F"),
952+ "{}",
953+ res.text()
954+ );
955+ // This app forgets the person on the very answer, whatever im then
956+ // does with the central session.
957+ assert!(res.clears_session());
958+ }
959+
919 #[route(GET "/whoami")]960 #[route(GET "/whoami")]
920 async fn whoami(cx: &Cx) -> Result<Response, topcoat::Error> {961 async fn whoami(cx: &Cx) -> Result<Response, topcoat::Error> {
921 match current_user(cx).await {962 match current_user(cx).await {
@@ -932,6 +973,7 @@ mod tests {
932 redirect_uri: "http://app.test/auth/callback".into(),973 redirect_uri: "http://app.test/auth/callback".into(),
933 cookie_name: "in_session".into(),974 cookie_name: "in_session".into(),
934 cookie_key: [7u8; 32],975 cookie_key: [7u8; 32],
976+ logout_back: "http://app.test".into(),
935 }977 }
936 }978 }
937 979
crates/in-core/src/config.rsmodified+102 -0
@@ -302,6 +302,10 @@ pub struct Config {
302 /// banners that mint them — when the file sets one. `None` follows the302 /// banners that mint them — when the file sets one. `None` follows the
303 /// address bound.303 /// address bound.
304 pub base_url: Option<String>,304 pub base_url: Option<String>,
305+ /// The suite the signed-in chrome's switcher links to, from the
306+ /// `[[services]]` tables. An empty list is a file silent about any
307+ /// suite, and the chrome stays exactly as it has always been.
308+ pub services: Vec<ServiceConfig>,
305 /// The OIDC provider In trusts.309 /// The OIDC provider In trusts.
306 pub oidc: OidcConfig,310 pub oidc: OidcConfig,
307 /// Keys the file sets that nothing here reads, in the order the file311 /// Keys the file sets that nothing here reads, in the order the file
@@ -478,6 +482,22 @@ impl Config {
478 })?;482 })?;
479 }483 }
480 484
485+ // The suite the chrome's switcher links to. A silent list keeps the
486+ // single-app chrome; an entry present must be whole, because a
487+ // wordmark pointing nowhere is worse than none — and its url must
488+ // be joinable to a link for the same reason `base_url` must.
489+ let mut services = Vec::new();
490+ for (i, entry) in toml.services.unwrap_or_default().into_iter().enumerate() {
491+ let key = value(entry.key)
492+ .ok_or_else(|| service_error(i, "its key is missing or empty".into()))?;
493+ let name = value(entry.name)
494+ .ok_or_else(|| service_error(i, "its name is missing or empty".into()))?;
495+ let url = value(entry.url)
496+ .ok_or_else(|| service_error(i, "its url is missing or empty".into()))?;
497+ Config::validate_base_url(&url).map_err(|why| service_error(i, why))?;
498+ services.push(ServiceConfig { key, name, url });
499+ }
500+
481 let oidc_toml = toml.oidc.ok_or(ConfigError::Missing("[oidc]"))?;501 let oidc_toml = toml.oidc.ok_or(ConfigError::Missing("[oidc]"))?;
482 let issuer = value(oidc_toml.issuer).ok_or(ConfigError::Missing("oidc.issuer"))?;502 let issuer = value(oidc_toml.issuer).ok_or(ConfigError::Missing("oidc.issuer"))?;
483 let client_id = value(oidc_toml.client_id).ok_or(ConfigError::Missing("oidc.client_id"))?;503 let client_id = value(oidc_toml.client_id).ok_or(ConfigError::Missing("oidc.client_id"))?;
@@ -501,6 +521,7 @@ impl Config {
501 purge_after_days,521 purge_after_days,
502 default_quota_bytes,522 default_quota_bytes,
503 base_url,523 base_url,
524+ services,
504 oidc: OidcConfig {525 oidc: OidcConfig {
505 issuer,526 issuer,
506 client_id,527 client_id,
@@ -581,6 +602,15 @@ fn listen_url_of(listen: &SocketAddr) -> String {
581 }602 }
582 }603 }
583 604
605+/// The boot error for a `[[services]]` entry that is not whole. Entries are
606+/// numbered from one, so the message names the offender a human can find.
607+fn service_error(index: usize, why: String) -> ConfigError {
608+ ConfigError::Invalid {
609+ key: "services",
610+ why: format!("entry {}: {why}", index + 1),
611+ }
612+}
613+
584 impl Config {614 impl Config {
585 /// Whether a base URL is an origin a public link can be built on: an615 /// Whether a base URL is an origin a public link can be built on: an
586 /// `http` or `https` scheme and no trailing slash. Shared by the file's616 /// `http` or `https` scheme and no trailing slash. Shared by the file's
@@ -917,6 +947,78 @@ redirect_uri = "https://files.example.com/auth/callback"
917 ));947 ));
918 }948 }
919 949
950+ /// The switcher is off until the file names a suite: a `[[services]]`-less
951+ /// file is the chrome as it has always been, no half-rendered trio.
952+ #[test]
953+ fn a_file_without_services_leaves_the_switcher_off() {
954+ let scratch = Scratch::new();
955+ scratch.write(FULL);
956+ let config = scratch.load().unwrap();
957+ assert!(config.services.is_empty());
958+ }
959+
960+ #[test]
961+ fn services_parse_in_the_order_the_file_gives_them() {
962+ let scratch = Scratch::new();
963+ scratch.write(&FULL.replace(
964+ "[oidc]",
965+ "[[services]]\n\
966+ key = \"in\"\n\
967+ name = \"Files\"\n\
968+ url = \"https://files.example.com\"\n\
969+ \n\
970+ [[services]]\n\
971+ key = \"im\"\n\
972+ name = \"Account\"\n\
973+ url = \"https://id.example.com\"\n\
974+ [oidc]",
975+ ));
976+ let config = scratch.load().unwrap();
977+ assert_eq!(
978+ config.services,
979+ vec![
980+ ServiceConfig {
981+ key: "in".into(),
982+ name: "Files".into(),
983+ url: "https://files.example.com".into(),
984+ },
985+ ServiceConfig {
986+ key: "im".into(),
987+ name: "Account".into(),
988+ url: "https://id.example.com".into(),
989+ },
990+ ]
991+ );
992+ }
993+
994+ #[test]
995+ fn a_service_url_without_a_scheme_is_refused() {
996+ let scratch = Scratch::new();
997+ scratch.write(&FULL.replace(
998+ "[oidc]",
999+ "[[services]]\nkey = \"im\"\nname = \"Account\"\nurl = \"id.example.com\"\n[oidc]",
1000+ ));
1001+ assert!(matches!(
1002+ scratch.load().unwrap_err(),
1003+ ConfigError::Invalid { key: "services", .. }
1004+ ));
1005+ }
1006+
1007+ #[test]
1008+ fn an_incomplete_service_entry_names_the_offender() {
1009+ let scratch = Scratch::new();
1010+ scratch.write(&FULL.replace(
1011+ "[oidc]",
1012+ "[[services]]\nkey = \"im\"\nname = \"\"\nurl = \"https://id.example.com\"\n[oidc]",
1013+ ));
1014+ let err = scratch.load().unwrap_err();
1015+ assert!(matches!(
1016+ err,
1017+ ConfigError::Invalid { key: "services", .. }
1018+ ));
1019+ assert!(err.to_string().contains("entry 1"), "{err}");
1020+ }
1021+
920 #[test]1022 #[test]
921 fn zero_live_seconds_is_refused() {1023 fn zero_live_seconds_is_refused() {
922 let scratch = Scratch::new();1024 let scratch = Scratch::new();
crates/in-core/src/lib.rsmodified+1 -1
@@ -20,7 +20,7 @@ pub use store::{
20 };20 };
21 21
22 #[cfg(feature = "server")]22 #[cfg(feature = "server")]
23-pub use config::{Config, ConfigError, OidcConfig};23+pub use config::{Config, ConfigError, OidcConfig, ServiceConfig};
24 #[cfg(feature = "server")]24 #[cfg(feature = "server")]
25 pub use live::{Change, Topic, next_seq};25 pub use live::{Change, Topic, next_seq};
26 #[cfg(feature = "server")]26 #[cfg(feature = "server")]
crates/in-web/src/layout.rsmodified+39 -2
@@ -221,14 +221,51 @@ pub async fn topbar_nav(cx: &Cx, active: NavPage, lang: Lang) -> Result {
221 }221 }
222 }222 }
223 223
224-/// The signed-in chrome: the monogram, the page nav, the identity menu.224+/// This app's key in the `[[services]]` list: the entry matching it is the
225-/// Wave-2 pages render their content under this.225+/// one marked as where the reader already is.
226+const SELF_KEY: &str = "in";
227+
228+/// The topbar's suite switcher: every `[[services]]` entry as its wordmark,
229+/// beside the page nav, the current one marked. Rendered only when the file
230+/// names a suite — a file silent about the others keeps the chrome exactly
231+/// as it has always been. The links point at the services' own addresses,
232+/// so the cross-origin ones navigate the browser natively; this app's entry
233+/// lands where a soft-nav swap would have gone anyway.
234+async fn app_switcher(cx: &Cx) -> Result {
235+ let empty = app(cx).config.services.is_empty();
236+ view! {
237+ cx =>
238+ if !empty {
239+ <nav class="app-switcher">
240+ for service in &app(cx).config.services {
241+ <a
242+ class=(if service.key == SELF_KEY {
243+ "app-switcher-mark app-switcher-here"
244+ } else {
245+ "app-switcher-mark"
246+ })
247+ href=(format!("{}/", service.url))
248+ title=(service.name.clone())
249+ aria-current=((service.key == SELF_KEY).then_some("page"))
250+ >
251+ (service.key.clone())
252+ </a>
253+ }
254+ </nav>
255+ <span class="topbar-divider"></span>
256+ }
257+ }
258+}
259+
260+/// The signed-in chrome: the monogram, the page nav, the suite switcher,
261+/// the identity menu. Wave-2 pages render their content under this.
226 pub async fn topbar(cx: &Cx, active: NavPage, user: &User, lang: Lang) -> Result {262 pub async fn topbar(cx: &Cx, active: NavPage, user: &User, lang: Lang) -> Result {
227 view! {263 view! {
228 cx =>264 cx =>
229 <header class="topbar">265 <header class="topbar">
230 (mark(cx).await?)266 (mark(cx).await?)
231 (topbar_nav(cx, active, lang).await?)267 (topbar_nav(cx, active, lang).await?)
268+ (app_switcher(cx).await?)
232 (user_menu(cx, user, lang).await?)269 (user_menu(cx, user, lang).await?)
233 </header>270 </header>
234 (avatar_script(cx).await?)271 (avatar_script(cx).await?)
crates/in-web/src/main.rsmodified+3 -0
@@ -207,6 +207,9 @@ async fn main() {
207 redirect_uri: config.oidc.redirect_uri.clone(),207 redirect_uri: config.oidc.redirect_uri.clone(),
208 cookie_name: "in_session".to_string(),208 cookie_name: "in_session".to_string(),
209 cookie_key,209 cookie_key,
210+ // Where im's `/logout` sends the browser after the central
211+ // sign-out: the same origin public links carry.
212+ logout_back: config.public_origin(),
210 };213 };
211 214
212 // Told when the process is stopping, so the live streams end instead of215 // Told when the process is stopping, so the live streams end instead of
crates/in-web/tests/http.rsmodified+58 -7
@@ -9,14 +9,13 @@
9 //!9 //!
10 //! New HTTP tests belong in this file rather than a new `tests/*.rs`: one10 //! New HTTP tests belong in this file rather than a new `tests/*.rs`: one
11 //! test binary links and runs once.11 //! test binary links and runs once.
12-12+use in_core::{Config, OidcConfig, ServiceConfig};
13 use std::collections::HashMap;13 use std::collections::HashMap;
14 use std::path::PathBuf;14 use std::path::PathBuf;
15 use std::sync::{Arc, Mutex};15 use std::sync::{Arc, Mutex};
16 16
17 use http::{HeaderValue, Request, StatusCode, header};17 use http::{HeaderValue, Request, StatusCode, header};
18 use in_core::store::{ShareKind, Store, TursoStore};18 use in_core::store::{ShareKind, Store, TursoStore};
19-use in_core::{Config, OidcConfig};
20 use in_web::server::App;19 use in_web::server::App;
21 use topcoat::asset::{AssetBundle, RouterBuilderAssetExt};20 use topcoat::asset::{AssetBundle, RouterBuilderAssetExt};
22 use topcoat::cookie::RouterBuilderCookieExt;21 use topcoat::cookie::RouterBuilderCookieExt;
@@ -316,12 +315,13 @@ struct TestApp {
316 315
317 impl TestApp {316 impl TestApp {
318 async fn build() -> Self {317 async fn build() -> Self {
319- Self::build_with(None).await318+ Self::build_with(None, Vec::new()).await
320 }319 }
321 320
322 /// The same workspace with a config `base_url` set — the key that321 /// The same workspace with a config `base_url` set — the key that
323- /// decides where the public links are told to point.322+ /// decides where the public links are told to point — and optional
324- async fn build_with(base_url: Option<&str>) -> Self {323+ /// `[[services]]` entries, the suite the topbar's switcher links to.
324+ async fn build_with(base_url: Option<&str>, services: Vec<ServiceConfig>) -> Self {
325 let dir = std::env::temp_dir().join(format!("in-http-{}", Ulid::new()));325 let dir = std::env::temp_dir().join(format!("in-http-{}", Ulid::new()));
326 std::fs::create_dir_all(&dir).unwrap();326 std::fs::create_dir_all(&dir).unwrap();
327 let db = dir.join("in.db");327 let db = dir.join("in.db");
@@ -339,6 +339,7 @@ impl TestApp {
339 redirect_uri: "http://127.0.0.1:7655/auth/callback".to_string(),339 redirect_uri: "http://127.0.0.1:7655/auth/callback".to_string(),
340 cookie_name: "in_session".to_string(),340 cookie_name: "in_session".to_string(),
341 cookie_key: [7u8; 32],341 cookie_key: [7u8; 32],
342+ logout_back: "http://127.0.0.1:7655".to_string(),
342 };343 };
343 let config = Config {344 let config = Config {
344 database: db.to_str().unwrap().to_string(),345 database: db.to_str().unwrap().to_string(),
@@ -348,6 +349,7 @@ impl TestApp {
348 purge_after_days: 30,349 purge_after_days: 30,
349 default_quota_bytes: 10 * 1024 * 1024 * 1024,350 default_quota_bytes: 10 * 1024 * 1024 * 1024,
350 base_url: base_url.map(str::to_string),351 base_url: base_url.map(str::to_string),
352+ services,
351 r2: None,353 r2: None,
352 oidc: OidcConfig {354 oidc: OidcConfig {
353 issuer: fake.url(),355 issuer: fake.url(),
@@ -2693,6 +2695,55 @@ async fn topbar_nav_has_no_search_link() {
2693 assert!(!nav.contains("Search"), "search leaked into the nav: {nav}");2695 assert!(!nav.contains("Search"), "search leaked into the nav: {nav}");
2694 }2696 }
2695 2697
2698+#[tokio::test]
2699+async fn the_suite_switcher_renders_when_services_are_set() {
2700+ // No [[services]]: no switcher — the chrome as it always was.
2701+ let bare = TestApp::build().await;
2702+ let cookie = bare
2703+ .sign_in("sub-switch0", "switch0@in.test", "Switch0")
2704+ .await;
2705+ let page = bare.get("/drive", Some(&cookie)).await;
2706+ assert_eq!(page.status, StatusCode::OK, "{}", page.text());
2707+ assert!(!page.text().contains("app-switcher"), "{}", page.text());
2708+
2709+ let app = TestApp::build_with(
2710+ None,
2711+ vec![
2712+ ServiceConfig {
2713+ key: "in".into(),
2714+ name: "Files".into(),
2715+ url: "https://files.example.com".into(),
2716+ },
2717+ ServiceConfig {
2718+ key: "im".into(),
2719+ name: "Account".into(),
2720+ url: "https://id.example.com".into(),
2721+ },
2722+ ServiceConfig {
2723+ key: "iz".into(),
2724+ name: "Board".into(),
2725+ url: "https://board.example.com".into(),
2726+ },
2727+ ],
2728+ )
2729+ .await;
2730+ let cookie = app.sign_in("sub-switch", "switch@in.test", "Switch").await;
2731+ let page = app.get("/drive", Some(&cookie)).await;
2732+ assert_eq!(page.status, StatusCode::OK, "{}", page.text());
2733+ let body = page.text();
2734+ let nav_start = body.find("app-switcher").expect("no switcher");
2735+ let nav_end = body[nav_start..]
2736+ .find("</nav>")
2737+ .expect("switcher never closes");
2738+ let nav = &body[nav_start..nav_start + nav_end];
2739+ assert!(nav.contains("href=\"https://files.example.com/\""), "{nav}");
2740+ assert!(nav.contains("href=\"https://id.example.com/\""), "{nav}");
2741+ assert!(nav.contains("href=\"https://board.example.com/\""), "{nav}");
2742+ assert!(nav.contains("title=\"Files\""), "{nav}");
2743+ // Exactly the app the reader is already in is marked.
2744+ assert_eq!(nav.matches("aria-current").count(), 1, "{nav}");
2745+}
2746+
2696 // -- settings ---------------------------------------------------------------2747 // -- settings ---------------------------------------------------------------
2697 2748
2698 #[tokio::test]2749 #[tokio::test]
@@ -2791,7 +2842,7 @@ async fn settings_quota_and_disable_guards() {
2791 /// `base_url`.2842 /// `base_url`.
2792 #[tokio::test]2843 #[tokio::test]
2793 async fn share_links_carry_the_configured_base_url() {2844 async fn share_links_carry_the_configured_base_url() {
2794- let app = TestApp::build_with(Some("https://files.example.com")).await;2845+ let app = TestApp::build_with(Some("https://files.example.com"), Vec::new()).await;
2795 let admin = app.sign_in("sub-admin", "ada@in.test", "Ada").await;2846 let admin = app.sign_in("sub-admin", "ada@in.test", "Ada").await;
2796 let owner = owner_of(&app, "sub-admin").await;2847 let owner = owner_of(&app, "sub-admin").await;
2797 let file = file_id(&app, &owner, "notes.txt", b"hello in").await;2848 let file = file_id(&app, &owner, "notes.txt", b"hello in").await;
@@ -3118,7 +3169,7 @@ async fn server_address_setting_drives_share_links() {
3118 /// file sets one: the setting wins only while it is non-empty.3169 /// file sets one: the setting wins only while it is non-empty.
3119 #[tokio::test]3170 #[tokio::test]
3120 async fn cleared_setting_falls_back_to_the_configured_base_url() {3171 async fn cleared_setting_falls_back_to_the_configured_base_url() {
3121- let app = TestApp::build_with(Some("https://cfg.example.com")).await;3172+ let app = TestApp::build_with(Some("https://cfg.example.com"), Vec::new()).await;
3122 let admin = app.sign_in("sub-admin", "ada@in.test", "Ada").await;3173 let admin = app.sign_in("sub-admin", "ada@in.test", "Ada").await;
3123 let owner = owner_of(&app, "sub-admin").await;3174 let owner = owner_of(&app, "sub-admin").await;
3124 let file = file_id(&app, &owner, "notes.txt", b"hello in").await;3175 let file = file_id(&app, &owner, "notes.txt", b"hello in").await;
style/main.scssmodified+32 -0
@@ -479,6 +479,34 @@ a {
479 }479 }
480 }480 }
481 481
482+// The suite switcher: the other apps of the family, as their wordmarks,
483+// beside the page nav. Rendered only when `[[services]]` is set; the app
484+// the reader is already in is marked the way the page nav marks itself.
485+.app-switcher {
486+ display: flex;
487+ align-items: center;
488+ gap: 14px;
489+ // The trio keeps its width at every width: the page nav beside it is the
490+ // region that pans under the finger, this never squishes.
491+ flex: none;
492+
493+ &-mark {
494+ font-family: var(--font-mono);
495+ font-size: 13px;
496+ font-weight: 500;
497+ letter-spacing: 0.02em;
498+ color: var(--muted);
499+ text-decoration: none;
500+
501+ &:hover { color: var(--ink); }
502+ }
503+ // The current app, spelled out — `&` stays at the head of a compound
504+ // selector here, so the pair of classes cannot ride the ampersand.
505+ .app-switcher-mark.app-switcher-here {
506+ color: var(--ink);
507+ box-shadow: inset 0 -2px 0 var(--ink);
508+ }
509+}
482 .scaffold-note {510 .scaffold-note {
483 margin: 24px;511 margin: 24px;
484 padding: 20px 24px;512 padding: 20px 24px;
@@ -4318,6 +4346,8 @@ input[type="radio"] {
4318 &::-webkit-scrollbar { display: none; }4346 &::-webkit-scrollbar { display: none; }
4319 }4347 }
4320 4348
4349+ .app-switcher { gap: 10px; }
4350+
4321 // The avatar says who is signed in at this width; the name is the menu's.4351 // The avatar says who is signed in at this width; the name is the menu's.
4322 .user-menu-trigger-name { display: none; }4352 .user-menu-trigger-name { display: none; }
4323 4353
@@ -4330,6 +4360,8 @@ input[type="radio"] {
4330 }4360 }
4331 4361
4332 .topbar-nav-links { gap: 10px; }4362 .topbar-nav-links { gap: 10px; }
4363+
4364+ .app-switcher { gap: 8px; }
4333 }4365 }
4334 4366
4335 // -- board -----------------------------------------------------------------4367 // -- board -----------------------------------------------------------------