forge
Explore
Log in

Don't you dare go Hollow

Topcoat 0.12.1: path params read through their generated functions (owner(cx)), app_context is context, every component, page and route takes cx: &Cx first, view! captures cx, cookies come from CookieLayer, compression is off through with(Compression::disable()), and the avatar body limits sit on their routes 🎨 style: cargo fmt

Browse files at this commit

fe7f9a01ea677d578d6653047e5cd80008f15720Ahmet Kaan GümüşParent: 29a1eb3
All checks have passed
Show checks
  • deps
    • topcoat 0.12.1: path params read through their generated functions (owner(cx)), app_context is context, every component, page and route takes cx: &Cx first, view! captures cx, cookies come from CookieLayer, compression is off through with(Compression::disable()), and the avatar body limits sit on their routes 🎨 style: cargo fmt
Show full message
⬆️ deps: topcoat 0.12.1: path params read through their generated functions (owner(cx)), app_context is context, every component, page and route takes cx: &Cx first, view! captures cx, cookies come from CookieLayer, compression is off through with(Compression::disable()), and the avatar body limits sit on their routes 🎨 style: cargo fmt

162 changed files +2031 -1640

Cargo.lockmodified+73 -68
@@ -242,12 +242,6 @@ version = "1.0.105"
242242 source = "registry+https://github.com/rust-lang/crates.io-index"
243243 checksum = "2cb931c189b85683d69a5cfad41d4d418671e1ac413dd209f3f2fc31e3cfd902"
244244
245-[[package]]
246-name = "anymap3"
247-version = "1.1.0"
248-source = "registry+https://github.com/rust-lang/crates.io-index"
249-checksum = "fb5dfbc6d8d2675589ccbe4d0fd61df2419075625f8c1a62325e718e2b0049f9"
250-
251245 [[package]]
252246 name = "arc-swap"
253247 version = "1.9.5"
@@ -3396,17 +3390,6 @@ dependencies = [
33963390 "windows-sys 0.61.2",
33973391 ]
33983392
3399-[[package]]
3400-name = "hostname"
3401-version = "0.4.2"
3402-source = "registry+https://github.com/rust-lang/crates.io-index"
3403-checksum = "617aaa3557aef3810a6369d0a99fac8a080891b68bd9f9812a1eeda0c0730cbd"
3404-dependencies = [
3405- "cfg-if",
3406- "libc",
3407- "windows-link 0.2.1",
3408-]
3409-
34103393 [[package]]
34113394 name = "html5ever"
34123395 version = "0.40.1"
@@ -4146,7 +4129,6 @@ dependencies = [
41464129 "fastrand",
41474130 "futures-io",
41484131 "futures-util",
4149- "hostname",
41504132 "httpdate",
41514133 "idna",
41524134 "mime",
@@ -7180,9 +7162,9 @@ checksum = "009dbb7700f11c55ef83aebbe4c0e9cf1f1ac0844bd8d6f00dc38f302026e13a"
71807162
71817163 [[package]]
71827164 name = "topcoat"
7183-version = "0.11.0"
7165+version = "0.12.1"
71847166 source = "registry+https://github.com/rust-lang/crates.io-index"
7185-checksum = "70b5093d8133b513742b7461a28d374107b8bf9168aa60f4f567ad89acd2ed9e"
7167+checksum = "16bfbdbedee481dc7a9e89ed7c5be0a8fda008d6170fe9012c220590297eb4b9"
71867168 dependencies = [
71877169 "futures-util",
71887170 "inventory",
@@ -7190,13 +7172,14 @@ dependencies = [
71907172 "tokio",
71917173 "tokio-tungstenite",
71927174 "topcoat-asset",
7175+ "topcoat-asset-macro",
71937176 "topcoat-cookie",
71947177 "topcoat-core",
71957178 "topcoat-core-macro",
71967179 "topcoat-font",
71977180 "topcoat-font-macro",
71987181 "topcoat-l10n",
7199- "topcoat-mail",
7182+ "topcoat-metadata",
72007183 "topcoat-router",
72017184 "topcoat-router-macro",
72027185 "topcoat-runtime",
@@ -7208,9 +7191,9 @@ dependencies = [
72087191
72097192 [[package]]
72107193 name = "topcoat-asset"
7211-version = "0.11.0"
7194+version = "0.12.1"
72127195 source = "registry+https://github.com/rust-lang/crates.io-index"
7213-checksum = "ac70debf9eee62714ce45416eae27b283c3a44a0f9ebcb2ac088fda48b533f3e"
7196+checksum = "14de3c5734f7bb8ffc85ae33baa00e7dafee22978d02ef13e2ce3ad992fb1bc8"
72147197 dependencies = [
72157198 "http",
72167199 "memchr",
@@ -7225,11 +7208,34 @@ dependencies = [
72257208 "topcoat-view",
72267209 ]
72277210
7211+[[package]]
7212+name = "topcoat-asset-grammar"
7213+version = "0.12.1"
7214+source = "registry+https://github.com/rust-lang/crates.io-index"
7215+checksum = "7ce8fec8374473aa09ec85dd51469aca40ee6175397c4a7e38f7dc22f4798d03"
7216+dependencies = [
7217+ "proc-macro2",
7218+ "quote",
7219+ "syn 3.0.10",
7220+ "topcoat-core-grammar",
7221+]
7222+
7223+[[package]]
7224+name = "topcoat-asset-macro"
7225+version = "0.12.1"
7226+source = "registry+https://github.com/rust-lang/crates.io-index"
7227+checksum = "c3d98de54cc49ab5f9d5af639064ed1bb1b562ac170d346280b706cec7a1553d"
7228+dependencies = [
7229+ "quote",
7230+ "syn 3.0.10",
7231+ "topcoat-asset-grammar",
7232+]
7233+
72287234 [[package]]
72297235 name = "topcoat-cookie"
7230-version = "0.11.0"
7236+version = "0.12.1"
72317237 source = "registry+https://github.com/rust-lang/crates.io-index"
7232-checksum = "df79aba10192abe21fbd01dfcb46bb04dab5ae64adb4432d9f078eb05f94e6a5"
7238+checksum = "7fa34d585203cb080afce31749310bf5d9f238491636806d875726c7faebe10c"
72337239 dependencies = [
72347240 "cookie",
72357241 "getrandom 0.2.17",
@@ -7242,11 +7248,10 @@ dependencies = [
72427248
72437249 [[package]]
72447250 name = "topcoat-core"
7245-version = "0.11.0"
7251+version = "0.12.1"
72467252 source = "registry+https://github.com/rust-lang/crates.io-index"
7247-checksum = "ffff49b885744cdb89ee158c5d81cc8c619692bd9f4ab3cae92ad1adc0ce612e"
7253+checksum = "121a7616ec29bc5525a4a580554c3d5330ce4314655a13d0d8d10cc1a083fc7a"
72487254 dependencies = [
7249- "anymap3",
72507255 "base64 0.22.1",
72517256 "elsa",
72527257 "http",
@@ -7258,9 +7263,9 @@ dependencies = [
72587263
72597264 [[package]]
72607265 name = "topcoat-core-grammar"
7261-version = "0.11.0"
7266+version = "0.12.1"
72627267 source = "registry+https://github.com/rust-lang/crates.io-index"
7263-checksum = "b788a2010234cd29fc050268e52ceb393d2124b20f669a83d8f61a9dbf895bb6"
7268+checksum = "6d2326406a37c4eb212d60bc421589f3b600f50ca440b8e39dbdb7f7d032cb8a"
72647269 dependencies = [
72657270 "proc-macro-crate",
72667271 "proc-macro2",
@@ -7270,9 +7275,9 @@ dependencies = [
72707275
72717276 [[package]]
72727277 name = "topcoat-core-macro"
7273-version = "0.11.0"
7278+version = "0.12.1"
72747279 source = "registry+https://github.com/rust-lang/crates.io-index"
7275-checksum = "3e3786bf2ee2c8b4f728d3fb53c41f639aa66583788b3135acbd63c11458b25b"
7280+checksum = "020d81b3dfe852b7b5e44bbb2079c6b1346d6dfe50bc267e5d5a05c40bf5d9a4"
72767281 dependencies = [
72777282 "quote",
72787283 "syn 3.0.10",
@@ -7281,9 +7286,9 @@ dependencies = [
72817286
72827287 [[package]]
72837288 name = "topcoat-font"
7284-version = "0.11.0"
7289+version = "0.12.1"
72857290 source = "registry+https://github.com/rust-lang/crates.io-index"
7286-checksum = "caa4656294aac116def1e7633f03117a84b65126c503242793ff4adc78577fb8"
7291+checksum = "5e4382e452ddefff5b03cee1b3c84bcd36783e50afd2fea1e21fc9b41807142e"
72877292 dependencies = [
72887293 "heck",
72897294 "inventory",
@@ -7298,9 +7303,9 @@ dependencies = [
72987303
72997304 [[package]]
73007305 name = "topcoat-font-grammar"
7301-version = "0.11.0"
7306+version = "0.12.1"
73027307 source = "registry+https://github.com/rust-lang/crates.io-index"
7303-checksum = "b462fae28641a1bb24eab1fa9c473520389ca690331ca53fd6143d5b2746045e"
7308+checksum = "d6159e8e361f19367ddb11de5e5ff9b04f92d91e0c46ef9b1a076404d83fcfe8"
73047309 dependencies = [
73057310 "proc-macro2",
73067311 "quote",
@@ -7311,9 +7316,9 @@ dependencies = [
73117316
73127317 [[package]]
73137318 name = "topcoat-font-macro"
7314-version = "0.11.0"
7319+version = "0.12.1"
73157320 source = "registry+https://github.com/rust-lang/crates.io-index"
7316-checksum = "40776cd3087aaea5e0c8b597126b1c09dbfb0d69833088d7f3b229305bbbb87f"
7321+checksum = "7e3d3a71216cec0a27497716d4559e34245e61328f6e04fc2a2bac3b80679b31"
73177322 dependencies = [
73187323 "quote",
73197324 "syn 3.0.10",
@@ -7322,10 +7327,11 @@ dependencies = [
73227327
73237328 [[package]]
73247329 name = "topcoat-l10n"
7325-version = "0.11.0"
7330+version = "0.12.1"
73267331 source = "registry+https://github.com/rust-lang/crates.io-index"
7327-checksum = "34da63b3a5aea3d6c243d9fa8c98ca79b181b985f6a0a042f630672f54d12e9e"
7332+checksum = "d877822424504842f90d9f018dbaa61be2d52071653bc0f0921652ef925fdabd"
73287333 dependencies = [
7334+ "http",
73297335 "icu_locale",
73307336 "icu_locale_core",
73317337 "topcoat-core",
@@ -7333,24 +7339,24 @@ dependencies = [
73337339 ]
73347340
73357341 [[package]]
7336-name = "topcoat-mail"
7337-version = "0.11.0"
7342+name = "topcoat-metadata"
7343+version = "0.12.1"
73387344 source = "registry+https://github.com/rust-lang/crates.io-index"
7339-checksum = "54a13c10c6399d9eb9b0bde38bd3d947eba56ddfaea99d9a4f971b74b6a651db"
7345+checksum = "bf250ddbaea17bd63c7d6f124ce8f883dee44ece584cfab979ec33a87a030875"
73407346 dependencies = [
7341- "lettre",
7342- "thiserror 2.0.21",
7343- "time",
7347+ "topcoat-asset",
73447348 "topcoat-core",
7349+ "topcoat-core-macro",
73457350 "topcoat-router",
73467351 "topcoat-view",
7352+ "topcoat-view-macro",
73477353 ]
73487354
73497355 [[package]]
73507356 name = "topcoat-router"
7351-version = "0.11.0"
7357+version = "0.12.1"
73527358 source = "registry+https://github.com/rust-lang/crates.io-index"
7353-checksum = "b9488065b08f293208b0f1aeb6667d5836b66c12dfced5e330f9a8f1d7f1ca1a"
7359+checksum = "c86534384925992375ac979e9b5af7e4086119803b4586c6ac9bca814e814ed2"
73547360 dependencies = [
73557361 "bytes",
73567362 "form_urlencoded",
@@ -7384,11 +7390,10 @@ dependencies = [
73847390
73857391 [[package]]
73867392 name = "topcoat-router-grammar"
7387-version = "0.11.0"
7393+version = "0.12.1"
73887394 source = "registry+https://github.com/rust-lang/crates.io-index"
7389-checksum = "ac3f51fa1a1e538bd34e02f88ebba554ac5931e55c688303a58a8e78123dfb04"
7395+checksum = "0aa0f6bb59f921cdde73395cc526374d8a553d3285c3f4ac8086c40bedc5be3a"
73907396 dependencies = [
7391- "heck",
73927397 "proc-macro2",
73937398 "quote",
73947399 "syn 3.0.10",
@@ -7397,9 +7402,9 @@ dependencies = [
73977402
73987403 [[package]]
73997404 name = "topcoat-router-macro"
7400-version = "0.11.0"
7405+version = "0.12.1"
74017406 source = "registry+https://github.com/rust-lang/crates.io-index"
7402-checksum = "3c1b56d3bf19d54bddf300d6d57ca754531d7ad5481afca0b2302ac33f5d43af"
7407+checksum = "71ddd5e527cdab30c73293f907e8f40ef16c421484bb7bad107ecd967a6b98c3"
74037408 dependencies = [
74047409 "quote",
74057410 "syn 3.0.10",
@@ -7408,9 +7413,9 @@ dependencies = [
74087413
74097414 [[package]]
74107415 name = "topcoat-runtime"
7411-version = "0.11.0"
7416+version = "0.12.1"
74127417 source = "registry+https://github.com/rust-lang/crates.io-index"
7413-checksum = "03b22136b99694b349a950cd757387a04b080fdb131eecdd51d0511e1a45ebf5"
7418+checksum = "3e8f8651d36f003dd85a6a36ff5e1161b01af1cc5ae5baa38e649bda3605037a"
74147419 dependencies = [
74157420 "futures-util",
74167421 "pin-project-lite",
@@ -7419,6 +7424,7 @@ dependencies = [
74197424 "serde_json",
74207425 "tokio",
74217426 "topcoat-asset",
7427+ "topcoat-asset-macro",
74227428 "topcoat-core",
74237429 "topcoat-router",
74247430 "topcoat-view",
@@ -7427,9 +7433,9 @@ dependencies = [
74277433
74287434 [[package]]
74297435 name = "topcoat-runtime-grammar"
7430-version = "0.11.0"
7436+version = "0.12.1"
74317437 source = "registry+https://github.com/rust-lang/crates.io-index"
7432-checksum = "ab93a83c38a045a4f541c2e548d30ba5dfdd3173c18de8b1c7b049709c29db97"
7438+checksum = "1650432fe7adeab5aa815b84245c29c3ea5390a3b4a41d7cc2868e8f60f6277b"
74337439 dependencies = [
74347440 "proc-macro2",
74357441 "quote",
@@ -7443,9 +7449,9 @@ dependencies = [
74437449
74447450 [[package]]
74457451 name = "topcoat-runtime-macro"
7446-version = "0.11.0"
7452+version = "0.12.1"
74477453 source = "registry+https://github.com/rust-lang/crates.io-index"
7448-checksum = "5acb1db0bdba3c36e4f80f7ef530945779a1b0294b1087e7d877e33005da6283"
7454+checksum = "f4ea7a5b61e948d702a5cb6727c38a3b0c934b630cc003971ca86a9262c16b0c"
74497455 dependencies = [
74507456 "quote",
74517457 "syn 3.0.10",
@@ -7454,9 +7460,9 @@ dependencies = [
74547460
74557461 [[package]]
74567462 name = "topcoat-session"
7457-version = "0.11.0"
7463+version = "0.12.1"
74587464 source = "registry+https://github.com/rust-lang/crates.io-index"
7459-checksum = "2325c30a484b1b1b6f5012b50bc18994d37c33c6bd2f71be8ff509b591a17457"
7465+checksum = "d705011dbdf07ea9e3f74397f177cf3224a2fa0ff600a2514c11837ef04e1858"
74607466 dependencies = [
74617467 "base64 0.22.1",
74627468 "getrandom 0.4.3",
@@ -7465,15 +7471,14 @@ dependencies = [
74657471 "tokio",
74667472 "topcoat-cookie",
74677473 "topcoat-core",
7468- "topcoat-router",
74697474 "web-time",
74707475 ]
74717476
74727477 [[package]]
74737478 name = "topcoat-view"
7474-version = "0.11.0"
7479+version = "0.12.1"
74757480 source = "registry+https://github.com/rust-lang/crates.io-index"
7476-checksum = "db4553b91f30e30c71c2bd95ae8e931a33326c6ffb604663b9d214008f12947c"
7481+checksum = "654e102f97a4c26ba9b7deb72bdac45c8587ced30480b431155a56a935d12e86"
74777482 dependencies = [
74787483 "futures-core",
74797484 "futures-util",
@@ -7487,9 +7492,9 @@ dependencies = [
74877492
74887493 [[package]]
74897494 name = "topcoat-view-grammar"
7490-version = "0.11.0"
7495+version = "0.12.1"
74917496 source = "registry+https://github.com/rust-lang/crates.io-index"
7492-checksum = "75dd093ffc848370da4cce7670ccdfd4e98eab48e178d5d0da5509f747d85ca6"
7497+checksum = "28e348a794d04565ee00e7899f215c02db9acf0711bb8eefbba2ffa14bc72a5c"
74937498 dependencies = [
74947499 "heck",
74957500 "proc-macro2",
@@ -7501,9 +7506,9 @@ dependencies = [
75017506
75027507 [[package]]
75037508 name = "topcoat-view-macro"
7504-version = "0.11.0"
7509+version = "0.12.1"
75057510 source = "registry+https://github.com/rust-lang/crates.io-index"
7506-checksum = "ffa1688d165704f08d58c03710453d0d39553292bea61b18be7959a996c3e39b"
7511+checksum = "eed1edf71f2fe9f5edf9dcfa2ec3e55b9bae443c015497f80347f82cf6b7af8d"
75077512 dependencies = [
75087513 "quote",
75097514 "syn 3.0.10",
Cargo.tomlmodified+1 -1
@@ -82,7 +82,7 @@ multer = "3.1.0"
8282 lettre = { version = "0.11.24", default-features = false, features = ["smtp-transport", "builder", "tokio1-rustls", "ring", "webpki-roots", "pool"] }
8383
8484 # web framework
85-topcoat = { version = "0.11.0", default-features = false, features = ["router", "view", "runtime", "cookie", "asset", "serve", "sse", "discover", "multipart"] }
85+topcoat = { version = "0.12.1", default-features = false, features = ["router", "view", "runtime", "cookie", "asset", "serve", "sse", "discover", "multipart"] }
8686
8787 # ssh server
8888 russh = { version = "0.65.4", default-features = false, features = ["flate2", "aws-lc-rs"] }
crates/forge-core/src/store/migrate.rsmodified+8 -2
@@ -117,8 +117,14 @@ pub const MIGRATIONS: &[(u32, &str)] = &[
117117 include_str!("../../migrations/0070_pull_viewed_files.sql"),
118118 ),
119119 (71, include_str!("../../migrations/0071_ci_job_steps.sql")),
120- (72, include_str!("../../migrations/0072_ember_anvil_default.sql")),
121- (73, include_str!("../../migrations/0073_sage_ink_default.sql")),
120+ (
121+ 72,
122+ include_str!("../../migrations/0072_ember_anvil_default.sql"),
123+ ),
124+ (
125+ 73,
126+ include_str!("../../migrations/0073_sage_ink_default.sql"),
127+ ),
122128 ];
123129
124130 /// The highest migration version this binary knows about.
crates/forge-core/src/tz.rsmodified+5 -1
@@ -23,7 +23,11 @@ pub fn local_date(ts: Timestamp, tz: &str) -> civil::Date {
2323 /// it. `None` at the edge of the range jiff can represent. Unknown zones fall back to UTC.
2424 pub fn day_span(date: civil::Date, tz: &str) -> Option<(i64, i64)> {
2525 let zone = zone_or_utc(tz);
26- let start = date.at(0, 0, 0, 0).to_zoned_datetime(zone.clone()).ok()?.timestamp();
26+ let start = date
27+ .at(0, 0, 0, 0)
28+ .to_zoned_datetime(zone.clone())
29+ .ok()?
30+ .timestamp();
2731 let next = date
2832 .tomorrow()
2933 .ok()?
crates/forge-e2e/tests/e2e/browse_e2e.rsmodified+5 -1
@@ -127,7 +127,11 @@ fn element_texts(body: &str, selector: &str) -> Vec<String> {
127127 /// Checks the latest commit in a repo page's head line: its short sha linking to the commit, no
128128 /// subject, and the commit count label.
129129 fn assert_latest_bar(body: &str, what: &str, subject: &str, oid: &str, count: &str) {
130- assert_eq!(element_texts(body, ".head-sub").len(), 1, "{what}: one head line");
130+ assert_eq!(
131+ element_texts(body, ".head-sub").len(),
132+ 1,
133+ "{what}: one head line"
134+ );
131135 let shas = element_texts(body, ".head-sub a.mono");
132136 assert_eq!(shas.len(), 1, "{what}: the head line must show the sha");
133137 assert_eq!(shas[0].trim(), &oid[..7], "{what}: short sha");
crates/forge-e2e/tests/e2e/community_i18n_e2e.rsmodified+2 -8
@@ -50,10 +50,7 @@ async fn snippets_page_follows_the_browser_language() {
5050 assert_eq!(turkish.status().as_u16(), 200);
5151 let body = turkish.text().await.expect("read body");
5252 assert!(body.contains("<html lang=\"tr\""), "html lang is tr");
53- assert!(
54- body.contains("<h1>Parçacıklar</h1>"),
55- "Turkish heading"
56- );
53+ assert!(body.contains("<h1>Parçacıklar</h1>"), "Turkish heading");
5754 assert!(
5855 body.contains("Gösterilecek parçacık yok."),
5956 "Turkish empty state"
@@ -67,9 +64,6 @@ async fn snippets_page_follows_the_browser_language() {
6764 .await
6865 .expect("GET /snippets (en)");
6966 let body = english.text().await.expect("read body");
70- assert!(
71- body.contains("<h1>Snippets</h1>"),
72- "English heading"
73- );
67+ assert!(body.contains("<h1>Snippets</h1>"), "English heading");
7468 assert!(body.contains("No snippets to show."), "English empty state");
7569 }
crates/forge-e2e/tests/e2e/pulls_e2e.rsmodified+2 -1
@@ -23,7 +23,8 @@ const REPO_PATH: &str = "/tahinli/r";
2323 /// Text of the first state badge on a page, e.g. `Open`, `Closed` or `Merged`.
2424 fn state_badge(body: &str) -> String {
2525 let doc = scraper::Html::parse_document(body);
26- let selector = scraper::Selector::parse(".head-sub > .badge, .head-sub > .issue-badge").expect("selector");
26+ let selector =
27+ scraper::Selector::parse(".head-sub > .badge, .head-sub > .issue-badge").expect("selector");
2728 doc.select(&selector)
2829 .next()
2930 .map(|el| el.text().collect::<String>().trim().to_owned())
crates/forge-e2e/tests/e2e/repo_rename_e2e.rsmodified+3 -1
@@ -388,7 +388,9 @@ async fn repo_rename_end_to_end() {
388388 200,
389389 "repo unchanged until accepted"
390390 );
391- let offered = http.get("/bob/newpub/settings?section=danger", Some(&bob)).await;
391+ let offered = http
392+ .get("/bob/newpub/settings?section=danger", Some(&bob))
393+ .await;
392394 assert!(offered.body.contains("Pending transfer to carol"));
393395 let inbox = http.get("/notifications", Some(&carol)).await;
394396 let accept_action = form_action(&inbox.body, "/accept");
crates/forge-e2e/tests/e2e/repo_settings_e2e.rsmodified+17 -4
@@ -249,7 +249,10 @@ async fn repo_settings_end_to_end() {
249249 // The home page is the signed-in viewer's own page, not a redirect.
250250 let home = http.get("/", Some(&bob)).await;
251251 assert_eq!(home.status, 200, "home page for a signed-in viewer");
252- assert!(home.body.contains("Your repositories"), "home lists their repositories");
252+ assert!(
253+ home.body.contains("Your repositories"),
254+ "home lists their repositories"
255+ );
253256
254257 // An admin who does not own the repo can delete it.
255258 let admin_page = http.get("/bob/priv/settings", Some(&tahinli)).await;
@@ -523,7 +526,11 @@ async fn branch_protection_end_to_end() {
523526 let updated = http
524527 .post_form(
525528 "/bob/app/settings/branches",
526- &[("csrf", &owner_csrf), ("pattern", "main"), ("existing", "1")],
529+ &[
530+ ("csrf", &owner_csrf),
531+ ("pattern", "main"),
532+ ("existing", "1"),
533+ ],
527534 Some(&bob),
528535 )
529536 .await;
@@ -538,7 +545,10 @@ async fn branch_protection_end_to_end() {
538545 )
539546 .await;
540547 assert_eq!(duplicate.status, 200, "duplicate rule re-renders the page");
541- assert!(duplicate.body.contains("already exists"), "duplicate rule names the clash");
548+ assert!(
549+ duplicate.body.contains("already exists"),
550+ "duplicate rule names the clash"
551+ );
542552 let page = http
543553 .get("/bob/app/settings?section=branches", Some(&bob))
544554 .await;
@@ -864,7 +874,10 @@ async fn general_settings_end_to_end() {
864874 page.body
865875 .contains("href=\"/bob/gen/settings/collaborators\"")
866876 );
867- assert!(page.body.contains("href=\"/bob/gen/settings?section=danger\""));
877+ assert!(
878+ page.body
879+ .contains("href=\"/bob/gen/settings?section=danger\"")
880+ );
868881
869882 // Description: control characters are stripped and it shows on the repo header.
870883 let csrf = csrf_for(&http, &bob).await;
crates/forge-e2e/tests/e2e/repo_transfer_e2e.rsmodified+9 -3
@@ -148,14 +148,18 @@ async fn repo_transfer_offers_declines_cancels_and_org_targets() {
148148 offered.header(LOCATION).as_deref(),
149149 Some("/bob/priv/settings?section=danger")
150150 );
151- let status = http.get("/bob/priv/settings?section=danger", Some(&bob)).await;
151+ let status = http
152+ .get("/bob/priv/settings?section=danger", Some(&bob))
153+ .await;
152154 assert!(status.body.contains("Pending transfer to carol"));
153155 // Carol cannot read the private repo, yet the inbox offers her the actions.
154156 assert_eq!(http.get("/bob/priv", Some(&carol)).await.status, 404);
155157 let declined = act_from(&http, &carol, "/notifications", "/decline").await;
156158 assert_eq!(declined.status, 303, "decline: {}", declined.body);
157159 assert_eq!(declined.header(LOCATION).as_deref(), Some("/notifications"));
158- let after = http.get("/bob/priv/settings?section=danger", Some(&bob)).await;
160+ let after = http
161+ .get("/bob/priv/settings?section=danger", Some(&bob))
162+ .await;
159163 assert!(!after.body.contains("Pending transfer"));
160164 assert_eq!(http.get("/bob/priv", Some(&bob)).await.status, 200);
161165
@@ -167,7 +171,9 @@ async fn repo_transfer_offers_declines_cancels_and_org_targets() {
167171 cancelled.header(LOCATION).as_deref(),
168172 Some("/bob/priv/settings?section=danger")
169173 );
170- let after = http.get("/bob/priv/settings?section=danger", Some(&bob)).await;
174+ let after = http
175+ .get("/bob/priv/settings?section=danger", Some(&bob))
176+ .await;
171177 assert!(!after.body.contains("Pending transfer"));
172178
173179 // A transfer to an org: plain members get no accept form, owners do.
crates/forge-web-base/src/accent.rsmodified+9 -1
@@ -327,7 +327,15 @@ mod tests {
327327 ] {
328328 assert!(!is_offered(id), "{id}");
329329 }
330- for id in ["stone", "mist", "fern", "graphite", "dune", "slate-blue", "spark"] {
330+ for id in [
331+ "stone",
332+ "mist",
333+ "fern",
334+ "graphite",
335+ "dune",
336+ "slate-blue",
337+ "spark",
338+ ] {
331339 assert!(!is_offered_base(id), "{id}");
332340 }
333341 }
crates/forge-web-base/src/compression.rsmodified+1 -1
@@ -200,7 +200,7 @@ mod tests {
200200 ))
201201 .route(RouteFn::new(Method::GET, "/tahinli/demo/blob.bin", binary))
202202 .layer(TowerLayer::new(ResponseCompression))
203- .compression(Compression::off())
203+ .with(Compression::disable())
204204 .build()
205205 }
206206
crates/forge-web-base/src/i18n/admin.rsmodified+2 -6
@@ -368,12 +368,8 @@ pub fn t(lang: Lang, key: K) -> &'static str {
368368 (RunnerEnabledNotice, Tr) => "Çalıştırıcı etkinleştirildi.",
369369 (Runners, En) => "Runners",
370370 (Runners, Tr) => "Çalıştırıcılar",
371- (ScheduledBackupsOff, En) => {
372- "Scheduled backups are off."
373- }
374- (ScheduledBackupsOff, Tr) => {
375- "Zamanlanmış yedeklemeler kapalı."
376- }
371+ (ScheduledBackupsOff, En) => "Scheduled backups are off.",
372+ (ScheduledBackupsOff, Tr) => "Zamanlanmış yedeklemeler kapalı.",
377373 (SecurityLogTitle, En) => "Security log",
378374 (SecurityLogTitle, Tr) => "Güvenlik günlüğü",
379375 (SecurityNone, En) => "None (plain text)",
crates/forge-web-base/src/i18n/issues.rsmodified+3 -1
@@ -673,7 +673,9 @@ pub fn reaction_more(lang: Lang, names: &str, more: usize) -> String {
673673
674674 /// Several label additions in one run: "added labels a, b and c". `names` holds at least two.
675675 pub fn event_labels_added(lang: Lang, names: &[String]) -> String {
676- let (last, rest) = names.split_last().map_or(("", &[][..]), |(last, rest)| (last.as_str(), rest));
676+ let (last, rest) = names
677+ .split_last()
678+ .map_or(("", &[][..]), |(last, rest)| (last.as_str(), rest));
677679 let list = match lang {
678680 Lang::En => match rest.is_empty() {
679681 true => last.to_owned(),
crates/forge-web-base/src/render/markdown.rsmodified+8 -2
@@ -390,12 +390,18 @@ fn text_with_links<'a>(
390390 Some(n) => new_node(
391391 arena,
392392 sourcepos,
393- NodeValue::Link(Box::new(NodeLink::new(format!("{issues_base}/{n}"), ISSUE_REF_TITLE.to_string()))),
393+ NodeValue::Link(Box::new(NodeLink::new(
394+ format!("{issues_base}/{n}"),
395+ ISSUE_REF_TITLE.to_string(),
396+ ))),
394397 ),
395398 None => new_node(
396399 arena,
397400 sourcepos,
398- NodeValue::Link(Box::new(NodeLink::new(format!("/{}", &label[1..]), USER_MENTION_TITLE.to_string()))),
401+ NodeValue::Link(Box::new(NodeLink::new(
402+ format!("/{}", &label[1..]),
403+ USER_MENTION_TITLE.to_string(),
404+ ))),
399405 ),
400406 };
401407 link.append(new_node(
crates/forge-web/src/api/gitea.rsmodified+23 -32
@@ -25,7 +25,7 @@ use forge_core::{Action, Repo as CoreRepo, User, Visibility};
2525 use http::HeaderMap;
2626 use http::header::{AUTHORIZATION, HeaderName, HeaderValue};
2727 use serde_json::{Value, json};
28-use topcoat::context::{Cx, app_context};
28+use topcoat::context::{Cx, context};
2929 use topcoat::router::request::{headers, uri};
3030 use topcoat::router::response::Response;
3131 use topcoat::router::{StatusCode, path_param, route};
@@ -108,7 +108,7 @@ fn effective_headers(cx: &Cx) -> HeaderMap {
108108
109109 /// Who is asking, and the raw token they used (for the clone URL of a private repo).
110110 async fn caller(cx: &Cx) -> Result<(Option<User>, Option<String>), Refusal> {
111- let state = app_context::<AppState>(cx);
111+ let state = context::<AppState>(cx);
112112 let map = effective_headers(cx);
113113 let actor = api::authenticate(state, client_ip(cx), &map).await?;
114114 let token = api::presented_token(&map).flatten();
@@ -122,16 +122,9 @@ struct Ctx {
122122 }
123123
124124 async fn read_ctx(cx: &Cx) -> Result<Ctx, Refusal> {
125- let state = app_context::<AppState>(cx);
125+ let state = context::<AppState>(cx);
126126 let (actor, token) = caller(cx).await?;
127- let repo = api::load_repo(
128- state,
129- actor.as_ref(),
130- path_param::<Owner>(cx),
131- path_param::<Repo>(cx),
132- Action::Read,
133- )
134- .await?;
127+ let repo = api::load_repo(state, actor.as_ref(), owner(cx), repo(cx), Action::Read).await?;
135128 Ok(Ctx {
136129 repo,
137130 token: actor.and(token),
@@ -178,7 +171,7 @@ pub fn slice<T>(items: Vec<T>, pg: &Paging) -> (Vec<T>, usize) {
178171 pub fn page_response(cx: &Cx, items: Vec<Value>, total: usize, pg: &Paging) -> Response {
179172 let mut res = api::json(StatusCode::OK, &Value::Array(items));
180173 let last = total.div_ceil(pg.limit.max(1)).max(1);
181- let state = app_context::<AppState>(cx);
174+ let state = context::<AppState>(cx);
182175 let base = state.config.base_url.trim_end_matches('/');
183176 let mut rest = String::new();
184177 if let Some(query) = uri(cx).query() {
@@ -230,7 +223,7 @@ fn internal(e: impl std::fmt::Display) -> Refusal {
230223 }
231224
232225 #[route(GET "/api/v1/version")]
233-async fn version_route(_cx: &Cx) -> topcoat::Result<Response> {
226+async fn version_route(cx: &Cx) -> topcoat::Result<Response> {
234227 Ok(api::json(
235228 StatusCode::OK,
236229 &json!({ "version": GITEA_VERSION }),
@@ -238,7 +231,7 @@ async fn version_route(_cx: &Cx) -> topcoat::Result<Response> {
238231 }
239232
240233 #[route(GET "/api/v1/settings/api")]
241-async fn settings_api(_cx: &Cx) -> topcoat::Result<Response> {
234+async fn settings_api(cx: &Cx) -> topcoat::Result<Response> {
242235 Ok(api::json(
243236 StatusCode::OK,
244237 &json!({
@@ -302,7 +295,7 @@ pub async fn repo_json(
302295
303296 #[route(GET "/api/v1/repos/{owner}/{repo}")]
304297 async fn get_repo(cx: &Cx) -> topcoat::Result<Response> {
305- let state = app_context::<AppState>(cx);
298+ let state = context::<AppState>(cx);
306299 let ctx = match read_ctx(cx).await {
307300 Ok(ctx) => ctx,
308301 Err(res) => return Ok(*res),
@@ -336,7 +329,7 @@ fn label_json(base: &str, repo: &CoreRepo, label: &Label) -> Value {
336329
337330 #[route(GET "/api/v1/repos/{owner}/{repo}/labels")]
338331 async fn list_labels_route(cx: &Cx) -> topcoat::Result<Response> {
339- let state = app_context::<AppState>(cx);
332+ let state = context::<AppState>(cx);
340333 let ctx = match read_ctx(cx).await {
341334 Ok(ctx) => ctx,
342335 Err(res) => return Ok(*res),
@@ -389,7 +382,7 @@ fn state_filter(cx: &Cx) -> Result<Option<IssueState>, Refusal> {
389382
390383 #[route(GET "/api/v1/repos/{owner}/{repo}/milestones")]
391384 async fn list_milestones_route(cx: &Cx) -> topcoat::Result<Response> {
392- let state = app_context::<AppState>(cx);
385+ let state = context::<AppState>(cx);
393386 let ctx = match read_ctx(cx).await {
394387 Ok(ctx) => ctx,
395388 Err(res) => return Ok(*res),
@@ -495,7 +488,7 @@ fn filter_of(cx: &Cx, pg: &Paging) -> Result<IssueFilter, Refusal> {
495488
496489 #[route(GET "/api/v1/repos/{owner}/{repo}/issues")]
497490 async fn list_issues_route(cx: &Cx) -> topcoat::Result<Response> {
498- let state = app_context::<AppState>(cx);
491+ let state = context::<AppState>(cx);
499492 let ctx = match read_ctx(cx).await {
500493 Ok(ctx) => ctx,
501494 Err(res) => return Ok(*res),
@@ -572,13 +565,13 @@ fn comment_json(
572565
573566 #[route(GET "/api/v1/repos/{owner}/{repo}/issues/{index}/comments")]
574567 async fn issue_comments(cx: &Cx) -> topcoat::Result<Response> {
575- let state = app_context::<AppState>(cx);
568+ let state = context::<AppState>(cx);
576569 let ctx = match read_ctx(cx).await {
577570 Ok(ctx) => ctx,
578571 Err(res) => return Ok(*res),
579572 };
580573 let result: Result<Response, Refusal> = async {
581- let issue = issue_row(state, &ctx.repo, path_param::<Index>(cx)).await?;
574+ let issue = issue_row(state, &ctx.repo, index(cx)).await?;
582575 let all = state
583576 .store
584577 .list_comments(&issue.id)
@@ -634,13 +627,13 @@ async fn reactions_json(
634627
635628 #[route(GET "/api/v1/repos/{owner}/{repo}/issues/{index}/reactions")]
636629 async fn issue_reactions(cx: &Cx) -> topcoat::Result<Response> {
637- let state = app_context::<AppState>(cx);
630+ let state = context::<AppState>(cx);
638631 let ctx = match read_ctx(cx).await {
639632 Ok(ctx) => ctx,
640633 Err(res) => return Ok(*res),
641634 };
642635 let result: Result<Response, Refusal> = async {
643- let issue = issue_row(state, &ctx.repo, path_param::<Index>(cx)).await?;
636+ let issue = issue_row(state, &ctx.repo, index(cx)).await?;
644637 let all = reactions_json(
645638 state,
646639 &ctx,
@@ -659,15 +652,13 @@ async fn issue_reactions(cx: &Cx) -> topcoat::Result<Response> {
659652
660653 #[route(GET "/api/v1/repos/{owner}/{repo}/issues/comments/{id}/reactions")]
661654 async fn comment_reactions(cx: &Cx) -> topcoat::Result<Response> {
662- let state = app_context::<AppState>(cx);
655+ let state = context::<AppState>(cx);
663656 let ctx = match read_ctx(cx).await {
664657 Ok(ctx) => ctx,
665658 Err(res) => return Ok(*res),
666659 };
667660 let result: Result<Response, Refusal> = async {
668- let id: i64 = path_param::<Id>(cx)
669- .parse()
670- .map_err(|_| bad("invalid comment id"))?;
661+ let id: i64 = id(cx).parse().map_err(|_| bad("invalid comment id"))?;
671662 let (number, position) =
672663 split_comment_id(id).ok_or_else(|| not_found("comment not found"))?;
673664 let issue = issue_row(state, &ctx.repo, &number.to_string()).await?;
@@ -803,7 +794,7 @@ async fn pull_json(
803794
804795 #[route(GET "/api/v1/repos/{owner}/{repo}/pulls")]
805796 async fn list_pulls_route(cx: &Cx) -> topcoat::Result<Response> {
806- let state = app_context::<AppState>(cx);
797+ let state = context::<AppState>(cx);
807798 let ctx = match read_ctx(cx).await {
808799 Ok(ctx) => ctx,
809800 Err(res) => return Ok(*res),
@@ -893,13 +884,13 @@ async fn review_comments(state: &AppState, issue_id: &str) -> Result<Vec<ReviewC
893884
894885 #[route(GET "/api/v1/repos/{owner}/{repo}/pulls/{index}/reviews")]
895886 async fn pull_reviews(cx: &Cx) -> topcoat::Result<Response> {
896- let state = app_context::<AppState>(cx);
887+ let state = context::<AppState>(cx);
897888 let ctx = match read_ctx(cx).await {
898889 Ok(ctx) => ctx,
899890 Err(res) => return Ok(*res),
900891 };
901892 let result: Result<Response, Refusal> = async {
902- let issue = pull_issue(state, &ctx.repo, path_param::<Index>(cx)).await?;
893+ let issue = pull_issue(state, &ctx.repo, index(cx)).await?;
903894 let reviews = state
904895 .store
905896 .list_reviews(&issue.id)
@@ -967,14 +958,14 @@ fn review_comment_json(ctx: &Ctx, number: i64, c: &ReviewComment) -> Value {
967958
968959 #[route(GET "/api/v1/repos/{owner}/{repo}/pulls/{index}/reviews/{review_id}/comments")]
969960 async fn pull_review_comments(cx: &Cx) -> topcoat::Result<Response> {
970- let state = app_context::<AppState>(cx);
961+ let state = context::<AppState>(cx);
971962 let ctx = match read_ctx(cx).await {
972963 Ok(ctx) => ctx,
973964 Err(res) => return Ok(*res),
974965 };
975966 let result: Result<Response, Refusal> = async {
976- let issue = pull_issue(state, &ctx.repo, path_param::<Index>(cx)).await?;
977- let raw = path_param::<ReviewId>(cx);
967+ let issue = pull_issue(state, &ctx.repo, index(cx)).await?;
968+ let raw = review_id(cx);
978969 let reviews = state
979970 .store
980971 .list_reviews(&issue.id)
crates/forge-web/src/api/packages.rsmodified+22 -42
@@ -13,7 +13,7 @@ use http::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, HeaderValue};
1313 use http_body::Frame;
1414 use http_body_util::StreamBody;
1515 use serde_json::{Value, json};
16-use topcoat::context::{Cx, app_context};
16+use topcoat::context::{Cx, context};
1717 use topcoat::router::request::headers;
1818 use topcoat::router::response::Response;
1919 use topcoat::router::{Body, StatusCode, path_param, route};
@@ -33,7 +33,7 @@ path_param!(version);
3333 /// The caller of a registry request. Reads with a token that lacks the scope are served as
3434 /// anonymous, so a token made for another purpose cannot break a public install. Writes refuse.
3535 async fn caller(cx: &Cx, scope_required: bool) -> Result<Option<User>, Refusal> {
36- let state = app_context::<AppState>(cx);
36+ let state = context::<AppState>(cx);
3737 let normalized = bare_token_as_bearer(headers(cx));
3838 let (user, token_id, scopes) =
3939 match api::authenticate_token(state, client_ip(cx), &normalized).await {
@@ -120,8 +120,8 @@ fn text(body: String) -> Response {
120120
121121 /// Loads the registry owner named in the path, as the caller may see it. A missing owner is 404.
122122 async fn owner_of(cx: &Cx) -> Result<User, Refusal> {
123- let state = app_context::<AppState>(cx);
124- match package_ops::owner_named(state, path_param::<Owner>(cx)).await {
123+ let state = context::<AppState>(cx);
124+ match package_ops::owner_named(state, owner(cx)).await {
125125 Ok(Some(found)) => Ok(found),
126126 Ok(_) => Err(Box::new(failure(PackageError::NotFound))),
127127 Err(e) => Err(Box::new(failure(e))),
@@ -130,7 +130,7 @@ async fn owner_of(cx: &Cx) -> Result<User, Refusal> {
130130
131131 #[route(GET "/api/packages/{owner}/cargo/config.json")]
132132 async fn config(cx: &Cx) -> topcoat::Result<Response> {
133- let state = app_context::<AppState>(cx);
133+ let state = context::<AppState>(cx);
134134 if let Err(res) = caller(cx, false).await {
135135 return Ok(*res);
136136 }
@@ -164,7 +164,7 @@ async fn index_long(cx: &Cx) -> topcoat::Result<Response> {
164164 }
165165
166166 async fn index_response(cx: &Cx) -> Response {
167- let state = app_context::<AppState>(cx);
167+ let state = context::<AppState>(cx);
168168 let actor = match caller(cx, false).await {
169169 Ok(actor) => actor,
170170 Err(res) => return *res,
@@ -173,13 +173,11 @@ async fn index_response(cx: &Cx) -> Response {
173173 Ok(owner) => owner,
174174 Err(res) => return *res,
175175 };
176- let package =
177- match package_ops::readable_package(state, actor.as_ref(), &owner, path_param::<Name>(cx))
178- .await
179- {
180- Ok(package) => package,
181- Err(e) => return failure(e),
182- };
176+ let package = match package_ops::readable_package(state, actor.as_ref(), &owner, name(cx)).await
177+ {
178+ Ok(package) => package,
179+ Err(e) => return failure(e),
180+ };
183181 match package_ops::index_file(state, &package).await {
184182 Ok(body) => text(body),
185183 Err(e) => failure(e),
@@ -189,7 +187,7 @@ async fn index_response(cx: &Cx) -> Response {
189187 /// The `.crate` file of one version, streamed from the blob store.
190188 #[route(GET "/api/packages/{owner}/cargo/download/{name}/{version}")]
191189 async fn download(cx: &Cx) -> topcoat::Result<Response> {
192- let state = app_context::<AppState>(cx);
190+ let state = context::<AppState>(cx);
193191 let actor = match caller(cx, false).await {
194192 Ok(actor) => actor,
195193 Err(res) => return Ok(*res),
@@ -198,18 +196,11 @@ async fn download(cx: &Cx) -> topcoat::Result<Response> {
198196 Ok(owner) => owner,
199197 Err(res) => return Ok(*res),
200198 };
201- let read = match package_ops::download(
202- state,
203- actor.as_ref(),
204- &owner,
205- path_param::<Name>(cx),
206- path_param::<Version>(cx),
207- )
208- .await
209- {
210- Ok(read) => read,
211- Err(e) => return Ok(failure(e)),
212- };
199+ let read =
200+ match package_ops::download(state, actor.as_ref(), &owner, name(cx), version(cx)).await {
201+ Ok(read) => read,
202+ Err(e) => return Ok(failure(e)),
203+ };
213204 let chunks = read.stream.map(|chunk| chunk.map(Frame::data));
214205 let mut res = Response::new(Body::new(StreamBody::new(chunks)));
215206 *res.status_mut() = StatusCode::OK;
@@ -226,7 +217,7 @@ async fn download(cx: &Cx) -> topcoat::Result<Response> {
226217 /// length-prefixed `.crate`. It is read whole, up to the publish limit.
227218 #[route(PUT "/api/packages/{owner}/cargo/api/v1/crates/new")]
228219 async fn publish(cx: &Cx, body: Body) -> topcoat::Result<Response> {
229- let state = app_context::<AppState>(cx);
220+ let state = context::<AppState>(cx);
230221 let actor = match caller(cx, true).await {
231222 Ok(Some(actor)) => actor,
232223 Ok(None) => {
@@ -271,7 +262,7 @@ async fn unyank(cx: &Cx) -> topcoat::Result<Response> {
271262 }
272263
273264 async fn set_yank(cx: &Cx, yanked: bool) -> topcoat::Result<Response> {
274- let state = app_context::<AppState>(cx);
265+ let state = context::<AppState>(cx);
275266 let actor = match caller(cx, true).await {
276267 Ok(Some(actor)) => actor,
277268 Ok(None) => {
@@ -286,16 +277,7 @@ async fn set_yank(cx: &Cx, yanked: bool) -> topcoat::Result<Response> {
286277 Ok(owner) => owner,
287278 Err(res) => return Ok(*res),
288279 };
289- match package_ops::set_yanked(
290- state,
291- &owner,
292- &actor,
293- path_param::<Name>(cx),
294- path_param::<Version>(cx),
295- yanked,
296- )
297- .await
298- {
280+ match package_ops::set_yanked(state, &owner, &actor, name(cx), version(cx), yanked).await {
299281 Ok(()) => Ok(api::json(StatusCode::OK, &json!({ "ok": true }))),
300282 Err(e) => Ok(failure(e)),
301283 }
@@ -305,7 +287,7 @@ async fn set_yank(cx: &Cx, yanked: bool) -> topcoat::Result<Response> {
305287 /// an org, its owners. Read-only: adding or removing owners is done in the forge.
306288 #[route(GET "/api/packages/{owner}/cargo/api/v1/crates/{name}/owners")]
307289 async fn owners(cx: &Cx) -> topcoat::Result<Response> {
308- let state = app_context::<AppState>(cx);
290+ let state = context::<AppState>(cx);
309291 let actor = match caller(cx, false).await {
310292 Ok(actor) => actor,
311293 Err(res) => return Ok(*res),
@@ -314,9 +296,7 @@ async fn owners(cx: &Cx) -> topcoat::Result<Response> {
314296 Ok(owner) => owner,
315297 Err(res) => return Ok(*res),
316298 };
317- if let Err(e) =
318- package_ops::readable_package(state, actor.as_ref(), &owner, path_param::<Name>(cx)).await
319- {
299+ if let Err(e) = package_ops::readable_package(state, actor.as_ref(), &owner, name(cx)).await {
320300 return Ok(failure(e));
321301 }
322302 let people: Vec<User> = if owner.is_org() {
crates/forge-web/src/api/releases.rsmodified+24 -38
@@ -13,7 +13,7 @@ use futures_util::StreamExt;
1313 use http::header::CONTENT_TYPE;
1414 use serde::Deserialize;
1515 use serde_json::{Value, json};
16-use topcoat::context::{Cx, app_context};
16+use topcoat::context::{Cx, context};
1717 use topcoat::router::request::headers;
1818 use topcoat::router::response::Response;
1919 use topcoat::router::{Body, StatusCode, path_param, route};
@@ -55,7 +55,7 @@ struct PatchBody {
5555
5656 #[route(GET "/api/v1/repos/{owner}/{repo}/releases")]
5757 async fn list_releases(cx: &Cx) -> topcoat::Result<Response> {
58- let state = app_context::<AppState>(cx);
58+ let state = context::<AppState>(cx);
5959 let (repo, can_write) = match read_context(cx).await {
6060 Ok(found) => found,
6161 Err(res) => return Ok(*res),
@@ -82,17 +82,17 @@ async fn list_releases(cx: &Cx) -> topcoat::Result<Response> {
8282 /// Gitea's `GET .../releases/{id}/assets/{attachment_id}`: one asset of one release.
8383 #[route(GET "/api/v1/repos/{owner}/{repo}/releases/{id}/assets/{asset}")]
8484 async fn get_asset(cx: &Cx) -> topcoat::Result<Response> {
85- let state = app_context::<AppState>(cx);
85+ let state = context::<AppState>(cx);
8686 let (repo, can_write) = match read_context(cx).await {
8787 Ok(found) => found,
8888 Err(res) => return Ok(*res),
8989 };
90- let release = match release_in_repo(state, &repo, path_param::<Id>(cx)).await {
90+ let release = match release_in_repo(state, &repo, id(cx)).await {
9191 Ok(release) if can_write || !release.draft => release,
9292 Ok(_) => return Ok(not_found()),
9393 Err(res) => return Ok(*res),
9494 };
95- let wanted = path_param::<Asset>(cx);
95+ let wanted = asset(cx);
9696 let assets = match state.store.list_release_assets(&release.id).await {
9797 Ok(assets) => assets,
9898 Err(e) => return Ok(*api::internal(e)),
@@ -112,12 +112,12 @@ async fn get_asset(cx: &Cx) -> topcoat::Result<Response> {
112112
113113 #[route(GET "/api/v1/repos/{owner}/{repo}/releases/tags/{tag}")]
114114 async fn get_release_by_tag(cx: &Cx) -> topcoat::Result<Response> {
115- let state = app_context::<AppState>(cx);
115+ let state = context::<AppState>(cx);
116116 let (repo, can_write) = match read_context(cx).await {
117117 Ok(found) => found,
118118 Err(res) => return Ok(*res),
119119 };
120- let tag_name = path_param::<Tag>(cx);
120+ let tag_name = tag(cx);
121121 let release = match state.store.release_by_tag(&repo.id, tag_name).await {
122122 Ok(Some(release)) if can_write || !release.draft => release,
123123 Ok(_) => return Ok(not_found()),
@@ -131,7 +131,7 @@ async fn get_release_by_tag(cx: &Cx) -> topcoat::Result<Response> {
131131
132132 #[route(POST "/api/v1/repos/{owner}/{repo}/releases")]
133133 async fn create_release(cx: &Cx, body: Body) -> topcoat::Result<Response> {
134- let state = app_context::<AppState>(cx);
134+ let state = context::<AppState>(cx);
135135 let (repo, user) = match write_context(cx).await {
136136 Ok(found) => found,
137137 Err(res) => return Ok(*res),
@@ -176,12 +176,12 @@ async fn create_release(cx: &Cx, body: Body) -> topcoat::Result<Response> {
176176
177177 #[route(PATCH "/api/v1/repos/{owner}/{repo}/releases/{id}")]
178178 async fn edit_release(cx: &Cx, body: Body) -> topcoat::Result<Response> {
179- let state = app_context::<AppState>(cx);
179+ let state = context::<AppState>(cx);
180180 let (repo, user) = match write_context(cx).await {
181181 Ok(found) => found,
182182 Err(res) => return Ok(*res),
183183 };
184- let release = match release_in_repo(state, &repo, path_param::<Id>(cx)).await {
184+ let release = match release_in_repo(state, &repo, id(cx)).await {
185185 Ok(release) => release,
186186 Err(res) => return Ok(*res),
187187 };
@@ -218,12 +218,12 @@ async fn edit_release(cx: &Cx, body: Body) -> topcoat::Result<Response> {
218218
219219 #[route(DELETE "/api/v1/repos/{owner}/{repo}/releases/{id}")]
220220 async fn delete_release(cx: &Cx) -> topcoat::Result<Response> {
221- let state = app_context::<AppState>(cx);
221+ let state = context::<AppState>(cx);
222222 let (repo, user) = match write_context(cx).await {
223223 Ok(found) => found,
224224 Err(res) => return Ok(*res),
225225 };
226- let release = match release_in_repo(state, &repo, path_param::<Id>(cx)).await {
226+ let release = match release_in_repo(state, &repo, id(cx)).await {
227227 Ok(release) => release,
228228 Err(res) => return Ok(*res),
229229 };
@@ -236,12 +236,12 @@ async fn delete_release(cx: &Cx) -> topcoat::Result<Response> {
236236 /// Streams the raw request body into an asset. `201` for a new name, `200` when it replaces one.
237237 #[route(PUT "/api/v1/repos/{owner}/{repo}/releases/{id}/assets/{asset}")]
238238 async fn upload_asset(cx: &Cx, body: Body) -> topcoat::Result<Response> {
239- let state = app_context::<AppState>(cx);
239+ let state = context::<AppState>(cx);
240240 let (repo, user) = match write_context(cx).await {
241241 Ok(found) => found,
242242 Err(res) => return Ok(*res),
243243 };
244- let release = match release_in_repo(state, &repo, path_param::<Id>(cx)).await {
244+ let release = match release_in_repo(state, &repo, id(cx)).await {
245245 Ok(release) => release,
246246 Err(res) => return Ok(*res),
247247 };
@@ -264,7 +264,7 @@ async fn upload_asset(cx: &Cx, body: Body) -> topcoat::Result<Response> {
264264 &repo,
265265 &release,
266266 &user,
267- path_param::<Asset>(cx),
267+ asset(cx),
268268 content_type.as_deref(),
269269 stream,
270270 max_bytes,
@@ -287,17 +287,17 @@ async fn upload_asset(cx: &Cx, body: Body) -> topcoat::Result<Response> {
287287
288288 #[route(DELETE "/api/v1/repos/{owner}/{repo}/releases/{id}/assets/{asset}")]
289289 async fn delete_asset(cx: &Cx) -> topcoat::Result<Response> {
290- let state = app_context::<AppState>(cx);
290+ let state = context::<AppState>(cx);
291291 let (repo, _user) = match write_context(cx).await {
292292 Ok(found) => found,
293293 Err(res) => return Ok(*res),
294294 };
295- let release = match release_in_repo(state, &repo, path_param::<Id>(cx)).await {
295+ let release = match release_in_repo(state, &repo, id(cx)).await {
296296 Ok(release) => release,
297297 Err(res) => return Ok(*res),
298298 };
299299 // The asset may be named by its forge id or by the integer shown as `id` in the JSON.
300- let mut asset = path_param::<Asset>(cx).to_owned();
300+ let mut asset = asset(cx).to_owned();
301301 if gitea::is_numeric(&asset)
302302 && let Ok(assets) = state.store.list_release_assets(&release.id).await
303303 && let Some(found) = assets
@@ -318,21 +318,14 @@ const MAX_JSON_BYTES: usize = 64 * 1024;
318318 /// Authenticates an optional caller and loads the repo for reading. Also reports whether the
319319 /// caller may write, which decides whether drafts are visible.
320320 async fn read_context(cx: &Cx) -> Result<(CoreRepo, bool), Refusal> {
321- let state = app_context::<AppState>(cx);
321+ let state = context::<AppState>(cx);
322322 let actor = api::authenticate(state, client_ip(cx), headers(cx)).await?;
323- let repo = api::load_repo(
324- state,
325- actor.as_ref(),
326- path_param::<Owner>(cx),
327- path_param::<Repo>(cx),
328- Action::Read,
329- )
330- .await?;
323+ let repo = api::load_repo(state, actor.as_ref(), owner(cx), repo(cx), Action::Read).await?;
331324 let can_write = api::load_repo(
332325 state,
333326 actor.as_ref(),
334- path_param::<Owner>(cx),
335- path_param::<Repo>(cx),
327+ owner(cx),
328+ self::repo(cx),
336329 Action::Write,
337330 )
338331 .await
@@ -342,16 +335,9 @@ async fn read_context(cx: &Cx) -> Result<(CoreRepo, bool), Refusal> {
342335
343336 /// Authenticates a required caller with write access and loads the repo.
344337 async fn write_context(cx: &Cx) -> Result<(CoreRepo, User), Refusal> {
345- let state = app_context::<AppState>(cx);
338+ let state = context::<AppState>(cx);
346339 let actor = api::authenticate(state, client_ip(cx), headers(cx)).await?;
347- let repo = api::load_repo(
348- state,
349- actor.as_ref(),
350- path_param::<Owner>(cx),
351- path_param::<Repo>(cx),
352- Action::Write,
353- )
354- .await?;
340+ let repo = api::load_repo(state, actor.as_ref(), owner(cx), repo(cx), Action::Write).await?;
355341 match actor {
356342 Some(user) => Ok((repo, user)),
357343 None => Err(Box::new(api::unauthorized())),
crates/forge-web/src/api/statuses.rsmodified+7 -21
@@ -8,7 +8,7 @@ use forge_core::Action;
88 use forge_core::store::commit_status::{CommitStatus, DEFAULT_CONTEXT, StatusState, combine};
99 use serde::Deserialize;
1010 use serde_json::{Value, json};
11-use topcoat::context::{Cx, app_context};
11+use topcoat::context::{Cx, context};
1212 use topcoat::router::request::headers;
1313 use topcoat::router::response::Response;
1414 use topcoat::router::{Body, StatusCode, path_param, route};
@@ -35,19 +35,12 @@ struct ReportBody {
3535
3636 #[route(POST "/api/v1/repos/{owner}/{repo}/statuses/{sha}")]
3737 async fn report_status(cx: &Cx, body: Body) -> topcoat::Result<Response> {
38- let state = app_context::<AppState>(cx);
38+ let state = context::<AppState>(cx);
3939 let actor = match api::authenticate(state, client_ip(cx), headers(cx)).await {
4040 Ok(actor) => actor,
4141 Err(res) => return Ok(*res),
4242 };
43- let repo = match api::load_repo(
44- state,
45- actor.as_ref(),
46- path_param::<Owner>(cx),
47- path_param::<Repo>(cx),
48- Action::Write,
49- )
50- .await
43+ let repo = match api::load_repo(state, actor.as_ref(), owner(cx), repo(cx), Action::Write).await
5144 {
5245 Ok(repo) => repo,
5346 Err(res) => return Ok(*res),
@@ -55,7 +48,7 @@ async fn report_status(cx: &Cx, body: Body) -> topcoat::Result<Response> {
5548 let Some(user) = actor else {
5649 return Ok(api::unauthorized());
5750 };
58- let Some(sha) = api::normalize_sha(path_param::<Sha>(cx)) else {
51+ let Some(sha) = api::normalize_sha(sha(cx)) else {
5952 return Ok(not_a_full_sha());
6053 };
6154 let bytes = match api::read_body(body, MAX_BODY_BYTES).await {
@@ -117,24 +110,17 @@ async fn report_status(cx: &Cx, body: Body) -> topcoat::Result<Response> {
117110
118111 #[route(GET "/api/v1/repos/{owner}/{repo}/commits/{sha}/statuses")]
119112 async fn list_statuses(cx: &Cx) -> topcoat::Result<Response> {
120- let state = app_context::<AppState>(cx);
113+ let state = context::<AppState>(cx);
121114 let actor = match api::authenticate(state, client_ip(cx), headers(cx)).await {
122115 Ok(actor) => actor,
123116 Err(res) => return Ok(*res),
124117 };
125- let repo = match api::load_repo(
126- state,
127- actor.as_ref(),
128- path_param::<Owner>(cx),
129- path_param::<Repo>(cx),
130- Action::Read,
131- )
132- .await
118+ let repo = match api::load_repo(state, actor.as_ref(), owner(cx), repo(cx), Action::Read).await
133119 {
134120 Ok(repo) => repo,
135121 Err(res) => return Ok(*res),
136122 };
137- let Some(sha) = api::normalize_sha(path_param::<Sha>(cx)) else {
123+ let Some(sha) = api::normalize_sha(sha(cx)) else {
138124 return Ok(not_a_full_sha());
139125 };
140126 let path = match api::repo_dir(state, &repo) {
crates/forge-web/src/auth.rsmodified+5 -5
@@ -13,7 +13,7 @@ use forge_core::token::{constant_time_eq, hash_token};
1313 use forge_core::{Session, Store, User, secret, totp};
1414 use tokio::sync::Semaphore;
1515 use topcoat::Result;
16-use topcoat::context::{Cx, app_context};
16+use topcoat::context::{Cx, context};
1717 use topcoat::cookie::{Cookie, Cookies, SameSite, cookies, time};
1818 use topcoat::router::error::{forbidden, see_other};
1919 use topcoat::router::request::{headers, uri};
@@ -54,7 +54,7 @@ pub async fn current_user(cx: &Cx) -> forge_core::Result<Option<(User, Session)>
5454 let Some(cookie) = session_jar(cx).get(SESSION_COOKIE) else {
5555 return Ok(None);
5656 };
57- let store = &app_context::<AppState>(cx).store;
57+ let store = &context::<AppState>(cx).store;
5858 let Some(session) = store
5959 .session_by_token_hash(&hash_token(cookie.value()))
6060 .await?
@@ -76,7 +76,7 @@ pub async fn current_user(cx: &Cx) -> forge_core::Result<Option<(User, Session)>
7676
7777 /// Creates a session for `user` and sets the session cookie on the response.
7878 pub async fn login(cx: &Cx, user: &User) -> forge_core::Result<Session> {
79- let store = &app_context::<AppState>(cx).store;
79+ let store = &context::<AppState>(cx).store;
8080 let token = new_session_token();
8181 let addr = client_addr(cx).to_string();
8282 let session = store
@@ -90,7 +90,7 @@ pub async fn login(cx: &Cx, user: &User) -> forge_core::Result<Session> {
9090 )
9191 .await?;
9292 // A new sign-in shows up in the user's session list in their other open tabs.
93- app_context::<AppState>(cx)
93+ context::<AppState>(cx)
9494 .live
9595 .bump(&crate::live::Topic::Account(user.id.clone()));
9696 let max_age = time::Duration::seconds(i64::try_from(SESSION_TTL.as_secs()).unwrap_or(i64::MAX));
@@ -108,7 +108,7 @@ pub async fn login(cx: &Cx, user: &User) -> forge_core::Result<Session> {
108108
109109 /// Deletes the session row and clears the cookie.
110110 pub async fn logout(cx: &Cx, session: &Session) -> forge_core::Result<()> {
111- let state = app_context::<AppState>(cx);
111+ let state = context::<AppState>(cx);
112112 state.store.delete_session(&session.id).await?;
113113 // The user's other tabs may show this session (a page that now leaves for the login page).
114114 crate::pages::settings_live::bump_account(state, &session.user_id);
crates/forge-web/src/boot.rsmodified+4 -6
@@ -18,7 +18,7 @@ use tokio::net::{TcpListener, UnixListener};
1818 use tokio::signal::unix::{SignalKind, signal};
1919 use tokio::sync::Notify;
2020 use tokio::sync::watch;
21-use topcoat::cookie::RouterBuilderCookieExt;
21+use topcoat::cookie::CookieLayer;
2222 use topcoat::router::tower::TowerLayer;
2323 use topcoat::router::{Compression, Router, RouterBuilderDiscoverExt, RouterService};
2424
@@ -169,11 +169,9 @@ pub async fn serve(
169169 // `ResponseCompression` compresses text responses only and skips git, LFS, raw and archive paths.
170170 let public: Router = Router::builder()
171171 .discover()
172- .app_context(state.clone())
172+ .with(state.clone())
173173 .layer(crate::pages::settings_live::AccountWriteLayer)
174- .cookies()
175- .layer(crate::pages::settings_profile::avatar_body_limit())
176- .layer(crate::pages::settings_profile::org_avatar_body_limit())
174+ .layer(CookieLayer::new())
177175 .layer(crate::pages::repo_ctx::RepoMovedLayer)
178176 .layer(crate::pages::pull_live::PullWriteLayer)
179177 .layer(crate::pages::discussion_live::DiscussionWriteLayer)
@@ -181,7 +179,7 @@ pub async fn serve(
181179 .layer(crate::pages::repo_settings_live::RepoSettingsWriteLayer)
182180 .layer(crate::pages::not_found_page::NotFoundLayer)
183181 .layer(TowerLayer::new(crate::compression::ResponseCompression))
184- .compression(Compression::off())
182+ .with(Compression::disable())
185183 .build();
186184 let internal_router = internal::router(state.clone());
187185 let raw_router = raw::router(state.clone());
crates/forge-web/src/ci/api.rsmodified+19 -19
@@ -22,7 +22,7 @@ use futures_util::StreamExt;
2222 use http::header::HeaderValue;
2323 use serde_json::json;
2424 use std::collections::BTreeMap;
25-use topcoat::context::{Cx, app_context};
25+use topcoat::context::{Cx, context};
2626 use topcoat::router::request::headers;
2727 use topcoat::router::response::Response;
2828 use topcoat::router::{Body, HeaderMap, StatusCode, path_param, route};
@@ -146,7 +146,7 @@ pub fn valid_artifact_name(name: &str) -> bool {
146146
147147 #[route(POST "/api/v1/ci/runners/register")]
148148 async fn register(cx: &Cx, body: Body) -> topcoat::Result<Response> {
149- let state = app_context::<AppState>(cx);
149+ let state = context::<AppState>(cx);
150150 let request: RegisterRequest = match json_body(body).await {
151151 Ok(request) => request,
152152 Err(res) => return Ok(*res),
@@ -189,7 +189,7 @@ async fn register(cx: &Cx, body: Body) -> topcoat::Result<Response> {
189189
190190 #[route(POST "/api/v1/ci/runners/claim")]
191191 async fn claim(cx: &Cx, body: Body) -> topcoat::Result<Response> {
192- let state = app_context::<AppState>(cx);
192+ let state = context::<AppState>(cx);
193193 // The labels in the request are ignored: the labels stored at registration are used, plus the
194194 // arch and OS the runner reports, so `runs_on = ["aarch64"]` needs no admin to type a label.
195195 let mut runner = match runner_from(state, headers(cx)).await {
@@ -330,7 +330,7 @@ async fn set_restart_header(state: &AppState, runner_id: &str, res: &mut Respons
330330 /// number the forge wants for this boot id, so the runner resends what was lost.
331331 #[route(POST "/api/v1/ci/runners/log")]
332332 async fn runner_log(cx: &Cx, body: Body) -> topcoat::Result<Response> {
333- let state = app_context::<AppState>(cx);
333+ let state = context::<AppState>(cx);
334334 let runner = match runner_from(state, headers(cx)).await {
335335 Ok(runner) => runner,
336336 Err(res) => return Ok(*res),
@@ -364,7 +364,7 @@ async fn runner_log(cx: &Cx, body: Body) -> topcoat::Result<Response> {
364364 /// page. Answers 204 with no body.
365365 #[route(POST "/api/v1/ci/runners/metrics")]
366366 async fn runner_metrics(cx: &Cx, body: Body) -> topcoat::Result<Response> {
367- let state = app_context::<AppState>(cx);
367+ let state = context::<AppState>(cx);
368368 let runner = match runner_from(state, headers(cx)).await {
369369 Ok(runner) => runner,
370370 Err(res) => return Ok(*res),
@@ -397,7 +397,7 @@ async fn runner_metrics(cx: &Cx, body: Body) -> topcoat::Result<Response> {
397397 /// starts, applies them to its in-memory config, then reports its effective config here.
398398 #[route(GET "/api/v1/ci/runners/config")]
399399 async fn runner_config_get(cx: &Cx) -> topcoat::Result<Response> {
400- let state = app_context::<AppState>(cx);
400+ let state = context::<AppState>(cx);
401401 let runner = match runner_from(state, headers(cx)).await {
402402 Ok(runner) => runner,
403403 Err(res) => return Ok(*res),
@@ -407,7 +407,7 @@ async fn runner_config_get(cx: &Cx) -> topcoat::Result<Response> {
407407
408408 #[route(PUT "/api/v1/ci/runners/config")]
409409 async fn runner_config_put(cx: &Cx, body: Body) -> topcoat::Result<Response> {
410- let state = app_context::<AppState>(cx);
410+ let state = context::<AppState>(cx);
411411 let runner = match runner_from(state, headers(cx)).await {
412412 Ok(runner) => runner,
413413 Err(res) => return Ok(*res),
@@ -557,7 +557,7 @@ fn idle_text(skips: &QueueSkips, free: Option<u64>) -> Option<String> {
557557 /// The running binary, for a runner that updates itself. 404 unless self-update is enabled.
558558 #[route(GET "/api/v1/ci/runners/binary")]
559559 async fn runner_binary(cx: &Cx) -> topcoat::Result<Response> {
560- let state = app_context::<AppState>(cx);
560+ let state = context::<AppState>(cx);
561561 if let Err(res) = runner_from(state, headers(cx)).await {
562562 return Ok(*res);
563563 }
@@ -768,8 +768,8 @@ async fn is_fork_run(state: &AppState, run: &CiRun) -> Result<bool, Refusal> {
768768
769769 #[route(POST "/api/v1/ci/jobs/{job_id}/heartbeat")]
770770 async fn heartbeat(cx: &Cx) -> topcoat::Result<Response> {
771- let state = app_context::<AppState>(cx);
772- let job = match job_from(state, headers(cx), path_param::<JobId>(cx)).await {
771+ let state = context::<AppState>(cx);
772+ let job = match job_from(state, headers(cx), job_id(cx)).await {
773773 Ok(job) => job,
774774 Err(res) => return Ok(*res),
775775 };
@@ -845,9 +845,9 @@ enum LogWrite {
845845
846846 #[route(POST "/api/v1/ci/jobs/{job_id}/logs")]
847847 async fn append_log(cx: &Cx, body: Body) -> topcoat::Result<Response> {
848- let state = app_context::<AppState>(cx);
848+ let state = context::<AppState>(cx);
849849 let headers = headers(cx);
850- let job = match job_from(state, headers, path_param::<JobId>(cx)).await {
850+ let job = match job_from(state, headers, job_id(cx)).await {
851851 Ok(job) => job,
852852 Err(res) => return Ok(*res),
853853 };
@@ -1037,12 +1037,12 @@ async fn store_log_bytes(
10371037
10381038 #[route(PUT "/api/v1/ci/jobs/{job_id}/artifacts/{artifact_name}")]
10391039 async fn upload_artifact(cx: &Cx, body: Body) -> topcoat::Result<Response> {
1040- let state = app_context::<AppState>(cx);
1041- let job = match job_from(state, headers(cx), path_param::<JobId>(cx)).await {
1040+ let state = context::<AppState>(cx);
1041+ let job = match job_from(state, headers(cx), job_id(cx)).await {
10421042 Ok(job) => job,
10431043 Err(res) => return Ok(*res),
10441044 };
1045- let name = path_param::<ArtifactName>(cx);
1045+ let name = artifact_name(cx);
10461046 if !valid_artifact_name(name) {
10471047 return Ok(api::error(
10481048 StatusCode::UNPROCESSABLE_ENTITY,
@@ -1187,8 +1187,8 @@ fn upload_failure(e: CoreError, interrupted: bool) -> Refusal {
11871187
11881188 #[route(POST "/api/v1/ci/jobs/{job_id}/finish")]
11891189 async fn finish(cx: &Cx, body: Body) -> topcoat::Result<Response> {
1190- let state = app_context::<AppState>(cx);
1191- let job = match job_from(state, headers(cx), path_param::<JobId>(cx)).await {
1190+ let state = context::<AppState>(cx);
1191+ let job = match job_from(state, headers(cx), job_id(cx)).await {
11921192 Ok(job) => job,
11931193 Err(res) => return Ok(*res),
11941194 };
@@ -1210,8 +1210,8 @@ async fn finish(cx: &Cx, body: Body) -> topcoat::Result<Response> {
12101210
12111211 #[route(POST "/api/v1/ci/jobs/{job_id}/requeue")]
12121212 async fn requeue(cx: &Cx, body: Body) -> topcoat::Result<Response> {
1213- let state = app_context::<AppState>(cx);
1214- let job = match job_from(state, headers(cx), path_param::<JobId>(cx)).await {
1213+ let state = context::<AppState>(cx);
1214+ let job = match job_from(state, headers(cx), job_id(cx)).await {
12151215 Ok(job) => job,
12161216 Err(res) => return Ok(*res),
12171217 };
crates/forge-web/src/client_ip.rsmodified+2 -2
@@ -8,7 +8,7 @@
88 use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
99
1010 use ipnet::IpNet;
11-use topcoat::context::{Cx, app_context};
11+use topcoat::context::{Cx, context};
1212 use topcoat::router::request::{headers, remote_addr};
1313
1414 use crate::state::AppState;
@@ -24,7 +24,7 @@ pub fn client_ip(cx: &Cx) -> IpAddr {
2424 /// The exact client address for this request, normalized but not bucketed, for display and audit.
2525 /// Unix-socket requests map to the unspecified address.
2626 pub fn client_addr(cx: &Cx) -> IpAddr {
27- let live = app_context::<AppState>(cx).live();
27+ let live = context::<AppState>(cx).live();
2828 let trusted = &live.trusted_proxies;
2929 let peer = remote_addr(cx).map(|addr| addr.ip());
3030 let forwarded = headers(cx)
crates/forge-web/src/git_http.rsmodified+8 -8
@@ -2,7 +2,7 @@
22 //! Streams bodies to and from `git <svc> --stateless-rpc`; gzip request bodies are decoded.
33 //!
44 //! Compression must be off for these responses. Topcoat's compression is configured only on the
5-//! router builder (`Router::builder().compression(Compression::off())`), so boot.rs has to set it.
5+//! router builder (`Router::builder().with(Compression::disable())`), so boot.rs has to set it.
66
77 use std::net::IpAddr;
88 use std::time::Instant;
@@ -20,7 +20,7 @@ use http_body_util::StreamBody;
2020 use tokio::io::AsyncReadExt;
2121 use tokio::process::{Child, ChildStdin};
2222 use tokio_util::io::{ReaderStream, StreamReader};
23-use topcoat::context::{Cx, app_context};
23+use topcoat::context::{Cx, context};
2424 use topcoat::router::request::headers;
2525 use topcoat::router::response::Response;
2626 use topcoat::router::{Body, HeaderMap, StatusCode, path_param, query_params, route};
@@ -46,10 +46,10 @@ async fn info_refs(cx: &Cx) -> topcoat::Result<Response> {
4646 return Ok(text(StatusCode::FORBIDDEN, "dumb protocol not supported"));
4747 };
4848
49- let state = app_context::<AppState>(cx);
49+ let state = context::<AppState>(cx);
5050 let headers = headers(cx);
51- let owner = path_param::<Owner>(cx);
52- let repo_name = path_param::<Repo>(cx);
51+ let owner = owner(cx);
52+ let repo_name = repo(cx);
5353
5454 let (actor, repo, path) =
5555 match caller_repo(state, client_ip(cx), headers, owner, repo_name, service).await {
@@ -102,10 +102,10 @@ async fn receive_pack(cx: &Cx, body: Body) -> topcoat::Result<Response> {
102102 /// Shared body of the two POST routes: authorize, spawn `git <svc> --stateless-rpc`, pipe the
103103 /// request body into its stdin and stream its stdout back.
104104 async fn serve_rpc(cx: &Cx, service: GitService, body: Body) -> Response {
105- let state = app_context::<AppState>(cx);
105+ let state = context::<AppState>(cx);
106106 let headers = headers(cx);
107- let owner = path_param::<Owner>(cx);
108- let repo_name = path_param::<Repo>(cx);
107+ let owner = owner(cx);
108+ let repo_name = repo(cx);
109109
110110 let (actor, repo, path) =
111111 match caller_repo(state, client_ip(cx), headers, owner, repo_name, service).await {
crates/forge-web/src/internal.rsmodified+7 -7
@@ -14,7 +14,7 @@ use forge_core::protection::effective;
1414 use forge_core::{Repo, Role, Store};
1515 use forge_git::{GitCommand, GitEnv};
1616 use serde::{Deserialize, Serialize};
17-use topcoat::context::{Cx, app_context};
17+use topcoat::context::{Cx, context};
1818 use topcoat::router::content::Json;
1919 use topcoat::router::error::{bad_request, forbidden};
2020 use topcoat::router::request::headers;
@@ -121,7 +121,7 @@ pub fn router(state: AppState) -> Router {
121121 "/internal/admin/live",
122122 admin_live,
123123 ))
124- .app_context(state)
124+ .with(state)
125125 .build()
126126 }
127127
@@ -144,7 +144,7 @@ async fn hook_endpoint(
144144 body: Body,
145145 stage: Stage,
146146 ) -> topcoat::Result<topcoat::router::response::Response> {
147- let state = app_context::<AppState>(cx);
147+ let state = context::<AppState>(cx);
148148 let presented = headers(cx)
149149 .get(TOKEN_HEADER)
150150 .and_then(|v| v.to_str().ok())
@@ -219,7 +219,7 @@ struct AdminLiveRequest {
219219 /// `POST /internal/admin/live`. Wakes the open pages of the running server for a write made by
220220 /// another process (the admin CLI). The body is small and the answer carries no data.
221221 async fn admin_live_endpoint(cx: &Cx, body: Body) -> topcoat::Result<Response> {
222- let state = app_context::<AppState>(cx);
222+ let state = context::<AppState>(cx);
223223 if !admin_authorized(cx, state) {
224224 return Err(forbidden().into());
225225 }
@@ -261,7 +261,7 @@ async fn admin_live_endpoint(cx: &Cx, body: Body) -> topcoat::Result<Response> {
261261
262262 /// `POST /internal/admin/lfs-gc`. The body is ignored.
263263 async fn admin_lfs_gc_endpoint(cx: &Cx, _body: Body) -> topcoat::Result<Response> {
264- let state = app_context::<AppState>(cx);
264+ let state = context::<AppState>(cx);
265265 if !admin_authorized(cx, state) {
266266 return Err(forbidden().into());
267267 }
@@ -306,7 +306,7 @@ fn admin_authorized(cx: &Cx, state: &AppState) -> bool {
306306 }
307307
308308 async fn admin_backup_endpoint(cx: &Cx, body: Body) -> topcoat::Result<Response> {
309- let state = app_context::<AppState>(cx);
309+ let state = context::<AppState>(cx);
310310 if !admin_authorized(cx, state) {
311311 return Err(forbidden().into());
312312 }
@@ -348,7 +348,7 @@ async fn admin_backup_endpoint(cx: &Cx, body: Body) -> topcoat::Result<Response>
348348 }
349349
350350 async fn admin_fsck_endpoint(cx: &Cx, body: Body) -> topcoat::Result<Response> {
351- let state = app_context::<AppState>(cx);
351+ let state = context::<AppState>(cx);
352352 if !admin_authorized(cx, state) {
353353 return Err(forbidden().into());
354354 }
crates/forge-web/src/lfs/routes.rsmodified+15 -15
@@ -21,7 +21,7 @@ use serde_json::{Value, json};
2121 use sha2::{Digest, Sha256};
2222 use tokio::io::AsyncWriteExt;
2323 use tokio_util::io::ReaderStream;
24-use topcoat::context::{Cx, app_context};
24+use topcoat::context::{Cx, context};
2525 use topcoat::router::request::headers;
2626 use topcoat::router::response::Response;
2727 use topcoat::router::{Body, HeaderMap, StatusCode, path_param, route, to_bytes};
@@ -74,10 +74,10 @@ struct VerifyRequest {
7474
7575 #[route(POST "/{owner}/{repo}/info/lfs/objects/batch")]
7676 async fn batch(cx: &Cx, body: Body) -> topcoat::Result<Response> {
77- let state = app_context::<AppState>(cx);
77+ let state = context::<AppState>(cx);
7878 let headers = headers(cx);
79- let owner = path_param::<Owner>(cx);
80- let name = path_param::<Repo>(cx);
79+ let owner = owner(cx);
80+ let name = repo(cx);
8181
8282 let bytes = to_bytes(body, MAX_BATCH_BYTES).await?;
8383 let BatchPlan { request, action } = match parse_batch_operation(&bytes) {
@@ -194,11 +194,11 @@ fn parse_batch_operation(bytes: &[u8]) -> Result<BatchPlan, Box<Response>> {
194194
195195 #[route(GET "/{owner}/{repo}/info/lfs/objects/{oid}")]
196196 async fn get_object(cx: &Cx) -> topcoat::Result<Response> {
197- let state = app_context::<AppState>(cx);
197+ let state = context::<AppState>(cx);
198198 let headers = headers(cx);
199- let owner = path_param::<Owner>(cx);
200- let name = path_param::<Repo>(cx);
201- let oid = path_param::<Oid>(cx);
199+ let owner = owner(cx);
200+ let name = repo(cx);
201+ let oid = oid(cx);
202202 if !is_valid_oid(oid) {
203203 return Ok(message(StatusCode::UNPROCESSABLE_ENTITY, "invalid oid"));
204204 }
@@ -234,11 +234,11 @@ async fn get_object(cx: &Cx) -> topcoat::Result<Response> {
234234
235235 #[route(PUT "/{owner}/{repo}/info/lfs/objects/{oid}")]
236236 async fn put_object(cx: &Cx, body: Body) -> topcoat::Result<Response> {
237- let state = app_context::<AppState>(cx);
237+ let state = context::<AppState>(cx);
238238 let headers = headers(cx);
239- let owner = path_param::<Owner>(cx);
240- let name = path_param::<Repo>(cx);
241- let oid = path_param::<Oid>(cx);
239+ let owner = owner(cx);
240+ let name = repo(cx);
241+ let oid = oid(cx);
242242 if !is_valid_oid(oid) {
243243 return Ok(message(StatusCode::UNPROCESSABLE_ENTITY, "invalid oid"));
244244 }
@@ -275,10 +275,10 @@ async fn put_object(cx: &Cx, body: Body) -> topcoat::Result<Response> {
275275
276276 #[route(POST "/{owner}/{repo}/info/lfs/objects/verify")]
277277 async fn verify(cx: &Cx, body: Body) -> topcoat::Result<Response> {
278- let state = app_context::<AppState>(cx);
278+ let state = context::<AppState>(cx);
279279 let headers = headers(cx);
280- let owner = path_param::<Owner>(cx);
281- let name = path_param::<Repo>(cx);
280+ let owner = owner(cx);
281+ let name = repo(cx);
282282
283283 let repo = match authorize(state, client_ip(cx), headers, owner, name, Action::Write).await {
284284 Ok(repo) => repo,
crates/forge-web/src/main.rsmodified+1 -1
@@ -77,7 +77,7 @@ const USAGE: &str = "usage: forge [--config <path>] [serve | hook <pre-receive|p
7777 const DEFAULT_CONFIG: &str = "config/forge.toml";
7878
7979 #[route(GET "/healthz")]
80-async fn healthz() -> Result<String, topcoat::Error> {
80+async fn healthz(cx: &topcoat::context::Cx) -> Result<String, topcoat::Error> {
8181 Ok(format!("ok {}", env!("FORGE_BUILD_SHA")))
8282 }
8383
crates/forge-web/src/oci/auth.rsmodified+2 -2
@@ -9,7 +9,7 @@ use forge_core::User;
99 use forge_core::oci as rules;
1010 use forge_core::packages::{KIND_OCI, Package};
1111 use http::header::{AUTHORIZATION, HeaderValue, WWW_AUTHENTICATE};
12-use topcoat::context::{Cx, app_context};
12+use topcoat::context::{Cx, context};
1313 use topcoat::router::StatusCode;
1414 use topcoat::router::request::headers;
1515 use topcoat::router::response::Response;
@@ -42,7 +42,7 @@ pub struct Target {
4242 /// verified here; anything else goes to the personal access token check the API uses. A bad
4343 /// credential is a 401 with the challenge, so the client can ask again.
4444 pub async fn caller(cx: &Cx) -> Result<Caller, Refusal> {
45- let state = app_context::<AppState>(cx);
45+ let state = context::<AppState>(cx);
4646 let headers = headers(cx);
4747 let Some(value) = headers.get(AUTHORIZATION).and_then(|v| v.to_str().ok()) else {
4848 return Ok(Caller { user: None });
crates/forge-web/src/oci/mod.rsmodified+5 -5
@@ -19,7 +19,7 @@ pub mod manifests;
1919 use forge_core::oci as rules;
2020 use http::header::{CONTENT_TYPE, HeaderValue};
2121 use serde_json::{Value, json};
22-use topcoat::context::{Cx, app_context};
22+use topcoat::context::{Cx, context};
2323 use topcoat::router::request::{headers, method, uri};
2424 use topcoat::router::response::Response;
2525 use topcoat::router::{Body, StatusCode, path_param, route};
@@ -105,7 +105,7 @@ fn query_value(pairs: &[(String, String)], key: &str) -> Option<String> {
105105 /// `GET /v2/`: the probe. A caller with valid credentials gets 200; anyone else the challenge.
106106 #[route(GET "/v2/")]
107107 async fn root(cx: &Cx) -> topcoat::Result<Response> {
108- let state = app_context::<AppState>(cx);
108+ let state = context::<AppState>(cx);
109109 Ok(match auth::caller(cx).await {
110110 Ok(Caller { user: Some(_) }) => json_response(StatusCode::OK, &json!({})),
111111 Ok(_) => auth::challenge(state, None),
@@ -117,7 +117,7 @@ async fn root(cx: &Cx) -> topcoat::Result<Response> {
117117 /// short-lived bearer token. Anonymous callers get an anonymous token, which reads public images.
118118 #[route(GET "/v2/token")]
119119 async fn token(cx: &Cx) -> topcoat::Result<Response> {
120- let state = app_context::<AppState>(cx);
120+ let state = context::<AppState>(cx);
121121 let caller = match auth::caller(cx).await {
122122 Ok(caller) => caller,
123123 Err(res) => return Ok(*res),
@@ -168,8 +168,8 @@ async fn delete_v2(cx: &Cx, body: Body) -> topcoat::Result<Response> {
168168 /// Routes a request below `/v2/` to its operation. The caller is resolved first, so every answer
169169 /// about a repository comes from the same identity.
170170 async fn dispatch(cx: &Cx, body: Body) -> Response {
171- let state = app_context::<AppState>(cx);
172- let segments: Vec<String> = path_param::<Rest>(cx).map(str::to_owned).collect();
171+ let state = context::<AppState>(cx);
172+ let segments: Vec<String> = rest(cx).map(str::to_owned).collect();
173173 let mut parts: Vec<&str> = segments.iter().map(String::as_str).collect();
174174 while parts.last() == Some(&"") {
175175 parts.pop();
crates/forge-web/src/pages/activity.rsmodified+3 -3
@@ -9,7 +9,7 @@ use forge_core::{Reason, User};
99 use http::header::{CACHE_CONTROL, CONTENT_TYPE, X_CONTENT_TYPE_OPTIONS};
1010 use serde_json::{Value, json};
1111 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};
12+use topcoat::context::{Cx, context};
1313 use topcoat::router::response::Response;
1414 use topcoat::router::{Body, HeaderValue, StatusCode, route};
1515
@@ -108,7 +108,7 @@ async fn activity(cx: &Cx) -> Result<Response> {
108108 *res.status_mut() = StatusCode::UNAUTHORIZED;
109109 return Ok(res);
110110 };
111- let state = app_context::<AppState>(cx);
111+ let state = context::<AppState>(cx);
112112 let body = activity_json(state, &user).await?;
113113 let mut response = Response::new(Body::from(body.to_string().into_bytes()));
114114 let headers = response.headers_mut();
@@ -131,7 +131,7 @@ async fn activity_stream(cx: &Cx) -> Result<Response> {
131131 *res.status_mut() = StatusCode::UNAUTHORIZED;
132132 return Ok(res);
133133 };
134- let state = app_context::<AppState>(cx).clone();
134+ let state = context::<AppState>(cx).clone();
135135 events_response(cx, activity_changes(state, user, "changed"))
136136 }
137137
crates/forge-web/src/pages/admin_backups.rsmodified+11 -7
@@ -12,7 +12,7 @@ use forge_core::store::backup_runs::{BackupRun, RunKind};
1212 use forge_core::{AuditAction, Error, Store, User};
1313 use serde::Deserialize;
1414 use topcoat::Result;
15-use topcoat::context::{Cx, app_context};
15+use topcoat::context::{Cx, context};
1616 use topcoat::router::content::Form;
1717 use topcoat::router::error::{forbidden, see_other};
1818 use topcoat::router::response::Response;
@@ -109,7 +109,7 @@ fn run_row(run: &BackupRun, lang: Lang) -> RunRow {
109109
110110 /// The rail of the Backups tab: Backups and Replication.
111111 #[component]
112-pub(crate) async fn backups_rail(lang: Lang, current: &'static str) -> Result<impl View> {
112+pub(crate) async fn backups_rail(cx: &Cx, lang: Lang, current: &'static str) -> Result<impl View> {
113113 let items = vec![
114114 RailItem {
115115 name: g::t(lang, K::Backups).to_owned(),
@@ -131,6 +131,7 @@ pub(crate) async fn backups_rail(lang: Lang, current: &'static str) -> Result<im
131131
132132 #[component]
133133 async fn backups_view(
134+ cx: &Cx,
134135 lang: Lang,
135136 csrf: String,
136137 enabled: bool,
@@ -213,7 +214,7 @@ async fn runs_fingerprint(store: &Store, running: Option<RunKind>) -> Result<Str
213214 #[route(GET "/admin/backups/events")]
214215 async fn backups_events(cx: &Cx) -> Result<Response> {
215216 admin_only(cx).await?;
216- let state = app_context::<AppState>(cx);
217+ let state = context::<AppState>(cx);
217218 let store = state.store.clone();
218219 let jobs = state.jobs.clone();
219220 stream_changes(
@@ -233,7 +234,7 @@ async fn backups_events(cx: &Cx) -> Result<Response> {
233234 async fn backups_page(cx: &Cx) -> Result<impl View> {
234235 let viewer = admin_only(cx).await?;
235236 let query = query_params::<NoticeQuery>(cx)?;
236- let state = app_context::<AppState>(cx);
237+ let state = context::<AppState>(cx);
237238 let lang = i18n::lang(cx, Some(&viewer.0));
238239 let runs = state.store.recent_runs(RUN_LIMIT).await?;
239240 let rows: Vec<RunRow> = runs.iter().map(|run| run_row(run, lang)).collect();
@@ -255,7 +256,7 @@ async fn backups_save(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> Res
255256 return Err(forbidden().into());
256257 }
257258 let lang = i18n::lang(cx, Some(&viewer.0));
258- let state = app_context::<AppState>(cx);
259+ let state = context::<AppState>(cx);
259260 let notice = notice_of(
260261 lang,
261262 save_topic(
@@ -289,7 +290,7 @@ async fn start_run(cx: &Cx, csrf: String, kind: RunKind) -> Result<Response> {
289290 return Err(forbidden().into());
290291 }
291292 let lang = i18n::lang(cx, Some(&viewer.0));
292- let state = app_context::<AppState>(cx);
293+ let state = context::<AppState>(cx);
293294 let notice = match launch(cx, state, &viewer.0, kind, lang).await {
294295 Ok(()) => g::started_notice(lang, kind),
295296 Err(e) => match e {
@@ -548,7 +549,10 @@ mod tests {
548549 assert_eq!(status, 200);
549550 assert!(body.contains("schedule"));
550551 assert!(body.contains("disk full"));
551- assert!(!body.contains("hc.example.test"), "a healthcheck URL is a secret and is never rendered");
552+ assert!(
553+ !body.contains("hc.example.test"),
554+ "a healthcheck URL is a secret and is never rendered"
555+ );
552556 assert!(
553557 !body.contains("SECRET-TOKEN"),
554558 "the healthcheck token must not be shown"
crates/forge-web/src/pages/admin_health.rsmodified+8 -5
@@ -14,12 +14,14 @@ use forge_core::store::replication::DB_SUBJECT;
1414 use forge_core::time::stamp_to_unix;
1515 use tokio::process::Command;
1616 use topcoat::Result;
17-use topcoat::context::{Cx, app_context};
17+use topcoat::context::{Cx, context};
1818 use topcoat::router::response::Response;
1919 use topcoat::router::{page, query_params, route};
2020 use topcoat::view::{View, component, view};
2121
22-use crate::i18n::accounts::{A, duration_short, duration_short_in, meta_line, needs_attention, on_disk, t as at};
22+use crate::i18n::accounts::{
23+ A, duration_short, duration_short_in, meta_line, needs_attention, on_disk, t as at,
24+};
2325 use crate::i18n::alerts as alert_text;
2426 use crate::i18n::{self, Lang};
2527 use crate::live::{Topic, stream_changes};
@@ -464,7 +466,7 @@ async fn alert_rows(state: &AppState, lang: Lang) -> Result<Vec<AlertRow>> {
464466
465467 /// The alert's raised time as a live relative time, worded per language.
466468 #[component]
467-async fn since_line(lang: Lang, stamp: &str) -> Result<impl View> {
469+async fn since_line(cx: &Cx, lang: Lang, stamp: &str) -> Result<impl View> {
468470 Ok(view! {
469471 if matches!(lang, Lang::Tr) {
470472 rel_time(lang: lang, stamp: stamp) " başladı"
@@ -476,6 +478,7 @@ async fn since_line(lang: Lang, stamp: &str) -> Result<impl View> {
476478
477479 #[component]
478480 async fn health_view(
481+ cx: &Cx,
479482 lang: Lang,
480483 health: Health,
481484 alerts: Vec<AlertRow>,
@@ -579,7 +582,7 @@ async fn health_view(
579582 async fn health_page(cx: &Cx) -> Result<impl View> {
580583 let viewer = admin_only(cx).await?;
581584 let lang = i18n::lang(cx, Some(&viewer.0));
582- let state = app_context::<AppState>(cx);
585+ let state = context::<AppState>(cx);
583586 let query = query_params::<HealthQuery>(cx)?;
584587 let health = gather(state, lang).await?;
585588 let all = alert_rows(state, lang).await?;
@@ -644,7 +647,7 @@ async fn health_fingerprint(state: &AppState) -> Result<String> {
644647 #[route(GET "/admin/health/events")]
645648 async fn health_events(cx: &Cx) -> Result<Response> {
646649 admin_only(cx).await?;
647- let state = app_context::<AppState>(cx).clone();
650+ let state = context::<AppState>(cx).clone();
648651 stream_changes(cx, crate::live::admin(), &[Topic::AdminHealth], move || {
649652 let state = state.clone();
650653 async move { health_fingerprint(&state).await }
crates/forge-web/src/pages/admin_mail.rsmodified+6 -5
@@ -19,7 +19,7 @@ use futures_util::{Stream, stream};
1919 use serde::Deserialize;
2020 use tokio::sync::watch;
2121 use topcoat::Result;
22-use topcoat::context::{Cx, app_context};
22+use topcoat::context::{Cx, context};
2323 use topcoat::router::content::Form;
2424 use topcoat::router::content::sse::Event;
2525 use topcoat::router::error::{forbidden, see_other};
@@ -199,6 +199,7 @@ async fn page_data(
199199
200200 #[component]
201201 async fn mail_view(
202+ cx: &Cx,
202203 lang: Lang,
203204 csrf: String,
204205 data: PageData,
@@ -332,7 +333,7 @@ async fn mail_view(
332333 async fn mail_page(cx: &Cx) -> Result<impl View> {
333334 let viewer = admin_only(cx).await?;
334335 let query = query_params::<NoticeQuery>(cx)?;
335- let state = app_context::<AppState>(cx);
336+ let state = context::<AppState>(cx);
336337 let lang = i18n::lang(cx, Some(&viewer.0));
337338 let tab = if query.tab.as_deref() == Some("queue") {
338339 Tab::Queue
@@ -398,7 +399,7 @@ async fn mail_save(cx: &Cx, Form(form): Form<SettingsForm>) -> Result<Response>
398399 return Err(forbidden().into());
399400 }
400401 let lang = i18n::lang(cx, Some(&viewer.0));
401- let state = app_context::<AppState>(cx);
402+ let state = context::<AppState>(cx);
402403 let saved = save_settings(cx, state, &viewer.0, &form, lang).await;
403404 let transport = if form.transport.is_empty() {
404405 Ok(None)
@@ -488,7 +489,7 @@ async fn mail_test(cx: &Cx, Form(form): Form<TestForm>) -> Result<Response> {
488489 return Err(forbidden().into());
489490 }
490491 let lang = i18n::lang(cx, Some(&viewer.0));
491- let state = app_context::<AppState>(cx);
492+ let state = context::<AppState>(cx);
492493 let notice = match queue_test(cx, state, &viewer.0, lang).await {
493494 Ok(()) => g::t(lang, K::TestQueued).to_owned(),
494495 Err(Error::Invalid(message)) => message,
@@ -577,7 +578,7 @@ async fn queue_action(cx: &Cx, form: QueueForm, action: QueueAction) -> Result<R
577578 return Err(forbidden().into());
578579 }
579580 let lang = i18n::lang(cx, Some(&viewer.0));
580- let state = app_context::<AppState>(cx);
581+ let state = context::<AppState>(cx);
581582 let now = now_stamp();
582583 let (done, notice) = match action {
583584 QueueAction::Retry => {
crates/forge-web/src/pages/admin_replication.rsmodified+6 -5
@@ -16,7 +16,7 @@ use forge_core::time::stamp_ago;
1616 use forge_core::{AuditAction, Error};
1717 use serde::Deserialize;
1818 use topcoat::Result;
19-use topcoat::context::{Cx, app_context};
19+use topcoat::context::{Cx, context};
2020 use topcoat::router::content::Form;
2121 use topcoat::router::error::{forbidden, see_other};
2222 use topcoat::router::response::Response;
@@ -229,6 +229,7 @@ async fn page_data(state: &AppState, lang: Lang) -> forge_core::Result<PageData>
229229
230230 #[component]
231231 async fn replication_view(
232+ cx: &Cx,
232233 lang: Lang,
233234 csrf: String,
234235 data: PageData,
@@ -352,7 +353,7 @@ async fn page_fingerprint(state: &AppState) -> Result<String> {
352353 #[route(GET "/admin/replication/events")]
353354 async fn replication_events(cx: &Cx) -> Result<Response> {
354355 admin_only(cx).await?;
355- let state = app_context::<AppState>(cx).clone();
356+ let state = context::<AppState>(cx).clone();
356357 stream_changes(
357358 cx,
358359 crate::live::admin(),
@@ -425,7 +426,7 @@ async fn replication_page(cx: &Cx) -> Result<impl View> {
425426 let viewer = admin_only(cx).await?;
426427 let query = query_params::<NoticeQuery>(cx)?;
427428 let lang = i18n::lang(cx, Some(&viewer.0));
428- let state = app_context::<AppState>(cx);
429+ let state = context::<AppState>(cx);
429430 let mut data = page_data(state, lang).await?;
430431 let list = repo_list(&mut data, query);
431432 let settings = setting_rows(state, lang, REPLICATION_KEYS).await?;
@@ -444,7 +445,7 @@ async fn replication_save(cx: &Cx, Form(form): Form<HashMap<String, String>>) ->
444445 return Err(forbidden().into());
445446 }
446447 let lang = i18n::lang(cx, Some(&viewer.0));
447- let state = app_context::<AppState>(cx);
448+ let state = context::<AppState>(cx);
448449 let notice = notice_of(
449450 lang,
450451 save_topic(
@@ -474,7 +475,7 @@ async fn replication_reconcile(cx: &Cx, Form(form): Form<ReconcileForm>) -> Resu
474475 return Err(forbidden().into());
475476 }
476477 let lang = i18n::lang(cx, Some(&viewer.0));
477- let state = app_context::<AppState>(cx);
478+ let state = context::<AppState>(cx);
478479 let notice = match reconcile_now(cx, state, &viewer.0, lang).await {
479480 Ok(()) => g::t(lang, K::ReconcileStarted).to_owned(),
480481 Err(Error::Config(message)) => message,
crates/forge-web/src/pages/admin_runners.rsmodified+39 -37
@@ -17,7 +17,7 @@ use serde::Deserialize;
1717 use time::OffsetDateTime;
1818 use time::format_description::well_known::Rfc3339;
1919 use topcoat::Result;
20-use topcoat::context::{Cx, app_context};
20+use topcoat::context::{Cx, context};
2121 use topcoat::router::content::Form;
2222 use topcoat::router::error::{SeeOther, forbidden, see_other};
2323 use topcoat::router::request::uri;
@@ -62,18 +62,8 @@ fn s(lang: Lang, en: &'static str, tr: &'static str) -> &'static str {
6262
6363 /// Extra notice words: (word, English, Turkish, is an error).
6464 const EXTRA_NOTICES: [(&str, &str, &str, bool); 8] = [
65- (
66- "saved",
67- "Saved.",
68- "Kaydedildi.",
69- false,
70- ),
71- (
72- "saved-restart",
73- "Saved.",
74- "Kaydedildi.",
75- false,
76- ),
65+ ("saved", "Saved.", "Kaydedildi.", false),
66+ ("saved-restart", "Saved.", "Kaydedildi.", false),
7767 (
7868 "reset",
7969 "Override removed.",
@@ -322,6 +312,7 @@ fn register_command(base_url: &str, token: &str) -> String {
322312
323313 #[component]
324314 async fn runners_view(
315+ cx: &Cx,
325316 lang: Lang,
326317 csrf: String,
327318 rows: Vec<RunnerRow>,
@@ -388,6 +379,7 @@ fn list_href(page: u64, notice: &str) -> String {
388379 /// that are not destructive, so the confirm button is soft.
389380 #[component]
390381 pub(crate) async fn confirm_post(
382+ cx: &Cx,
391383 lang: Lang,
392384 csrf: &str,
393385 action: &str,
@@ -433,6 +425,7 @@ fn disable_message(lang: Lang, name: &str) -> String {
433425 /// pending the control shows that instead, and the runner clears it by coming back with a new id.
434426 #[component]
435427 async fn restart_control(
428+ cx: &Cx,
436429 lang: Lang,
437430 csrf: &str,
438431 action: &str,
@@ -461,7 +454,7 @@ const PIP_MAX: u32 = 16;
461454
462455 /// The load of a runner: the jobs running, as a pip per concurrency slot, or a meter past `PIP_MAX`.
463456 #[component]
464-async fn load_meter(lang: Lang, running: u32, max: u32) -> Result<impl View> {
457+async fn load_meter(cx: &Cx, lang: Lang, running: u32, max: u32) -> Result<impl View> {
465458 let running_text = running.to_string();
466459 let meter_max = max.max(1).to_string();
467460 let use_pips = (1..=PIP_MAX).contains(&max);
@@ -492,11 +485,7 @@ async fn load_meter(lang: Lang, running: u32, max: u32) -> Result<impl View> {
492485 }
493486
494487 #[component]
495-async fn token_view(
496- lang: Lang,
497- token: String,
498- command: String,
499-) -> Result<impl View> {
488+async fn token_view(cx: &Cx, lang: Lang, token: String, command: String) -> Result<impl View> {
500489 Ok(view! {
501490 head(title: g::t(lang, K::RegistrationToken))
502491 <p class="state" role="status"><strong>(g::t(lang, K::CopyTokenNow))</strong></p>
@@ -522,7 +511,7 @@ async fn runners_page(cx: &Cx) -> Result<impl View> {
522511 let viewer = admin_only(cx).await?;
523512 let lang = i18n::lang(cx, Some(&viewer.0));
524513 let query = query_params::<RunnersQuery>(cx)?;
525- let state = app_context::<AppState>(cx);
514+ let state = context::<AppState>(cx);
526515 let tz = viewer.0.timezone.clone();
527516 let now = now_unix();
528517 let all: Vec<RunnerRow> = state
@@ -566,7 +555,7 @@ async fn runner_token_create(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<impl
566555 if !check_csrf(&viewer.1, &form.csrf) {
567556 return Err(forbidden().into());
568557 }
569- let state = app_context::<AppState>(cx);
558+ let state = context::<AppState>(cx);
570559 let lang = i18n::lang(cx, Some(&viewer.0));
571560 let ttl_hours = state.live().ci.registration_token_hours;
572561 let token = match state
@@ -617,8 +606,8 @@ async fn runner_set_disabled(cx: &Cx, Form(form): Form<DisableForm>) -> Result<S
617606 if !check_csrf(&viewer.1, &form.csrf) {
618607 return Err(forbidden().into());
619608 }
620- let id = path_param::<RunnerId>(cx);
621- let state = app_context::<AppState>(cx);
609+ let id = runner_id(cx);
610+ let state = context::<AppState>(cx);
622611 if runner_named(state, id).await?.is_none() {
623612 return Ok(back_to_list("missing"));
624613 }
@@ -636,8 +625,8 @@ async fn runner_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther>
636625 if !check_csrf(&viewer.1, &form.csrf) {
637626 return Err(forbidden().into());
638627 }
639- let id = path_param::<RunnerId>(cx);
640- let state = app_context::<AppState>(cx);
628+ let id = runner_id(cx);
629+ let state = context::<AppState>(cx);
641630 let Some(runner) = runner_named(state, id).await? else {
642631 return Ok(back_to_list("missing"));
643632 };
@@ -816,10 +805,18 @@ fn field_text(lang: Lang, key: &str) -> &'static str {
816805 "limits.cpus" => s(lang, "CPU limit", "CPU sınırı"),
817806 "limits.pids" => s(lang, "Process limit", "İşlem sınırı"),
818807 "work_dir" => s(lang, "Work directory", "Çalışma dizini"),
819- "limits.image_max_gb" => s(lang, "Image cache max (GB)", "Kalıp önbelleği üst sınırı (GB)"),
808+ "limits.image_max_gb" => s(
809+ lang,
810+ "Image cache max (GB)",
811+ "Kalıp önbelleği üst sınırı (GB)",
812+ ),
820813 "limits.job_disk_gb" => s(lang, "Disk per job (GB)", "İş başına disk (GB)"),
821814 "images.keep_days" => s(lang, "Keep images (days)", "Kalıpları sakla (gün)"),
822- "cache_max_gib" => s(lang, "Build cache max (GiB)", "Derleme önbelleği üst sınırı (GiB)"),
815+ "cache_max_gib" => s(
816+ lang,
817+ "Build cache max (GiB)",
818+ "Derleme önbelleği üst sınırı (GiB)",
819+ ),
823820 "sandbox.userns" => s(lang, "User namespaces", "Kullanıcı ad alanları"),
824821 "name" => s(lang, "Name", "Ad"),
825822 "url" => s(lang, "Forge URL", "Forge adresi"),
@@ -1371,6 +1368,7 @@ fn current(on: bool) -> Option<&'static str> {
13711368
13721369 #[component]
13731370 async fn runner_detail_view(
1371+ cx: &Cx,
13741372 lang: Lang,
13751373 csrf: String,
13761374 runner: CiRunner,
@@ -1418,7 +1416,11 @@ async fn runner_detail_view(
14181416 let slots = row.concurrency.parse::<u32>().unwrap_or(0);
14191417 let mut sub = vec![SubPart::text(row.state_text)];
14201418 if row.restart_pending.is_some() {
1421- sub.push(SubPart::text(s(lang, "restart pending", "yeniden başlatma bekliyor")));
1419+ sub.push(SubPart::text(s(
1420+ lang,
1421+ "restart pending",
1422+ "yeniden başlatma bekliyor",
1423+ )));
14221424 }
14231425 let jobs_href = format!("{}?tab=jobs", row.detail_href);
14241426 let save_action = format!("{}/settings", row.detail_href);
@@ -1644,8 +1646,8 @@ async fn runner_detail_view(
16441646 async fn runner_detail_page(cx: &Cx) -> Result<impl View> {
16451647 let viewer = admin_only(cx).await?;
16461648 let lang = i18n::lang(cx, Some(&viewer.0));
1647- let state = app_context::<AppState>(cx);
1648- let id = path_param::<RunnerId>(cx);
1649+ let state = context::<AppState>(cx);
1650+ let id = runner_id(cx);
16491651 let Some(runner) = runner_named(state, id).await? else {
16501652 return Err(back_to_list("missing").into());
16511653 };
@@ -1683,8 +1685,8 @@ async fn runner_save_settings(
16831685 if !check_csrf(&viewer.1, form.get("csrf").map_or("", String::as_str)) {
16841686 return Err(forbidden().into());
16851687 }
1686- let id = path_param::<RunnerId>(cx);
1687- let state = app_context::<AppState>(cx);
1688+ let id = runner_id(cx);
1689+ let state = context::<AppState>(cx);
16881690 let tab = tab_slug(form.get("tab").map(String::as_str));
16891691 let back = |notice: &str| {
16901692 see_other(format!(
@@ -1756,7 +1758,7 @@ async fn runner_save_settings(
17561758 #[route(GET "/admin/runners/events")]
17571759 async fn runners_events(cx: &Cx) -> Result<Response> {
17581760 admin_only(cx).await?;
1759- let state = app_context::<AppState>(cx);
1761+ let state = context::<AppState>(cx);
17601762 let wake = state.ci_live.subscribe_runners();
17611763 let events = futures_util::stream::unfold(wake, |mut wake| async move {
17621764 wake.changed().await.ok()?;
@@ -1776,8 +1778,8 @@ async fn runner_set_config(cx: &Cx, Form(form): Form<ConfigForm>) -> Result<SeeO
17761778 if !check_csrf(&viewer.1, &form.csrf) {
17771779 return Err(forbidden().into());
17781780 }
1779- let id = path_param::<RunnerId>(cx);
1780- let state = app_context::<AppState>(cx);
1781+ let id = runner_id(cx);
1782+ let state = context::<AppState>(cx);
17811783 let back = |notice: &str| {
17821784 if form.back == "detail" {
17831785 let tab = tab_slug(Some(form.tab.as_str()));
@@ -1851,8 +1853,8 @@ async fn runner_restart(cx: &Cx, Form(form): Form<RestartForm>) -> Result<SeeOth
18511853 if !check_csrf(&viewer.1, &form.csrf) {
18521854 return Err(forbidden().into());
18531855 }
1854- let id = path_param::<RunnerId>(cx);
1855- let state = app_context::<AppState>(cx);
1856+ let id = runner_id(cx);
1857+ let state = context::<AppState>(cx);
18561858 let back = |notice: &str| {
18571859 if form.back == "detail" {
18581860 see_other(format!("/admin/runners/{}?notice={}", enc(id), enc(notice)))
crates/forge-web/src/pages/admin_server.rsmodified+10 -9
@@ -21,7 +21,7 @@ use forge_core::{AuditAction, Error};
2121 use futures_util::StreamExt;
2222 use serde::Deserialize;
2323 use topcoat::Result;
24-use topcoat::context::{Cx, app_context};
24+use topcoat::context::{Cx, context};
2525 use topcoat::router::content::Form;
2626 use topcoat::router::error::{forbidden, see_other};
2727 use topcoat::router::response::Response;
@@ -546,7 +546,7 @@ pub(crate) fn with_notice(back: &str, notice: &str) -> String {
546546 /// The hidden form that resets one setting: the rows' "Reset to file value" buttons post to it by
547547 /// id. It goes outside the forms that save, since a form cannot hold another.
548548 #[component]
549-pub(crate) async fn reset_form(csrf: String, back: String) -> Result<impl View> {
549+pub(crate) async fn reset_form(cx: &Cx, csrf: String, back: String) -> Result<impl View> {
550550 Ok(view! {
551551 <form id="srv-reset" method="post" action="/admin/server/reset">
552552 <input type="hidden" name="csrf" value=(csrf.as_str())>
@@ -557,7 +557,7 @@ pub(crate) async fn reset_form(csrf: String, back: String) -> Result<impl View>
557557
558558 /// The rows of a settings topic, one line each. The caller's form holds them.
559559 #[component]
560-pub(crate) async fn setting_lines(lang: Lang, rows: Vec<Row>) -> Result<impl View> {
560+pub(crate) async fn setting_lines(cx: &Cx, lang: Lang, rows: Vec<Row>) -> Result<impl View> {
561561 Ok(view! {
562562 for r in rows.iter() {
563563 srv_row(lang: lang, row: r)
@@ -584,7 +584,7 @@ async fn search_hits(
584584 /// One setting on one line: its name, then its control (or its value when it cannot be changed
585585 /// here), then what to know about it. Every control is the same width, so the notes line up.
586586 #[component]
587-async fn srv_row(lang: Lang, row: &Row) -> Result<impl View> {
587+async fn srv_row(cx: &Cx, lang: Lang, row: &Row) -> Result<impl View> {
588588 let id = format!("srv-{}", row.key);
589589 let input = format!("srv-{}-in", row.key);
590590 Ok(view! {
@@ -619,7 +619,7 @@ async fn srv_row(lang: Lang, row: &Row) -> Result<impl View> {
619619
620620 /// The facts after a setting's control: its kind, whether a restart is needed, and its override.
621621 #[component]
622-async fn srv_hints(lang: Lang, row: &Row) -> Result<impl View> {
622+async fn srv_hints(cx: &Cx, lang: Lang, row: &Row) -> Result<impl View> {
623623 Ok(view! {
624624 <span class="srv-hints">
625625 if !row.kind_label.is_empty() {
@@ -644,6 +644,7 @@ async fn srv_hints(lang: Lang, row: &Row) -> Result<impl View> {
644644
645645 #[component]
646646 async fn server_view(
647+ cx: &Cx,
647648 lang: Lang,
648649 csrf: String,
649650 page: &'static SrvPage,
@@ -738,7 +739,7 @@ async fn server_view(
738739 async fn server_page(cx: &Cx) -> Result<impl View> {
739740 let viewer = admin_only(cx).await?;
740741 let query = query_params::<ServerQuery>(cx)?;
741- let state = app_context::<AppState>(cx);
742+ let state = context::<AppState>(cx);
742743 let lang = i18n::lang(cx, Some(&viewer.0));
743744 let slug = query.cat.as_deref().or(query.tab.as_deref()).unwrap_or("");
744745 if let Some(to) = moved_slug(slug) {
@@ -769,7 +770,7 @@ async fn server_save(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> Resu
769770 return Err(forbidden().into());
770771 }
771772 let lang = i18n::lang(cx, Some(&viewer.0));
772- let state = app_context::<AppState>(cx);
773+ let state = context::<AppState>(cx);
773774 let page = form
774775 .get("tab")
775776 .and_then(|t| page_by_slug(t))
@@ -841,7 +842,7 @@ async fn server_restart(cx: &Cx, Form(form): Form<RestartForm>) -> Result<Respon
841842 if !check_csrf(&viewer.1, &form.csrf) {
842843 return Err(forbidden().into());
843844 }
844- let state = app_context::<AppState>(cx);
845+ let state = context::<AppState>(cx);
845846 let group = Group::parse(&form.tab).unwrap_or(Group::General);
846847 audit::record(
847848 &state.store,
@@ -909,7 +910,7 @@ async fn server_reset(cx: &Cx, Form(form): Form<ResetForm>) -> Result<Response>
909910 return Err(forbidden().into());
910911 }
911912 let lang = i18n::lang(cx, Some(&viewer.0));
912- let state = app_context::<AppState>(cx);
913+ let state = context::<AppState>(cx);
913914 let notice = match reset(cx, state, &viewer.0, &form.key).await {
914915 Ok(()) => g::t(lang, K::SrvResetDone).to_owned(),
915916 Err(Error::Invalid(message)) => message,
crates/forge-web/src/pages/admin_user_detail.rsmodified+10 -8
@@ -10,7 +10,7 @@ use forge_core::store::user_delete::GHOST_USERNAME;
1010 use forge_core::{AuditAction, Store, User};
1111 use serde::Deserialize;
1212 use topcoat::Result;
13-use topcoat::context::{Cx, app_context};
13+use topcoat::context::{Cx, context};
1414 use topcoat::router::content::Form;
1515 use topcoat::router::error::{forbidden, not_found, see_other};
1616 use topcoat::router::response::Response;
@@ -88,7 +88,7 @@ fn is_ghost(user: &User) -> bool {
8888 }
8989
9090 async fn load(cx: &Cx) -> Result<Detail> {
91- let store = &app_context::<AppState>(cx).store;
91+ let store = &context::<AppState>(cx).store;
9292 let id = path_param_segment(cx, "user_id").to_owned();
9393 let Some(target) = store.user_by_id(&id).await? else {
9494 return Err(not_found().into());
@@ -161,6 +161,7 @@ fn local_stamp(stamp: &str, tz: &str) -> String {
161161
162162 #[component]
163163 async fn detail_body(
164+ cx: &Cx,
164165 lang: Lang,
165166 csrf: &str,
166167 viewer_id: &str,
@@ -445,6 +446,7 @@ async fn detail_body(
445446 /// delete, which opens the page that says what goes with it.
446447 #[component]
447448 async fn org_body(
449+ cx: &Cx,
448450 lang: Lang,
449451 org: User,
450452 members: Vec<(User, OrgMemberRole)>,
@@ -564,7 +566,7 @@ async fn account_fingerprint(store: &Store, user_id: &str) -> Result<String> {
564566 async fn detail_events(cx: &Cx) -> Result<Response> {
565567 admin_only(cx).await?;
566568 let id = path_param_segment(cx, "user_id").to_owned();
567- let store = app_context::<AppState>(cx).store.clone();
569+ let store = context::<AppState>(cx).store.clone();
568570 let topic = Topic::AdminUser(id.clone());
569571 stream_changes(cx, crate::live::admin(), &[topic], move || {
570572 let store = store.clone();
@@ -579,7 +581,7 @@ async fn detail_page(cx: &Cx) -> Result<impl View> {
579581 let viewer = admin_only(cx).await?;
580582 let lang = i18n::lang(cx, Some(&viewer.0));
581583 let query = query_params::<DoneQuery>(cx)?;
582- let store = &app_context::<AppState>(cx).store;
584+ let store = &context::<AppState>(cx).store;
583585 let id = path_param_segment(cx, "user_id").to_owned();
584586 let org = match store.user_by_id(&id).await? {
585587 Some(user) if user.is_org() => {
@@ -625,7 +627,7 @@ async fn perform(cx: &Cx, form: &ActionForm, action: Action) -> Result<(Outcome,
625627 return Err(forbidden().into());
626628 }
627629 let lang = i18n::lang(cx, Some(&viewer.0));
628- let state = app_context::<AppState>(cx);
630+ let state = context::<AppState>(cx);
629631 let store = &state.store;
630632 let detail = load(cx).await?;
631633 let target = &detail.target;
@@ -661,7 +663,7 @@ async fn perform(cx: &Cx, form: &ActionForm, action: Action) -> Result<(Outcome,
661663 Ok(()) => {
662664 // A suspension ends the user's sessions: their open tabs must see it.
663665 crate::pages::settings_live::bump_account(
664- app_context::<AppState>(cx),
666+ context::<AppState>(cx),
665667 &target.id,
666668 );
667669 audit(
@@ -748,8 +750,8 @@ async fn perform(cx: &Cx, form: &ActionForm, action: Action) -> Result<(Outcome,
748750
749751 /// Redirects to the detail page after a success, or renders it with a message.
750752 async fn respond(cx: &Cx, form: ActionForm, action: Action) -> Result<impl View> {
751- // `view!` expects the `__cx` binding that `#[page]` provides.
752- let __cx = cx;
753+ // `view!` expects the `cx` binding that `#[page]` provides.
754+ let cx = cx;
753755 let (outcome, detail) = perform(cx, &form, action).await?;
754756 let viewer = admin_only(cx).await?;
755757 let lang = i18n::lang(cx, Some(&viewer.0));
crates/forge-web/src/pages/admin_users.rsmodified+11 -8
@@ -7,7 +7,7 @@ use forge_core::store::user_delete::{DeletionReport, GHOST_USERNAME};
77 use forge_core::{AuditAction, Session, Store, User};
88 use serde::Deserialize;
99 use topcoat::Result;
10-use topcoat::context::{Cx, app_context};
10+use topcoat::context::{Cx, context};
1111 use topcoat::router::content::Form;
1212 use topcoat::router::error::{forbidden, not_found, see_other};
1313 use topcoat::router::response::Response;
@@ -168,6 +168,7 @@ impl UserRow {
168168
169169 #[component]
170170 async fn users_view(
171+ cx: &Cx,
171172 lang: Lang,
172173 csrf: &str,
173174 users: Vec<User>,
@@ -289,7 +290,7 @@ async fn users_view(
289290
290291 /// The rail of the Users tab: Users and Invites. `current` is `users` or `invites`.
291292 #[component]
292-pub(crate) async fn users_rail(lang: Lang, current: &'static str) -> Result<impl View> {
293+pub(crate) async fn users_rail(cx: &Cx, lang: Lang, current: &'static str) -> Result<impl View> {
293294 let items = vec![
294295 RailItem {
295296 name: g::t(lang, K::Users).to_owned(),
@@ -333,7 +334,7 @@ async fn list_fingerprint(store: &Store) -> topcoat::Result<String> {
333334 #[route(GET "/admin/users/events")]
334335 async fn users_events(cx: &Cx) -> Result<Response> {
335336 admin_only(cx).await?;
336- let store = app_context::<AppState>(cx).store.clone();
337+ let store = context::<AppState>(cx).store.clone();
337338 stream_changes(cx, crate::live::admin(), &[Topic::AdminUsers], move || {
338339 let store = store.clone();
339340 async move { list_fingerprint(&store).await }
@@ -346,7 +347,7 @@ async fn users_page(cx: &Cx) -> Result<impl View> {
346347 let viewer = admin_only(cx).await?;
347348 let lang = i18n::lang(cx, Some(&viewer.0));
348349 let (finder, kind, page) = listing_args(query_params::<UsersQuery>(cx)?);
349- let users = app_context::<AppState>(cx).store.list_users().await?;
350+ let users = context::<AppState>(cx).store.list_users().await?;
350351 let csrf = viewer.1.csrf_token.clone();
351352 let title = g::t(lang, K::Users);
352353 Ok(view! {
@@ -361,7 +362,7 @@ async fn users_create(cx: &Cx, Form(form): Form<CreateUserForm>) -> Result<impl
361362 return Err(forbidden().into());
362363 }
363364 let lang = i18n::lang(cx, Some(&viewer.0));
364- let store = &app_context::<AppState>(cx).store;
365+ let store = &context::<AppState>(cx).store;
365366
366367 // Ok(Ok(user)) created; Ok(Err(message)) rejected with a user-facing message.
367368 let outcome: Result<std::result::Result<User, String>> = create_user(store, &form, lang).await;
@@ -487,6 +488,7 @@ async fn review_target(
487488
488489 #[component]
489490 async fn delete_body(
491+ cx: &Cx,
490492 lang: Lang,
491493 csrf: &str,
492494 target: User,
@@ -555,6 +557,7 @@ async fn delete_body(
555557 /// An organization is not a person: this points at its own settings instead of offering a delete.
556558 #[component]
557559 async fn org_delete_note(
560+ cx: &Cx,
558561 lang: Lang,
559562 target: User,
560563 repos: Vec<String>,
@@ -593,7 +596,7 @@ async fn org_delete_note(
593596 async fn user_delete_page(cx: &Cx) -> Result<impl View> {
594597 let viewer = admin_only(cx).await?;
595598 let lang = i18n::lang(cx, Some(&viewer.0));
596- let store = &app_context::<AppState>(cx).store;
599+ let store = &context::<AppState>(cx).store;
597600 let target_id = path_param_segment(cx, "user_id").to_owned();
598601 let Some(target) = store.user_by_id(&target_id).await? else {
599602 return Err(not_found().into());
@@ -632,7 +635,7 @@ async fn user_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<impl View>
632635 return Err(forbidden().into());
633636 }
634637 let lang = i18n::lang(cx, Some(&viewer.0));
635- let store = &app_context::<AppState>(cx).store;
638+ let store = &context::<AppState>(cx).store;
636639 let target_id = path_param_segment(cx, "user_id").to_owned();
637640 let Some(target) = store.user_by_id(&target_id).await? else {
638641 return Err(not_found().into());
@@ -654,7 +657,7 @@ async fn user_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<impl View>
654657 match store.delete_user(&target.id, &ghost.id).await {
655658 Ok(_) => {
656659 // Their sessions and keys are gone: any open tab of theirs must leave.
657- crate::pages::settings_live::bump_account(app_context::<AppState>(cx), &target.id);
660+ crate::pages::settings_live::bump_account(context::<AppState>(cx), &target.id);
658661 audit::record(
659662 store,
660663 Some(cx),
crates/forge-web/src/pages/archive.rsmodified+5 -5
@@ -17,7 +17,7 @@ use tokio::process::Child;
1717 use tokio::sync::{OwnedSemaphorePermit, Semaphore};
1818 use tokio_util::io::ReaderStream;
1919 use topcoat::Result;
20-use topcoat::context::{Cx, app_context};
20+use topcoat::context::{Cx, context};
2121 use topcoat::router::error::not_found;
2222 use topcoat::router::response::Response;
2323 use topcoat::router::{Body, path_param, route};
@@ -73,15 +73,15 @@ fn archive_prefix(repo: &str, reference: &str, commit: &str) -> String {
7373
7474 #[route(GET "/{owner}/{repo}/archive/{*rest}")]
7575 async fn archive(cx: &Cx) -> Result<Response> {
76- let owner = path_param::<Owner>(cx);
77- let name = path_param::<Repo>(cx);
78- let rest = path_param::<Rest>(cx).collect::<Vec<_>>().join("/");
76+ let owner = owner(cx);
77+ let name = repo(cx);
78+ let rest = rest(cx).collect::<Vec<_>>().join("/");
7979 let Some((reference, format)) = split_format(&rest) else {
8080 return Err(not_found().into());
8181 };
8282
8383 let ctx = load_repo(cx, owner, name).await?;
84- let state = app_context::<AppState>(cx);
84+ let state = context::<AppState>(cx);
8585
8686 let repo_dir = ctx.path.clone();
8787 let rev = reference.to_owned();
crates/forge-web/src/pages/assets.rsmodified+38 -20
@@ -134,7 +134,7 @@ const OFFLINE_HTML: &str = include_str!("../../assets/offline.html");
134134 const OFFLINE_JS: &str = include_str!("../../assets/offline.js");
135135
136136 #[route(GET "/assets/offline.html")]
137-async fn offline_html() -> Result<(StatusCode, HeaderMap, &'static str)> {
137+async fn offline_html(cx: &Cx) -> Result<(StatusCode, HeaderMap, &'static str)> {
138138 let mut headers = HeaderMap::new();
139139 headers.insert(
140140 header::CONTENT_TYPE,
@@ -150,7 +150,7 @@ async fn offline_html() -> Result<(StatusCode, HeaderMap, &'static str)> {
150150 }
151151
152152 #[route(GET "/assets/offline.js")]
153-async fn offline_js() -> Result<(StatusCode, HeaderMap, &'static str)> {
153+async fn offline_js(cx: &Cx) -> Result<(StatusCode, HeaderMap, &'static str)> {
154154 let mut headers = HeaderMap::new();
155155 headers.insert(
156156 header::CONTENT_TYPE,
@@ -216,42 +216,42 @@ const FONT_CACHE: &str = "public, max-age=31536000, immutable";
216216 const LICENSE_CACHE: &str = "public, max-age=86400";
217217
218218 #[route(GET "/assets/fonts/figtree-5.3.0-latin-wght.woff2")]
219-async fn figtree_latin() -> Result<Bytes> {
219+async fn figtree_latin(cx: &Cx) -> Result<Bytes> {
220220 Ok(bytes_response(FIGTREE_LATIN, "font/woff2", FONT_CACHE))
221221 }
222222
223223 #[route(GET "/assets/fonts/figtree-5.3.0-latin-ext-wght.woff2")]
224-async fn figtree_latin_ext() -> Result<Bytes> {
224+async fn figtree_latin_ext(cx: &Cx) -> Result<Bytes> {
225225 Ok(bytes_response(FIGTREE_LATIN_EXT, "font/woff2", FONT_CACHE))
226226 }
227227
228228 #[route(GET "/assets/fonts/archivo-5.3.0-latin-wdth.woff2")]
229-async fn archivo_latin() -> Result<Bytes> {
229+async fn archivo_latin(cx: &Cx) -> Result<Bytes> {
230230 Ok(bytes_response(ARCHIVO_LATIN, "font/woff2", FONT_CACHE))
231231 }
232232
233233 #[route(GET "/assets/fonts/archivo-5.3.0-latin-ext-wdth.woff2")]
234-async fn archivo_latin_ext() -> Result<Bytes> {
234+async fn archivo_latin_ext(cx: &Cx) -> Result<Bytes> {
235235 Ok(bytes_response(ARCHIVO_LATIN_EXT, "font/woff2", FONT_CACHE))
236236 }
237237
238238 #[route(GET "/assets/fonts/ibm-plex-mono-2.5.0-400.woff2")]
239-async fn plex_mono_400() -> Result<Bytes> {
239+async fn plex_mono_400(cx: &Cx) -> Result<Bytes> {
240240 Ok(bytes_response(PLEX_MONO_400, "font/woff2", FONT_CACHE))
241241 }
242242
243243 #[route(GET "/assets/fonts/ibm-plex-mono-2.5.0-500.woff2")]
244-async fn plex_mono_500() -> Result<Bytes> {
244+async fn plex_mono_500(cx: &Cx) -> Result<Bytes> {
245245 Ok(bytes_response(PLEX_MONO_500, "font/woff2", FONT_CACHE))
246246 }
247247
248248 #[route(GET "/assets/fonts/ibm-plex-mono-2.5.0-600.woff2")]
249-async fn plex_mono_600() -> Result<Bytes> {
249+async fn plex_mono_600(cx: &Cx) -> Result<Bytes> {
250250 Ok(bytes_response(PLEX_MONO_600, "font/woff2", FONT_CACHE))
251251 }
252252
253253 #[route(GET "/assets/fonts/ibm-plex-mono-2.5.0-400-italic.woff2")]
254-async fn plex_mono_400_italic() -> Result<Bytes> {
254+async fn plex_mono_400_italic(cx: &Cx) -> Result<Bytes> {
255255 Ok(bytes_response(
256256 PLEX_MONO_400_ITALIC,
257257 "font/woff2",
@@ -260,7 +260,7 @@ async fn plex_mono_400_italic() -> Result<Bytes> {
260260 }
261261
262262 #[route(GET "/assets/fonts/Figtree-OFL.txt")]
263-async fn figtree_license() -> Result<Bytes> {
263+async fn figtree_license(cx: &Cx) -> Result<Bytes> {
264264 Ok(bytes_response(
265265 FIGTREE_LICENSE,
266266 "text/plain; charset=utf-8",
@@ -269,7 +269,7 @@ async fn figtree_license() -> Result<Bytes> {
269269 }
270270
271271 #[route(GET "/assets/fonts/Archivo-OFL.txt")]
272-async fn archivo_license() -> Result<Bytes> {
272+async fn archivo_license(cx: &Cx) -> Result<Bytes> {
273273 Ok(bytes_response(
274274 ARCHIVO_LICENSE,
275275 "text/plain; charset=utf-8",
@@ -278,7 +278,7 @@ async fn archivo_license() -> Result<Bytes> {
278278 }
279279
280280 #[route(GET "/assets/fonts/IBMPlexMono-OFL.txt")]
281-async fn plex_mono_license() -> Result<Bytes> {
281+async fn plex_mono_license(cx: &Cx) -> Result<Bytes> {
282282 Ok(bytes_response(
283283 PLEX_MONO_LICENSE,
284284 "text/plain; charset=utf-8",
@@ -288,13 +288,16 @@ async fn plex_mono_license() -> Result<Bytes> {
288288
289289 #[cfg(test)]
290290 mod tests {
291- use topcoat::cookie::RouterBuilderCookieExt;
291+ use topcoat::cookie::CookieLayer;
292292 use topcoat::router::request::Request;
293293 use topcoat::router::{Body, Router, RouterBuilderDiscoverExt, to_bytes};
294294
295295 #[tokio::test]
296296 async fn fonts_and_licenses_are_served() {
297- let router: Router = Router::builder().discover().cookies().build();
297+ let router: Router = Router::builder()
298+ .discover()
299+ .layer(CookieLayer::new())
300+ .build();
298301 // Bundled fonts are immutable woff2 files.
299302 for uri in [
300303 "/assets/fonts/figtree-5.3.0-latin-wght.woff2",
@@ -347,7 +350,10 @@ mod tests {
347350
348351 #[tokio::test]
349352 async fn stylesheet_is_served_with_headers_from_the_security_layer() {
350- let router: Router = Router::builder().discover().cookies().build();
353+ let router: Router = Router::builder()
354+ .discover()
355+ .layer(CookieLayer::new())
356+ .build();
351357 let req = Request::builder()
352358 .method("GET")
353359 .uri(crate::views::STYLESHEET_HREF)
@@ -373,7 +379,10 @@ mod tests {
373379
374380 #[tokio::test]
375381 async fn immutable_assets_are_served_with_long_cache() {
376- let router: Router = Router::builder().discover().cookies().build();
382+ let router: Router = Router::builder()
383+ .discover()
384+ .layer(CookieLayer::new())
385+ .build();
377386 // Each bundle is immutable under its own type. Its body holds the marker, when one is given.
378387 for (uri, kind, marker) in [
379388 (crate::views::STYLESHEET_HREF, "text/css; charset=utf-8", ""),
@@ -422,7 +431,10 @@ mod tests {
422431 #[tokio::test]
423432 async fn alive_stream_sends_retry_first() {
424433 use http_body_util::BodyExt;
425- let router: Router = Router::builder().discover().cookies().build();
434+ let router: Router = Router::builder()
435+ .discover()
436+ .layer(CookieLayer::new())
437+ .build();
426438 let req = Request::builder()
427439 .method("GET")
428440 .uri("/-/alive")
@@ -447,7 +459,10 @@ mod tests {
447459
448460 #[tokio::test]
449461 async fn offline_page_and_script_are_served_without_caching() {
450- let router: Router = Router::builder().discover().cookies().build();
462+ let router: Router = Router::builder()
463+ .discover()
464+ .layer(CookieLayer::new())
465+ .build();
451466 for (uri, kind) in [
452467 ("/assets/offline.html", "text/html"),
453468 ("/assets/offline.js", "text/javascript"),
@@ -471,7 +486,10 @@ mod tests {
471486
472487 #[tokio::test]
473488 async fn custom_css_keys_the_hue_choices_and_is_empty_without_one() {
474- let router: Router = Router::builder().discover().cookies().build();
489+ let router: Router = Router::builder()
490+ .discover()
491+ .layer(CookieLayer::new())
492+ .build();
475493 let req = Request::builder()
476494 .method("GET")
477495 .uri("/theme/custom.css?al=hue-215&ad=plum&bl=hue-7&bd=hue-360")
crates/forge-web/src/pages/audit_log.rsmodified+27 -10
@@ -7,7 +7,7 @@
77
88 use forge_core::{AuditAction, AuditEntry, AuditFilter, Store};
99 use topcoat::Result;
10-use topcoat::context::{Cx, app_context};
10+use topcoat::context::{Cx, context};
1111 use topcoat::router::response::Response;
1212 use topcoat::router::{page, query_params, route};
1313 use topcoat::view::{View, component, view};
@@ -84,7 +84,11 @@ impl Span {
8484 fn from_query(query: &AuditQuery) -> Span {
8585 let clean = |v: &Option<String>| v.clone().unwrap_or_default().trim().to_owned();
8686 let when = clean(&query.when);
87- let when = if WHENS.contains(&when.as_str()) { when } else { String::new() };
87+ let when = if WHENS.contains(&when.as_str()) {
88+ when
89+ } else {
90+ String::new()
91+ };
8892 let (from, to) = if when == "custom" {
8993 (clean(&query.from), clean(&query.to))
9094 } else {
@@ -396,6 +400,7 @@ fn nav_for(
396400 /// The search and the action filter, in one GET form to `action`.
397401 #[component]
398402 async fn log_tools(
403+ cx: &Cx,
399404 lang: Lang,
400405 form_action: &str,
401406 finder: Finder,
@@ -451,6 +456,7 @@ async fn log_tools(
451456 /// The facts of one entry after its name: time, then whatever `show` asks for.
452457 #[component]
453458 async fn entry_facts(
459+ cx: &Cx,
454460 lang: Lang,
455461 row: RowView,
456462 show_actor: bool,
@@ -477,7 +483,12 @@ async fn entry_facts(
477483 }
478484
479485 #[component]
480-async fn audit_table(lang: Lang, groups: Vec<Group>, show_actor: bool) -> Result<impl View> {
486+async fn audit_table(
487+ cx: &Cx,
488+ lang: Lang,
489+ groups: Vec<Group>,
490+ show_actor: bool,
491+) -> Result<impl View> {
481492 Ok(view! {
482493 if groups.is_empty() {
483494 <p class="state">(g::t(lang, K::NoEntries))</p>
@@ -495,7 +506,7 @@ async fn audit_table(lang: Lang, groups: Vec<Group>, show_actor: bool) -> Result
495506
496507 /// One entry on its own line.
497508 #[component]
498-async fn single_row(lang: Lang, mut group: Group, show_actor: bool) -> Result<impl View> {
509+async fn single_row(cx: &Cx, lang: Lang, mut group: Group, show_actor: bool) -> Result<impl View> {
499510 let row = group.rows.remove(0);
500511 let name = row.name.clone();
501512 let action = row.action.clone();
@@ -510,10 +521,13 @@ async fn single_row(lang: Lang, mut group: Group, show_actor: bool) -> Result<im
510521 /// A run of entries: one row with the count and what they share, which opens to list each one
511522 /// with what differs.
512523 #[component]
513-async fn group_row(lang: Lang, mut group: Group, show_actor: bool) -> Result<impl View> {
524+async fn group_row(cx: &Cx, lang: Lang, mut group: Group, show_actor: bool) -> Result<impl View> {
514525 let count = group.rows.len().to_string();
515526 let target = group.shared_target().map(str::to_owned);
516- let ip = group.shared_ip().map(str::to_owned).filter(|ip| !ip.is_empty());
527+ let ip = group
528+ .shared_ip()
529+ .map(str::to_owned)
530+ .filter(|ip| !ip.is_empty());
517531 let details = group
518532 .shared_details()
519533 .map(str::to_owned)
@@ -568,6 +582,7 @@ async fn group_row(lang: Lang, mut group: Group, show_actor: bool) -> Result<imp
568582 /// One entry inside an opened run: its time and what the run's row does not already say.
569583 #[component]
570584 async fn item_line(
585+ cx: &Cx,
571586 lang: Lang,
572587 row: RowView,
573588 show_target: bool,
@@ -583,6 +598,7 @@ async fn item_line(
583598
584599 #[component]
585600 async fn admin_audit_view(
601+ cx: &Cx,
586602 lang: Lang,
587603 live: String,
588604 finder: Finder,
@@ -612,6 +628,7 @@ async fn admin_audit_view(
612628
613629 #[component]
614630 async fn own_log_view(
631+ cx: &Cx,
615632 lang: Lang,
616633 items: Vec<RailItem>,
617634 finder: Finder,
@@ -662,7 +679,7 @@ async fn admin_audit_page(cx: &Cx) -> Result<impl View> {
662679 let viewer = admin_only(cx).await?;
663680 let lang = i18n::lang(cx, Some(&viewer.0));
664681 let query = query_params::<AuditQuery>(cx)?;
665- let store = &app_context::<AppState>(cx).store;
682+ let store = &context::<AppState>(cx).store;
666683 let (finder, action, actor) = query_parts(query);
667684 let span = Span::from_query(query);
668685
@@ -734,7 +751,7 @@ async fn admin_audit_events(cx: &Cx) -> Result<Response> {
734751 let query = query_params::<AuditQuery>(cx)?;
735752 let action = query.action.clone().unwrap_or_default().trim().to_owned();
736753 let actor = query.actor.clone().unwrap_or_default().trim().to_owned();
737- let store = app_context::<AppState>(cx).store.clone();
754+ let store = context::<AppState>(cx).store.clone();
738755 stream_changes(cx, crate::live::admin(), &[Topic::AdminAudit], move || {
739756 let store = store.clone();
740757 let action = action.clone();
@@ -749,7 +766,7 @@ async fn own_log_page(cx: &Cx) -> Result<impl View> {
749766 let viewer = require_user(cx).await?;
750767 let lang = i18n::lang(cx, Some(&viewer.0));
751768 let query = query_params::<AuditQuery>(cx)?;
752- let store = &app_context::<AppState>(cx).store;
769+ let store = &context::<AppState>(cx).store;
753770 let (finder, action, _) = query_parts(query);
754771 let span = Span::from_query(query);
755772 let mut filter = AuditFilter {
@@ -768,7 +785,7 @@ async fn own_log_page(cx: &Cx) -> Result<impl View> {
768785 let mut params = keep_params(&finder, &action, "");
769786 params.extend(span.params());
770787 let nav = nav_for(page, pages, "/settings/security/log", &params);
771- let items = security_rail_for(app_context::<AppState>(cx), lang, &viewer, "log").await?;
788+ let items = security_rail_for(context::<AppState>(cx), lang, &viewer, "log").await?;
772789 let title = g::t(lang, K::SecurityLogTitle);
773790 Ok(view! {
774791 shell(title: title, viewer: Some(&viewer), own_log_view(lang: lang, items: items, finder: finder.clone(), action: action.clone(), span: span.clone(), total: total, groups: groups, page: page, pages: pages, nav: nav))
crates/forge-web/src/pages/authoring.rsmodified+11 -11
@@ -16,7 +16,7 @@ use http_body_util::StreamBody;
1616 use serde::Deserialize;
1717 use serde_json::json;
1818 use topcoat::Result;
19-use topcoat::context::{Cx, app_context};
19+use topcoat::context::{Cx, context};
2020 use topcoat::router::content::Form;
2121 use topcoat::router::error::{bad_request, forbidden, not_found};
2222 use topcoat::router::request::{headers, uri};
@@ -121,8 +121,8 @@ fn fail(status: StatusCode, message: &str) -> Response {
121121 /// comment can attach), and the repo must not be archived.
122122 #[route(POST "/{owner}/{repo}/attachments")]
123123 async fn upload(cx: &Cx, body: Body) -> Result<Response> {
124- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
125- let state = app_context::<AppState>(cx);
124+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
125+ let state = context::<AppState>(cx);
126126 if ctx.repo.archived {
127127 return Err(forbidden().into());
128128 }
@@ -228,11 +228,11 @@ async fn upload(cx: &Cx, body: Body) -> Result<Response> {
228228 /// Serves an attachment to anyone who can read its repo; everyone else gets 404.
229229 #[route(GET "/attachments/{id}/{name}")]
230230 async fn download(cx: &Cx) -> Result<Response> {
231- let state = app_context::<AppState>(cx);
232- let Some(att) = state.store.attachment(path_param::<Id>(cx)).await? else {
231+ let state = context::<AppState>(cx);
232+ let Some(att) = state.store.attachment(id(cx)).await? else {
233233 return Err(not_found().into());
234234 };
235- if att.name != path_param::<Name>(cx) {
235+ if att.name != name(cx) {
236236 return Err(not_found().into());
237237 }
238238 let Some(repo) = state.store.repo_by_id(&att.repo_id).await? else {
@@ -289,8 +289,8 @@ async fn download(cx: &Cx) -> Result<Response> {
289289 /// `kind=issue` lists issues and pull requests by number or title.
290290 #[route(GET "/{owner}/{repo}/suggest")]
291291 async fn suggest(cx: &Cx) -> Result<Response> {
292- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
293- let state = app_context::<AppState>(cx);
292+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
293+ let state = context::<AppState>(cx);
294294 if ctx.viewer.is_none() {
295295 return Err(forbidden().into());
296296 }
@@ -364,10 +364,10 @@ async fn pull_tasks(cx: &Cx, Form(form): Form<TaskForm>) -> Result<Response> {
364364 }
365365
366366 async fn toggle(cx: &Cx, kind: ItemKind, form: TaskForm) -> Result<Response> {
367- let number = parse_number(path_param::<Number>(cx))?;
368- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
367+ let number = parse_number(number(cx))?;
368+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
369369 let (user, _) = require_csrf(cx, &form.csrf).await?;
370- let state = app_context::<AppState>(cx);
370+ let state = context::<AppState>(cx);
371371 let item = item_for(state, &ctx, kind, number).await?;
372372 let Ok(index) = form.index.parse::<usize>() else {
373373 return Err(bad_request("bad task index").into());
crates/forge-web/src/pages/avatars.rsmodified+6 -3
@@ -8,7 +8,7 @@ use http::header::{
88 };
99 use sha2::{Digest, Sha256};
1010 use topcoat::Result;
11-use topcoat::context::{Cx, app_context};
11+use topcoat::context::{Cx, context};
1212 use topcoat::router::request::headers;
1313 use topcoat::router::{path_param_segment, query_params, route};
1414
@@ -96,7 +96,7 @@ async fn avatar(cx: &Cx) -> Result<(StatusCode, HeaderMap, Vec<u8>)> {
9696 .get(IF_NONE_MATCH)
9797 .and_then(|v| v.to_str().ok())
9898 .map(str::to_owned);
99- let store = &app_context::<AppState>(cx).store;
99+ let store = &context::<AppState>(cx).store;
100100
101101 let Some(user) = store.user_by_username(&name).await? else {
102102 return Ok((
@@ -155,7 +155,10 @@ mod tests {
155155 assert_eq!(svg, super::default_svg("<"));
156156 let url = super::default_data_url("<");
157157 assert!(url.starts_with("data:image/svg+xml,%3Csvg"), "{url}");
158- assert!(!url.contains('<') && !url.contains('#') && !url.contains('"'), "{url}");
158+ assert!(
159+ !url.contains('<') && !url.contains('#') && !url.contains('"'),
160+ "{url}"
161+ );
159162 assert!(super::PALETTE.iter().any(|c| svg.contains(c)));
160163 }
161164
crates/forge-web/src/pages/banner.rsmodified+3 -3
@@ -11,7 +11,7 @@ use forge_core::config::BannerConfig;
1111 use forge_core::token::hash_token;
1212 use serde::Deserialize;
1313 use topcoat::Result;
14-use topcoat::context::{Cx, app_context, try_app_context};
14+use topcoat::context::{Cx, context, try_context};
1515 use topcoat::cookie::{Cookie, Cookies, SameSite, cookies, time};
1616 use topcoat::router::content::Form;
1717 use topcoat::router::error::{SeeOther, see_other};
@@ -66,7 +66,7 @@ pub fn view_for(config: &BannerConfig, now: i64, dismissed: Option<&str>) -> Opt
6666 /// The banner for this request, read from the live settings. `prefs` is a signed-in viewer's
6767 /// account preferences; without them the dismissal comes from the cookie.
6868 pub fn current(cx: &Cx, prefs: Option<&HashMap<String, String>>) -> Option<BannerView> {
69- let state = try_app_context::<AppState>(cx)?;
69+ let state = try_context::<AppState>(cx)?;
7070 let live = state.live();
7171 if live.banner.message.trim().is_empty() {
7272 return None;
@@ -90,7 +90,7 @@ struct DismissForm {
9090 async fn dismiss(cx: &Cx, Form(form): Form<DismissForm>) -> Result<SeeOther> {
9191 let hash_ok = form.hash.len() == 16 && form.hash.bytes().all(|b| b.is_ascii_hexdigit());
9292 if hash_ok && let Some((user, _)) = current_user(cx).await? {
93- app_context::<AppState>(cx)
93+ context::<AppState>(cx)
9494 .store
9595 .set_user_pref(&user.id, BANNER_PREF, &form.hash)
9696 .await?;
crates/forge-web/src/pages/blame.rsmodified+11 -8
@@ -7,7 +7,7 @@ use std::time::Duration;
77 use forge_git::blame::{Blame, blame};
88 use forge_git::browse::EntryKind;
99 use topcoat::Result;
10-use topcoat::context::{Cx, app_context};
10+use topcoat::context::{Cx, context};
1111 use topcoat::router::error::not_found;
1212 use topcoat::router::{page, path_param};
1313 use topcoat::view::{Unescaped, View, component, view};
@@ -16,10 +16,10 @@ use crate::i18n::browse as b;
1616 use crate::i18n::code::{self as g, K};
1717 use crate::i18n::{self, Lang};
1818 use crate::pages::blob::{Line, text_lines};
19+use crate::pages::passkeys::s;
1920 use crate::pages::ref_live;
2021 use crate::pages::repo::repo_head;
2122 use crate::pages::repo_ctx::load_repo;
22-use crate::pages::passkeys::s;
2323 use crate::pages::tree::{MAX_BLOB_BYTES, read_file, resolve};
2424 use crate::render::emoji::emojify;
2525 use crate::state::AppState;
@@ -103,7 +103,7 @@ fn build_rows(
103103 }
104104
105105 #[component]
106-async fn blame_table(rows: Vec<Row>, lang: Lang) -> Result<impl View> {
106+async fn blame_table(cx: &Cx, rows: Vec<Row>, lang: Lang) -> Result<impl View> {
107107 Ok(view! {
108108 <div class="file-view">
109109 <table class="file-table blame-table">
@@ -141,12 +141,12 @@ async fn blame_table(rows: Vec<Row>, lang: Lang) -> Result<impl View> {
141141
142142 #[page("/{owner}/{repo}/blame/{*rest}")]
143143 async fn blame_page(cx: &Cx) -> Result<impl View> {
144- let owner = path_param::<Owner>(cx);
145- let name = path_param::<Repo>(cx);
146- let rest = path_param::<Rest>(cx).collect::<Vec<_>>().join("/");
144+ let owner = owner(cx);
145+ let name = repo(cx);
146+ let rest = rest(cx).collect::<Vec<_>>().join("/");
147147
148148 let ctx = load_repo(cx, owner, name).await?;
149- let state = app_context::<AppState>(cx);
149+ let state = context::<AppState>(cx);
150150 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
151151 let repo = &ctx.repo;
152152
@@ -199,7 +199,10 @@ async fn blame_page(cx: &Cx) -> Result<impl View> {
199199 );
200200 // Blame sits beside the file's source: a markdown file's plain view, any other file's own page.
201201 let markdown = matches!(
202- file_name.rsplit_once('.').map(|(_, ext)| ext.to_ascii_lowercase()).as_deref(),
202+ file_name
203+ .rsplit_once('.')
204+ .map(|(_, ext)| ext.to_ascii_lowercase())
205+ .as_deref(),
203206 Some("md" | "markdown")
204207 );
205208 let source_href = if markdown {
crates/forge-web/src/pages/blob.rsmodified+11 -7
@@ -4,7 +4,7 @@
44
55 use forge_git::browse::EntryKind;
66 use topcoat::Result;
7-use topcoat::context::{Cx, app_context};
7+use topcoat::context::{Cx, context};
88 use topcoat::router::error::not_found;
99 use topcoat::router::{page, path_param, query_params};
1010 use topcoat::view::{Unescaped, View, component, view};
@@ -91,7 +91,7 @@ pub fn text_lines(text: &str, file_name: &str) -> Vec<Line> {
9191 }
9292
9393 #[component]
94-async fn file_table(lines: Vec<Line>) -> Result<impl View> {
94+async fn file_table(cx: &Cx, lines: Vec<Line>) -> Result<impl View> {
9595 Ok(view! {
9696 <div class="file-view">
9797 <table class="file-table">
@@ -116,13 +116,13 @@ async fn file_table(lines: Vec<Line>) -> Result<impl View> {
116116
117117 #[page("/{owner}/{repo}/blob/{*rest}")]
118118 async fn blob_page(cx: &Cx) -> Result<impl View> {
119- let owner = path_param::<Owner>(cx);
120- let name = path_param::<Repo>(cx);
121- let rest = path_param::<Rest>(cx).collect::<Vec<_>>().join("/");
119+ let owner = owner(cx);
120+ let name = repo(cx);
121+ let rest = rest(cx).collect::<Vec<_>>().join("/");
122122 let plain = query_params::<BlobQuery>(cx)?.plain.as_deref() == Some("1");
123123
124124 let ctx = load_repo(cx, owner, name).await?;
125- let state = app_context::<AppState>(cx);
125+ let state = context::<AppState>(cx);
126126 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
127127 let repo = &ctx.repo;
128128
@@ -262,7 +262,11 @@ async fn blob_page(cx: &Cx) -> Result<impl View> {
262262 let mut views: Vec<(&'static str, String, bool)> = Vec::new();
263263 if is_markdown {
264264 views.push((g::t(lang, K::Rendered), base.clone(), !plain));
265- views.push((g::t(lang, K::SourceToggle), format!("{base}?plain=1"), plain));
265+ views.push((
266+ g::t(lang, K::SourceToggle),
267+ format!("{base}?plain=1"),
268+ plain,
269+ ));
266270 } else if is_text {
267271 views.push((g::t(lang, K::SourceToggle), base.clone(), true));
268272 }
crates/forge-web/src/pages/branches.rsmodified+12 -10
@@ -9,7 +9,7 @@ use forge_git::branches;
99 use forge_git::browse::{self, RefKind};
1010 use serde::Deserialize;
1111 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};
12+use topcoat::context::{Cx, context};
1313 use topcoat::cookie::{Cookie, Cookies, SameSite, cookies};
1414 use topcoat::router::content::Form;
1515 use topcoat::router::error::{SeeOther, forbidden, see_other};
@@ -102,6 +102,7 @@ struct BranchRow {
102102
103103 #[component]
104104 async fn new_branch_form(
105+ cx: &Cx,
105106 lang: Lang,
106107 action: String,
107108 csrf: String,
@@ -134,6 +135,7 @@ async fn new_branch_form(
134135
135136 #[component]
136137 async fn branch_table(
138+ cx: &Cx,
137139 rows: Vec<BranchRow>,
138140 lang: Lang,
139141 csrf: String,
@@ -175,10 +177,10 @@ async fn branch_table(
175177
176178 #[page("/{owner}/{repo}/branches")]
177179 async fn branches_page(cx: &Cx) -> Result<impl View> {
178- let owner = path_param::<Owner>(cx);
179- let name = path_param::<Repo>(cx);
180+ let owner = owner(cx);
181+ let name = repo(cx);
180182 let ctx = load_repo(cx, owner, name).await?;
181- let state = app_context::<AppState>(cx);
183+ let state = context::<AppState>(cx);
182184 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
183185 let repo = &ctx.repo;
184186 let now = now_unix();
@@ -322,14 +324,14 @@ fn back(cx: &Cx, ctx: &RepoCtx, word: &'static str) -> SeeOther {
322324 /// A protection rule that only accepts pull requests keeps the name closed to direct creation.
323325 #[route(POST "/{owner}/{repo}/branches")]
324326 async fn branch_create(cx: &Cx, Form(form): Form<CreateForm>) -> Result<SeeOther> {
325- let owner = path_param::<Owner>(cx);
326- let name = path_param::<Repo>(cx);
327+ let owner = owner(cx);
328+ let name = repo(cx);
327329 let ctx = load_repo(cx, owner, name).await?;
328330 let (user, _) = require_csrf(cx, &form.csrf).await?;
329331 if !ctx.can_write() {
330332 return Err(forbidden().into());
331333 }
332- let state = app_context::<AppState>(cx);
334+ let state = context::<AppState>(cx);
333335 let branch = form.name.trim().to_owned();
334336 let from = match form.from.trim() {
335337 "" => ctx.repo.default_branch.clone(),
@@ -382,14 +384,14 @@ async fn branch_create(cx: &Cx, Form(form): Form<CreateForm>) -> Result<SeeOther
382384 /// branches whose protection forbids deletion are refused.
383385 #[route(POST "/{owner}/{repo}/branches/delete")]
384386 async fn branch_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther> {
385- let owner = path_param::<Owner>(cx);
386- let name = path_param::<Repo>(cx);
387+ let owner = owner(cx);
388+ let name = repo(cx);
387389 let ctx = load_repo(cx, owner, name).await?;
388390 let (user, _) = require_csrf(cx, &form.csrf).await?;
389391 if !ctx.can_write() {
390392 return Err(forbidden().into());
391393 }
392- let state = app_context::<AppState>(cx);
394+ let state = context::<AppState>(cx);
393395 let branch = form.name.trim().to_owned();
394396 if branch == ctx.repo.default_branch {
395397 return Ok(back(cx, &ctx, "default"));
crates/forge-web/src/pages/ci_badge.rsmodified+4 -4
@@ -11,7 +11,7 @@
1111 use forge_core::ci::{JobState, RunState};
1212 use http::header::{CACHE_CONTROL, CONTENT_TYPE};
1313 use topcoat::Result;
14-use topcoat::context::{Cx, app_context};
14+use topcoat::context::{Cx, context};
1515 use topcoat::router::request::uri;
1616 use topcoat::router::response::Response;
1717 use topcoat::router::{Body, HeaderValue, StatusCode, path_param, route};
@@ -205,10 +205,10 @@ fn badge_query(cx: &Cx) -> BadgeQuery {
205205 /// uses, so a private repo the viewer cannot read is a 404.
206206 #[route(GET "/{owner}/{repo}/badge.svg")]
207207 async fn ci_badge(cx: &Cx) -> Result<Response> {
208- let owner = path_param::<Owner>(cx);
209- let name = path_param::<Repo>(cx);
208+ let owner = owner(cx);
209+ let name = repo(cx);
210210 let ctx = load_repo(cx, owner, name).await?;
211- let state = app_context::<AppState>(cx);
211+ let state = context::<AppState>(cx);
212212 let query = badge_query(cx);
213213 let branch = query
214214 .branch
crates/forge-web/src/pages/ci_fail.rsmodified+15 -8
@@ -3,6 +3,7 @@
33 //! not stored, so the failed job is the unit. The log is untrusted: its lines are rendered as text.
44
55 use topcoat::Result;
6+use topcoat::context::Cx;
67 use topcoat::view::{View, component, view};
78
89 use crate::ci::log_path;
@@ -59,14 +60,20 @@ impl FailFirst {
5960 /// The `file:line` in a compiler's or test's lines around an error: the first word that ends in
6061 /// digits after a colon and holds a dot.
6162 fn place_in(lines: &[String]) -> Option<String> {
62- lines.iter().flat_map(|line| line.split_whitespace()).find_map(|word| {
63- let word = word.trim_matches(|c: char| matches!(c, '(' | ')' | ','));
64- let mut parts = word.split(':');
65- let file = parts.next()?;
66- let line = parts.next()?;
67- (file.contains('.') && !file.contains("::") && !line.is_empty() && line.bytes().all(|b| b.is_ascii_digit()))
63+ lines
64+ .iter()
65+ .flat_map(|line| line.split_whitespace())
66+ .find_map(|word| {
67+ let word = word.trim_matches(|c: char| matches!(c, '(' | ')' | ','));
68+ let mut parts = word.split(':');
69+ let file = parts.next()?;
70+ let line = parts.next()?;
71+ (file.contains('.')
72+ && !file.contains("::")
73+ && !line.is_empty()
74+ && line.bytes().all(|b| b.is_ascii_digit()))
6875 .then(|| format!("{}:{line}", file.rsplit('/').next().unwrap_or(file)))
69- })
76+ })
7077 }
7178
7279 /// Reads the failed job's log tail (the same bounded read as the job page) and picks the lines to show.
@@ -108,7 +115,7 @@ pub(crate) async fn read(
108115 /// The failure row, pinned above the log, which opens at the first error line: why it failed, the
109116 /// place in the code, and a link to that line in the job's log.
110117 #[component]
111-pub(crate) async fn fail_first_block(lang: Lang, fail: FailFirst) -> Result<impl View> {
118+pub(crate) async fn fail_first_block(cx: &Cx, lang: Lang, fail: FailFirst) -> Result<impl View> {
112119 let line_href = fail.line_no.map(|no| format!("{}#L{no}", fail.job_href));
113120 let why = if fail.message.is_empty() {
114121 fail.error.clone().unwrap_or_else(|| fail.job_name.clone())
crates/forge-web/src/pages/ci_job.rsmodified+19 -18
@@ -21,7 +21,7 @@ use http_body_util::StreamBody;
2121 use tokio::io::{AsyncReadExt, AsyncSeekExt, SeekFrom};
2222 use tokio::sync::watch;
2323 use topcoat::Result;
24-use topcoat::context::{Cx, app_context};
24+use topcoat::context::{Cx, context};
2525 use topcoat::router::content::sse::{Event, last_event_id};
2626 use topcoat::router::error::not_found;
2727 use topcoat::router::request::uri;
@@ -419,6 +419,7 @@ async fn job_fingerprint_now(store: &Store, job_id: &str) -> Result<Option<Strin
419419 /// follows its artifacts and log too. The log tail carries the offset its text ends at.
420420 #[component]
421421 async fn job_body(
422+ cx: &Cx,
422423 head: RepoHead,
423424 lang: Lang,
424425 job: JobView,
@@ -521,12 +522,12 @@ async fn job_body(
521522 /// One job: its state, the last 512 KiB of its log and its artifacts.
522523 #[page("/{owner}/{repo}/ci/jobs/{job_id}")]
523524 async fn job_page(cx: &Cx) -> Result<impl View> {
524- let owner = path_param::<Owner>(cx);
525- let name = path_param::<Repo>(cx);
526- let id = path_param::<JobId>(cx).to_owned();
525+ let owner = owner(cx);
526+ let name = repo(cx);
527+ let id = job_id(cx).to_owned();
527528 let ctx = load_repo(cx, owner, name).await?;
528529 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
529- let state = app_context::<AppState>(cx);
530+ let state = context::<AppState>(cx);
530531 let (job, run) = job_of(state, &ctx, &id).await?;
531532 let Tail {
532533 text: log,
@@ -633,11 +634,11 @@ const LOG_EVENT_BYTES: u64 = 64 * 1024;
633634 /// this job (see `CiLive`), so a finished page still hears about deleted artifacts or logs.
634635 #[route(GET "/{owner}/{repo}/ci/jobs/{job_id}/events")]
635636 async fn job_events(cx: &Cx) -> Result<Response> {
636- let owner = path_param::<Owner>(cx);
637- let name = path_param::<Repo>(cx);
638- let id = path_param::<JobId>(cx).to_owned();
637+ let owner = owner(cx);
638+ let name = repo(cx);
639+ let id = job_id(cx).to_owned();
639640 let ctx = load_repo(cx, owner, name).await?;
640- let state = app_context::<AppState>(cx);
641+ let state = context::<AppState>(cx);
641642 let (job, _) = job_of(state, &ctx, &id).await?;
642643 let offset = last_event_id(cx)
643644 .and_then(|id| id.parse::<u64>().ok())
@@ -797,11 +798,11 @@ async fn read_log(
797798 /// is terminal.
798799 #[route(GET "/{owner}/{repo}/ci/jobs/{job_id}/log.txt")]
799800 async fn job_log(cx: &Cx) -> Result<Response> {
800- let owner = path_param::<Owner>(cx);
801- let name = path_param::<Repo>(cx);
802- let id = path_param::<JobId>(cx).to_owned();
801+ let owner = owner(cx);
802+ let name = repo(cx);
803+ let id = job_id(cx).to_owned();
803804 let ctx = load_repo(cx, owner, name).await?;
804- let state = app_context::<AppState>(cx);
805+ let state = context::<AppState>(cx);
805806 let (job, _) = job_of(state, &ctx, &id).await?;
806807 let path = log_path(&state.config.data_dir, &job.id);
807808 let chunks = follow_log(
@@ -834,12 +835,12 @@ async fn job_log(cx: &Cx) -> Result<Response> {
834835 /// Downloads an artifact of a job as an attachment.
835836 #[route(GET "/{owner}/{repo}/ci/jobs/{job_id}/artifacts/{artifact_name}")]
836837 async fn artifact_download(cx: &Cx) -> Result<Response> {
837- let owner = path_param::<Owner>(cx);
838- let name = path_param::<Repo>(cx);
839- let id = path_param::<JobId>(cx).to_owned();
840- let file_name = path_param::<ArtifactName>(cx).to_owned();
838+ let owner = owner(cx);
839+ let name = repo(cx);
840+ let id = job_id(cx).to_owned();
841+ let file_name = artifact_name(cx).to_owned();
841842 let ctx = load_repo(cx, owner, name).await?;
842- let state = app_context::<AppState>(cx);
843+ let state = context::<AppState>(cx);
843844 let (job, _) = job_of(state, &ctx, &id).await?;
844845 let Some(artifact) = state.store.artifact(&job.id, &file_name).await? else {
845846 return Err(not_found().into());
crates/forge-web/src/pages/ci_runs.rsmodified+81 -57
@@ -23,7 +23,7 @@ use time::format_description::well_known::Rfc3339;
2323 use tokio::io::{AsyncReadExt, AsyncSeekExt, SeekFrom};
2424 use tokio::sync::watch;
2525 use topcoat::Result;
26-use topcoat::context::{Cx, app_context};
26+use topcoat::context::{Cx, context};
2727 use topcoat::router::content::Form;
2828 use topcoat::router::content::sse::{Event, KeepAlive, Sse};
2929 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
@@ -1408,7 +1408,10 @@ fn job_steps(
14081408 })
14091409 })
14101410 .collect();
1411- let total: u64 = elapsed_of.iter().map(|secs| u64::try_from(*secs).unwrap_or(0)).sum();
1411+ let total: u64 = elapsed_of
1412+ .iter()
1413+ .map(|secs| u64::try_from(*secs).unwrap_or(0))
1414+ .sum();
14121415 for (step, elapsed) in steps.iter().zip(elapsed_of) {
14131416 let state = step.state(job.state);
14141417 let running = state == StepState::Running;
@@ -1593,6 +1596,7 @@ async fn usernames(
15931596 /// A small form that POSTs the CSRF token to `action`, with one button.
15941597 #[component]
15951598 async fn action_button(
1599+ cx: &Cx,
15961600 action: String,
15971601 csrf: String,
15981602 label: &'static str,
@@ -1628,11 +1632,11 @@ async fn runs_split(
16281632 job: Option<&str>,
16291633 step: Option<i64>,
16301634 ) -> Result<SplitPage> {
1631- let owner = path_param::<Owner>(cx);
1632- let name = path_param::<Repo>(cx);
1635+ let owner = owner(cx);
1636+ let name = repo(cx);
16331637 let ctx = load_repo(cx, owner, name).await?;
16341638 let lang = i18n::lang(cx, viewer_user(&ctx));
1635- let state = app_context::<AppState>(cx);
1639+ let state = context::<AppState>(cx);
16361640 let title = title_of(&ctx);
16371641 let base = ci_href(&title);
16381642 let page = page_from_query(cx);
@@ -1743,7 +1747,9 @@ async fn runs_split(
17431747 },
17441748 href: row_href(run.number),
17451749 // The list page alone draws no run, so it marks none.
1746- current: if number.is_some() && selected.as_ref().is_some_and(|sel| sel.id == run.id) {
1750+ current: if number.is_some()
1751+ && selected.as_ref().is_some_and(|sel| sel.id == run.id)
1752+ {
17471753 "true"
17481754 } else {
17491755 "false"
@@ -1937,8 +1943,16 @@ async fn run_detail(
19371943 } else {
19381944 None
19391945 };
1940- let gantt = (!jobs.is_empty())
1941- .then(|| gantt(&jobs, origin_of(run, now), run_end(run, now), now, lang, picked));
1946+ let gantt = (!jobs.is_empty()).then(|| {
1947+ gantt(
1948+ &jobs,
1949+ origin_of(run, now),
1950+ run_end(run, now),
1951+ now,
1952+ lang,
1953+ picked,
1954+ )
1955+ });
19421956 let writer = header.writer_csrf.is_some();
19431957 let rerunnable = writer && header.reachable;
19441958 let mut lines = Vec::with_capacity(jobs.len());
@@ -2099,7 +2113,11 @@ async fn run_detail(
20992113 .map_or(job.name.as_str(), |step| step.name.as_str())
21002114 })
21012115 },
2102- &duration_text(lang, Some(run.created_at.as_str()), run.finished_at.as_deref()),
2116+ &duration_text(
2117+ lang,
2118+ Some(run.created_at.as_str()),
2119+ run.finished_at.as_deref(),
2120+ ),
21032121 );
21042122 Ok(RunDetail {
21052123 number: run.number,
@@ -2181,7 +2199,7 @@ fn query_value(cx: &Cx, key: &str) -> Option<String> {
21812199
21822200 /// The head's one action on the runs list: Run workflow, for a writer. Its form sits in its menu.
21832201 #[component]
2184-async fn ci_menus(lang: Lang, list: &ListView) -> Result<impl View> {
2202+async fn ci_menus(cx: &Cx, lang: Lang, list: &ListView) -> Result<impl View> {
21852203 Ok(view! {
21862204 if let Some(form) = list.manual.as_ref() {
21872205 <details class="menu ci-tool">
@@ -2208,7 +2226,7 @@ async fn ci_menus(lang: Lang, list: &ListView) -> Result<impl View> {
22082226 /// The runs list: one sheet with its tools row, one line per run (each opens the run's page) and the
22092227 /// pager. The live list keeps its classes for the page script.
22102228 #[component]
2211-async fn runs_sheet(lang: Lang, list: &ListView) -> Result<impl View> {
2229+async fn runs_sheet(cx: &Cx, lang: Lang, list: &ListView) -> Result<impl View> {
22122230 let ListView {
22132231 badge,
22142232 total,
@@ -2295,6 +2313,7 @@ async fn runs_sheet(lang: Lang, list: &ListView) -> Result<impl View> {
22952313 /// The runs page body: the repo head with its Run workflow menu beside its title, then the runs sheet. The live region is the list's stream, so the list re-renders when a run changes.
22962314 #[component]
22972315 async fn runs_body(
2316+ cx: &Cx,
22982317 head: RepoHead,
22992318 lang: Lang,
23002319 notice: Option<(&'static str, bool)>,
@@ -2328,7 +2347,7 @@ async fn runs_body(
23282347 /// line of each job, and its artifacts. The list route draws it on the right, and the run page draws it
23292348 /// in its Timeline tab.
23302349 #[component]
2331-async fn run_timeline(lang: Lang, run: &RunDetail) -> Result<impl View> {
2350+async fn run_timeline(cx: &Cx, lang: Lang, run: &RunDetail) -> Result<impl View> {
23322351 Ok(view! {
23332352 if let Some(g) = run.gantt.as_ref() {
23342353 <div class="ci-gantt-scroll">
@@ -2426,12 +2445,15 @@ async fn run_timeline(lang: Lang, run: &RunDetail) -> Result<impl View> {
24262445 /// `all_href` adds the All
24272446 /// runs link, which the run page needs; the list page has the runs beside it.
24282447 #[component]
2429-async fn run_head(lang: Lang, run: &RunDetail, all_href: Option<String>) -> Result<impl View> {
2448+async fn run_head(
2449+ cx: &Cx,
2450+ lang: Lang,
2451+ run: &RunDetail,
2452+ all_href: Option<String>,
2453+) -> Result<impl View> {
24302454 let cancel_action = format!("{}/cancel", run.action_base);
2431- let rerun_failed_shown = run.writer_csrf.is_some()
2432- && run.can_rerun_failed
2433- && !run.can_approve
2434- && !run.can_cancel;
2455+ let rerun_failed_shown =
2456+ run.writer_csrf.is_some() && run.can_rerun_failed && !run.can_approve && !run.can_cancel;
24352457 Ok(view! {
24362458 <section class="head">
24372459 <div class="head-title">
@@ -2493,7 +2515,7 @@ async fn run_head(lang: Lang, run: &RunDetail, all_href: Option<String>) -> Resu
24932515 /// The jobs of a run with more than one job: one `.job-row` each, its name, its tick and a mini strip
24942516 /// of its steps. The selected job's row is marked; its steps are the strip under the head.
24952517 #[component]
2496-async fn run_jobs(lang: Lang, run: &RunDetail) -> Result<impl View> {
2518+async fn run_jobs(cx: &Cx, lang: Lang, run: &RunDetail) -> Result<impl View> {
24972519 Ok(view! {
24982520 if run.jobs.len() > 1 {
24992521 <div class="jobs ci-tl-list">
@@ -2532,7 +2554,7 @@ async fn run_jobs(lang: Lang, run: &RunDetail) -> Result<impl View> {
25322554 /// The steps of the selected job, one `.seg` each: a step's name, its time and its state. A step the
25332555 /// URL picks is marked, and a step with its log opens that part of the log.
25342556 #[component]
2535-async fn run_strip(run: &RunDetail) -> Result<impl View> {
2557+async fn run_strip(cx: &Cx, run: &RunDetail) -> Result<impl View> {
25362558 let job = run.jobs.iter().find(|job| job.selected);
25372559 Ok(view! {
25382560 if let Some(job) = job {
@@ -2567,7 +2589,7 @@ async fn run_strip(run: &RunDetail) -> Result<impl View> {
25672589
25682590 /// The run's artifacts: the zip of all of them and one download line each.
25692591 #[component]
2570-async fn run_artifacts(lang: Lang, run: &RunDetail) -> Result<impl View> {
2592+async fn run_artifacts(cx: &Cx, lang: Lang, run: &RunDetail) -> Result<impl View> {
25712593 Ok(view! {
25722594 if !run.artifacts.is_empty() {
25732595 <div class="sec">
@@ -2592,6 +2614,7 @@ async fn run_artifacts(lang: Lang, run: &RunDetail) -> Result<impl View> {
25922614 /// log on `--bg` (or the config errors and the fail-first block above it). The timeline is the other tab.
25932615 #[component]
25942616 async fn run_log(
2617+ cx: &Cx,
25952618 lang: Lang,
25962619 run: &RunDetail,
25972620 timeline: bool,
@@ -2681,6 +2704,7 @@ async fn run_log(
26812704 /// history. The live region wraps all of it, so the page re-renders when a run or a job changes.
26822705 #[component]
26832706 async fn run_body(
2707+ cx: &Cx,
26842708 head: RepoHead,
26852709 lang: Lang,
26862710 notice: Option<(&'static str, bool)>,
@@ -2745,7 +2769,7 @@ async fn runs_list_page(cx: &Cx) -> Result<impl View> {
27452769 /// A run that is not on the list page is still shown.
27462770 #[page("/{owner}/{repo}/ci/runs/{run_number}")]
27472771 async fn run_page(cx: &Cx) -> Result<impl View> {
2748- let number = path_param::<RunNumber>(cx).to_owned();
2772+ let number = run_number(cx).to_owned();
27492773 let wanted = job_from_query(cx);
27502774 let wanted_step = step_from_query(cx);
27512775 let SplitPage {
@@ -2761,7 +2785,7 @@ async fn run_page(cx: &Cx) -> Result<impl View> {
27612785 let Some(run) = detail else {
27622786 return Err(not_found().into());
27632787 };
2764- let state = app_context::<AppState>(cx);
2788+ let state = context::<AppState>(cx);
27652789 let bars = dock_bars(state, &ctx).await;
27662790 let owner = ctx.repo.owner_name.clone();
27672791 let repo = ctx.repo.name.clone();
@@ -2798,10 +2822,10 @@ pub(crate) async fn dock_bars(state: &AppState, ctx: &RepoCtx) -> Vec<StripBar>
27982822 /// created or changed state. Nothing is sent on connect, since the page was just rendered.
27992823 #[route(GET "/{owner}/{repo}/ci/events")]
28002824 async fn runs_events(cx: &Cx) -> Result<Response> {
2801- let owner = path_param::<Owner>(cx);
2802- let name = path_param::<Repo>(cx);
2825+ let owner = owner(cx);
2826+ let name = repo(cx);
28032827 let ctx = load_repo(cx, owner, name).await?;
2804- let state = app_context::<AppState>(cx);
2828+ let state = context::<AppState>(cx);
28052829 // Subscribed before the response is sent, so a change after this point is sent.
28062830 let wake = state.ci_live.subscribe_repo(&ctx.repo.id);
28072831 events_response(cx, repo_changes(wake))
@@ -2810,12 +2834,12 @@ async fn runs_events(cx: &Cx) -> Result<Response> {
28102834 /// Starts a manual run on a branch. Writers only. The branch must be one of the repo's branches.
28112835 #[route(POST "/{owner}/{repo}/ci")]
28122836 async fn manual_run_post(cx: &Cx, Form(form): Form<ManualForm>) -> Result<SeeOther> {
2813- let owner = path_param::<Owner>(cx);
2814- let name = path_param::<Repo>(cx);
2837+ let owner = owner(cx);
2838+ let name = repo(cx);
28152839 let ctx = load_repo(cx, owner, name).await?;
28162840 let (user, _) = require_csrf(cx, &form.csrf).await?;
28172841 require_write(&ctx)?;
2818- let state = app_context::<AppState>(cx);
2842+ let state = context::<AppState>(cx);
28192843 let title = title_of(&ctx);
28202844 let branch = form.branch.trim();
28212845 let refs = load_refs(ctx.path.clone()).await?;
@@ -2948,7 +2972,7 @@ impl StreamSlot {
29482972 /// A slot for this request's client, or `None` when a cap is reached. Without the app state
29492973 /// (unit tests of a bare router) nothing is counted.
29502974 fn take(cx: &Cx) -> Option<StreamSlot> {
2951- if topcoat::context::try_app_context::<AppState>(cx).is_none() {
2975+ if topcoat::context::try_context::<AppState>(cx).is_none() {
29522976 return Some(StreamSlot { ip: None });
29532977 }
29542978 let ip = crate::client_ip::client_ip(cx);
@@ -3023,11 +3047,11 @@ pub(crate) fn events_response(
30233047 /// or to one of its jobs, so the page can render its rows again.
30243048 #[route(GET "/{owner}/{repo}/ci/runs/{run_number}/events")]
30253049 async fn run_events(cx: &Cx) -> Result<Response> {
3026- let owner = path_param::<Owner>(cx);
3027- let name = path_param::<Repo>(cx);
3028- let number = path_param::<RunNumber>(cx).to_owned();
3050+ let owner = owner(cx);
3051+ let name = repo(cx);
3052+ let number = run_number(cx).to_owned();
30293053 let ctx = load_repo(cx, owner, name).await?;
3030- let state = app_context::<AppState>(cx);
3054+ let state = context::<AppState>(cx);
30313055 let run = run_of(state, &ctx, &number).await?;
30323056 // Subscribed before the status is read, so a change in between is sent.
30333057 let wake = state.ci_live.subscribe_run(&run.id);
@@ -3055,13 +3079,13 @@ async fn run_events(cx: &Cx) -> Result<Response> {
30553079 /// get a cancel request that their runner sees on its next heartbeat.
30563080 #[route(POST "/{owner}/{repo}/ci/runs/{run_number}/cancel")]
30573081 async fn run_cancel(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
3058- let owner = path_param::<Owner>(cx);
3059- let name = path_param::<Repo>(cx);
3060- let number = path_param::<RunNumber>(cx).to_owned();
3082+ let owner = owner(cx);
3083+ let name = repo(cx);
3084+ let number = run_number(cx).to_owned();
30613085 let ctx = load_repo(cx, owner, name).await?;
30623086 require_csrf(cx, &form.csrf).await?;
30633087 require_write(&ctx)?;
3064- let state = app_context::<AppState>(cx);
3088+ let state = context::<AppState>(cx);
30653089 let run = run_of(state, &ctx, &number).await?;
30663090 let href = run_href(&title_of(&ctx), run.number);
30673091 if run_finished(&run.state) {
@@ -3076,13 +3100,13 @@ async fn run_cancel(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
30763100 /// Approves a run that waits for approval: its jobs are queued. Anything else is refused.
30773101 #[route(POST "/{owner}/{repo}/ci/runs/{run_number}/approve")]
30783102 async fn run_approve(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
3079- let owner = path_param::<Owner>(cx);
3080- let name = path_param::<Repo>(cx);
3081- let number = path_param::<RunNumber>(cx).to_owned();
3103+ let owner = owner(cx);
3104+ let name = repo(cx);
3105+ let number = run_number(cx).to_owned();
30823106 let ctx = load_repo(cx, owner, name).await?;
30833107 require_csrf(cx, &form.csrf).await?;
30843108 require_write(&ctx)?;
3085- let state = app_context::<AppState>(cx);
3109+ let state = context::<AppState>(cx);
30863110 let run = run_of(state, &ctx, &number).await?;
30873111 let href = run_href(&title_of(&ctx), run.number);
30883112 if run.state != RunState::WaitingApproval {
@@ -3097,13 +3121,13 @@ async fn run_approve(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
30973121 /// Starts a new run with the same commit, ref, trigger and job specs, then opens it.
30983122 #[route(POST "/{owner}/{repo}/ci/runs/{run_number}/rerun")]
30993123 async fn run_rerun(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
3100- let owner = path_param::<Owner>(cx);
3101- let name = path_param::<Repo>(cx);
3102- let number = path_param::<RunNumber>(cx).to_owned();
3124+ let owner = owner(cx);
3125+ let name = repo(cx);
3126+ let number = run_number(cx).to_owned();
31033127 let ctx = load_repo(cx, owner, name).await?;
31043128 let (user, _) = require_csrf(cx, &form.csrf).await?;
31053129 require_write(&ctx)?;
3106- let state = app_context::<AppState>(cx);
3130+ let state = context::<AppState>(cx);
31073131 let run = run_of(state, &ctx, &number).await?;
31083132 if !commit_reachable_for(&ctx.path, &run.commit_oid).await? {
31093133 return Ok(notice_redirect(
@@ -3123,13 +3147,13 @@ async fn run_rerun(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
31233147 /// jobs that depend on them. The specs are the originals.
31243148 #[route(POST "/{owner}/{repo}/ci/runs/{run_number}/rerun-failed")]
31253149 async fn run_rerun_failed(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
3126- let owner = path_param::<Owner>(cx);
3127- let name = path_param::<Repo>(cx);
3128- let number = path_param::<RunNumber>(cx).to_owned();
3150+ let owner = owner(cx);
3151+ let name = repo(cx);
3152+ let number = run_number(cx).to_owned();
31293153 let ctx = load_repo(cx, owner, name).await?;
31303154 let (user, _) = require_csrf(cx, &form.csrf).await?;
31313155 require_write(&ctx)?;
3132- let state = app_context::<AppState>(cx);
3156+ let state = context::<AppState>(cx);
31333157 let run = run_of(state, &ctx, &number).await?;
31343158 let href = run_href(&title_of(&ctx), run.number);
31353159 if !commit_reachable_for(&ctx.path, &run.commit_oid).await? {
@@ -3159,13 +3183,13 @@ async fn run_rerun_failed(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOthe
31593183 /// originals.
31603184 #[route(POST "/{owner}/{repo}/ci/jobs/{job_id}/rerun")]
31613185 async fn job_rerun(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
3162- let owner = path_param::<Owner>(cx);
3163- let name = path_param::<Repo>(cx);
3164- let id = path_param::<JobId>(cx).to_owned();
3186+ let owner = owner(cx);
3187+ let name = repo(cx);
3188+ let id = job_id(cx).to_owned();
31653189 let ctx = load_repo(cx, owner, name).await?;
31663190 let (user, _) = require_csrf(cx, &form.csrf).await?;
31673191 require_write(&ctx)?;
3168- let state = app_context::<AppState>(cx);
3192+ let state = context::<AppState>(cx);
31693193 let Some(job) = state.store.job_by_id(&id).await? else {
31703194 return Err(not_found().into());
31713195 };
@@ -3225,11 +3249,11 @@ fn zip_path(job: &str, artifact: &str) -> String {
32253249 #[route(GET "/{owner}/{repo}/ci/runs/{run_number}/artifacts.zip")]
32263250 async fn run_artifacts_zip(cx: &Cx) -> Result<Response> {
32273251 use futures_util::TryStreamExt;
3228- let owner = path_param::<Owner>(cx);
3229- let name = path_param::<Repo>(cx);
3230- let number = path_param::<RunNumber>(cx).to_owned();
3252+ let owner = owner(cx);
3253+ let name = repo(cx);
3254+ let number = run_number(cx).to_owned();
32313255 let ctx = load_repo(cx, owner, name).await?;
3232- let state = app_context::<AppState>(cx);
3256+ let state = context::<AppState>(cx);
32333257 let run = run_of(state, &ctx, &number).await?;
32343258 let href = run_href(&title_of(&ctx), run.number);
32353259 let mut entries = Vec::new();
crates/forge-web/src/pages/ci_tests.rsmodified+4 -1
@@ -261,7 +261,10 @@ async fn access_follows_the_repo_role_on_every_route() {
261261 let run = run_with(&fx, &["build"], false).await;
262262 let run_url = format!("{RUN_BASE}/runs/{}", run.number);
263263 let writer = get(&fx.app, &run_url, Some(&cookie_for("bob-token"))).await;
264- assert!(!writer.text().contains(">Re-run<"), "a queued run has no re-run yet");
264+ assert!(
265+ !writer.text().contains(">Re-run<"),
266+ "a queued run has no re-run yet"
267+ );
265268 assert!(writer.text().contains(">Cancel<"), "writer sees cancel");
266269 let reader = get(&fx.app, &run_url, Some(&cookie_for("dave-token"))).await;
267270 assert_eq!(reader.status, 200);
crates/forge-web/src/pages/code_live.rsmodified+4 -4
@@ -16,7 +16,7 @@ use std::path::PathBuf;
1616 use forge_core::{Repo as RepoRecord, User, Visibility};
1717 use forge_git::browse::{RefInfo, RefKind};
1818 use topcoat::Result;
19-use topcoat::context::{Cx, app_context};
19+use topcoat::context::{Cx, context};
2020 use topcoat::router::response::Response;
2121 use topcoat::router::{path_param, query_params, route};
2222
@@ -161,13 +161,13 @@ async fn home_fingerprint(
161161 /// repo gets the same 404 as the page.
162162 #[route(GET "/{owner}/{repo}/events")]
163163 async fn repo_events(cx: &Cx) -> Result<Response> {
164- let owner = path_param::<Owner>(cx);
165- let name = path_param::<Repo>(cx);
164+ let owner = owner(cx);
165+ let name = repo(cx);
166166 let query = query_params::<LiveQuery>(cx)?;
167167 let branch = query.ref_name.clone().unwrap_or_default();
168168 let home = query.home.as_deref() == Some("1");
169169 let ctx = load_repo(cx, owner, name).await?;
170- let state = app_context::<AppState>(cx).clone();
170+ let state = context::<AppState>(cx).clone();
171171 let repo_id = ctx.repo.id.clone();
172172 let mut topics = vec![
173173 Topic::Repo(repo_id.clone()),
crates/forge-web/src/pages/code_search.rsmodified+4 -4
@@ -6,7 +6,7 @@
66 use forge_git::browse;
77 use forge_git::search::{GrepHit, GrepOptions, GrepResult, grep};
88 use topcoat::Result;
9-use topcoat::context::{Cx, app_context};
9+use topcoat::context::{Cx, context};
1010 use topcoat::router::error::not_found;
1111 use topcoat::router::{page, path_param, query_params};
1212 use topcoat::view::{View, view};
@@ -132,12 +132,12 @@ fn group_hits(
132132
133133 #[page("/{owner}/{repo}/search")]
134134 async fn search_page(cx: &Cx) -> Result<impl View> {
135- let owner = path_param::<Owner>(cx);
136- let name = path_param::<Repo>(cx);
135+ let owner = owner(cx);
136+ let name = repo(cx);
137137 let query = query_params::<SearchQuery>(cx)?;
138138
139139 let ctx = load_repo(cx, owner, name).await?;
140- let state = app_context::<AppState>(cx);
140+ let state = context::<AppState>(cx);
141141 let repo_name = ctx.repo.name.clone();
142142 let owner_name = ctx.repo.owner_name.clone();
143143 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
crates/forge-web/src/pages/commit.rsmodified+6 -6
@@ -5,7 +5,7 @@ use forge_git::browse;
55 use forge_git::history;
66 use forge_git::trailers;
77 use topcoat::Result;
8-use topcoat::context::{Cx, app_context};
8+use topcoat::context::{Cx, context};
99 use topcoat::router::error::{content_too_large, not_found};
1010 use topcoat::router::{page, path_param, route};
1111 use topcoat::view::{View, view};
@@ -95,15 +95,15 @@ impl Download {
9595
9696 #[page("/{owner}/{repo}/commit/{oid}")]
9797 async fn commit_page(cx: &Cx) -> Result<impl View> {
98- let owner = path_param::<Owner>(cx);
99- let name = path_param::<Repo>(cx);
100- let (rev, download) = Download::split(path_param::<Oid>(cx));
98+ let owner = owner(cx);
99+ let name = repo(cx);
100+ let (rev, download) = Download::split(oid(cx));
101101 if !is_hex_prefix(rev) {
102102 return Err(not_found().into());
103103 }
104104
105105 let ctx = load_repo(cx, owner, name).await?;
106- let state = app_context::<AppState>(cx);
106+ let state = context::<AppState>(cx);
107107 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
108108
109109 let repo_dir = ctx.path.clone();
@@ -360,7 +360,7 @@ async fn commit_page(cx: &Cx) -> Result<impl View> {
360360
361361 /// Other methods on a commit path get a plain 404.
362362 #[route(* "/{owner}/{repo}/commit/{oid}")]
363-async fn commit_other_methods() -> Result<&'static str> {
363+async fn commit_other_methods(cx: &Cx) -> Result<&'static str> {
364364 Err(not_found().into())
365365 }
366366
crates/forge-web/src/pages/commits.rsmodified+5 -5
@@ -11,7 +11,7 @@ use forge_git::browse::{self, CommitInfo};
1111 use forge_git::history;
1212 use jiff::{Timestamp, civil};
1313 use topcoat::Result;
14-use topcoat::context::{Cx, app_context};
14+use topcoat::context::{Cx, context};
1515 use topcoat::router::error::{bad_request, not_found};
1616 use topcoat::router::{page, path_param, query_params};
1717 use topcoat::view::{View, view};
@@ -241,9 +241,9 @@ impl CommitRow {
241241
242242 #[page("/{owner}/{repo}/commits/{*rest}")]
243243 async fn commits_page(cx: &Cx) -> Result<impl View> {
244- let owner = path_param::<Owner>(cx);
245- let name = path_param::<Repo>(cx);
246- let rest = path_param::<Rest>(cx).collect::<Vec<_>>().join("/");
244+ let owner = owner(cx);
245+ let name = repo(cx);
246+ let rest = rest(cx).collect::<Vec<_>>().join("/");
247247 let query = query_params::<CommitsQuery>(cx)?;
248248 let page_no = query.page.unwrap_or(1);
249249 if !(1..=MAX_PAGE).contains(&page_no) {
@@ -251,7 +251,7 @@ async fn commits_page(cx: &Cx) -> Result<impl View> {
251251 }
252252
253253 let ctx = load_repo(cx, owner, name).await?;
254- let state = app_context::<AppState>(cx);
254+ let state = context::<AppState>(cx);
255255 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
256256
257257 let repo_dir = ctx.path.clone();
crates/forge-web/src/pages/compare.rsmodified+14 -14
@@ -19,7 +19,7 @@ use forge_git::pulls;
1919 use forge_git::repo::repo_path;
2020 use serde::Deserialize;
2121 use topcoat::Result;
22-use topcoat::context::{Cx, app_context};
22+use topcoat::context::{Cx, context};
2323 use topcoat::router::content::Form;
2424 use topcoat::router::error::{bad_request, forbidden, not_found, see_other};
2525 use topcoat::router::{page, path_param, query_params};
@@ -236,7 +236,7 @@ async fn compare_view(
236236 draft: Option<(String, String)>,
237237 error: Option<String>,
238238 ) -> Result<impl View> {
239- let state = app_context::<AppState>(cx);
239+ let state = context::<AppState>(cx);
240240 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
241241 let owner = ctx.repo.owner_name.clone();
242242 let name = ctx.repo.name.clone();
@@ -328,7 +328,7 @@ async fn compare_view(
328328
329329 let mut header = ctx.head(state, "commits").await?;
330330 header.live = ref_live::live_url(&ctx.repo.owner_name, &ctx.repo.name);
331- let __cx = cx;
331+ let cx = cx;
332332 Ok(view! {
333333 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),
334334 repo_head(head: header, title: Some(compare_title))
@@ -410,7 +410,7 @@ async fn compare_view(
410410
411411 /// The picker: base and head fields as a plain GET form, with the repo's branches suggested.
412412 async fn picker_view(cx: &Cx, ctx: RepoCtx, base: String, head: String) -> Result<impl View> {
413- let state = app_context::<AppState>(cx);
413+ let state = context::<AppState>(cx);
414414 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
415415 let path = ctx.path.clone();
416416 let refs = blocking(move || browse::list_refs(&path)).await?;
@@ -423,7 +423,7 @@ async fn picker_view(cx: &Cx, ctx: RepoCtx, base: String, head: String) -> Resul
423423 let action = repo_href(&ctx.repo.owner_name, &ctx.repo.name, "compare", "");
424424 let mut header = ctx.head(state, "commits").await?;
425425 header.live = ref_live::live_url(&ctx.repo.owner_name, &ctx.repo.name);
426- let __cx = cx;
426+ let cx = cx;
427427 Ok(view! {
428428 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),
429429 repo_head(head: header, title: Some(g::t(lang, K::CompareBranches).to_owned()))
@@ -460,8 +460,8 @@ struct PickerQuery {
460460 /// Picker at `/{owner}/{repo}/compare`. Both fields filled in redirect to the comparison.
461461 #[page("/{owner}/{repo}/compare")]
462462 async fn compare_picker(cx: &Cx) -> Result<impl View> {
463- let owner = path_param::<Owner>(cx);
464- let name = path_param::<Repo>(cx);
463+ let owner = owner(cx);
464+ let name = repo(cx);
465465 let query = query_params::<PickerQuery>(cx)?;
466466 let ctx = load_repo(cx, owner, name).await?;
467467 let base = query.base.clone().unwrap_or_default();
@@ -485,12 +485,12 @@ async fn compare_picker(cx: &Cx) -> Result<impl View> {
485485 /// Comparison at `/{owner}/{repo}/compare/{base}...{head}`.
486486 #[page("/{owner}/{repo}/compare/{*spec}")]
487487 async fn compare_page(cx: &Cx) -> Result<impl View> {
488- let owner = path_param::<Owner>(cx);
489- let name = path_param::<Repo>(cx);
490- let full_spec = path_param::<Spec>(cx).collect::<Vec<_>>().join("/");
488+ let owner = owner(cx);
489+ let name = repo(cx);
490+ let full_spec = spec(cx).collect::<Vec<_>>().join("/");
491491 let (spec, download) = Download::split(&full_spec);
492492 let ctx = load_repo(cx, owner, name).await?;
493- let state = app_context::<AppState>(cx);
493+ let state = context::<AppState>(cx);
494494 let Some((base, head)) = spec.split_once("...") else {
495495 return Err(not_found().into());
496496 };
@@ -551,13 +551,13 @@ struct PullForm {
551551 /// Opens a pull request from a comparison: `POST /{owner}/{repo}/pulls`.
552552 #[page(POST "/{owner}/{repo}/pulls")]
553553 async fn pull_create(cx: &Cx, Form(form): Form<PullForm>) -> Result<impl View> {
554- let owner = path_param::<Owner>(cx);
555- let name = path_param::<Repo>(cx);
554+ let owner = owner(cx);
555+ let name = repo(cx);
556556 let ctx = load_repo(cx, owner, name).await?;
557557 let (user, session) = require_user(cx).await?;
558558 check_write(&ctx, &session, &form.csrf)?;
559559 let lang = i18n::lang(cx, Some(&user));
560- let state = app_context::<AppState>(cx);
560+ let state = context::<AppState>(cx);
561561
562562 let Some(cmp) = resolve_comparison(state, &ctx, &form.base, &form.head).await? else {
563563 return Err(bad_request(g::t(lang, K::UnknownBranches)).into());
crates/forge-web/src/pages/discussion_actions.rsmodified+31 -31
@@ -9,7 +9,7 @@
99 use forge_core::{AuditAction, Reaction, ReactionTarget};
1010 use serde::Deserialize;
1111 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};
12+use topcoat::context::{Cx, context};
1313 use topcoat::router::content::Form;
1414 use topcoat::router::error::{SeeOther, bad_request, forbidden, not_found, see_other};
1515 use topcoat::router::{page, path_param, route};
@@ -86,12 +86,12 @@ async fn own_comment(
8686
8787 #[page(POST "/{owner}/{repo}/discussions/{number}/comments")]
8888 async fn discussion_comment(cx: &Cx, Form(form): Form<ActionForm>) -> Result<impl View> {
89- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
90- let state = app_context::<AppState>(cx);
89+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
90+ let state = context::<AppState>(cx);
9191 let (user, _) = require_csrf(cx, &form.csrf).await?;
9292 let lang = i18n::lang(cx, Some(&user));
9393 ensure_enabled(state, &ctx).await?;
94- let discussion = discussion_by_number(state, &ctx, path_param::<Number>(cx)).await?;
94+ let discussion = discussion_by_number(state, &ctx, number(cx)).await?;
9595 if !may_converse(&ctx, discussion.locked) {
9696 return Err(forbidden().into());
9797 }
@@ -111,7 +111,7 @@ async fn discussion_comment(cx: &Cx, Form(form): Form<ActionForm>) -> Result<imp
111111 Ok(comment) => comment,
112112 Err(e) => {
113113 let message = refusal_message(e)?;
114- return Ok(view! { cx =>
114+ return Ok(view! {
115115 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),
116116 action_error_at(lang: lang, message: message, back: base))
117117 });
@@ -132,12 +132,12 @@ async fn discussion_comment(cx: &Cx, Form(form): Form<ActionForm>) -> Result<imp
132132
133133 #[page(POST "/{owner}/{repo}/discussions/{number}/edit")]
134134 async fn discussion_edit(cx: &Cx, Form(form): Form<ActionForm>) -> Result<impl View> {
135- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
136- let state = app_context::<AppState>(cx);
135+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
136+ let state = context::<AppState>(cx);
137137 let (user, _) = require_csrf(cx, &form.csrf).await?;
138138 let lang = i18n::lang(cx, Some(&user));
139139 ensure_enabled(state, &ctx).await?;
140- let discussion = discussion_by_number(state, &ctx, path_param::<Number>(cx)).await?;
140+ let discussion = discussion_by_number(state, &ctx, number(cx)).await?;
141141 if ctx.repo.archived || !is_author(&ctx, &discussion.author_id) {
142142 return Err(forbidden().into());
143143 }
@@ -148,7 +148,7 @@ async fn discussion_edit(cx: &Cx, Form(form): Form<ActionForm>) -> Result<impl V
148148 .await
149149 {
150150 let message = refusal_message(e)?;
151- return Ok(view! { cx =>
151+ return Ok(view! {
152152 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),
153153 action_error_at(lang: lang, message: message, back: base))
154154 });
@@ -177,11 +177,11 @@ async fn discussion_edit(cx: &Cx, Form(form): Form<ActionForm>) -> Result<impl V
177177 /// Deletes the discussion with its comments. Its author only.
178178 #[route(POST "/{owner}/{repo}/discussions/{number}/delete")]
179179 async fn discussion_delete(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther> {
180- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
181- let state = app_context::<AppState>(cx);
180+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
181+ let state = context::<AppState>(cx);
182182 let (user, _) = require_csrf(cx, &form.csrf).await?;
183183 ensure_enabled(state, &ctx).await?;
184- let discussion = discussion_by_number(state, &ctx, path_param::<Number>(cx)).await?;
184+ let discussion = discussion_by_number(state, &ctx, number(cx)).await?;
185185 if ctx.repo.archived || !is_author(&ctx, &discussion.author_id) {
186186 return Err(forbidden().into());
187187 }
@@ -205,11 +205,11 @@ async fn discussion_delete(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeO
205205 /// Locks (`locked=1`) or unlocks (`locked=0`) a discussion. Triage holders only.
206206 #[route(POST "/{owner}/{repo}/discussions/{number}/lock")]
207207 async fn discussion_lock(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther> {
208- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
209- let state = app_context::<AppState>(cx);
208+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
209+ let state = context::<AppState>(cx);
210210 let (user, _) = require_csrf(cx, &form.csrf).await?;
211211 ensure_enabled(state, &ctx).await?;
212- let discussion = discussion_by_number(state, &ctx, path_param::<Number>(cx)).await?;
212+ let discussion = discussion_by_number(state, &ctx, number(cx)).await?;
213213 if !can_triage(&ctx) {
214214 return Err(forbidden().into());
215215 }
@@ -233,12 +233,12 @@ async fn discussion_lock(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOth
233233 /// Triage holder may do it.
234234 #[page(POST "/{owner}/{repo}/discussions/{number}/answer")]
235235 async fn discussion_answer(cx: &Cx, Form(form): Form<ActionForm>) -> Result<impl View> {
236- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
237- let state = app_context::<AppState>(cx);
236+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
237+ let state = context::<AppState>(cx);
238238 let (user, _) = require_csrf(cx, &form.csrf).await?;
239239 let lang = i18n::lang(cx, Some(&user));
240240 ensure_enabled(state, &ctx).await?;
241- let discussion = discussion_by_number(state, &ctx, path_param::<Number>(cx)).await?;
241+ let discussion = discussion_by_number(state, &ctx, number(cx)).await?;
242242 if ctx.repo.archived || !(can_triage(&ctx) || is_author(&ctx, &discussion.author_id)) {
243243 return Err(forbidden().into());
244244 }
@@ -256,7 +256,7 @@ async fn discussion_answer(cx: &Cx, Form(form): Form<ActionForm>) -> Result<impl
256256 .await
257257 {
258258 let message = refusal_message(e)?;
259- return Ok(view! { cx =>
259+ return Ok(view! {
260260 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),
261261 action_error_at(lang: lang, message: message, back: base))
262262 });
@@ -278,13 +278,13 @@ async fn discussion_answer(cx: &Cx, Form(form): Form<ActionForm>) -> Result<impl
278278
279279 #[page(POST "/{owner}/{repo}/discussions/{number}/comments/{comment_id}/edit")]
280280 async fn discussion_comment_edit(cx: &Cx, Form(form): Form<ActionForm>) -> Result<impl View> {
281- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
282- let state = app_context::<AppState>(cx);
281+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
282+ let state = context::<AppState>(cx);
283283 let (user, _) = require_csrf(cx, &form.csrf).await?;
284284 ensure_enabled(state, &ctx).await?;
285- let discussion = discussion_by_number(state, &ctx, path_param::<Number>(cx)).await?;
285+ let discussion = discussion_by_number(state, &ctx, number(cx)).await?;
286286 let lang = i18n::lang(cx, Some(&user));
287- let comment = own_comment(state, &ctx, &discussion.id, path_param::<CommentId>(cx)).await?;
287+ let comment = own_comment(state, &ctx, &discussion.id, comment_id(cx)).await?;
288288 let base = base_of(&ctx, discussion.number);
289289 if let Err(e) = state
290290 .store
@@ -292,7 +292,7 @@ async fn discussion_comment_edit(cx: &Cx, Form(form): Form<ActionForm>) -> Resul
292292 .await
293293 {
294294 let message = refusal_message(e)?;
295- return Ok(view! { cx =>
295+ return Ok(view! {
296296 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),
297297 action_error_at(lang: lang, message: message, back: base))
298298 });
@@ -320,12 +320,12 @@ async fn discussion_comment_edit(cx: &Cx, Form(form): Form<ActionForm>) -> Resul
320320
321321 #[route(POST "/{owner}/{repo}/discussions/{number}/comments/{comment_id}/delete")]
322322 async fn discussion_comment_delete(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther> {
323- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
324- let state = app_context::<AppState>(cx);
323+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
324+ let state = context::<AppState>(cx);
325325 let (user, _) = require_csrf(cx, &form.csrf).await?;
326326 ensure_enabled(state, &ctx).await?;
327- let discussion = discussion_by_number(state, &ctx, path_param::<Number>(cx)).await?;
328- let comment = own_comment(state, &ctx, &discussion.id, path_param::<CommentId>(cx)).await?;
327+ let discussion = discussion_by_number(state, &ctx, number(cx)).await?;
328+ let comment = own_comment(state, &ctx, &discussion.id, comment_id(cx)).await?;
329329 state.store.delete_discussion_comment(&comment.id).await?;
330330 audit_discussion(
331331 cx,
@@ -343,11 +343,11 @@ async fn discussion_comment_delete(cx: &Cx, Form(form): Form<ActionForm>) -> Res
343343 /// comments (`target_kind=discussion_comment`).
344344 #[route(POST "/{owner}/{repo}/discussions/{number}/reactions")]
345345 async fn discussion_reaction(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther> {
346- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
347- let state = app_context::<AppState>(cx);
346+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
347+ let state = context::<AppState>(cx);
348348 let (user, _) = require_csrf(cx, &form.csrf).await?;
349349 ensure_enabled(state, &ctx).await?;
350- let discussion = discussion_by_number(state, &ctx, path_param::<Number>(cx)).await?;
350+ let discussion = discussion_by_number(state, &ctx, number(cx)).await?;
351351 if !may_converse(&ctx, discussion.locked) {
352352 return Err(forbidden().into());
353353 }
crates/forge-web/src/pages/discussion_live.rsmodified+7 -7
@@ -13,7 +13,7 @@
1313 //! that is not there.
1414
1515 use topcoat::Result;
16-use topcoat::context::{Cx, app_context};
16+use topcoat::context::{Cx, context};
1717 use topcoat::router::request::{method, uri};
1818 use topcoat::router::response::Response;
1919 use topcoat::router::{Body, Layer, LayerFuture, Method, Next, Path, path_param, route};
@@ -40,8 +40,8 @@ pub fn item_live_url(owner: &str, repo: &str, number: i64) -> String {
4040 /// The change stream of the discussion list.
4141 #[route(GET "/{owner}/{repo}/discussions/live")]
4242 async fn discussions_live(cx: &Cx) -> Result<Response> {
43- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
44- let state = app_context::<AppState>(cx);
43+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
44+ let state = context::<AppState>(cx);
4545 ensure_enabled(state, &ctx).await?;
4646 stream_wakes(cx, &state.live, &[Topic::Discussions(ctx.repo.id.clone())])
4747 }
@@ -49,10 +49,10 @@ async fn discussions_live(cx: &Cx) -> Result<Response> {
4949 /// The change stream of one discussion page.
5050 #[route(GET "/{owner}/{repo}/discussions/{number}/live")]
5151 async fn discussion_live(cx: &Cx) -> Result<Response> {
52- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
53- let state = app_context::<AppState>(cx);
52+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
53+ let state = context::<AppState>(cx);
5454 ensure_enabled(state, &ctx).await?;
55- let discussion = discussion_by_number(state, &ctx, path_param::<Number>(cx)).await?;
55+ let discussion = discussion_by_number(state, &ctx, number(cx)).await?;
5656 stream_wakes(cx, &state.live, &[Topic::Discussion(discussion.id.clone())])
5757 }
5858
@@ -128,7 +128,7 @@ async fn topics_of(state: &AppState, target: Written) -> Vec<Topic> {
128128 /// through unchanged, so a refused write (an error or a redirect) bumps too: the page re-reads and
129129 /// agrees.
130130 async fn bump_after_write(cx: &Cx, body: Body, next: Next<'_>) -> topcoat::Result<Response> {
131- let state = app_context::<AppState>(cx);
131+ let state = context::<AppState>(cx);
132132 let topics = match written(cx) {
133133 Some(target) => topics_of(state, target).await,
134134 None => Vec::new(),
crates/forge-web/src/pages/discussion_settings.rsmodified+10 -4
@@ -5,7 +5,7 @@
55 use forge_core::AuditAction;
66 use serde::Deserialize;
77 use topcoat::Result;
8-use topcoat::context::{Cx, app_context};
8+use topcoat::context::{Cx, context};
99 use topcoat::router::content::Form;
1010 use topcoat::router::error::{SeeOther, forbidden, see_other};
1111 use topcoat::router::{path_param, route};
@@ -26,6 +26,7 @@ path_param!(repo);
2626 /// the form on change (`data-autosubmit`); an unchecked box sends no `enabled`, which the handler reads as off.
2727 #[component]
2828 pub(crate) async fn discussions_switch(
29+ cx: &Cx,
2930 lang: Lang,
3031 action: String,
3132 csrf: String,
@@ -53,13 +54,13 @@ struct ToggleForm {
5354
5455 #[route(POST "/{owner}/{repo}/settings/discussions")]
5556 async fn settings_discussions_save(cx: &Cx, Form(form): Form<ToggleForm>) -> Result<SeeOther> {
56- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
57+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
5758 let (user, _) = require_csrf(cx, &form.csrf).await?;
5859 if !ctx.can_admin() {
5960 return Err(forbidden().into());
6061 }
6162 let enabled = form.enabled == "1";
62- let state = app_context::<AppState>(cx);
63+ let state = context::<AppState>(cx);
6364 state
6465 .store
6566 .set_discussions_enabled(&ctx.repo.id, enabled)
@@ -85,5 +86,10 @@ async fn settings_discussions_save(cx: &Cx, Form(form): Form<ToggleForm>) -> Res
8586 serde_json::Value::Null,
8687 )
8788 .await;
88- Ok(see_other(repo_href(&ctx.repo.owner_name, &ctx.repo.name, "settings", "")))
89+ Ok(see_other(repo_href(
90+ &ctx.repo.owner_name,
91+ &ctx.repo.name,
92+ "settings",
93+ "",
94+ )))
8995 }
crates/forge-web/src/pages/discussion_view.rsmodified+11 -7
@@ -8,7 +8,7 @@ use std::collections::HashMap;
88 use forge_core::discussions::{Discussion, DiscussionCategory, DiscussionComment};
99 use forge_core::{ReactionMap, ReactionTarget};
1010 use topcoat::Result;
11-use topcoat::context::{Cx, app_context};
11+use topcoat::context::{Cx, context};
1212 use topcoat::router::{page, path_param};
1313 use topcoat::view::{Unescaped, View, component, view};
1414
@@ -151,7 +151,7 @@ fn comment_view(
151151
152152 /// One comment, with its reactions and the forms the viewer may use.
153153 #[component]
154-async fn comment_article(item: CommentView) -> Result<impl View> {
154+async fn comment_article(cx: &Cx, item: CommentView) -> Result<impl View> {
155155 let CommentView {
156156 lang,
157157 anchor,
@@ -246,7 +246,11 @@ async fn comment_article(item: CommentView) -> Result<impl View> {
246246
247247 /// A top-level comment with its replies indented under it.
248248 #[component]
249-async fn comment_thread(root: CommentView, replies: Vec<CommentView>) -> Result<impl View> {
249+async fn comment_thread(
250+ cx: &Cx,
251+ root: CommentView,
252+ replies: Vec<CommentView>,
253+) -> Result<impl View> {
250254 Ok(view! {
251255 <div class="discussion-thread">
252256 comment_article(item: root)
@@ -263,9 +267,9 @@ async fn comment_thread(root: CommentView, replies: Vec<CommentView>) -> Result<
263267
264268 #[page("/{owner}/{repo}/discussions/{number}")]
265269 async fn discussion_show(cx: &Cx) -> Result<impl View> {
266- let number = path_param::<Number>(cx);
267- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
268- let state = app_context::<AppState>(cx);
270+ let number = number(cx);
271+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
272+ let state = context::<AppState>(cx);
269273 ensure_enabled(state, &ctx).await?;
270274 let discussion = discussion_by_number(state, &ctx, number).await?;
271275 discussion_page(cx, state, ctx, discussion).await
@@ -415,7 +419,7 @@ async fn discussion_page(
415419 sub.push(SubPart::link(author.clone(), author_profile.clone()));
416420 sub.push(SubPart::text(opened.relative.clone()));
417421 sub.push(SubPart::text(comments_label));
418- Ok(view! { cx =>
422+ Ok(view! {
419423 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(),
420424 repo_head(head: header, title: Some(discussion.title.clone()), sub: sub,
421425 <span class="num">(number_label.as_str())</span>
crates/forge-web/src/pages/discussions.rsmodified+11 -10
@@ -9,7 +9,7 @@ use forge_core::discussions::{
99 };
1010 use forge_core::{Action, AuditAction, Role, User, authorize};
1111 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};
12+use topcoat::context::{Cx, context};
1313 use topcoat::router::content::RawForm;
1414 use topcoat::router::error::{bad_request, forbidden, not_found, see_other};
1515 use topcoat::router::{StatusCode, page, path_param, query_params};
@@ -225,11 +225,11 @@ fn row_view(
225225
226226 #[page("/{owner}/{repo}/discussions")]
227227 async fn discussions_list_page(cx: &Cx) -> Result<impl View> {
228- let owner = path_param::<Owner>(cx);
229- let name = path_param::<Repo>(cx);
228+ let owner = owner(cx);
229+ let name = repo(cx);
230230 let query = query_params::<ListQuery>(cx)?;
231231 let ctx = load_repo(cx, owner, name).await?;
232- let state = app_context::<AppState>(cx);
232+ let state = context::<AppState>(cx);
233233 ensure_enabled(state, &ctx).await?;
234234 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
235235
@@ -373,6 +373,7 @@ struct DraftDiscussion {
373373
374374 #[component]
375375 async fn new_discussion_body(
376+ cx: &Cx,
376377 lang: Lang,
377378 head: RepoHead,
378379 csrf: String,
@@ -416,10 +417,10 @@ async fn new_discussion_body(
416417
417418 #[page("/{owner}/{repo}/discussions/new")]
418419 async fn discussion_new_page(cx: &Cx) -> Result<impl View> {
419- let owner = path_param::<Owner>(cx);
420- let name = path_param::<Repo>(cx);
420+ let owner = owner(cx);
421+ let name = repo(cx);
421422 let ctx = load_repo(cx, owner, name).await?;
422- let state = app_context::<AppState>(cx);
423+ let state = context::<AppState>(cx);
423424 ensure_enabled(state, &ctx).await?;
424425 let viewer = require_user(cx).await?;
425426 let lang = i18n::lang(cx, Some(&viewer.0));
@@ -443,10 +444,10 @@ async fn discussion_new_page(cx: &Cx) -> Result<impl View> {
443444
444445 #[page(POST "/{owner}/{repo}/discussions/new")]
445446 async fn discussion_create(cx: &Cx, RawForm(raw): RawForm) -> Result<impl View> {
446- let owner = path_param::<Owner>(cx);
447- let name = path_param::<Repo>(cx);
447+ let owner = owner(cx);
448+ let name = repo(cx);
448449 let ctx = load_repo(cx, owner, name).await?;
449- let state = app_context::<AppState>(cx);
450+ let state = context::<AppState>(cx);
450451 ensure_enabled(state, &ctx).await?;
451452 let fields = form_pairs(&raw[..]);
452453 let viewer = require_csrf(cx, &form_field(&fields, "csrf")).await?;
crates/forge-web/src/pages/edit_history.rsmodified+10 -13
@@ -10,7 +10,7 @@ use std::sync::Arc;
1010 use forge_core::{EditVersion, Issue, Thread};
1111 use similar::{ChangeTag, TextDiff};
1212 use topcoat::Result;
13-use topcoat::context::{Cx, app_context};
13+use topcoat::context::{Cx, context};
1414 use topcoat::router::error::not_found;
1515 use topcoat::router::{page, path_param};
1616 use topcoat::view::{View, component, view};
@@ -174,7 +174,7 @@ async fn history_page(
174174 ) -> Result<impl View> {
175175 let target = target.as_str();
176176 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
177- let state = app_context::<AppState>(cx);
177+ let state = context::<AppState>(cx);
178178 let owner = ctx.repo.owner_name.clone();
179179 let name = ctx.repo.name.clone();
180180 let number = item.number;
@@ -229,17 +229,14 @@ async fn history_page(
229229 let heading = g::history_heading(lang, what);
230230 let back_label = g::back_to_item(lang, number);
231231 let count_label = g::earlier_versions(lang, entries.len());
232- let sub = vec![
233- SubPart::link(back_label, back),
234- SubPart::text(count_label),
235- ];
232+ let sub = vec![SubPart::link(back_label, back), SubPart::text(count_label)];
236233 // A history follows its item: a new edit adds a version to the list.
237234 let live = match kind_item {
238235 ItemKind::Issue => item_live_url(&owner, &name, number),
239236 ItemKind::Pull => pull_live_url(&owner, &name, number),
240237 };
241238
242- Ok(view! { cx =>
239+ Ok(view! {
243240 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(),
244241 repo_head(head: header, title: Some(heading), sub: sub)
245242 <div class="work" data-live=(live.as_str()) data-live-now="">
@@ -260,7 +257,7 @@ async fn history_page(
260257
261258 /// One version: the editor and time, the title change if any, the diff and the raw text.
262259 #[component]
263-async fn history_entry(lang: Lang, entry: HistoryEntry) -> Result<impl View> {
260+async fn history_entry(cx: &Cx, lang: Lang, entry: HistoryEntry) -> Result<impl View> {
264261 let HistoryEntry {
265262 editor,
266263 when,
@@ -315,11 +312,11 @@ fn parse_kind(raw: &str) -> Result<&'static str> {
315312 }
316313
317314 async fn history_route(cx: &Cx, item_kind: ItemKind) -> Result<impl View> {
318- let number = parse_number(path_param::<Number>(cx))?;
319- let target_kind = parse_kind(path_param::<Kind>(cx))?;
320- let target = path_param::<TargetId>(cx).to_owned();
321- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
322- let state = app_context::<AppState>(cx);
315+ let number = parse_number(number(cx))?;
316+ let target_kind = parse_kind(kind(cx))?;
317+ let target = target_id(cx).to_owned();
318+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
319+ let state = context::<AppState>(cx);
323320 let item = item_for(state, &ctx, item_kind, number).await?;
324321 history_page(cx, ctx, item_kind, item, target_kind, target).await
325322 }
crates/forge-web/src/pages/explore.rsmodified+25 -10
@@ -4,10 +4,10 @@
44 //! page fits the window. `explore` is a reserved username, so this
55 //! route cannot collide with a profile.
66
7-use forge_core::{Repo, User};
87 use forge_core::store::RepoSort;
8+use forge_core::{Repo, User};
99 use topcoat::Result;
10-use topcoat::context::{Cx, app_context};
10+use topcoat::context::{Cx, context};
1111 use topcoat::router::response::Response;
1212 use topcoat::router::{page, query_params, route};
1313 use topcoat::view::{View, component, view};
@@ -16,13 +16,13 @@ use crate::auth::current_user;
1616 use crate::i18n::orgs::{self as g, K};
1717 use crate::i18n::{self, Lang};
1818 use crate::live::{Topic, stream_changes};
19+use crate::pages::issues_list::list_href;
1920 use crate::state::AppState;
21+use crate::views::find::{Finder, finder_field};
2022 use crate::views::parts::head;
2123 use crate::views::repo_list::{
2224 PageLink, RepoRow, SortLink, pager, pager_links, repo_rows, sort_chips,
2325 };
24-use crate::pages::issues_list::list_href;
25-use crate::views::find::{Finder, finder_field};
2626 use crate::views::{now_unix, shell};
2727
2828 const PER_PAGE: u64 = 12;
@@ -162,7 +162,7 @@ async fn explore_page(cx: &Cx) -> Result<impl View> {
162162 let live = explore_href(&finder, sort, page).replacen("/explore?", "/explore/events?", 1);
163163 let viewer = current_user(cx).await?;
164164 let lang = i18n::lang(cx, viewer.as_ref().map(|(u, _)| u));
165- let state = app_context::<AppState>(cx);
165+ let state = context::<AppState>(cx);
166166 let on_orgs = orgs_tab(query);
167167 let (listed, repo_total) = listing(state, &finder, sort, page).await?;
168168 let (org_page, org_total) = org_listing(state, &finder, page).await?;
@@ -206,12 +206,22 @@ async fn explore_page(cx: &Cx) -> Result<impl View> {
206206 pager_links(page, pages, |n| explore_href(&finder, sort, n))
207207 };
208208 let tabs = vec![
209- (g::t(lang, K::Repositories), explore_href(&Finder::default(), sort, 1), repos_all, !on_orgs),
210- (g::t(lang, K::Organizations), orgs_href(&Finder::default(), 1), orgs_all, on_orgs),
209+ (
210+ g::t(lang, K::Repositories),
211+ explore_href(&Finder::default(), sort, 1),
212+ repos_all,
213+ !on_orgs,
214+ ),
215+ (
216+ g::t(lang, K::Organizations),
217+ orgs_href(&Finder::default(), 1),
218+ orgs_all,
219+ on_orgs,
220+ ),
211221 ];
212222 let title = g::t(lang, K::Explore);
213223
214- Ok(view! { cx =>
224+ Ok(view! {
215225 shell(title: title, viewer: viewer.as_ref(),
216226 explore_body(finder: finder, sort: sort, sort_links: sort_links, rows: rows,
217227 total: total, page: page, pages: pages, nav: nav, orgs: orgs, lang: lang, live: live,
@@ -227,7 +237,7 @@ async fn explore_events(cx: &Cx) -> Result<Response> {
227237 let query = query_params::<ExploreQuery>(cx)?;
228238 let (finder, sort, page) = listing_args(query);
229239 let on_orgs = orgs_tab(query);
230- let state = app_context::<AppState>(cx).clone();
240+ let state = context::<AppState>(cx).clone();
231241 stream_changes(cx, &state.live.clone(), &[Topic::Explore], move || {
232242 let state = state.clone();
233243 let finder = finder.clone();
@@ -263,6 +273,7 @@ async fn explore_fingerprint(
263273
264274 #[component]
265275 async fn explore_body(
276+ cx: &Cx,
266277 finder: Finder,
267278 sort: &'static str,
268279 sort_links: Vec<SortLink>,
@@ -277,7 +288,11 @@ async fn explore_body(
277288 on_orgs: bool,
278289 tabs: Vec<(&'static str, String, u64, bool)>,
279290 ) -> Result<impl View> {
280- let empty = if on_orgs { orgs.is_empty() } else { rows.is_empty() };
291+ let empty = if on_orgs {
292+ orgs.is_empty()
293+ } else {
294+ rows.is_empty()
295+ };
281296 let has_search = !finder.is_empty();
282297 let (links, prev, next) = nav;
283298 let clear_href = if on_orgs {
crates/forge-web/src/pages/finder.rsmodified+6 -5
@@ -5,7 +5,7 @@
55 use forge_git::history;
66 use http::header::{CACHE_CONTROL, CONTENT_TYPE};
77 use topcoat::Result;
8-use topcoat::context::{Cx, app_context};
8+use topcoat::context::{Cx, context};
99 use topcoat::router::error::not_found;
1010 use topcoat::router::response::Response;
1111 use topcoat::router::{Body, HeaderValue, path_param, route};
@@ -28,6 +28,7 @@ pub const MAX_PATHS: usize = 20_000;
2828 /// The "Go to file" button and its dialog for the tree at `ref_name`.
2929 #[component]
3030 pub async fn file_finder(
31+ cx: &Cx,
3132 lang: Lang,
3233 owner: String,
3334 repo: String,
@@ -58,11 +59,11 @@ pub async fn file_finder(
5859 /// `{"ref": ..., "commit": ..., "paths": [...], "truncated": bool}` for the tree at the ref.
5960 #[route(GET "/{owner}/{repo}/paths/{*rest}")]
6061 async fn tree_paths(cx: &Cx) -> Result<Response> {
61- let owner = path_param::<Owner>(cx);
62- let name = path_param::<Repo>(cx);
63- let rest = path_param::<Rest>(cx).collect::<Vec<_>>().join("/");
62+ let owner = owner(cx);
63+ let name = repo(cx);
64+ let rest = rest(cx).collect::<Vec<_>>().join("/");
6465 let ctx = load_repo(cx, owner, name).await?;
65- let state = app_context::<AppState>(cx);
66+ let state = context::<AppState>(cx);
6667
6768 let Some((ref_name, commit, path)) = resolve(ctx.path.clone(), rest).await? else {
6869 return Err(not_found().into());
crates/forge-web/src/pages/forgot.rsmodified+7 -6
@@ -8,7 +8,7 @@ use std::time::Instant;
88 use forge_core::AuditAction;
99 use serde::Deserialize;
1010 use topcoat::Result;
11-use topcoat::context::{Cx, app_context};
11+use topcoat::context::{Cx, context};
1212 use topcoat::router::content::Form;
1313 use topcoat::router::error::forbidden;
1414 use topcoat::router::{page, path_param_segment};
@@ -57,7 +57,7 @@ enum ResetMode {
5757 }
5858
5959 #[component]
60-async fn forgot_form(lang: Lang, precsrf: &str) -> Result<impl View> {
60+async fn forgot_form(cx: &Cx, lang: Lang, precsrf: &str) -> Result<impl View> {
6161 Ok(view! {
6262 head(title: t(lang, Key::ForgotTitle))
6363 <div class="sheet fit">
@@ -74,7 +74,7 @@ async fn forgot_form(lang: Lang, precsrf: &str) -> Result<impl View> {
7474 }
7575
7676 #[component]
77-async fn forgot_sent(lang: Lang) -> Result<impl View> {
77+async fn forgot_sent(cx: &Cx, lang: Lang) -> Result<impl View> {
7878 Ok(view! {
7979 head(title: t(lang, Key::ForgotTitle))
8080 <div class="sheet fit">
@@ -110,7 +110,7 @@ async fn forgot_submit(cx: &Cx, Form(form): Form<ForgotForm>) -> Result<impl Vie
110110 if !check_pre_csrf(cx, &form.precsrf) {
111111 return Err(forbidden().into());
112112 }
113- let state = app_context::<AppState>(cx);
113+ let state = context::<AppState>(cx);
114114 let lang = i18n::lang(cx, None);
115115 let address = form.email.trim().to_owned();
116116 let now = Instant::now();
@@ -143,6 +143,7 @@ async fn forgot_submit(cx: &Cx, Form(form): Form<ForgotForm>) -> Result<impl Vie
143143
144144 #[component]
145145 async fn reset_body(
146+ cx: &Cx,
146147 lang: Lang,
147148 token: &str,
148149 precsrf: &str,
@@ -188,7 +189,7 @@ async fn reset_body(
188189
189190 #[page("/reset/{token}")]
190191 async fn reset_page(cx: &Cx) -> Result<impl View> {
191- let state = app_context::<AppState>(cx);
192+ let state = context::<AppState>(cx);
192193 let lang = i18n::lang(cx, None);
193194 let token = path_param_segment(cx, "token").to_owned();
194195 let mode = if state.store.reset_token_is_live(&token).await? {
@@ -207,7 +208,7 @@ async fn reset_submit(cx: &Cx, Form(form): Form<ResetForm>) -> Result<impl View>
207208 if !check_pre_csrf(cx, &form.precsrf) {
208209 return Err(forbidden().into());
209210 }
210- let state = app_context::<AppState>(cx);
211+ let state = context::<AppState>(cx);
211212 let lang = i18n::lang(cx, None);
212213 let token = path_param_segment(cx, "token").to_owned();
213214 let mut mode = ResetMode::Form;
crates/forge-web/src/pages/fork.rsmodified+4 -4
@@ -8,7 +8,7 @@ use forge_core::AuditAction;
88 use forge_git::repo::{fork_bare, repo_path};
99 use serde::Deserialize;
1010 use topcoat::Result;
11-use topcoat::context::{Cx, app_context};
11+use topcoat::context::{Cx, context};
1212 use topcoat::router::content::Form;
1313 use topcoat::router::error::{SeeOther, see_other};
1414 use topcoat::router::{path_param, route};
@@ -30,11 +30,11 @@ struct ForkForm {
3030
3131 #[route(POST "/{owner}/{repo}/fork")]
3232 async fn fork_post(cx: &Cx, Form(form): Form<ForkForm>) -> Result<SeeOther> {
33- let owner = path_param::<Owner>(cx);
34- let name = path_param::<Repo>(cx);
33+ let owner = owner(cx);
34+ let name = repo(cx);
3535 let source = load_repo(cx, owner, name).await?;
3636 let (viewer, _) = require_csrf(cx, &form.csrf).await?;
37- let state = app_context::<AppState>(cx);
37+ let state = context::<AppState>(cx);
3838 let source_repo = &source.repo;
3939
4040 // Forking your own repo is a no-op: send the viewer back to it.
crates/forge-web/src/pages/home.rsmodified+5 -5
@@ -7,7 +7,7 @@ use forge_core::authz::{Action, authorize};
77 use forge_core::store::RepoSort;
88 use forge_core::store::repo_listing::RepoScope;
99 use topcoat::Result;
10-use topcoat::context::{Cx, app_context};
10+use topcoat::context::{Cx, context};
1111 use topcoat::router::page;
1212 use topcoat::view::{View, component, view};
1313
@@ -24,7 +24,7 @@ use crate::pages::repo_settings::{notice_banner_for, take_notice};
2424 use crate::state::AppState;
2525 use crate::views::parts::head;
2626 use crate::views::repo_list::private_fact;
27-use crate::views::{repo_href, rel_time, shell, user_href};
27+use crate::views::{rel_time, repo_href, shell, user_href};
2828
2929 /// Rows a topic lists on the home page, before its link to the full list.
3030 const TOPIC_ROWS: usize = 5;
@@ -54,7 +54,7 @@ struct SignedHome {
5454
5555 #[page("/")]
5656 async fn home(cx: &Cx) -> Result<impl View> {
57- let state = app_context::<AppState>(cx);
57+ let state = context::<AppState>(cx);
5858 let viewer = current_user(cx).await?;
5959 let lang = i18n::lang(cx, viewer.as_ref().map(|(user, _)| user));
6060 let notice = take_notice(cx);
@@ -197,7 +197,7 @@ async fn load_home(state: &AppState, user: &User, lang: Lang) -> Result<SignedHo
197197
198198 /// The signed-in home: the head's actions, then the two topics on one sheet.
199199 #[component]
200-async fn signed_home(lang: Lang, data: SignedHome, may_org: bool) -> Result<impl View> {
200+async fn signed_home(cx: &Cx, lang: Lang, data: SignedHome, may_org: bool) -> Result<impl View> {
201201 let SignedHome {
202202 needs,
203203 repos,
@@ -257,7 +257,7 @@ async fn signed_home(lang: Lang, data: SignedHome, may_org: bool) -> Result<impl
257257
258258 /// The visitor's landing: the wordmark's tagline and the way in.
259259 #[component]
260-async fn landing(has_users: bool, lang: Lang) -> Result<impl View> {
260+async fn landing(cx: &Cx, has_users: bool, lang: Lang) -> Result<impl View> {
261261 Ok(view! {
262262 head(title: "forge",
263263 <a class="button primary" href="/login">(g::t(lang, K::LogIn))</a>
crates/forge-web/src/pages/import.rsmodified+44 -30
@@ -10,7 +10,7 @@ use forge_git::repo::{init_bare, repo_path};
1010 use futures_util::stream;
1111 use serde::Deserialize;
1212 use topcoat::Result;
13-use topcoat::context::{Cx, app_context};
13+use topcoat::context::{Cx, context};
1414 use topcoat::router::content::Form;
1515 use topcoat::router::error::{SeeOther, not_found, see_other};
1616 use topcoat::router::response::Response;
@@ -165,7 +165,7 @@ fn token_of(raw: &str) -> Option<String> {
165165 // ---- shared pieces ----
166166
167167 #[component]
168-pub(crate) async fn newrepo_tabs(lang: Lang, active: &str) -> Result<impl View> {
168+pub(crate) async fn newrepo_tabs(cx: &Cx, lang: Lang, active: &str) -> Result<impl View> {
169169 let create = active == "create";
170170 let import = active == "import";
171171 let history = active == "history";
@@ -179,7 +179,7 @@ pub(crate) async fn newrepo_tabs(lang: Lang, active: &str) -> Result<impl View>
179179 }
180180
181181 #[component]
182-async fn source_tabs(lang: Lang, base: &str, active: Source) -> Result<impl View> {
182+async fn source_tabs(cx: &Cx, lang: Lang, base: &str, active: Source) -> Result<impl View> {
183183 let git = format!("{base}?source=git");
184184 let github = format!("{base}?source=github");
185185 let gitlab = format!("{base}?source=gitlab");
@@ -199,7 +199,7 @@ async fn source_tabs(lang: Lang, base: &str, active: Source) -> Result<impl View
199199
200200 /// Public or private, as two switches with what each means under it. Shared with the create page.
201201 #[component]
202-pub(crate) async fn visibility_pick(lang: Lang, private: bool) -> Result<impl View> {
202+pub(crate) async fn visibility_pick(cx: &Cx, lang: Lang, private: bool) -> Result<impl View> {
203203 Ok(view! {
204204 <div class="field">
205205 <span class="field-label">(crate::i18n::misc::t(lang, crate::i18n::misc::K::VisibilityLegend))</span>
@@ -212,7 +212,7 @@ pub(crate) async fn visibility_pick(lang: Lang, private: bool) -> Result<impl Vi
212212 }
213213
214214 #[component]
215-async fn option_boxes(lang: Lang, opts: ImportOptions) -> Result<impl View> {
215+async fn option_boxes(cx: &Cx, lang: Lang, opts: ImportOptions) -> Result<impl View> {
216216 Ok(view! {
217217 <div class="field" role="group" aria-labelledby="import-what">
218218 <span class="field-label" id="import-what">(g::t(lang, K::WhatToImport))</span>
@@ -283,6 +283,7 @@ impl Draft {
283283
284284 #[component]
285285 async fn import_form(
286+ cx: &Cx,
286287 lang: Lang,
287288 username: String,
288289 csrf: &str,
@@ -391,6 +392,7 @@ async fn import_form(
391392 /// The GET import page: the form. Past imports are on the Import history tab.
392393 #[component]
393394 async fn import_home(
395+ cx: &Cx,
394396 lang: Lang,
395397 username: String,
396398 csrf: String,
@@ -405,6 +407,7 @@ async fn import_home(
405407 /// The import form again after a rejected submit.
406408 #[component]
407409 async fn import_error_body(
410+ cx: &Cx,
408411 lang: Lang,
409412 username: String,
410413 csrf: String,
@@ -423,10 +426,10 @@ async fn import_page(cx: &Cx) -> Result<impl View> {
423426 let lang = i18n::lang(cx, Some(&viewer.0));
424427 let query = query_params::<SourceQuery>(cx)?;
425428 let source = source_of(query.source.as_deref());
426- let state = app_context::<AppState>(cx);
429+ let state = context::<AppState>(cx);
427430 let owners = owner_choices(state, &viewer.0).await?;
428431 let csrf = viewer.1.csrf_token.clone();
429- Ok(view! { cx =>
432+ Ok(view! {
430433 shell(title: g::t(lang, K::ImportTitle), viewer: Some(&viewer),
431434 import_home(lang: lang, username: viewer.0.username.clone(), csrf: csrf, draft: Draft::fresh(source), owners: owners))
432435 })
@@ -440,10 +443,10 @@ async fn import_submit(cx: &Cx, Form(form): Form<ImportForm>) -> Result<impl Vie
440443 match start_single(cx, &viewer.0, lang, source, &form).await? {
441444 Ok(job_id) => Err(see_other(format!("/import/{job_id}")).into()),
442445 Err(message) => {
443- let owners = owner_choices(app_context::<AppState>(cx), &viewer.0).await?;
446+ let owners = owner_choices(context::<AppState>(cx), &viewer.0).await?;
444447 let csrf = viewer.1.csrf_token.clone();
445448 let draft = Draft::from_form(&form, source);
446- Ok(view! { cx =>
449+ Ok(view! {
447450 shell(title: g::t(lang, K::ImportTitle), viewer: Some(&viewer),
448451 import_error_body(lang: lang, username: viewer.0.username.clone(), csrf: csrf, draft: draft, error: message, owners: owners))
449452 })
@@ -460,7 +463,7 @@ async fn start_single(
460463 source: Source,
461464 form: &ImportForm,
462465 ) -> Result<std::result::Result<String, String>> {
463- let state = app_context::<AppState>(cx);
466+ let state = context::<AppState>(cx);
464467 let Some((remote, instance)) = parse_remote(source, &form.remote, &form.instance) else {
465468 let message = if has_instance(source) && form.remote.trim().starts_with("http") {
466469 g::t(lang, K::ErrBadInstance)
@@ -526,7 +529,7 @@ async fn begin(
526529 visibility: Visibility,
527530 spec: JobSpec,
528531 ) -> Result<std::result::Result<String, String>> {
529- let state = app_context::<AppState>(cx);
532+ let state = context::<AppState>(cx);
530533 let lang = i18n::lang(cx, Some(actor));
531534 let name = match forge_core::names::validate_name(name) {
532535 Ok(name) => name,
@@ -589,6 +592,7 @@ async fn begin(
589592
590593 #[component]
591594 async fn bulk_form(
595+ cx: &Cx,
592596 lang: Lang,
593597 username: String,
594598 csrf: &str,
@@ -652,6 +656,7 @@ struct Listed {
652656
653657 #[component]
654658 async fn bulk_select(
659+ cx: &Cx,
655660 lang: Lang,
656661 username: String,
657662 csrf: &str,
@@ -748,9 +753,9 @@ async fn bulk_page(cx: &Cx) -> Result<impl View> {
748753 Source::Git => Source::GitHub,
749754 other => other,
750755 };
751- let owners = owner_choices(app_context::<AppState>(cx), &viewer.0).await?;
756+ let owners = owner_choices(context::<AppState>(cx), &viewer.0).await?;
752757 let csrf = viewer.1.csrf_token.clone();
753- Ok(view! { cx =>
758+ Ok(view! {
754759 shell(title: g::t(lang, K::BulkTitle), viewer: Some(&viewer),
755760 bulk_form(lang: lang, username: viewer.0.username.clone(), csrf: csrf.as_str(), source: source, instance: default_instance(source), owners: owners, error: query.error.clone().filter(|e| e.len() < 300)))
756761 })
@@ -790,7 +795,7 @@ async fn list_remote(
790795 async fn bulk_submit(cx: &Cx, Form(form): Form<BulkForm>) -> Result<impl View> {
791796 let viewer = require_csrf(cx, &form.csrf).await?;
792797 let lang = i18n::lang(cx, Some(&viewer.0));
793- let state = app_context::<AppState>(cx);
798+ let state = context::<AppState>(cx);
794799 let source = match source_of(Some(&form.source)) {
795800 Source::Git => Source::GitHub,
796801 other => other,
@@ -849,7 +854,7 @@ async fn bulk_submit(cx: &Cx, Form(form): Form<BulkForm>) -> Result<impl View> {
849854 (None, Some((echo, repos)))
850855 }
851856 };
852- Ok(view! { cx =>
857+ Ok(view! {
853858 shell(title: g::t(lang, K::BulkTitle), viewer: Some(&viewer),
854859 bulk_stage(lang: lang, username: viewer.0.username.clone(), csrf: csrf.as_str(), source: source, instance: instance.as_str(), owners: owners, error: error, picker: picker))
855860 })
@@ -858,6 +863,7 @@ async fn bulk_submit(cx: &Cx, Form(form): Form<BulkForm>) -> Result<impl View> {
858863 /// The bulk page body: the picker once a listing exists, the lookup form otherwise.
859864 #[component]
860865 async fn bulk_stage(
866+ cx: &Cx,
861867 lang: Lang,
862868 username: String,
863869 csrf: &str,
@@ -885,7 +891,7 @@ async fn run_bulk(
885891 instance: &str,
886892 form: &BulkForm,
887893 ) -> Result<std::convert::Infallible> {
888- let state = app_context::<AppState>(cx);
894+ let state = context::<AppState>(cx);
889895 let mut picked: Vec<(usize, &String)> = form
890896 .extra
891897 .iter()
@@ -1025,7 +1031,7 @@ async fn load_job_rows(
10251031
10261032 /// The import job rows, shared by the Import history page and the recent list on the Import tab.
10271033 #[component]
1028-async fn job_rows(lang: Lang, jobs: Vec<(ImportJob, Option<Repo>)>) -> Result<impl View> {
1034+async fn job_rows(cx: &Cx, lang: Lang, jobs: Vec<(ImportJob, Option<Repo>)>) -> Result<impl View> {
10291035 Ok(view! {
10301036 <div>
10311037 for (job, repo) in jobs.iter() {
@@ -1046,6 +1052,7 @@ async fn job_rows(lang: Lang, jobs: Vec<(ImportJob, Option<Repo>)>) -> Result<im
10461052
10471053 #[component]
10481054 async fn jobs_list(
1055+ cx: &Cx,
10491056 lang: Lang,
10501057 username: String,
10511058 jobs: Vec<(ImportJob, Option<Repo>)>,
@@ -1108,7 +1115,7 @@ async fn jobs_fingerprint(state: &AppState, user_id: &str) -> Result<String> {
11081115 #[route(GET "/import/events")]
11091116 async fn jobs_events(cx: &Cx) -> Result<Response> {
11101117 let viewer = require_user(cx).await?;
1111- let state = app_context::<AppState>(cx).clone();
1118+ let state = context::<AppState>(cx).clone();
11121119 let user_id = viewer.0.id.clone();
11131120 stream_changes(
11141121 cx,
@@ -1130,7 +1137,7 @@ const HISTORY_ROWS: u64 = 10;
11301137 async fn jobs_page(cx: &Cx) -> Result<impl View> {
11311138 let viewer = require_user(cx).await?;
11321139 let lang = i18n::lang(cx, Some(&viewer.0));
1133- let state = app_context::<AppState>(cx);
1140+ let state = context::<AppState>(cx);
11341141 let query = query_params::<JobsQuery>(cx)?;
11351142 let all = state.store.list_import_jobs(&viewer.0.id, 1000).await?;
11361143 let pages = (all.len() as u64).div_ceil(HISTORY_ROWS).max(1);
@@ -1157,13 +1164,14 @@ async fn jobs_page(cx: &Cx) -> Result<impl View> {
11571164 .clone()
11581165 .filter(|s| !s.is_empty() && s.len() < 2000)
11591166 .map(|s| g::bulk_skipped(lang, &s));
1160- Ok(view! { cx =>
1167+ Ok(view! {
11611168 shell(title: g::t(lang, K::JobsTitle), viewer: Some(&viewer), jobs_list(lang: lang, username: viewer.0.username.clone(), jobs: rows, skipped: skipped, page: page, pages: pages, nav: nav))
11621169 })
11631170 }
11641171
11651172 #[component]
11661173 async fn job_view(
1174+ cx: &Cx,
11671175 lang: Lang,
11681176 username: String,
11691177 csrf: &str,
@@ -1256,8 +1264,8 @@ async fn job_view(
12561264
12571265 /// The job when the viewer owns it. Anyone else gets 404.
12581266 async fn owned_job(cx: &Cx, viewer: &User) -> Result<ImportJob> {
1259- let id = path_param::<JobId>(cx).to_owned();
1260- let state = app_context::<AppState>(cx);
1267+ let id = job_id(cx).to_owned();
1268+ let state = context::<AppState>(cx);
12611269 match state.store.import_job(&id).await? {
12621270 Some(job) if job.user_id == viewer.id => Ok(job),
12631271 _ => Err(not_found().into()),
@@ -1268,13 +1276,13 @@ async fn owned_job(cx: &Cx, viewer: &User) -> Result<ImportJob> {
12681276 async fn job_page(cx: &Cx) -> Result<impl View> {
12691277 let viewer = require_user(cx).await?;
12701278 let lang = i18n::lang(cx, Some(&viewer.0));
1271- let state = app_context::<AppState>(cx);
1279+ let state = context::<AppState>(cx);
12721280 let job = owned_job(cx, &viewer.0).await?;
12731281 let repo = job_repo(state, Some(&viewer.0), &job).await?;
12741282 let log = state.store.list_import_events(&job.id, 200).await?;
12751283 let csrf = viewer.1.csrf_token.clone();
12761284 let title = job.source_ref.clone();
1277- Ok(view! { cx =>
1285+ Ok(view! {
12781286 shell(title: title.as_str(), viewer: Some(&viewer),
12791287 job_view(lang: lang, username: viewer.0.username.clone(), csrf: csrf.as_str(), job: job, repo: repo, log: log))
12801288 })
@@ -1287,7 +1295,7 @@ async fn job_events(cx: &Cx) -> Result<Response> {
12871295 let viewer = require_user(cx).await?;
12881296 let job = owned_job(cx, &viewer.0).await?;
12891297 let query = query_params::<SeenQuery>(cx)?;
1290- let state = app_context::<AppState>(cx);
1298+ let state = context::<AppState>(cx);
12911299 let seen = query.v.clone().unwrap_or_default();
12921300 // Subscribed before the job is read again below, so a change in between is not lost.
12931301 let wake = (!job.state.is_finished()).then(|| importer::subscribe(&job.id));
@@ -1375,7 +1383,7 @@ async fn retry_job(state: &AppState, job: ImportJob, token: &str) -> Result<bool
13751383 #[route(POST "/import/{job_id}/retry")]
13761384 async fn job_retry(cx: &Cx, Form(form): Form<RetryForm>) -> Result<SeeOther> {
13771385 let viewer = require_csrf(cx, &form.csrf).await?;
1378- let state = app_context::<AppState>(cx);
1386+ let state = context::<AppState>(cx);
13791387 let job = owned_job(cx, &viewer.0).await?;
13801388 let href = format!("/import/{}", job.id);
13811389 retry_job(state, job, &form.token).await?;
@@ -1414,7 +1422,13 @@ fn source_label(raw: &str) -> &'static str {
14141422 }
14151423
14161424 #[component]
1417-async fn retry_list(lang: Lang, username: String, csrf: &str, rows: Vec<(ImportJob, Repo)>) -> Result<impl View> {
1425+async fn retry_list(
1426+ cx: &Cx,
1427+ lang: Lang,
1428+ username: String,
1429+ csrf: &str,
1430+ rows: Vec<(ImportJob, Repo)>,
1431+) -> Result<impl View> {
14181432 let count = rows.len();
14191433 let empty = rows.is_empty();
14201434 Ok(view! {
@@ -1462,10 +1476,10 @@ async fn retry_list(lang: Lang, username: String, csrf: &str, rows: Vec<(ImportJ
14621476 async fn retry_page(cx: &Cx) -> Result<impl View> {
14631477 let viewer = require_user(cx).await?;
14641478 let lang = i18n::lang(cx, Some(&viewer.0));
1465- let state = app_context::<AppState>(cx);
1479+ let state = context::<AppState>(cx);
14661480 let rows = retry_candidates(state, &viewer.0).await?;
14671481 let csrf = viewer.1.csrf_token.clone();
1468- Ok(view! { cx =>
1482+ Ok(view! {
14691483 shell(title: g::t(lang, K::RetryFailedTitle), viewer: Some(&viewer),
14701484 retry_list(lang: lang, username: viewer.0.username.clone(), csrf: csrf.as_str(), rows: rows))
14711485 })
@@ -1485,7 +1499,7 @@ struct RetrySelectedForm {
14851499 #[route(POST "/import/retry")]
14861500 async fn retry_submit(cx: &Cx, Form(form): Form<RetrySelectedForm>) -> Result<SeeOther> {
14871501 let viewer = require_csrf(cx, &form.csrf).await?;
1488- let state = app_context::<AppState>(cx);
1502+ let state = context::<AppState>(cx);
14891503 let mut picked: Vec<(usize, &String)> = form
14901504 .extra
14911505 .iter()
crates/forge-web/src/pages/invites.rsmodified+3 -2
@@ -6,7 +6,7 @@ use forge_core::store::validate_email;
66 use forge_core::{AuditAction, Registration};
77 use serde::Deserialize;
88 use topcoat::Result;
9-use topcoat::context::{Cx, app_context};
9+use topcoat::context::{Cx, context};
1010 use topcoat::router::content::Form;
1111 use topcoat::router::error::forbidden;
1212 use topcoat::router::page;
@@ -31,6 +31,7 @@ struct InviteForm {
3131
3232 #[component]
3333 async fn invite_body(
34+ cx: &Cx,
3435 lang: Lang,
3536 csrf: &str,
3637 notice: Option<&'static str>,
@@ -78,7 +79,7 @@ async fn invites_submit(cx: &Cx, Form(form): Form<InviteForm>) -> Result<impl Vi
7879 if !check_csrf(&viewer.1, &form.csrf) {
7980 return Err(forbidden().into());
8081 }
81- let state = app_context::<AppState>(cx);
82+ let state = context::<AppState>(cx);
8283 let lang = i18n::lang(cx, Some(&viewer.0));
8384 let address = form.email.trim().to_owned();
8485 let mut notice = None;
crates/forge-web/src/pages/issue_meta.rsmodified+25 -19
@@ -9,7 +9,7 @@ use forge_core::User;
99 use forge_core::authz::{Action, authorize};
1010 use forge_core::issues::{Issue, Label};
1111 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};
12+use topcoat::context::{Cx, context};
1313 use topcoat::router::content::RawForm;
1414 use topcoat::router::error::{forbidden, not_found, see_other};
1515 use topcoat::router::{page, path_param};
@@ -85,7 +85,12 @@ pub(crate) fn refusal_message(e: forge_core::Error) -> Result<String> {
8585 /// Links between the issue-adjacent pages of a repo: Issues, Labels and Milestones. The one named
8686 /// by `active` is the current page.
8787 #[component]
88-pub(crate) async fn issue_subnav(lang: Lang, title: String, active: String) -> Result<impl View> {
88+pub(crate) async fn issue_subnav(
89+ cx: &Cx,
90+ lang: Lang,
91+ title: String,
92+ active: String,
93+) -> Result<impl View> {
8994 let issues = format!("/{title}/issues");
9095 let labels = format!("/{title}/labels");
9196 let milestones = format!("/{title}/milestones");
@@ -170,7 +175,7 @@ pub(crate) async fn item_from_path(
170175 let Some(n) = number.parse::<i64>().ok() else {
171176 return Err(not_found().into());
172177 };
173- let store = &app_context::<AppState>(cx).store;
178+ let store = &context::<AppState>(cx).store;
174179 let found = match kind {
175180 ItemKind::Issue => store.issue_by_number(&ctx.repo.id, n).await?,
176181 ItemKind::Pull => store
@@ -197,6 +202,7 @@ pub(crate) fn item_href(ctx: &RepoCtx, kind: ItemKind, number: i64) -> String {
197202 /// The error box with a link back to where the action came from, in the viewer's language.
198203 #[component]
199204 pub(crate) async fn action_error_at(
205+ cx: &Cx,
200206 lang: Lang,
201207 message: String,
202208 back: String,
@@ -224,19 +230,19 @@ async fn pull_labels_save(cx: &Cx, RawForm(raw): RawForm) -> Result<impl View> {
224230 }
225231
226232 async fn labels_save(cx: &Cx, kind: ItemKind, fields: Vec<(String, String)>) -> Result<impl View> {
227- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
228- let item = item_from_path(cx, &ctx, kind, path_param::<Number>(cx)).await?;
233+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
234+ let item = item_from_path(cx, &ctx, kind, number(cx)).await?;
229235 let user = triage_guard(cx, &ctx, &form_field(&fields, "csrf")).await?;
230236 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
231237 let ids = form_all(&fields, "label");
232238 let back = item_href(&ctx, kind, item.number);
233- let state = app_context::<AppState>(cx);
239+ let state = context::<AppState>(cx);
234240 let pull = matches!(kind, ItemKind::Pull);
235241 let before = item_labels(state, &item.id).await;
236242 let result = state.store.set_issue_labels(&item.id, &user.id, &ids).await;
237243 if let Err(e) = result {
238244 let message = refusal_message(e)?;
239- return Ok(view! { cx =>
245+ return Ok(view! {
240246 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),
241247 action_error_at(lang: lang, message: message, back: back))
242248 });
@@ -264,8 +270,8 @@ async fn assignees_save(
264270 kind: ItemKind,
265271 fields: Vec<(String, String)>,
266272 ) -> Result<impl View> {
267- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
268- let item = item_from_path(cx, &ctx, kind, path_param::<Number>(cx)).await?;
273+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
274+ let item = item_from_path(cx, &ctx, kind, number(cx)).await?;
269275 let user = triage_guard(cx, &ctx, &form_field(&fields, "csrf")).await?;
270276 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
271277 let usernames: Vec<String> = form_field(&fields, "assignees")
@@ -275,7 +281,7 @@ async fn assignees_save(
275281 .map(str::to_owned)
276282 .collect();
277283 let back = item_href(&ctx, kind, item.number);
278- let state = app_context::<AppState>(cx);
284+ let state = context::<AppState>(cx);
279285 let pull = matches!(kind, ItemKind::Pull);
280286 let before = assignee_names(state, &item.id).await;
281287 let result = state
@@ -284,7 +290,7 @@ async fn assignees_save(
284290 .await;
285291 if let Err(e) = result {
286292 let message = refusal_message(e)?;
287- return Ok(view! { cx =>
293+ return Ok(view! {
288294 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),
289295 action_error_at(lang: lang, message: message, back: back))
290296 });
@@ -335,14 +341,14 @@ async fn pull_lock_save(cx: &Cx, RawForm(raw): RawForm) -> Result<impl View> {
335341 }
336342
337343 async fn lock_save(cx: &Cx, kind: ItemKind, fields: Vec<(String, String)>) -> Result<impl View> {
338- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
339- let item = item_from_path(cx, &ctx, kind, path_param::<Number>(cx)).await?;
344+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
345+ let item = item_from_path(cx, &ctx, kind, number(cx)).await?;
340346 let user = triage_guard(cx, &ctx, &form_field(&fields, "csrf")).await?;
341347 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
342348 let locked = form_field(&fields, "locked") == "1";
343349 let reason = form_field(&fields, "reason");
344350 let back = item_href(&ctx, kind, item.number);
345- let state = app_context::<AppState>(cx);
351+ let state = context::<AppState>(cx);
346352 let result = state
347353 .store
348354 .set_issue_locked(&item.id, Some(&user.id), locked, Some(reason.as_str()))
@@ -351,7 +357,7 @@ async fn lock_save(cx: &Cx, kind: ItemKind, fields: Vec<(String, String)>) -> Re
351357 Ok(changed) => changed,
352358 Err(e) => {
353359 let message = refusal_message(e)?;
354- return Ok(view! { cx =>
360+ return Ok(view! {
355361 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),
356362 action_error_at(lang: lang, message: message, back: back))
357363 });
@@ -383,14 +389,14 @@ async fn milestone_save(
383389 kind: ItemKind,
384390 fields: Vec<(String, String)>,
385391 ) -> Result<impl View> {
386- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
387- let item = item_from_path(cx, &ctx, kind, path_param::<Number>(cx)).await?;
392+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
393+ let item = item_from_path(cx, &ctx, kind, number(cx)).await?;
388394 let user = triage_guard(cx, &ctx, &form_field(&fields, "csrf")).await?;
389395 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
390396 let milestone_id = form_field(&fields, "milestone_id");
391397 let milestone = (!milestone_id.is_empty()).then_some(milestone_id.as_str());
392398 let back = item_href(&ctx, kind, item.number);
393- let state = app_context::<AppState>(cx);
399+ let state = context::<AppState>(cx);
394400 let before = match item.milestone_id.as_deref() {
395401 Some(id) => milestone_title(state, &ctx.repo.id, id).await,
396402 None => None,
@@ -401,7 +407,7 @@ async fn milestone_save(
401407 .await;
402408 if let Err(e) = result {
403409 let message = refusal_message(e)?;
404- return Ok(view! { cx =>
410+ return Ok(view! {
405411 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),
406412 action_error_at(lang: lang, message: message, back: back))
407413 });
crates/forge-web/src/pages/issue_parts.rsmodified+42 -14
@@ -4,6 +4,7 @@
44 //! On a pull request the timeline also holds its submitted reviews, each with its threads.
55
66 use std::collections::HashSet;
7+use topcoat::context::Cx;
78
89 use forge_core::{Action, Comment, Issue, IssueEvent, IssueState, Session, StateReason, User};
910 use forge_core::{Reaction, ReactionSummary, ReactionTarget};
@@ -25,13 +26,13 @@ use crate::pages::repo_ctx::RepoCtx;
2526 use crate::pages::tree::link_context;
2627 use crate::render::markdown::{LinkContext, render_markdown};
2728 use crate::state::AppState;
29+use crate::views::parts::{confirm_act, post_act, reveal};
2830 use crate::views::review_thread::{ThreadCtx, review_thread_in};
2931 use crate::views::user_facing_message;
3032 use crate::views::{
31- alert, avatar_url, avatar_url_unknown, display_name, iso_time, now_unix, relative_time, repo_href, short_oid,
32- user_href, user_link,
33+ alert, avatar_url, avatar_url_unknown, display_name, iso_time, now_unix, relative_time,
34+ repo_href, short_oid, user_href, user_link,
3335 };
34-use crate::views::parts::{confirm_act, post_act, reveal};
3536 use crate::webhooks::emit::{Sender, emit_comment, emit_item_action};
3637
3738 /// Which kind of item a page shows. It decides the URL segment of the item's own links and which
@@ -433,7 +434,7 @@ fn event_line(
433434 }
434435
435436 #[component]
436-pub(crate) async fn comment_item(lang: Lang, item: CommentView) -> Result<impl View> {
437+pub(crate) async fn comment_item(cx: &Cx, lang: Lang, item: CommentView) -> Result<impl View> {
437438 let CommentView {
438439 anchor,
439440 author,
@@ -499,7 +500,7 @@ pub(crate) async fn comment_item(lang: Lang, item: CommentView) -> Result<impl V
499500
500501 /// The reaction row under an item or comment: the buttons, then the picker when the viewer may react.
501502 #[component]
502-pub(crate) async fn reaction_row(lang: Lang, bar: ReactionBar) -> Result<impl View> {
503+pub(crate) async fn reaction_row(cx: &Cx, lang: Lang, bar: ReactionBar) -> Result<impl View> {
503504 let ReactionBar {
504505 chips,
505506 picker,
@@ -519,7 +520,11 @@ pub(crate) async fn reaction_row(lang: Lang, bar: ReactionBar) -> Result<impl Vi
519520
520521 /// The React tool: a word that opens the reaction options in place.
521522 #[component]
522-pub(crate) async fn reaction_picker(lang: Lang, picker: Vec<ReactionButton>) -> Result<impl View> {
523+pub(crate) async fn reaction_picker(
524+ cx: &Cx,
525+ lang: Lang,
526+ picker: Vec<ReactionButton>,
527+) -> Result<impl View> {
523528 Ok(view! {
524529 <details class="reaction-picker">
525530 <summary class="act">(g::t(lang, K::AddReaction))</summary>
@@ -535,7 +540,7 @@ pub(crate) async fn reaction_picker(lang: Lang, picker: Vec<ReactionButton>) ->
535540 /// One reaction button. Enabled buttons are POST forms that toggle the viewer's reaction; the
536541 /// others only show the emoji and count.
537542 #[component]
538-pub(crate) async fn reaction_button(button: ReactionButton) -> Result<impl View> {
543+pub(crate) async fn reaction_button(cx: &Cx, button: ReactionButton) -> Result<impl View> {
539544 let ReactionButton {
540545 action,
541546 csrf,
@@ -581,7 +586,7 @@ pub(crate) async fn reaction_button(button: ReactionButton) -> Result<impl View>
581586 }
582587
583588 #[component]
584-pub(crate) async fn event_item(line: EventLine) -> Result<impl View> {
589+pub(crate) async fn event_item(cx: &Cx, line: EventLine) -> Result<impl View> {
585590 let EventLine {
586591 actor,
587592 when,
@@ -617,8 +622,11 @@ pub(crate) async fn event_item(line: EventLine) -> Result<impl View> {
617622 /// Consecutive events by one actor, one line: the actor, each event's words joined with " · ", then
618623 /// the time of the last one.
619624 #[component]
620-pub(crate) async fn event_run(lines: Vec<EventLine>) -> Result<impl View> {
621- let actor = lines.first().map(|line| line.actor.clone()).unwrap_or_default();
625+pub(crate) async fn event_run(cx: &Cx, lines: Vec<EventLine>) -> Result<impl View> {
626+ let actor = lines
627+ .first()
628+ .map(|line| line.actor.clone())
629+ .unwrap_or_default();
622630 let when = lines.last().map(|line| line.when.clone());
623631 Ok(view! {
624632 <div class="thread-event">
@@ -663,7 +671,7 @@ fn dismissed_verb(lang: Lang, from: Option<ReviewState>) -> &'static str {
663671
664672 /// One submitted review: the reviewer, the verb, the dismissal reason, the body, then its threads.
665673 #[component]
666-pub(crate) async fn review_item(lang: Lang, review: ReviewView) -> Result<impl View> {
674+pub(crate) async fn review_item(cx: &Cx, lang: Lang, review: ReviewView) -> Result<impl View> {
667675 let ReviewView {
668676 anchor,
669677 author,
@@ -705,7 +713,7 @@ pub(crate) async fn review_item(lang: Lang, review: ReviewView) -> Result<impl V
705713 }
706714
707715 #[component]
708-pub(crate) async fn timeline_entry(lang: Lang, entry: Entry) -> Result<impl View> {
716+pub(crate) async fn timeline_entry(cx: &Cx, lang: Lang, entry: Entry) -> Result<impl View> {
709717 Ok(view! {
710718 match entry {
711719 Entry::Comment(item) => comment_item(lang: lang, item: item),
@@ -718,7 +726,11 @@ pub(crate) async fn timeline_entry(lang: Lang, entry: Entry) -> Result<impl View
718726
719727 /// The body followed by every timeline entry.
720728 #[component]
721-pub(crate) async fn discussion_timeline(lang: Lang, discussion: Discussion) -> Result<impl View> {
729+pub(crate) async fn discussion_timeline(
730+ cx: &Cx,
731+ lang: Lang,
732+ discussion: Discussion,
733+) -> Result<impl View> {
722734 let Discussion { body, entries, .. } = discussion;
723735 Ok(view! {
724736 <div class="issue-timeline">
@@ -1023,7 +1035,15 @@ pub(crate) fn reaction_bar_for(
10231035 .collect();
10241036 let picker = Reaction::ALL
10251037 .into_iter()
1026- .map(|r| button(r.name(), r.emoji(), 0, reaction_label(lang, r).to_owned(), false))
1038+ .map(|r| {
1039+ button(
1040+ r.name(),
1041+ r.emoji(),
1042+ 0,
1043+ reaction_label(lang, r).to_owned(),
1044+ false,
1045+ )
1046+ })
10271047 .collect();
10281048 Some(ReactionBar {
10291049 chips,
@@ -1219,6 +1239,7 @@ pub(crate) async fn load_sidebar(state: &AppState, repo_id: &str, item: &Issue)
12191239
12201240 #[component]
12211241 pub(crate) async fn labels_box(
1242+ cx: &Cx,
12221243 lang: Lang,
12231244 write: bool,
12241245 action: String,
@@ -1266,6 +1287,7 @@ pub(crate) async fn labels_box(
12661287
12671288 #[component]
12681289 pub(crate) async fn assignees_box(
1290+ cx: &Cx,
12691291 lang: Lang,
12701292 write: bool,
12711293 action: String,
@@ -1312,6 +1334,7 @@ pub(crate) async fn assignees_box(
13121334
13131335 #[component]
13141336 pub(crate) async fn milestone_box(
1337+ cx: &Cx,
13151338 lang: Lang,
13161339 write: bool,
13171340 action: String,
@@ -1358,6 +1381,7 @@ pub(crate) async fn milestone_box(
13581381 /// triage holders. Locking is one of the tools at the foot of the sidebar (`item_tools`).
13591382 #[component]
13601383 pub(crate) async fn lock_box(
1384+ cx: &Cx,
13611385 lang: Lang,
13621386 write: bool,
13631387 action: String,
@@ -1395,6 +1419,7 @@ pub(crate) async fn lock_box(
13951419 /// reason. `pin` is the pin action when the issue is not pinned and the viewer may pin it.
13961420 #[component]
13971421 pub(crate) async fn item_tools(
1422+ cx: &Cx,
13981423 lang: Lang,
13991424 pin: Option<String>,
14001425 lock: Option<String>,
@@ -1439,6 +1464,7 @@ pub(crate) async fn item_tools(
14391464 /// `(pinned, action)` for an issue; the pinned row sits in the page (`pin_box`).
14401465 #[component]
14411466 pub(crate) async fn item_sidebar(
1467+ cx: &Cx,
14421468 lang: Lang,
14431469 write: bool,
14441470 base: String,
@@ -1492,6 +1518,7 @@ pub(crate) const COMMENT_FORM: &str = "item-comment";
14921518 /// and is given only when the viewer may close the item.
14931519 #[component]
14941520 pub(crate) async fn item_head_tools(
1521+ cx: &Cx,
14951522 lang: Lang,
14961523 close: Option<(bool, String)>,
14971524 notify: Option<NotifyBox>,
@@ -1523,6 +1550,7 @@ pub(crate) async fn item_head_tools(
15231550 /// readers only.
15241551 #[component]
15251552 pub(crate) async fn comment_form(
1553+ cx: &Cx,
15261554 lang: Lang,
15271555 action: String,
15281556 csrf: String,
crates/forge-web/src/pages/issue_pin.rsmodified+6 -5
@@ -6,7 +6,7 @@
66 use serde::Deserialize;
77 use serde_json::Value as Json;
88 use topcoat::Result;
9-use topcoat::context::{Cx, app_context};
9+use topcoat::context::{Cx, context};
1010 use topcoat::router::content::Form;
1111 use topcoat::router::error::{bad_request, see_other};
1212 use topcoat::router::{page, path_param};
@@ -37,8 +37,8 @@ struct PinForm {
3737
3838 #[page(POST "/{owner}/{repo}/issues/{number}/pin")]
3939 async fn issue_pin_save(cx: &Cx, Form(form): Form<PinForm>) -> Result<impl View> {
40- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
41- let issue = item_from_path(cx, &ctx, ItemKind::Issue, path_param::<Number>(cx)).await?;
40+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
41+ let issue = item_from_path(cx, &ctx, ItemKind::Issue, number(cx)).await?;
4242 let user = triage_guard(cx, &ctx, &form.csrf).await?;
4343 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
4444 let pin = match form.pinned.as_str() {
@@ -47,7 +47,7 @@ async fn issue_pin_save(cx: &Cx, Form(form): Form<PinForm>) -> Result<impl View>
4747 _ => return Err(bad_request("pinned must be 1 or 0").into()),
4848 };
4949 let back = item_href(&ctx, ItemKind::Issue, issue.number);
50- let state = app_context::<AppState>(cx);
50+ let state = context::<AppState>(cx);
5151 let result = if pin {
5252 state.store.pin_issue(&ctx.repo.id, &issue.id).await
5353 } else {
@@ -66,7 +66,7 @@ async fn issue_pin_save(cx: &Cx, Form(form): Form<PinForm>) -> Result<impl View>
6666 }
6767 Err(e) => {
6868 let message = refusal_message(e)?;
69- return Ok(view! { cx =>
69+ return Ok(view! {
7070 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),
7171 action_error_at(lang: lang, message: message, back: back))
7272 });
@@ -79,6 +79,7 @@ async fn issue_pin_save(cx: &Cx, Form(form): Form<PinForm>) -> Result<impl View>
7979 /// Pinning is a tool at the foot of the sidebar (`item_tools`).
8080 #[component]
8181 pub(crate) async fn pin_box(
82+ cx: &Cx,
8283 lang: Lang,
8384 write: bool,
8485 pinned: bool,
crates/forge-web/src/pages/issue_pin_tests.rsmodified+4 -1
@@ -328,7 +328,10 @@ async fn pin_controls_and_cards_show_for_the_right_viewers() {
328328 .contains(&format!("/tahinli/forge/issues/{number}\"")),
329329 "pinned card links the pinned issue"
330330 );
331- let card_at = reply.body.find("aria-label=\"Pinned issues\"").expect("card");
331+ let card_at = reply
332+ .body
333+ .find("aria-label=\"Pinned issues\"")
334+ .expect("card");
332335 let list_at = reply.body.find("class=\"line issue-row\"").expect("list");
333336 assert!(card_at < list_at, "pinned cards sit above the list");
334337
crates/forge-web/src/pages/issue_view.rsmodified+31 -31
@@ -9,7 +9,7 @@ use forge_core::{Comment, Issue, IssueState, StateReason};
99 use forge_core::{validate_body, validate_title};
1010 use serde::Deserialize;
1111 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};
12+use topcoat::context::{Cx, context};
1313 use topcoat::router::content::Form;
1414 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
1515 use topcoat::router::{page, path_param, route};
@@ -49,7 +49,7 @@ async fn issue_page(
4949 error: Option<String>,
5050 ) -> Result<impl View> {
5151 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
52- let state = app_context::<AppState>(cx);
52+ let state = context::<AppState>(cx);
5353 let owner = ctx.repo.owner_name.clone();
5454 let name = ctx.repo.name.clone();
5555 let number = issue.number;
@@ -104,7 +104,7 @@ async fn issue_page(
104104 let live_href = item_live_url(&owner, &name, number);
105105
106106 let header = ctx.head(state, "issues").await?;
107- Ok(view! { cx =>
107+ Ok(view! {
108108 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(), extra_stylesheet: Some(labels_href.as_str()),
109109 repo_head(head: header, title: Some(issue.title.clone()), sub: sub,
110110 <span class="num">(number_label.as_str())</span>
@@ -134,9 +134,9 @@ async fn issue_page(
134134
135135 #[page("/{owner}/{repo}/issues/{number}")]
136136 async fn issue_show(cx: &Cx) -> Result<impl View> {
137- let number = parse_number(path_param::<Number>(cx))?;
138- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
139- let state = app_context::<AppState>(cx);
137+ let number = parse_number(number(cx))?;
138+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
139+ let state = context::<AppState>(cx);
140140 let Some(issue) = state.store.issue_by_number(&ctx.repo.id, number).await? else {
141141 if state
142142 .store
@@ -161,11 +161,11 @@ async fn issue_show(cx: &Cx) -> Result<impl View> {
161161 /// reopen; without that the request is 403 and nothing is written.
162162 #[page(POST "/{owner}/{repo}/issues/{number}/comment")]
163163 async fn issue_comment(cx: &Cx, Form(form): Form<CommentForm>) -> Result<impl View> {
164- let number = parse_number(path_param::<Number>(cx))?;
165- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
164+ let number = parse_number(number(cx))?;
165+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
166166 let (user, session) = require_user(cx).await?;
167167 check_write(&ctx, &session, &form.csrf)?;
168- let state = app_context::<AppState>(cx);
168+ let state = context::<AppState>(cx);
169169 let issue = issue_for(state, &ctx, number).await?;
170170 let lang = i18n::lang(cx, Some(&user));
171171 match post_comment(lang, state, &ctx, &user, &issue, false, &form).await? {
@@ -205,7 +205,7 @@ async fn edit_item_page(
205205 error: Option<String>,
206206 ) -> Result<impl View> {
207207 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
208- let state = app_context::<AppState>(cx);
208+ let state = context::<AppState>(cx);
209209 let owner = ctx.repo.owner_name.clone();
210210 let name = ctx.repo.name.clone();
211211 let csrf = csrf_of(&ctx);
@@ -215,7 +215,7 @@ async fn edit_item_page(
215215 let page_title = g::edit_title(lang, number, &format!("{owner}/{name}"));
216216 let heading = g::edit_heading(lang, kind == ItemKind::Pull, number);
217217 let header = ctx.head(state, kind_tab(kind)).await?;
218- Ok(view! { cx =>
218+ Ok(view! {
219219 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(),
220220 repo_head(head: header, title: Some(heading))
221221 <div class="sheet fit">
@@ -252,10 +252,10 @@ fn kind_tab(kind: ItemKind) -> &'static str {
252252
253253 /// Shows the edit form. Only the author or Triage; anyone else is 403.
254254 async fn item_edit_form(cx: &Cx, kind: ItemKind) -> Result<impl View> {
255- let number = parse_number(path_param::<Number>(cx))?;
256- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
255+ let number = parse_number(number(cx))?;
256+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
257257 require_user(cx).await?;
258- let item = item_for(app_context::<AppState>(cx), &ctx, kind, number).await?;
258+ let item = item_for(context::<AppState>(cx), &ctx, kind, number).await?;
259259 if !may_change(&ctx, &item.author_id) {
260260 return Err(forbidden().into());
261261 }
@@ -264,11 +264,11 @@ async fn item_edit_form(cx: &Cx, kind: ItemKind) -> Result<impl View> {
264264
265265 /// Saves the title and body. Only the author or Triage; the store records the edit history.
266266 async fn item_edit_save(cx: &Cx, kind: ItemKind, form: IssueForm) -> Result<impl View> {
267- let number = parse_number(path_param::<Number>(cx))?;
268- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
267+ let number = parse_number(number(cx))?;
268+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
269269 let (user, session) = require_user(cx).await?;
270270 check_write(&ctx, &session, &form.csrf)?;
271- let state = app_context::<AppState>(cx);
271+ let state = context::<AppState>(cx);
272272 let item = item_for(state, &ctx, kind, number).await?;
273273 if !may_change(&ctx, &item.author_id) {
274274 return Err(forbidden().into());
@@ -313,7 +313,7 @@ async fn edit_comment_page(
313313 error: Option<String>,
314314 ) -> Result<impl View> {
315315 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
316- let state = app_context::<AppState>(cx);
316+ let state = context::<AppState>(cx);
317317 let owner = ctx.repo.owner_name.clone();
318318 let name = ctx.repo.name.clone();
319319 let csrf = csrf_of(&ctx);
@@ -330,7 +330,7 @@ async fn edit_comment_page(
330330 );
331331 let page_title = g::edit_comment_title(lang, number, &format!("{owner}/{name}"));
332332 let header = ctx.head(state, kind_tab(kind)).await?;
333- Ok(view! { cx =>
333+ Ok(view! {
334334 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(),
335335 repo_head(head: header, title: Some(g::t(lang, K::EditComment).to_owned()))
336336 <div class="sheet fit">
@@ -355,12 +355,12 @@ async fn edit_comment_page(
355355
356356 /// Shows the edit form for a comment. Its author or Triage; anyone else is 403.
357357 async fn item_comment_edit_form(cx: &Cx, kind: ItemKind) -> Result<impl View> {
358- let number = parse_number(path_param::<Number>(cx))?;
359- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
358+ let number = parse_number(number(cx))?;
359+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
360360 require_user(cx).await?;
361- let state = app_context::<AppState>(cx);
361+ let state = context::<AppState>(cx);
362362 let item = item_for(state, &ctx, kind, number).await?;
363- let comment = comment_for(state, &item, path_param::<CommentId>(cx)).await?;
363+ let comment = comment_for(state, &item, comment_id(cx)).await?;
364364 if !may_change(&ctx, &comment.author_id) {
365365 return Err(forbidden().into());
366366 }
@@ -378,13 +378,13 @@ async fn item_comment_edit_form(cx: &Cx, kind: ItemKind) -> Result<impl View> {
378378
379379 /// Saves an edited comment. Its author or Triage; the store records the previous body.
380380 async fn item_comment_edit_save(cx: &Cx, kind: ItemKind, form: CommentForm) -> Result<impl View> {
381- let number = parse_number(path_param::<Number>(cx))?;
382- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
381+ let number = parse_number(number(cx))?;
382+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
383383 let (user, session) = require_user(cx).await?;
384384 check_write(&ctx, &session, &form.csrf)?;
385- let state = app_context::<AppState>(cx);
385+ let state = context::<AppState>(cx);
386386 let item = item_for(state, &ctx, kind, number).await?;
387- let comment = comment_for(state, &item, path_param::<CommentId>(cx)).await?;
387+ let comment = comment_for(state, &item, comment_id(cx)).await?;
388388 if !may_change(&ctx, &comment.author_id) {
389389 return Err(forbidden().into());
390390 }
@@ -446,13 +446,13 @@ struct CsrfForm {
446446
447447 /// Deletes one comment: its author or Triage. The item's comment count goes down.
448448 async fn item_comment_delete(cx: &Cx, kind: ItemKind, form: CsrfForm) -> Result<SeeOther> {
449- let number = parse_number(path_param::<Number>(cx))?;
450- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
449+ let number = parse_number(number(cx))?;
450+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
451451 let (user, session) = require_user(cx).await?;
452452 check_write(&ctx, &session, &form.csrf)?;
453- let state = app_context::<AppState>(cx);
453+ let state = context::<AppState>(cx);
454454 let item = item_for(state, &ctx, kind, number).await?;
455- let comment = comment_for(state, &item, path_param::<CommentId>(cx)).await?;
455+ let comment = comment_for(state, &item, comment_id(cx)).await?;
456456 if !may_change(&ctx, &comment.author_id) {
457457 return Err(forbidden().into());
458458 }
crates/forge-web/src/pages/issues_list.rsmodified+17 -11
@@ -9,7 +9,7 @@ use forge_core::{
99 IssueFilter, IssueListItem, IssueSort, IssueState, validate_body, validate_title,
1010 };
1111 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};
12+use topcoat::context::{Cx, context};
1313 use topcoat::router::content::RawForm;
1414 use topcoat::router::error::{forbidden, see_other};
1515 use topcoat::router::{StatusCode, page, path_param, query_params};
@@ -439,11 +439,11 @@ fn list_sub(lang: Lang, open: u64, closed: u64, assigned: Option<u64>) -> Vec<Su
439439
440440 #[page("/{owner}/{repo}/issues")]
441441 async fn issues_list_page(cx: &Cx) -> Result<impl View> {
442- let owner = path_param::<Owner>(cx);
443- let name = path_param::<Repo>(cx);
442+ let owner = owner(cx);
443+ let name = repo(cx);
444444 let query = query_params::<ListQuery>(cx)?;
445445 let ctx = load_repo(cx, owner, name).await?;
446- let state = app_context::<AppState>(cx);
446+ let state = context::<AppState>(cx);
447447 let sel = Selection::parse(query);
448448 let search_value = sel.search_text();
449449 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
@@ -499,7 +499,12 @@ async fn issues_list_page(cx: &Cx) -> Result<impl View> {
499499 ),
500500 None => (0, 0),
501501 };
502- let sub = list_sub(lang, open_count, closed_count, me.as_ref().map(|_| assigned_count));
502+ let sub = list_sub(
503+ lang,
504+ open_count,
505+ closed_count,
506+ me.as_ref().map(|_| assigned_count),
507+ );
503508 let clear_href = list_href(&base, &[("state", sel.state)]);
504509 let has_filters = sel.has_filters();
505510
@@ -745,6 +750,7 @@ fn check_draft(title: &str, body: &str) -> forge_core::Result<std::result::Resul
745750 /// chooser (`chooser` is `Some`) or the form.
746751 #[component]
747752 async fn new_issue_body(
753+ cx: &Cx,
748754 lang: Lang,
749755 head: RepoHead,
750756 csrf: String,
@@ -814,8 +820,8 @@ async fn new_issue_body(
814820
815821 #[page("/{owner}/{repo}/issues/new")]
816822 async fn new_issue_page(cx: &Cx) -> Result<impl View> {
817- let owner = path_param::<Owner>(cx);
818- let name = path_param::<Repo>(cx);
823+ let owner = owner(cx);
824+ let name = repo(cx);
819825 let query = query_params::<NewIssueQuery>(cx)?;
820826 let ctx = load_repo(cx, owner, name).await?;
821827 let viewer = require_user(cx).await?;
@@ -823,7 +829,7 @@ async fn new_issue_page(cx: &Cx) -> Result<impl View> {
823829 if ctx.repo.archived {
824830 return Err(forbidden().into());
825831 }
826- let state = app_context::<AppState>(cx);
832+ let state = context::<AppState>(cx);
827833 let header = ctx.head(state, "issues").await?;
828834 let title = g::new_issue_title(lang, &format!("{}/{}", ctx.repo.owner_name, ctx.repo.name));
829835 let csrf = viewer.1.csrf_token.clone();
@@ -871,8 +877,8 @@ async fn new_issue_page(cx: &Cx) -> Result<impl View> {
871877
872878 #[page(POST "/{owner}/{repo}/issues/new")]
873879 async fn new_issue_submit(cx: &Cx, RawForm(raw): RawForm) -> Result<impl View> {
874- let owner = path_param::<Owner>(cx);
875- let name = path_param::<Repo>(cx);
880+ let owner = owner(cx);
881+ let name = repo(cx);
876882 let ctx = load_repo(cx, owner, name).await?;
877883 let fields = form_pairs(&raw[..]);
878884 let viewer = require_csrf(cx, &form_field(&fields, "csrf")).await?;
@@ -880,7 +886,7 @@ async fn new_issue_submit(cx: &Cx, RawForm(raw): RawForm) -> Result<impl View> {
880886 if ctx.repo.archived {
881887 return Err(forbidden().into());
882888 }
883- let state = app_context::<AppState>(cx);
889+ let state = context::<AppState>(cx);
884890 let typed_title = form_field(&fields, "title");
885891 let typed_body = form_field(&fields, "body");
886892 let picked = form_all(&fields, "label");
crates/forge-web/src/pages/issues_live.rsmodified+6 -6
@@ -6,7 +6,7 @@
66 //! repo, or an issue that is not there, gets the same 404 as the page.
77
88 use topcoat::Result;
9-use topcoat::context::{Cx, app_context};
9+use topcoat::context::{Cx, context};
1010 use topcoat::router::error::not_found;
1111 use topcoat::router::response::Response;
1212 use topcoat::router::{path_param, route};
@@ -33,17 +33,17 @@ pub fn item_live_url(owner: &str, repo: &str, number: i64) -> String {
3333 /// The change stream of the issue list, labels and milestones pages.
3434 #[route(GET "/{owner}/{repo}/issues/live")]
3535 async fn issues_live(cx: &Cx) -> Result<Response> {
36- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
37- let state = app_context::<AppState>(cx);
36+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
37+ let state = context::<AppState>(cx);
3838 stream_wakes(cx, &state.live, &[Topic::RepoIssues(ctx.repo.id.clone())])
3939 }
4040
4141 /// The change stream of one issue page.
4242 #[route(GET "/{owner}/{repo}/issues/{number}/live")]
4343 async fn issue_live(cx: &Cx) -> Result<Response> {
44- let number = parse_number(path_param::<Number>(cx))?;
45- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
46- let state = app_context::<AppState>(cx);
44+ let number = parse_number(number(cx))?;
45+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
46+ let state = context::<AppState>(cx);
4747 let Some(issue) = state.store.issue_by_number(&ctx.repo.id, number).await? else {
4848 return Err(not_found().into());
4949 };
crates/forge-web/src/pages/labels_css.rsmodified+4 -4
@@ -13,7 +13,7 @@ use http::header::{
1313 };
1414 use sha2::{Digest, Sha256};
1515 use topcoat::Result;
16-use topcoat::context::{Cx, app_context};
16+use topcoat::context::{Cx, context};
1717 use topcoat::router::request::headers;
1818 use topcoat::router::{path_param, route};
1919
@@ -78,14 +78,14 @@ fn etag_matches(if_none_match: &str, etag: &str) -> bool {
7878
7979 #[route(GET "/{owner}/{repo}/labels.css")]
8080 async fn labels_css(cx: &Cx) -> Result<(StatusCode, HeaderMap, String)> {
81- let owner = path_param::<Owner>(cx);
82- let name = path_param::<Repo>(cx);
81+ let owner = owner(cx);
82+ let name = repo(cx);
8383 let ctx = load_repo(cx, owner, name).await?;
8484 let if_none_match = headers(cx)
8585 .get(IF_NONE_MATCH)
8686 .and_then(|v| v.to_str().ok())
8787 .map(str::to_owned);
88- let state = app_context::<AppState>(cx);
88+ let state = context::<AppState>(cx);
8989
9090 let labels = state.store.list_labels(&ctx.repo.id).await?;
9191 let css = label_css(&labels);
crates/forge-web/src/pages/labels_page.rsmodified+24 -31
@@ -6,7 +6,7 @@ use std::collections::HashMap;
66
77 use serde::Deserialize;
88 use topcoat::Result;
9-use topcoat::context::{Cx, app_context};
9+use topcoat::context::{Cx, context};
1010 use topcoat::router::content::Form;
1111 use topcoat::router::error::see_other;
1212 use topcoat::router::{page, path_param, query_params};
@@ -80,6 +80,7 @@ fn labels_href(title: &str) -> String {
8080 /// The header, the label list and, for triage holders, the forms.
8181 #[component]
8282 async fn labels_body(
83+ cx: &Cx,
8384 lang: Lang,
8485 frame: RepoFrame,
8586 rows: Vec<LabelRow>,
@@ -184,19 +185,19 @@ async fn labels_body(
184185 /// Gets the labels page. Hidden repos are 404 (checked in `load_repo`).
185186 #[page("/{owner}/{repo}/labels")]
186187 async fn labels_page(cx: &Cx) -> Result<impl View> {
187- let owner = path_param::<Owner>(cx);
188- let name = path_param::<Repo>(cx);
188+ let owner = owner(cx);
189+ let name = repo(cx);
189190 let query = query_params::<LabelsQuery>(cx)?;
190191 let ctx = load_repo(cx, owner, name).await?;
191192 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
192- let store = &app_context::<AppState>(cx).store;
193+ let store = &context::<AppState>(cx).store;
193194 let labels = store.list_labels(&ctx.repo.id).await?;
194195 let counts: HashMap<String, i64> = store
195196 .label_open_counts(&ctx.repo.id)
196197 .await?
197198 .into_iter()
198199 .collect();
199- let frame = RepoFrame::new(&ctx, app_context::<AppState>(cx), "issues").await?;
200+ let frame = RepoFrame::new(&ctx, context::<AppState>(cx), "issues").await?;
200201 let title = frame.title.clone();
201202 let all: Vec<LabelRow> = labels
202203 .into_iter()
@@ -243,21 +244,19 @@ async fn labels_page(cx: &Cx) -> Result<impl View> {
243244 /// Creates a label. A duplicate name is shown on the error page.
244245 #[page(POST "/{owner}/{repo}/labels")]
245246 async fn label_create(cx: &Cx, Form(form): Form<LabelForm>) -> Result<impl View> {
246- let owner = path_param::<Owner>(cx);
247- let name = path_param::<Repo>(cx);
247+ let owner = owner(cx);
248+ let name = repo(cx);
248249 let ctx = load_repo(cx, owner, name).await?;
249250 triage_guard(cx, &ctx, &form.csrf).await?;
250251 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
251252 let back = labels_href(&format!("{}/{}", ctx.repo.owner_name, ctx.repo.name));
252- let result = app_context::<AppState>(cx)
253+ let result = context::<AppState>(cx)
253254 .store
254255 .create_label(&ctx.repo.id, &form.name, &form.color, &form.description)
255256 .await;
256257 match result {
257258 Ok(_) => {
258- app_context::<AppState>(cx)
259- .live
260- .bump_repo_issues(&ctx.repo.id);
259+ context::<AppState>(cx).live.bump_repo_issues(&ctx.repo.id);
261260 Err(see_other(back).into())
262261 }
263262 Err(e) => {
@@ -273,22 +272,20 @@ async fn label_create(cx: &Cx, Form(form): Form<LabelForm>) -> Result<impl View>
273272 /// Updates a label's name, color and description.
274273 #[page(POST "/{owner}/{repo}/labels/{label_id}")]
275274 async fn label_update(cx: &Cx, Form(form): Form<LabelForm>) -> Result<impl View> {
276- let owner = path_param::<Owner>(cx);
277- let name = path_param::<Repo>(cx);
278- let id = path_param::<LabelId>(cx);
275+ let owner = owner(cx);
276+ let name = repo(cx);
277+ let id = label_id(cx);
279278 let ctx = load_repo(cx, owner, name).await?;
280279 triage_guard(cx, &ctx, &form.csrf).await?;
281280 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
282281 let back = labels_href(&format!("{}/{}", ctx.repo.owner_name, ctx.repo.name));
283- let result = app_context::<AppState>(cx)
282+ let result = context::<AppState>(cx)
284283 .store
285284 .update_label(&ctx.repo.id, id, &form.name, &form.color, &form.description)
286285 .await;
287286 match result {
288287 Ok(()) => {
289- app_context::<AppState>(cx)
290- .live
291- .bump_repo_issues(&ctx.repo.id);
288+ context::<AppState>(cx).live.bump_repo_issues(&ctx.repo.id);
292289 Err(see_other(back).into())
293290 }
294291 Err(e) => {
@@ -305,21 +302,19 @@ async fn label_update(cx: &Cx, Form(form): Form<LabelForm>) -> Result<impl View>
305302 /// exist are skipped, so a repeated submit adds nothing.
306303 #[page(POST "/{owner}/{repo}/labels/defaults")]
307304 async fn label_defaults(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<impl View> {
308- let owner = path_param::<Owner>(cx);
309- let name = path_param::<Repo>(cx);
305+ let owner = owner(cx);
306+ let name = repo(cx);
310307 let ctx = load_repo(cx, owner, name).await?;
311308 triage_guard(cx, &ctx, &form.csrf).await?;
312309 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
313310 let back = labels_href(&format!("{}/{}", ctx.repo.owner_name, ctx.repo.name));
314- let result = app_context::<AppState>(cx)
311+ let result = context::<AppState>(cx)
315312 .store
316313 .create_default_labels(&ctx.repo.id)
317314 .await;
318315 match result {
319316 Ok(_) => {
320- app_context::<AppState>(cx)
321- .live
322- .bump_repo_issues(&ctx.repo.id);
317+ context::<AppState>(cx).live.bump_repo_issues(&ctx.repo.id);
323318 Err(see_other(back).into())
324319 }
325320 Err(e) => {
@@ -335,22 +330,20 @@ async fn label_defaults(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<impl View
335330 /// Deletes a label and its links to issues.
336331 #[page(POST "/{owner}/{repo}/labels/{label_id}/delete")]
337332 async fn label_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<impl View> {
338- let owner = path_param::<Owner>(cx);
339- let name = path_param::<Repo>(cx);
340- let id = path_param::<LabelId>(cx);
333+ let owner = owner(cx);
334+ let name = repo(cx);
335+ let id = label_id(cx);
341336 let ctx = load_repo(cx, owner, name).await?;
342337 triage_guard(cx, &ctx, &form.csrf).await?;
343338 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
344339 let back = labels_href(&format!("{}/{}", ctx.repo.owner_name, ctx.repo.name));
345- let result = app_context::<AppState>(cx)
340+ let result = context::<AppState>(cx)
346341 .store
347342 .delete_label(&ctx.repo.id, id)
348343 .await;
349344 match result {
350345 Ok(()) => {
351- app_context::<AppState>(cx)
352- .live
353- .bump_repo_issues(&ctx.repo.id);
346+ context::<AppState>(cx).live.bump_repo_issues(&ctx.repo.id);
354347 Err(see_other(back).into())
355348 }
356349 Err(e) => {
crates/forge-web/src/pages/login.rsmodified+15 -8
@@ -8,7 +8,7 @@ use http::header::{HeaderValue, RETRY_AFTER};
88 use serde::Deserialize;
99 use serde_json::json;
1010 use topcoat::Result;
11-use topcoat::context::{Cx, app_context};
11+use topcoat::context::{Cx, context};
1212 use topcoat::router::content::Form;
1313 use topcoat::router::error::{SeeOther, forbidden, see_other};
1414 use topcoat::router::{HeaderMap, StatusCode, page, query_params, route};
@@ -71,6 +71,7 @@ struct TwoFactorForm {
7171
7272 #[component]
7373 async fn login_form(
74+ cx: &Cx,
7475 lang: Lang,
7576 next: &str,
7677 username: &str,
@@ -120,8 +121,9 @@ async fn login_page(cx: &Cx) -> Result<impl View> {
120121 let next = safe_next(next.as_deref()).to_owned();
121122 let precsrf = pre_csrf_token(cx);
122123 let lang = i18n::lang(cx, None);
123- let passkeys = passkeys_available(app_context::<AppState>(cx));
124- let can_register = app_context::<AppState>(cx).live().registration == forge_core::Registration::Open;
124+ let passkeys = passkeys_available(context::<AppState>(cx));
125+ let can_register =
126+ context::<AppState>(cx).live().registration == forge_core::Registration::Open;
125127 Ok(view! {
126128 shell(title: t(lang, Key::LogIn), viewer: None, login_form(lang: lang, next: next.as_str(), username: "", precsrf: precsrf.as_str(), error: None, passkeys: passkeys, can_register: can_register))
127129 })
@@ -133,7 +135,7 @@ async fn login_submit(cx: &Cx, Form(form): Form<LoginForm>) -> Result<impl View>
133135 if !check_pre_csrf(cx, &form.precsrf) {
134136 return Err(forbidden().into());
135137 }
136- let state = app_context::<AppState>(cx);
138+ let state = context::<AppState>(cx);
137139 let lang = i18n::lang(cx, None);
138140 let limiter = &state.throttle;
139141 let now = Instant::now();
@@ -277,7 +279,12 @@ async fn login_submit(cx: &Cx, Form(form): Form<LoginForm>) -> Result<impl View>
277279 }
278280
279281 #[component]
280-async fn two_factor_form(lang: Lang, precsrf: &str, error: Option<String>) -> Result<impl View> {
282+async fn two_factor_form(
283+ cx: &Cx,
284+ lang: Lang,
285+ precsrf: &str,
286+ error: Option<String>,
287+) -> Result<impl View> {
281288 Ok(view! {
282289 head(title: t(lang, Key::TwoFactorCheck))
283290 <div class="sheet fit">
@@ -299,7 +306,7 @@ async fn two_factor_form(lang: Lang, precsrf: &str, error: Option<String>) -> Re
299306 /// The second-factor step. Needs a live pending-login cookie; otherwise back to `/login`.
300307 #[page("/login/2fa")]
301308 async fn two_factor_page(cx: &Cx) -> Result<impl View> {
302- let state = app_context::<AppState>(cx);
309+ let state = context::<AppState>(cx);
303310 if pending_login(cx, &state.key).is_none() {
304311 return Err(see_other("/login").into());
305312 }
@@ -315,7 +322,7 @@ async fn two_factor_submit(cx: &Cx, Form(form): Form<TwoFactorForm>) -> Result<i
315322 if !check_pre_csrf(cx, &form.precsrf) {
316323 return Err(forbidden().into());
317324 }
318- let state = app_context::<AppState>(cx);
325+ let state = context::<AppState>(cx);
319326 let lang = i18n::lang(cx, None);
320327 let Some(pending) = pending_login(cx, &state.key) else {
321328 return Err(see_other("/login").into());
@@ -398,7 +405,7 @@ async fn logout_submit(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther>
398405 if !check_csrf(&session, &form.csrf) {
399406 return Err(forbidden().into());
400407 }
401- let state = app_context::<AppState>(cx);
408+ let state = context::<AppState>(cx);
402409 logout(cx, &session).await?;
403410 audit::record(
404411 &state.store,
crates/forge-web/src/pages/media.rsmodified+2 -2
@@ -10,7 +10,7 @@ use http_body::Frame;
1010 use http_body_util::StreamBody;
1111 use serde::Deserialize;
1212 use tokio_util::io::ReaderStream;
13-use topcoat::context::{Cx, app_context};
13+use topcoat::context::{Cx, context};
1414 use topcoat::router::request::method;
1515 use topcoat::router::response::Response;
1616 use topcoat::router::{
@@ -58,7 +58,7 @@ pub(crate) fn media_file(cx: &Cx, _body: Body) -> RouteFuture<'_> {
5858
5959 /// Serves one LFS object. Every failure is turned into a response here, so the route never errors.
6060 async fn serve(cx: &Cx) -> Response {
61- let state = app_context::<AppState>(cx).clone();
61+ let state = context::<AppState>(cx).clone();
6262 let owner = path_param_segment(cx, "owner").to_owned();
6363 let name = path_param_segment(cx, "repo").to_owned();
6464 let rest = path_param_segments(cx, "rest")
crates/forge-web/src/pages/merge_queue.rsmodified+16 -18
@@ -17,7 +17,7 @@ use futures_util::{Stream, stream};
1717 use serde::Deserialize;
1818 use tokio::sync::watch;
1919 use topcoat::Result;
20-use topcoat::context::{Cx, app_context};
20+use topcoat::context::{Cx, context};
2121 use topcoat::router::content::Form;
2222 use topcoat::router::content::sse::Event;
2323 use topcoat::router::error::{bad_request, forbidden, not_found, see_other};
@@ -78,7 +78,7 @@ fn back_to_pull(href: &str, code: Option<&str>) -> Result<Response> {
7878 }
7979
8080 async fn load_pull(cx: &Cx, ctx: &RepoCtx, number: i64) -> Result<PullRequest> {
81- let state = app_context::<AppState>(cx);
81+ let state = context::<AppState>(cx);
8282 match state.store.pull_by_number(&ctx.repo.id, number).await? {
8383 Some(pr) => Ok(pr),
8484 None => Err(not_found().into()),
@@ -87,8 +87,8 @@ async fn load_pull(cx: &Cx, ctx: &RepoCtx, number: i64) -> Result<PullRequest> {
8787
8888 #[route(POST "/{owner}/{repo}/pulls/{number}/merge-queue")]
8989 async fn enqueue_post(cx: &Cx, Form(form): Form<QueueForm>) -> Result<Response> {
90- let number = parse_number(path_param::<Number>(cx))?;
91- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
90+ let number = parse_number(number(cx))?;
91+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
9292 let (user, _) = require_csrf(cx, &form.csrf).await?;
9393 if ctx.repo.archived
9494 || authorize(
@@ -102,7 +102,7 @@ async fn enqueue_post(cx: &Cx, Form(form): Form<QueueForm>) -> Result<Response>
102102 {
103103 return Err(forbidden().into());
104104 }
105- let state = app_context::<AppState>(cx);
105+ let state = context::<AppState>(cx);
106106 let pr = load_pull(cx, &ctx, number).await?;
107107 let href = pull_href(&ctx, number);
108108 if pr.merged_at.is_some() || pr.issue.state != forge_core::IssueState::Open {
@@ -126,8 +126,8 @@ async fn enqueue_post(cx: &Cx, Form(form): Form<QueueForm>) -> Result<Response>
126126
127127 #[route(POST "/{owner}/{repo}/pulls/{number}/merge-queue/remove")]
128128 async fn remove_post(cx: &Cx, Form(form): Form<QueueForm>) -> Result<Response> {
129- let number = parse_number(path_param::<Number>(cx))?;
130- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
129+ let number = parse_number(number(cx))?;
130+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
131131 let (user, _) = require_csrf(cx, &form.csrf).await?;
132132 if ctx.repo.archived
133133 || authorize(
@@ -141,7 +141,7 @@ async fn remove_post(cx: &Cx, Form(form): Form<QueueForm>) -> Result<Response> {
141141 {
142142 return Err(forbidden().into());
143143 }
144- let state = app_context::<AppState>(cx);
144+ let state = context::<AppState>(cx);
145145 let pr = load_pull(cx, &ctx, number).await?;
146146 let href = pull_href(&ctx, number);
147147 if let Some(entry) = state.store.queue_entry_for_pull(&pr.issue.id).await? {
@@ -154,10 +154,10 @@ async fn remove_post(cx: &Cx, Form(form): Form<QueueForm>) -> Result<Response> {
154154 /// The queue page: waiting entries, or the history with `?show=history`.
155155 #[page("/{owner}/{repo}/merge-queue")]
156156 async fn queue_page(cx: &Cx) -> Result<impl View> {
157- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
157+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
158158 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
159159 let history = query_params::<QueueQuery>(cx)?.show.as_deref() == Some("history");
160- let state = app_context::<AppState>(cx);
160+ let state = context::<AppState>(cx);
161161 let frame = crate::pages::issue_meta::RepoFrame::new(&ctx, state, "pulls").await?;
162162 let entries = state.store.queue_overview(&ctx.repo.id).await?;
163163 let rows = queue_rows(state, &ctx, lang, entries, history).await?;
@@ -332,8 +332,8 @@ fn reason_label(lang: Lang, reason: &str) -> String {
332332 /// after that point is sent.
333333 #[route(GET "/{owner}/{repo}/merge-queue/events")]
334334 async fn queue_events(cx: &Cx) -> Result<Response> {
335- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
336- let state = app_context::<AppState>(cx);
335+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
336+ let state = context::<AppState>(cx);
337337 let wake = state.ci_live.subscribe_queue(&ctx.repo.id);
338338 events_response(cx, queue_changes(wake))
339339 }
@@ -347,6 +347,7 @@ fn queue_changes(wake: watch::Receiver<u64>) -> impl Stream<Item = Result<Event>
347347
348348 #[component]
349349 async fn queue_body(
350+ cx: &Cx,
350351 lang: Lang,
351352 head: crate::pages::repo_ctx::RepoHead,
352353 waiting_href: String,
@@ -359,12 +360,9 @@ async fn queue_body(
359360 csrf: String,
360361 ) -> Result<impl View> {
361362 let remove_label = g::t(lang, K::RemoveFromQueue);
362- let remove_note = crate::pages::passkeys::s(
363- lang,
364- "Remove it from the queue?",
365- "Sıradan çıkarılsın mı?",
366- )
367- .to_owned();
363+ let remove_note =
364+ crate::pages::passkeys::s(lang, "Remove it from the queue?", "Sıradan çıkarılsın mı?")
365+ .to_owned();
368366 Ok(view! {
369367 repo_head(head: head, title: Some(g::t(lang, K::MergeQueueTitle).to_owned()))
370368 <nav class="tabs" aria-label=(g::t(lang, K::MergeQueueNav))>
crates/forge-web/src/pages/milestones_page.rsmodified+28 -31
@@ -8,7 +8,7 @@ use jiff::Timestamp;
88 use jiff::tz::TimeZone;
99 use serde::Deserialize;
1010 use topcoat::Result;
11-use topcoat::context::{Cx, app_context};
11+use topcoat::context::{Cx, context};
1212 use topcoat::router::content::Form;
1313 use topcoat::router::error::{forbidden, not_found, see_other};
1414 use topcoat::router::{page, path_param, query_params};
@@ -100,7 +100,7 @@ fn due_on_field(raw: &str) -> Option<&str> {
100100
101101 /// The Open and Closed filter as the sheet's tools row: the shown state in bold, the other a link.
102102 #[component]
103-async fn state_tabs(lang: Lang, title: String, closed: bool) -> Result<impl View> {
103+async fn state_tabs(cx: &Cx, lang: Lang, title: String, closed: bool) -> Result<impl View> {
104104 let open_href = format!("{}?state=open", milestones_href(&title));
105105 let closed_href = format!("{}?state=closed", milestones_href(&title));
106106 Ok(view! {
@@ -120,6 +120,7 @@ async fn state_tabs(lang: Lang, title: String, closed: bool) -> Result<impl View
120120 /// and the triage controls.
121121 #[component]
122122 async fn milestone_row(
123+ cx: &Cx,
123124 lang: Lang,
124125 row: MilestoneRow,
125126 csrf: String,
@@ -166,8 +167,8 @@ async fn milestone_row(
166167 /// Gets the milestone list for one state (open by default).
167168 #[page("/{owner}/{repo}/milestones")]
168169 async fn milestones_page(cx: &Cx) -> Result<impl View> {
169- let owner = path_param::<Owner>(cx);
170- let name = path_param::<Repo>(cx);
170+ let owner = owner(cx);
171+ let name = repo(cx);
171172 let ctx = load_repo(cx, owner, name).await?;
172173 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
173174 let query = query_params::<MilestoneQuery>(cx)?;
@@ -177,11 +178,11 @@ async fn milestones_page(cx: &Cx) -> Result<impl View> {
177178 } else {
178179 IssueState::Open
179180 };
180- let milestones = app_context::<AppState>(cx)
181+ let milestones = context::<AppState>(cx)
181182 .store
182183 .list_milestones(&ctx.repo.id, Some(state))
183184 .await?;
184- let frame = RepoFrame::new(&ctx, app_context::<AppState>(cx), "issues").await?;
185+ let frame = RepoFrame::new(&ctx, context::<AppState>(cx), "issues").await?;
185186 let today = today_in(ctx.viewer_tz());
186187 let title = frame.title.clone();
187188 let all: Vec<MilestoneRow> = milestones
@@ -236,6 +237,7 @@ async fn milestones_page(cx: &Cx) -> Result<impl View> {
236237 /// The header, state tabs, milestone rows and the create form.
237238 #[component]
238239 async fn milestones_body(
240+ cx: &Cx,
239241 lang: Lang,
240242 frame: RepoFrame,
241243 rows: Vec<MilestoneRow>,
@@ -310,13 +312,13 @@ async fn milestones_body(
310312 /// Creates a milestone with an optional due date.
311313 #[page(POST "/{owner}/{repo}/milestones")]
312314 async fn milestone_create(cx: &Cx, Form(form): Form<MilestoneForm>) -> Result<impl View> {
313- let owner = path_param::<Owner>(cx);
314- let name = path_param::<Repo>(cx);
315+ let owner = owner(cx);
316+ let name = repo(cx);
315317 let ctx = load_repo(cx, owner, name).await?;
316318 triage_guard(cx, &ctx, &form.csrf).await?;
317319 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
318320 let back = milestones_href(&format!("{}/{}", ctx.repo.owner_name, ctx.repo.name));
319- let result = app_context::<AppState>(cx)
321+ let result = context::<AppState>(cx)
320322 .store
321323 .create_milestone(
322324 &ctx.repo.id,
@@ -327,9 +329,7 @@ async fn milestone_create(cx: &Cx, Form(form): Form<MilestoneForm>) -> Result<im
327329 .await;
328330 match result {
329331 Ok(_) => {
330- app_context::<AppState>(cx)
331- .live
332- .bump_repo_issues(&ctx.repo.id);
332+ context::<AppState>(cx).live.bump_repo_issues(&ctx.repo.id);
333333 Err(see_other(back).into())
334334 }
335335 Err(e) => {
@@ -345,23 +345,23 @@ async fn milestone_create(cx: &Cx, Form(form): Form<MilestoneForm>) -> Result<im
345345 /// The edit page: title, description, due date and state. Triage holders only.
346346 #[page("/{owner}/{repo}/milestones/{milestone_id}/edit")]
347347 async fn milestone_edit_page(cx: &Cx) -> Result<impl View> {
348- let owner = path_param::<Owner>(cx);
349- let name = path_param::<Repo>(cx);
350- let id = path_param::<MilestoneId>(cx);
348+ let owner = owner(cx);
349+ let name = repo(cx);
350+ let id = milestone_id(cx);
351351 let ctx = load_repo(cx, owner, name).await?;
352352 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
353353 require_user(cx).await?;
354354 if !can_triage(&ctx) {
355355 return Err(forbidden().into());
356356 }
357- let Some(milestone) = app_context::<AppState>(cx)
357+ let Some(milestone) = context::<AppState>(cx)
358358 .store
359359 .milestone_by_id(&ctx.repo.id, id)
360360 .await?
361361 else {
362362 return Err(not_found().into());
363363 };
364- let frame = RepoFrame::new(&ctx, app_context::<AppState>(cx), "issues").await?;
364+ let frame = RepoFrame::new(&ctx, context::<AppState>(cx), "issues").await?;
365365 let page_title = g::milestone_edit_title(lang, &frame.title);
366366 let action = format!("{}/{}/edit", milestones_href(&frame.title), milestone.id);
367367 let due = milestone.due_on.clone().unwrap_or_default();
@@ -376,6 +376,7 @@ async fn milestone_edit_page(cx: &Cx) -> Result<impl View> {
376376 /// The edit form body.
377377 #[component]
378378 async fn milestone_edit_body(
379+ cx: &Cx,
379380 lang: Lang,
380381 frame: RepoFrame,
381382 action: String,
@@ -425,9 +426,9 @@ async fn milestone_edit_body(
425426 /// Saves the edit form. A state of `closed` closes the milestone; anything else reopens it.
426427 #[page(POST "/{owner}/{repo}/milestones/{milestone_id}/edit")]
427428 async fn milestone_edit_save(cx: &Cx, Form(form): Form<MilestoneForm>) -> Result<impl View> {
428- let owner = path_param::<Owner>(cx);
429- let name = path_param::<Repo>(cx);
430- let id = path_param::<MilestoneId>(cx);
429+ let owner = owner(cx);
430+ let name = repo(cx);
431+ let id = milestone_id(cx);
431432 let ctx = load_repo(cx, owner, name).await?;
432433 triage_guard(cx, &ctx, &form.csrf).await?;
433434 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
@@ -437,7 +438,7 @@ async fn milestone_edit_save(cx: &Cx, Form(form): Form<MilestoneForm>) -> Result
437438 } else {
438439 IssueState::Open
439440 };
440- let result = app_context::<AppState>(cx)
441+ let result = context::<AppState>(cx)
441442 .store
442443 .update_milestone(
443444 &ctx.repo.id,
@@ -450,9 +451,7 @@ async fn milestone_edit_save(cx: &Cx, Form(form): Form<MilestoneForm>) -> Result
450451 .await;
451452 match result {
452453 Ok(()) => {
453- app_context::<AppState>(cx)
454- .live
455- .bump_repo_issues(&ctx.repo.id);
454+ context::<AppState>(cx).live.bump_repo_issues(&ctx.repo.id);
456455 Err(see_other(back).into())
457456 }
458457 Err(e) => {
@@ -468,22 +467,20 @@ async fn milestone_edit_save(cx: &Cx, Form(form): Form<MilestoneForm>) -> Result
468467 /// Deletes a milestone. Its issues stay open or closed; they just lose the milestone.
469468 #[page(POST "/{owner}/{repo}/milestones/{milestone_id}/delete")]
470469 async fn milestone_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<impl View> {
471- let owner = path_param::<Owner>(cx);
472- let name = path_param::<Repo>(cx);
473- let id = path_param::<MilestoneId>(cx);
470+ let owner = owner(cx);
471+ let name = repo(cx);
472+ let id = milestone_id(cx);
474473 let ctx = load_repo(cx, owner, name).await?;
475474 triage_guard(cx, &ctx, &form.csrf).await?;
476475 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
477476 let back = milestones_href(&format!("{}/{}", ctx.repo.owner_name, ctx.repo.name));
478- let result = app_context::<AppState>(cx)
477+ let result = context::<AppState>(cx)
479478 .store
480479 .delete_milestone(&ctx.repo.id, id)
481480 .await;
482481 match result {
483482 Ok(()) => {
484- app_context::<AppState>(cx)
485- .live
486- .bump_repo_issues(&ctx.repo.id);
483+ context::<AppState>(cx).live.bump_repo_issues(&ctx.repo.id);
487484 Err(see_other(back).into())
488485 }
489486 Err(e) => {
crates/forge-web/src/pages/needs_you.rsmodified+4 -4
@@ -9,7 +9,7 @@ use forge_core::User;
99 use forge_core::authz::{Action, authorize};
1010 use forge_core::store::needs::Verdict;
1111 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};
12+use topcoat::context::{Cx, context};
1313 use topcoat::router::response::Response;
1414 use topcoat::router::{Body, StatusCode, page, query_params, route};
1515 use topcoat::view::{View, component, view};
@@ -344,7 +344,7 @@ async fn load_full(
344344
345345 /// One section of the page: its head, its rows as a compact list, its full-list link and its pager.
346346 #[component]
347-pub(crate) async fn need_section(lang: Lang, section: NeedSection) -> Result<impl View> {
347+pub(crate) async fn need_section(cx: &Cx, lang: Lang, section: NeedSection) -> Result<impl View> {
348348 let NeedSection {
349349 heading,
350350 more,
@@ -386,7 +386,7 @@ pub(crate) async fn need_section(lang: Lang, section: NeedSection) -> Result<imp
386386 #[page("/needs-you")]
387387 async fn needs_you(cx: &Cx) -> Result<impl View> {
388388 let viewer = require_user(cx).await?;
389- let state = app_context::<AppState>(cx);
389+ let state = context::<AppState>(cx);
390390 let user = &viewer.0;
391391 let lang = i18n::lang(cx, Some(user));
392392 let query = query_params::<NeedsQuery>(cx)?;
@@ -444,7 +444,7 @@ async fn needs_you_events(cx: &Cx) -> Result<Response> {
444444 *res.status_mut() = StatusCode::UNAUTHORIZED;
445445 return Ok(res);
446446 };
447- let state = app_context::<AppState>(cx);
447+ let state = context::<AppState>(cx);
448448 stream_wakes(
449449 cx,
450450 &state.live,
crates/forge-web/src/pages/new_repo.rsmodified+7 -6
@@ -7,7 +7,7 @@ use forge_core::{AuditAction, User, Visibility};
77 use forge_git::repo::{init_bare, repo_path};
88 use serde::Deserialize;
99 use topcoat::Result;
10-use topcoat::context::{Cx, app_context};
10+use topcoat::context::{Cx, context};
1111 use topcoat::router::content::Form;
1212 use topcoat::router::error::see_other;
1313 // Named by the `#[query_params]` attribute below, which the unused-import lint does not see.
@@ -208,6 +208,7 @@ impl Draft {
208208
209209 #[component]
210210 async fn new_repo_form(
211+ cx: &Cx,
211212 lang: Lang,
212213 username: String,
213214 csrf: &str,
@@ -329,7 +330,7 @@ async fn new_repo_page(cx: &Cx) -> Result<impl View> {
329330 let viewer = require_user(cx).await?;
330331 let lang = i18n::lang(cx, Some(&viewer.0));
331332 let wanted = query_params::<NewRepoQuery>(cx)?.owner.clone();
332- let owners = owner_choices(app_context::<AppState>(cx), &viewer.0).await?;
333+ let owners = owner_choices(context::<AppState>(cx), &viewer.0).await?;
333334 let mut draft = Draft::fresh();
334335 if let Some(wanted) = wanted.as_deref()
335336 && let Some(owner) = owners.iter().find(|name| name.eq_ignore_ascii_case(wanted))
@@ -337,7 +338,7 @@ async fn new_repo_page(cx: &Cx) -> Result<impl View> {
337338 draft.owner = owner.clone();
338339 }
339340 let csrf = viewer.1.csrf_token.clone();
340- Ok(view! { cx =>
341+ Ok(view! {
341342 shell(title: i18n::t(lang, Key::NewRepository), viewer: Some(&viewer), new_repo_form(lang: lang, username: viewer.0.username.clone(), csrf: csrf.as_str(), draft: draft, error: None, owners: owners))
342343 })
343344 }
@@ -350,10 +351,10 @@ async fn new_repo_submit(cx: &Cx, Form(form): Form<NewRepoForm>) -> Result<impl
350351 match outcome {
351352 Ok(location) => Err(see_other(location).into()),
352353 Err(message) => {
353- let owners = owner_choices(app_context::<AppState>(cx), &viewer.0).await?;
354+ let owners = owner_choices(context::<AppState>(cx), &viewer.0).await?;
354355 let csrf = viewer.1.csrf_token.clone();
355356 let draft = Draft::from_form(&form);
356- Ok(view! { cx =>
357+ Ok(view! {
357358 shell(title: i18n::t(lang, Key::NewRepository), viewer: Some(&viewer), new_repo_form(lang: lang, username: viewer.0.username.clone(), csrf: csrf.as_str(), draft: draft, error: Some(message), owners: owners))
358359 })
359360 }
@@ -389,7 +390,7 @@ async fn create_repo(
389390 owner: &User,
390391 form: &NewRepoForm,
391392 ) -> Result<std::result::Result<String, String>> {
392- let state = app_context::<AppState>(cx);
393+ let state = context::<AppState>(cx);
393394 let lang = i18n::lang(cx, Some(owner));
394395 let name = match validate_name(&form.name) {
395396 Ok(name) => name,
crates/forge-web/src/pages/not_found_page.rsmodified+2 -2
@@ -46,7 +46,7 @@ fn texts(lang: Lang) -> (&'static str, &'static str, &'static str) {
4646 }
4747
4848 #[component]
49-async fn not_found_body(lang: Lang) -> Result<impl View> {
49+async fn not_found_body(cx: &Cx, lang: Lang) -> Result<impl View> {
5050 let (title, hint, back) = texts(lang);
5151 Ok(view! {
5252 head(title: title, sub: vec![SubPart::mono("404")])
@@ -101,7 +101,7 @@ fn forbidden_texts(lang: Lang) -> (&'static str, &'static str, &'static str) {
101101 }
102102
103103 #[component]
104-async fn forbidden_body(lang: Lang) -> Result<impl View> {
104+async fn forbidden_body(cx: &Cx, lang: Lang) -> Result<impl View> {
105105 let (title, hint, back) = forbidden_texts(lang);
106106 Ok(view! {
107107 head(title: title, sub: vec![SubPart::mono("403")])
crates/forge-web/src/pages/notifications.rsmodified+47 -29
@@ -15,7 +15,7 @@ use forge_core::{Notification, Reason, Role, SubState, User, WatchLevel};
1515 use futures_util::{Stream, StreamExt, future, stream};
1616 use serde::Deserialize;
1717 use topcoat::Result;
18-use topcoat::context::{Cx, app_context};
18+use topcoat::context::{Cx, context};
1919 use topcoat::router::content::Form;
2020 use topcoat::router::content::sse::Event;
2121 use topcoat::router::error::{SeeOther, bad_request, not_found, see_other};
@@ -320,7 +320,7 @@ async fn entry_visible(
320320 #[page("/notifications")]
321321 async fn inbox(cx: &Cx) -> Result<impl View> {
322322 let viewer = require_user(cx).await?;
323- let state = app_context::<AppState>(cx);
323+ let state = context::<AppState>(cx);
324324 let query = query_params::<InboxQuery>(cx)?;
325325 let all = query.all.as_deref() == Some("1");
326326 let before = query.before.clone().filter(|s| !s.is_empty());
@@ -545,7 +545,7 @@ async fn inbox_events(cx: &Cx) -> Result<Response> {
545545 return Ok(res);
546546 };
547547 let all = query_params::<InboxQuery>(cx)?.all.as_deref() == Some("1");
548- let state = app_context::<AppState>(cx).clone();
548+ let state = context::<AppState>(cx).clone();
549549 let topic = Topic::Inbox(user.id.clone());
550550 stream_changes(cx, &state.live.clone(), &[topic], move || {
551551 let state = state.clone();
@@ -560,8 +560,8 @@ async fn inbox_events(cx: &Cx) -> Result<Response> {
560560 #[route(GET "/notifications/{note}/open")]
561561 async fn open_notification(cx: &Cx) -> Result<SeeOther> {
562562 let (user, _) = require_user(cx).await?;
563- let state = app_context::<AppState>(cx);
564- let id = path_param::<Note>(cx);
563+ let state = context::<AppState>(cx);
564+ let id = note(cx);
565565 let Some(target) = state.store.notification_target(&user.id, id).await? else {
566566 return Err(not_found().into());
567567 };
@@ -585,8 +585,8 @@ async fn open_notification(cx: &Cx) -> Result<SeeOther> {
585585 #[route(GET "/notifications/discussions/{discussion_id}/open")]
586586 async fn open_discussion_notification(cx: &Cx) -> Result<SeeOther> {
587587 let (user, _) = require_user(cx).await?;
588- let state = app_context::<AppState>(cx);
589- let id = path_param::<DiscussionId>(cx);
588+ let state = context::<AppState>(cx);
589+ let id = discussion_id(cx);
590590 let Some(note) = state.store.discussion_notification(&user.id, id).await? else {
591591 return Err(not_found().into());
592592 };
@@ -611,8 +611,8 @@ async fn open_discussion_notification(cx: &Cx) -> Result<SeeOther> {
611611 #[route(POST "/notifications/discussions/{discussion_id}/read")]
612612 async fn read_discussion_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
613613 let (user, _) = require_csrf(cx, &form.csrf).await?;
614- let state = app_context::<AppState>(cx);
615- let id = path_param::<DiscussionId>(cx);
614+ let state = context::<AppState>(cx);
615+ let id = discussion_id(cx);
616616 state
617617 .store
618618 .mark_discussion_notification_read(&user.id, id)
@@ -626,8 +626,8 @@ async fn read_discussion_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Re
626626 #[route(GET "/notifications/advisories/{advisory_repo_id}/open")]
627627 async fn open_advisory_notification(cx: &Cx) -> Result<SeeOther> {
628628 let (user, _) = require_user(cx).await?;
629- let state = app_context::<AppState>(cx);
630- let repo_id = path_param::<AdvisoryRepoId>(cx);
629+ let state = context::<AppState>(cx);
630+ let repo_id = advisory_repo_id(cx);
631631 let Some(notice) = state.store.advisory_notification(&user.id, repo_id).await? else {
632632 return Err(not_found().into());
633633 };
@@ -651,8 +651,8 @@ async fn open_advisory_notification(cx: &Cx) -> Result<SeeOther> {
651651 #[route(POST "/notifications/advisories/{advisory_repo_id}/read")]
652652 async fn read_advisory_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
653653 let (user, _) = require_csrf(cx, &form.csrf).await?;
654- let state = app_context::<AppState>(cx);
655- let repo_id = path_param::<AdvisoryRepoId>(cx);
654+ let state = context::<AppState>(cx);
655+ let repo_id = advisory_repo_id(cx);
656656 state
657657 .store
658658 .mark_advisory_notification_read(&user.id, repo_id)
@@ -666,8 +666,8 @@ async fn read_advisory_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Resu
666666 #[route(GET "/notifications/admin/{admin_note}/open")]
667667 async fn open_admin_notification(cx: &Cx) -> Result<SeeOther> {
668668 let (user, _) = require_user(cx).await?;
669- let state = app_context::<AppState>(cx);
670- let id = path_param::<AdminNote>(cx);
669+ let state = context::<AppState>(cx);
670+ let id = admin_note(cx);
671671 let owned = state
672672 .store
673673 .list_admin_notices(&user.id, false, None, 200)
@@ -686,8 +686,8 @@ async fn open_admin_notification(cx: &Cx) -> Result<SeeOther> {
686686 #[route(POST "/notifications/admin/{admin_note}/read")]
687687 async fn read_admin_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
688688 let (user, _) = require_csrf(cx, &form.csrf).await?;
689- let state = app_context::<AppState>(cx);
690- let id = path_param::<AdminNote>(cx);
689+ let state = context::<AppState>(cx);
690+ let id = admin_note(cx);
691691 state.store.mark_admin_notice_read(&user.id, id).await?;
692692 publish_unread(state, &user.id).await;
693693 Ok(see_other(back(cx)))
@@ -697,8 +697,8 @@ async fn read_admin_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<
697697 #[route(POST "/notifications/{note}/read")]
698698 async fn read_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
699699 let (user, _) = require_csrf(cx, &form.csrf).await?;
700- let state = app_context::<AppState>(cx);
701- let id = path_param::<Note>(cx);
700+ let state = context::<AppState>(cx);
701+ let id = note(cx);
702702 state.store.mark_read(&user.id, id).await?;
703703 publish_unread(state, &user.id).await;
704704 Ok(see_other(back(cx)))
@@ -708,7 +708,7 @@ async fn read_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOth
708708 #[route(POST "/notifications/mark_all_read")]
709709 async fn mark_all_read(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
710710 let (user, _) = require_csrf(cx, &form.csrf).await?;
711- let state = app_context::<AppState>(cx);
711+ let state = context::<AppState>(cx);
712712 let query = query_params::<RepoQuery>(cx)?;
713713 let repo_id = query.repo.as_deref().filter(|s| !s.is_empty());
714714 if repo_id == Some(ADMIN_GROUP) {
@@ -765,7 +765,7 @@ async fn notification_stream(cx: &Cx) -> Result<Response> {
765765 *res.status_mut() = StatusCode::UNAUTHORIZED;
766766 return Ok(res);
767767 };
768- let state = app_context::<AppState>(cx);
768+ let state = context::<AppState>(cx);
769769 let events = unread_changes(state, &user.id).await?;
770770 events_response(cx, events)
771771 }
@@ -783,10 +783,10 @@ async fn pull_subscription(cx: &Cx, Form(form): Form<SubscriptionForm>) -> Resul
783783 }
784784
785785 async fn set_subscription(cx: &Cx, pull: bool, form: &SubscriptionForm) -> Result<SeeOther> {
786- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
786+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
787787 let (user, _) = require_csrf(cx, &form.csrf).await?;
788- let state = app_context::<AppState>(cx);
789- let number = parse_number(path_param::<Number>(cx))?;
788+ let state = context::<AppState>(cx);
789+ let number = parse_number(number(cx))?;
790790 let issue = if pull {
791791 state
792792 .store
@@ -841,7 +841,7 @@ async fn set_subscription(cx: &Cx, pull: bool, form: &SubscriptionForm) -> Resul
841841 /// Sets the viewer's watch level on a repo. The viewer must be able to read the repo.
842842 #[route(POST "/{owner}/{repo}/watch")]
843843 async fn set_watch(cx: &Cx, Form(form): Form<WatchForm>) -> Result<SeeOther> {
844- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
844+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
845845 let (user, _) = require_csrf(cx, &form.csrf).await?;
846846 let level = match form.level.as_str() {
847847 "participating" => WatchLevel::Participating,
@@ -849,7 +849,7 @@ async fn set_watch(cx: &Cx, Form(form): Form<WatchForm>) -> Result<SeeOther> {
849849 "ignoring" => WatchLevel::Ignoring,
850850 _ => return Err(bad_request("unknown watch level").into()),
851851 };
852- let state = app_context::<AppState>(cx);
852+ let state = context::<AppState>(cx);
853853 state.store.set_watch(&user.id, &ctx.repo.id, level).await?;
854854 state.live.bump_repo(&ctx.repo.owner_id, &ctx.repo.id);
855855 Ok(see_other(repo_href(
@@ -973,8 +973,18 @@ pub(crate) fn inbox_items(lang: Lang, current: &str, unread_count: u64) -> Vec<R
973973 current: key == current,
974974 };
975975 vec![
976- item("unread", g::t(lang, K::Unread), unread_count.to_string(), "/notifications"),
977- item("all", g::t(lang, K::AllTab), String::new(), "/notifications?all=1"),
976+ item(
977+ "unread",
978+ g::t(lang, K::Unread),
979+ unread_count.to_string(),
980+ "/notifications",
981+ ),
982+ item(
983+ "all",
984+ g::t(lang, K::AllTab),
985+ String::new(),
986+ "/notifications?all=1",
987+ ),
978988 item(
979989 "needs",
980990 crate::i18n::needs::t(lang, crate::i18n::needs::K::NeedsYou),
@@ -992,7 +1002,12 @@ pub(crate) fn inbox_items(lang: Lang, current: &str, unread_count: u64) -> Vec<R
9921002
9931003 /// The inbox rail as Needs you and Review requests show it, beside their sheet.
9941004 #[component]
995-pub(crate) async fn inbox_rail(lang: Lang, current: &str, unread_count: u64) -> Result<impl View> {
1005+pub(crate) async fn inbox_rail(
1006+ cx: &Cx,
1007+ lang: Lang,
1008+ current: &str,
1009+ unread_count: u64,
1010+) -> Result<impl View> {
9961011 let items = inbox_items(lang, current, unread_count);
9971012 Ok(view! {
9981013 rail(label: g::t(lang, K::NotificationFilter), items: items)
@@ -1003,6 +1018,7 @@ pub(crate) async fn inbox_rail(lang: Lang, current: &str, unread_count: u64) ->
10031018 /// sheet holding the transfers, the repo groups and the older-rows link.
10041019 #[component]
10051020 async fn inbox_list(
1021+ cx: &Cx,
10061022 lang: Lang,
10071023 all: bool,
10081024 unread_count: u64,
@@ -1076,6 +1092,7 @@ async fn inbox_list(
10761092 /// The Subscribe or Unsubscribe pill of an issue or pull request, in its head.
10771093 #[component]
10781094 pub(crate) async fn notify_pill(
1095+ cx: &Cx,
10791096 lang: Lang,
10801097 action: String,
10811098 csrf: String,
@@ -1100,6 +1117,7 @@ pub(crate) async fn notify_pill(
11001117 /// without JavaScript; nav.js submits them in place and closes the menu.
11011118 #[component]
11021119 pub(crate) async fn watch_form(
1120+ cx: &Cx,
11031121 lang: Lang,
11041122 action: String,
11051123 csrf: String,
crates/forge-web/src/pages/org_ctx.rsmodified+4 -3
@@ -9,7 +9,7 @@ use forge_core::store::orgs::OrgMemberRole;
99 use forge_core::store::repo_listing::RepoScope;
1010 use forge_core::{Role, Session, User};
1111 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};
12+use topcoat::context::{Cx, context};
1313 use topcoat::router::error::{forbidden, not_found};
1414 use topcoat::router::request::uri;
1515 use topcoat::view::{View, component, view};
@@ -102,7 +102,7 @@ impl OrgCtx {
102102 /// names and people (anything that is not an org) are 404.
103103 pub async fn load_org(cx: &Cx, name: &str) -> Result<OrgCtx> {
104104 let viewer = require_user(cx).await?;
105- let state = app_context::<AppState>(cx);
105+ let state = context::<AppState>(cx);
106106 let Some(org) = state.store.user_by_username(name).await? else {
107107 return Err(not_found().into());
108108 };
@@ -201,6 +201,7 @@ pub async fn org_tab_counts(state: &AppState, org: &User, viewer: &User) -> Resu
201201 /// Teams are always listed; an owner also gets Settings. `current` marks the page's own tab.
202202 #[component]
203203 pub async fn org_tabs(
204+ cx: &Cx,
204205 lang: Lang,
205206 name: String,
206207 current: String,
@@ -251,7 +252,7 @@ pub async fn org_tabs(
251252
252253 /// The notice after a write: an error alert, or a status line.
253254 #[component]
254-pub async fn org_notice(notice: Option<(&'static str, bool)>) -> Result<impl View> {
255+pub async fn org_notice(cx: &Cx, notice: Option<(&'static str, bool)>) -> Result<impl View> {
255256 Ok(view! {
256257 if let Some((text, is_error)) = notice {
257258 if is_error {
crates/forge-web/src/pages/org_live.rsmodified+11 -11
@@ -15,7 +15,7 @@ use forge_core::User;
1515 use forge_core::store::Store;
1616 use forge_core::store::orgs::OrgMemberRole;
1717 use topcoat::Result;
18-use topcoat::context::{Cx, app_context};
18+use topcoat::context::{Cx, context};
1919 use topcoat::router::request::{method, uri};
2020 use topcoat::router::response::Response;
2121 use topcoat::router::{Body, Layer, LayerFuture, Method, Next, Path, path_param, route};
@@ -130,9 +130,9 @@ async fn settings_fingerprint(store: &Store, org_id: &str) -> Result<String> {
130130 /// The members page's change stream. Members only, as the page.
131131 #[route(GET "/org/{org}/members/events")]
132132 async fn org_members_events(cx: &Cx) -> Result<Response> {
133- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
133+ let ctx = load_org(cx, org(cx)).await?;
134134 require_member(&ctx)?;
135- let state = app_context::<AppState>(cx);
135+ let state = context::<AppState>(cx);
136136 let org_id = ctx.org.id.clone();
137137 let store = state.store.clone();
138138 stream_changes(cx, &state.live, &[Topic::Org(org_id.clone())], move || {
@@ -146,9 +146,9 @@ async fn org_members_events(cx: &Cx) -> Result<Response> {
146146 /// The teams list's change stream. Members only, as the page.
147147 #[route(GET "/org/{org}/teams/events")]
148148 async fn org_teams_events(cx: &Cx) -> Result<Response> {
149- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
149+ let ctx = load_org(cx, org(cx)).await?;
150150 require_member(&ctx)?;
151- let state = app_context::<AppState>(cx);
151+ let state = context::<AppState>(cx);
152152 let org_id = ctx.org.id.clone();
153153 let store = state.store.clone();
154154 stream_changes(cx, &state.live, &[Topic::Org(org_id.clone())], move || {
@@ -163,10 +163,10 @@ async fn org_teams_events(cx: &Cx) -> Result<Response> {
163163 /// It also follows each repo the team links, for a rename or a visibility change.
164164 #[route(GET "/org/{org}/teams/{team}/events")]
165165 async fn org_team_events(cx: &Cx) -> Result<Response> {
166- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
166+ let ctx = load_org(cx, org(cx)).await?;
167167 require_member(&ctx)?;
168- let state = app_context::<AppState>(cx);
169- let team = team_of(state, &ctx, path_param::<Team>(cx)).await?;
168+ let state = context::<AppState>(cx);
169+ let team = team_of(state, &ctx, team(cx)).await?;
170170 let linked = state.store.team_repos(&team.id).await?;
171171 let mut topics = vec![Topic::Org(ctx.org.id.clone())];
172172 topics.extend(linked.iter().map(|repo| Topic::Repo(repo.id.clone())));
@@ -187,9 +187,9 @@ async fn org_team_events(cx: &Cx) -> Result<Response> {
187187 /// The settings page's change stream. Owners only, as the page.
188188 #[route(GET "/org/{org}/settings/events")]
189189 async fn org_settings_events(cx: &Cx) -> Result<Response> {
190- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
190+ let ctx = load_org(cx, org(cx)).await?;
191191 require_owner(&ctx)?;
192- let state = app_context::<AppState>(cx);
192+ let state = context::<AppState>(cx);
193193 let org_id = ctx.org.id.clone();
194194 let store = state.store.clone();
195195 stream_changes(cx, &state.live, &[Topic::Org(org_id.clone())], move || {
@@ -222,7 +222,7 @@ async fn bump_after_write(cx: &Cx, body: Body, next: Next<'_>) -> topcoat::Resul
222222 let Some(name) = written_org(cx) else {
223223 return next.run(cx, body).await;
224224 };
225- let state = app_context::<AppState>(cx);
225+ let state = context::<AppState>(cx);
226226 let org_id = match state.store.user_by_username(&name).await {
227227 Ok(Some(org)) if org.is_org() => Some(org.id),
228228 Ok(_) => None,
crates/forge-web/src/pages/org_members.rsmodified+20 -11
@@ -9,7 +9,7 @@ use forge_core::AuditAction;
99 use forge_core::store::orgs::OrgMemberRole;
1010 use serde::Deserialize;
1111 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};
12+use topcoat::context::{Cx, context};
1313 use topcoat::router::content::Form;
1414 use topcoat::router::error::{SeeOther, see_other};
1515 use topcoat::router::{page, path_param, route};
@@ -61,6 +61,7 @@ struct RemoveForm {
6161 /// else sees the plain list.
6262 #[component]
6363 async fn members_body(
64+ cx: &Cx,
6465 name: String,
6566 description: String,
6667 base: String,
@@ -115,10 +116,10 @@ async fn members_body(
115116 /// Gets the members page. Non-members get 404.
116117 #[page("/org/{org}/members")]
117118 async fn org_members_page(cx: &Cx) -> Result<impl View> {
118- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
119+ let ctx = load_org(cx, org(cx)).await?;
119120 require_member(&ctx)?;
120121 let lang = i18n::lang(cx, Some(&ctx.viewer.0));
121- let state = app_context::<AppState>(cx);
122+ let state = context::<AppState>(cx);
122123 let members = state.store.org_members(&ctx.org.id).await?;
123124 let rows: Vec<PersonRow> = members
124125 .into_iter()
@@ -132,7 +133,15 @@ async fn org_members_page(cx: &Cx) -> Result<impl View> {
132133 label: display_name(lang, &user.username),
133134 username: user.username,
134135 role: if is_owner { "owner" } else { "member" }.to_owned(),
135- role_name: g::t(lang, if is_owner { K::RoleOwner } else { K::RoleMember }).to_owned(),
136+ role_name: g::t(
137+ lang,
138+ if is_owner {
139+ K::RoleOwner
140+ } else {
141+ K::RoleMember
142+ },
143+ )
144+ .to_owned(),
136145 remove_label: g::t(lang, if is_self { K::Leave } else { K::Remove }).to_owned(),
137146 }
138147 })
@@ -146,7 +155,7 @@ async fn org_members_page(cx: &Cx) -> Result<impl View> {
146155 let csrf = ctx.viewer.1.csrf_token.clone();
147156 let live = ctx.href("/members/events");
148157 let (repo_count, package_count) = org_tab_counts(state, &ctx.org, &ctx.viewer.0).await?;
149- Ok(view! { cx =>
158+ Ok(view! {
150159 shell(title: title.as_str(), viewer: Some(&ctx.viewer),
151160 members_body(name: name, description: description, base: base, owner: owner,
152161 rows: rows, csrf: csrf, notice: notice, lang: lang, live: live,
@@ -157,10 +166,10 @@ async fn org_members_page(cx: &Cx) -> Result<impl View> {
157166 /// Adds a person as a member or owner. Owners only.
158167 #[route(POST "/org/{org}/members/add")]
159168 async fn org_members_add(cx: &Cx, Form(form): Form<AddForm>) -> Result<SeeOther> {
160- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
169+ let ctx = load_org(cx, org(cx)).await?;
161170 require_form_csrf(&ctx, &form.csrf)?;
162171 require_owner(&ctx)?;
163- let state = app_context::<AppState>(cx);
172+ let state = context::<AppState>(cx);
164173 let back = ctx.href("/members");
165174
166175 let Some(role) = parse_member_role(form.role.trim()) else {
@@ -208,10 +217,10 @@ async fn org_members_add(cx: &Cx, Form(form): Form<AddForm>) -> Result<SeeOther>
208217 /// Changes a member's org role. Owners only. Demoting the last owner is refused.
209218 #[route(POST "/org/{org}/members/role")]
210219 async fn org_members_role(cx: &Cx, Form(form): Form<RoleForm>) -> Result<SeeOther> {
211- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
220+ let ctx = load_org(cx, org(cx)).await?;
212221 require_form_csrf(&ctx, &form.csrf)?;
213222 require_owner(&ctx)?;
214- let state = app_context::<AppState>(cx);
223+ let state = context::<AppState>(cx);
215224 let back = ctx.href("/members");
216225
217226 let Some(role) = parse_member_role(form.role.trim()) else {
@@ -257,10 +266,10 @@ async fn org_members_role(cx: &Cx, Form(form): Form<RoleForm>) -> Result<SeeOthe
257266 /// leaving member is sent to the public org page, since the members page is no longer theirs.
258267 #[route(POST "/org/{org}/members/remove")]
259268 async fn org_members_remove(cx: &Cx, Form(form): Form<RemoveForm>) -> Result<SeeOther> {
260- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
269+ let ctx = load_org(cx, org(cx)).await?;
261270 require_form_csrf(&ctx, &form.csrf)?;
262271 require_member(&ctx)?;
263- let state = app_context::<AppState>(cx);
272+ let state = context::<AppState>(cx);
264273 let user_id = form.user_id.trim().to_owned();
265274 let self_removal = user_id == ctx.viewer.0.id;
266275 if !self_removal {
crates/forge-web/src/pages/org_new.rsmodified+6 -5
@@ -6,7 +6,7 @@ use forge_core::config::OrgCreation;
66 use forge_core::{AuditAction, User};
77 use serde::Deserialize;
88 use topcoat::Result;
9-use topcoat::context::{Cx, app_context};
9+use topcoat::context::{Cx, context};
1010 use topcoat::router::content::Form;
1111 use topcoat::router::error::{forbidden, see_other};
1212 use topcoat::router::page;
@@ -43,6 +43,7 @@ pub(crate) fn may_create_org(state: &AppState, user: &User) -> bool {
4343
4444 #[component]
4545 async fn new_org_form(
46+ cx: &Cx,
4647 csrf: String,
4748 name: String,
4849 description: String,
@@ -76,13 +77,13 @@ async fn new_org_form(
7677 #[page("/org/new")]
7778 async fn new_org_page(cx: &Cx) -> Result<impl View> {
7879 let viewer = require_user(cx).await?;
79- if !may_create_org(app_context::<AppState>(cx), &viewer.0) {
80+ if !may_create_org(context::<AppState>(cx), &viewer.0) {
8081 return Err(forbidden().into());
8182 }
8283 let lang = i18n::lang(cx, Some(&viewer.0));
8384 let title = g::t(lang, K::NewOrganization);
8485 let csrf = viewer.1.csrf_token.clone();
85- Ok(view! { cx =>
86+ Ok(view! {
8687 shell(title: title, viewer: Some(&viewer),
8788 new_org_form(csrf: csrf, name: String::new(), description: String::new(), error: None, lang: lang, username: viewer.0.username.clone()))
8889 })
@@ -91,7 +92,7 @@ async fn new_org_page(cx: &Cx) -> Result<impl View> {
9192 #[page(POST "/org/new")]
9293 async fn new_org_submit(cx: &Cx, Form(form): Form<NewOrgForm>) -> Result<impl View> {
9394 let viewer = require_csrf(cx, &form.csrf).await?;
94- let state = app_context::<AppState>(cx);
95+ let state = context::<AppState>(cx);
9596 if !may_create_org(state, &viewer.0) {
9697 return Err(forbidden().into());
9798 }
@@ -103,7 +104,7 @@ async fn new_org_submit(cx: &Cx, Form(form): Form<NewOrgForm>) -> Result<impl Vi
103104 let csrf = viewer.1.csrf_token.clone();
104105 let name = form.name.clone();
105106 let description = form.description.clone();
106- Ok(view! { cx =>
107+ Ok(view! {
107108 shell(title: title, viewer: Some(&viewer),
108109 new_org_form(csrf: csrf, name: name, description: description, error: Some(message), lang: lang, username: viewer.0.username.clone()))
109110 })
crates/forge-web/src/pages/org_settings.rsmodified+14 -13
@@ -10,7 +10,7 @@ use forge_core::AuditAction;
1010 use forge_core::store::orgs::{DefaultRepoRole, OrgSettings};
1111 use serde::Deserialize;
1212 use topcoat::Result;
13-use topcoat::context::{Cx, app_context};
13+use topcoat::context::{Cx, context};
1414 use topcoat::router::content::Form;
1515 use topcoat::router::content::multipart::Multipart;
1616 use topcoat::router::error::{SeeOther, see_other};
@@ -67,6 +67,7 @@ struct DeleteForm {
6767
6868 #[component]
6969 async fn settings_body(
70+ cx: &Cx,
7071 name: String,
7172 display_name: String,
7273 description: String,
@@ -169,10 +170,10 @@ async fn settings_body(
169170 /// Gets the settings page. Owners only.
170171 #[page("/org/{org}/settings")]
171172 async fn org_settings_page(cx: &Cx) -> Result<impl View> {
172- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
173+ let ctx = load_org(cx, org(cx)).await?;
173174 require_owner(&ctx)?;
174175 let lang = i18n::lang(cx, Some(&ctx.viewer.0));
175- let state = app_context::<AppState>(cx);
176+ let state = context::<AppState>(cx);
176177 let settings = state.store.org_settings(&ctx.org.id).await?;
177178 let default_role = settings.default_repo_role.as_str().to_owned();
178179 let members_can_create = settings.members_can_create_repos;
@@ -188,7 +189,7 @@ async fn org_settings_page(cx: &Cx) -> Result<impl View> {
188189 let csrf = ctx.viewer.1.csrf_token.clone();
189190 let live = ctx.href("/settings/events");
190191 let (repo_count, package_count) = org_tab_counts(state, &ctx.org, &ctx.viewer.0).await?;
191- Ok(view! { cx =>
192+ Ok(view! {
192193 shell(title: title.as_str(), viewer: Some(&ctx.viewer),
193194 settings_body(name: name, display_name: display_name, description: description,
194195 has_avatar: has_avatar, avatar_src: avatar_src, base: base, csrf: csrf,
@@ -201,10 +202,10 @@ async fn org_settings_page(cx: &Cx) -> Result<impl View> {
201202 /// store refuses redirects with a notice before anything is written.
202203 #[route(POST "/org/{org}/settings")]
203204 async fn org_settings_save(cx: &Cx, Form(form): Form<SettingsForm>) -> Result<SeeOther> {
204- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
205+ let ctx = load_org(cx, org(cx)).await?;
205206 require_form_csrf(&ctx, &form.csrf)?;
206207 require_owner(&ctx)?;
207- let state = app_context::<AppState>(cx);
208+ let state = context::<AppState>(cx);
208209 let back = ctx.href("/settings");
209210
210211 let description = form.description.trim();
@@ -262,7 +263,7 @@ async fn org_settings_save(cx: &Cx, Form(form): Form<SettingsForm>) -> Result<Se
262263
263264 /// Uploads the org's avatar. Owners only. The multipart fields are read as the person's upload
264265 /// reads them, then the CSRF token and the role are checked before the image is decoded.
265-#[route(POST "/org/{org}/settings/avatar")]
266+#[route(POST "/org/{org}/settings/avatar", with(topcoat::router::BodyLimit::max(crate::pages::settings_profile::AVATAR_BODY_LIMIT)))]
266267 async fn org_avatar_upload(cx: &Cx, mut multipart: Multipart) -> Result<SeeOther> {
267268 let mut csrf = String::new();
268269 let mut image = None;
@@ -274,10 +275,10 @@ async fn org_avatar_upload(cx: &Cx, mut multipart: Multipart) -> Result<SeeOther
274275 _ => {}
275276 }
276277 }
277- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
278+ let ctx = load_org(cx, org(cx)).await?;
278279 require_form_csrf(&ctx, &csrf)?;
279280 require_owner(&ctx)?;
280- let state = app_context::<AppState>(cx);
281+ let state = context::<AppState>(cx);
281282 let lang = i18n::lang(cx, Some(&ctx.viewer.0));
282283 let back = ctx.href("/settings");
283284
@@ -308,10 +309,10 @@ async fn org_avatar_upload(cx: &Cx, mut multipart: Multipart) -> Result<SeeOther
308309 /// Removes the org's avatar. Owners only.
309310 #[route(POST "/org/{org}/settings/avatar/delete")]
310311 async fn org_avatar_remove(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
311- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
312+ let ctx = load_org(cx, org(cx)).await?;
312313 require_form_csrf(&ctx, &form.csrf)?;
313314 require_owner(&ctx)?;
314- let state = app_context::<AppState>(cx);
315+ let state = context::<AppState>(cx);
315316 let back = ctx.href("/settings");
316317
317318 state.store.delete_avatar(&ctx.org.id).await?;
@@ -335,10 +336,10 @@ async fn org_avatar_remove(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOth
335336 /// repositories; then the settings page says so.
336337 #[route(POST "/org/{org}/settings/delete")]
337338 async fn org_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther> {
338- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
339+ let ctx = load_org(cx, org(cx)).await?;
339340 require_form_csrf(&ctx, &form.csrf)?;
340341 require_owner(&ctx)?;
341- let state = app_context::<AppState>(cx);
342+ let state = context::<AppState>(cx);
342343 let back = ctx.href("/settings");
343344
344345 if form.confirm.trim() != ctx.org.username {
crates/forge-web/src/pages/org_teams.rsmodified+30 -28
@@ -9,7 +9,7 @@ use forge_core::authz::{Action, authorize};
99 use forge_core::{AuditAction, Role};
1010 use serde::Deserialize;
1111 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};
12+use topcoat::context::{Cx, context};
1313 use topcoat::router::content::Form;
1414 use topcoat::router::error::{SeeOther, not_found, see_other};
1515 use topcoat::router::{page, path_param, route};
@@ -183,6 +183,7 @@ pub(crate) async fn visible_team_repos(
183183
184184 #[component]
185185 async fn teams_body(
186+ cx: &Cx,
186187 name: String,
187188 description: String,
188189 base: String,
@@ -258,10 +259,10 @@ async fn teams_body(
258259 /// Gets the teams list. Members only.
259260 #[page("/org/{org}/teams")]
260261 async fn org_teams_page(cx: &Cx) -> Result<impl View> {
261- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
262+ let ctx = load_org(cx, org(cx)).await?;
262263 require_member(&ctx)?;
263264 let lang = i18n::lang(cx, Some(&ctx.viewer.0));
264- let state = app_context::<AppState>(cx);
265+ let state = context::<AppState>(cx);
265266 let teams = state.store.teams_for_org(&ctx.org.id).await?;
266267 let rows: Vec<TeamRow> = teams
267268 .into_iter()
@@ -282,7 +283,7 @@ async fn org_teams_page(cx: &Cx) -> Result<impl View> {
282283 let csrf = ctx.viewer.1.csrf_token.clone();
283284 let live = ctx.href("/teams/events");
284285 let (repo_count, package_count) = org_tab_counts(state, &ctx.org, &ctx.viewer.0).await?;
285- Ok(view! { cx =>
286+ Ok(view! {
286287 shell(title: title.as_str(), viewer: Some(&ctx.viewer),
287288 teams_body(name: name, description: description, base: base, owner: owner,
288289 csrf: csrf, rows: rows, notice: notice, lang: lang, live: live,
@@ -292,6 +293,7 @@ async fn org_teams_page(cx: &Cx) -> Result<impl View> {
292293
293294 #[component]
294295 async fn team_body(
296+ cx: &Cx,
295297 data: TeamPage,
296298 notice: Option<(&'static str, bool)>,
297299 lang: Lang,
@@ -443,11 +445,11 @@ async fn team_body(
443445 /// Gets one team's page. Members only; a team of another org is 404.
444446 #[page("/org/{org}/teams/{team}")]
445447 async fn org_team_page(cx: &Cx) -> Result<impl View> {
446- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
448+ let ctx = load_org(cx, org(cx)).await?;
447449 require_member(&ctx)?;
448450 let lang = i18n::lang(cx, Some(&ctx.viewer.0));
449- let state = app_context::<AppState>(cx);
450- let team = team_of(state, &ctx, path_param::<Team>(cx)).await?;
451+ let state = context::<AppState>(cx);
452+ let team = team_of(state, &ctx, team(cx)).await?;
451453 let members: Vec<TeamMemberRow> = state
452454 .store
453455 .team_members(&team.id)
@@ -492,7 +494,7 @@ async fn org_team_page(cx: &Cx) -> Result<impl View> {
492494 choices,
493495 };
494496 let notice = take_notice(cx, lang);
495- Ok(view! { cx =>
497+ Ok(view! {
496498 shell(title: title.as_str(), viewer: Some(&ctx.viewer),
497499 team_body(data: data, notice: notice, lang: lang))
498500 })
@@ -501,10 +503,10 @@ async fn org_team_page(cx: &Cx) -> Result<impl View> {
501503 /// Creates a team. Owners only.
502504 #[route(POST "/org/{org}/teams/new")]
503505 async fn org_team_create(cx: &Cx, Form(form): Form<TeamForm>) -> Result<SeeOther> {
504- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
506+ let ctx = load_org(cx, org(cx)).await?;
505507 require_form_csrf(&ctx, &form.csrf)?;
506508 require_owner(&ctx)?;
507- let state = app_context::<AppState>(cx);
509+ let state = context::<AppState>(cx);
508510 let back = ctx.href("/teams");
509511
510512 let Some(role) = parse_team_role(&form.role) else {
@@ -552,11 +554,11 @@ async fn org_team_create(cx: &Cx, Form(form): Form<TeamForm>) -> Result<SeeOther
552554 /// Renames a team and changes its description, role and coverage. Owners only.
553555 #[route(POST "/org/{org}/teams/{team}/update")]
554556 async fn org_team_update(cx: &Cx, Form(form): Form<TeamForm>) -> Result<SeeOther> {
555- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
557+ let ctx = load_org(cx, org(cx)).await?;
556558 require_form_csrf(&ctx, &form.csrf)?;
557559 require_owner(&ctx)?;
558- let state = app_context::<AppState>(cx);
559- let team = team_of(state, &ctx, path_param::<Team>(cx)).await?;
560+ let state = context::<AppState>(cx);
561+ let team = team_of(state, &ctx, team(cx)).await?;
560562 let back = ctx.href(&format!("/teams/{}", team.id));
561563
562564 let Some(role) = parse_team_role(&form.role) else {
@@ -603,11 +605,11 @@ async fn org_team_update(cx: &Cx, Form(form): Form<TeamForm>) -> Result<SeeOther
603605 /// Deletes a team. Owners only.
604606 #[route(POST "/org/{org}/teams/{team}/delete")]
605607 async fn org_team_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
606- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
608+ let ctx = load_org(cx, org(cx)).await?;
607609 require_form_csrf(&ctx, &form.csrf)?;
608610 require_owner(&ctx)?;
609- let state = app_context::<AppState>(cx);
610- let team = team_of(state, &ctx, path_param::<Team>(cx)).await?;
611+ let state = context::<AppState>(cx);
612+ let team = team_of(state, &ctx, team(cx)).await?;
611613 let name = team.name.clone();
612614 state.store.delete_team(&team.id).await?;
613615 audit::record(
@@ -629,11 +631,11 @@ async fn org_team_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther
629631 /// Adds an organization member to a team. Owners only.
630632 #[route(POST "/org/{org}/teams/{team}/members/add")]
631633 async fn org_team_member_add(cx: &Cx, Form(form): Form<TeamMemberForm>) -> Result<SeeOther> {
632- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
634+ let ctx = load_org(cx, org(cx)).await?;
633635 require_form_csrf(&ctx, &form.csrf)?;
634636 require_owner(&ctx)?;
635- let state = app_context::<AppState>(cx);
636- let team = team_of(state, &ctx, path_param::<Team>(cx)).await?;
637+ let state = context::<AppState>(cx);
638+ let team = team_of(state, &ctx, team(cx)).await?;
637639 let back = ctx.href(&format!("/teams/{}", team.id));
638640
639641 let username = form.username.trim();
@@ -675,11 +677,11 @@ async fn org_team_member_add(cx: &Cx, Form(form): Form<TeamMemberForm>) -> Resul
675677 /// Removes a person from a team. Owners only.
676678 #[route(POST "/org/{org}/teams/{team}/members/remove")]
677679 async fn org_team_member_remove(cx: &Cx, Form(form): Form<TeamUserForm>) -> Result<SeeOther> {
678- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
680+ let ctx = load_org(cx, org(cx)).await?;
679681 require_form_csrf(&ctx, &form.csrf)?;
680682 require_owner(&ctx)?;
681- let state = app_context::<AppState>(cx);
682- let team = team_of(state, &ctx, path_param::<Team>(cx)).await?;
683+ let state = context::<AppState>(cx);
684+ let team = team_of(state, &ctx, team(cx)).await?;
683685 let back = ctx.href(&format!("/teams/{}", team.id));
684686
685687 let user_id = form.user_id.trim();
@@ -705,11 +707,11 @@ async fn org_team_member_remove(cx: &Cx, Form(form): Form<TeamUserForm>) -> Resu
705707 /// Links one of the org's repos to a team. Owners only.
706708 #[route(POST "/org/{org}/teams/{team}/repos/add")]
707709 async fn org_team_repo_add(cx: &Cx, Form(form): Form<TeamRepoForm>) -> Result<SeeOther> {
708- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
710+ let ctx = load_org(cx, org(cx)).await?;
709711 require_form_csrf(&ctx, &form.csrf)?;
710712 require_owner(&ctx)?;
711- let state = app_context::<AppState>(cx);
712- let team = team_of(state, &ctx, path_param::<Team>(cx)).await?;
713+ let state = context::<AppState>(cx);
714+ let team = team_of(state, &ctx, team(cx)).await?;
713715 let back = ctx.href(&format!("/teams/{}", team.id));
714716
715717 let repo_id = form.repo_id.trim();
@@ -742,11 +744,11 @@ async fn org_team_repo_add(cx: &Cx, Form(form): Form<TeamRepoForm>) -> Result<Se
742744 /// Unlinks a repo from a team. Owners only.
743745 #[route(POST "/org/{org}/teams/{team}/repos/remove")]
744746 async fn org_team_repo_remove(cx: &Cx, Form(form): Form<TeamRepoForm>) -> Result<SeeOther> {
745- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
747+ let ctx = load_org(cx, org(cx)).await?;
746748 require_form_csrf(&ctx, &form.csrf)?;
747749 require_owner(&ctx)?;
748- let state = app_context::<AppState>(cx);
749- let team = team_of(state, &ctx, path_param::<Team>(cx)).await?;
750+ let state = context::<AppState>(cx);
751+ let team = team_of(state, &ctx, team(cx)).await?;
750752 let back = ctx.href(&format!("/teams/{}", team.id));
751753
752754 let repo_id = form.repo_id.trim();
crates/forge-web/src/pages/packages.rsmodified+11 -11
@@ -9,7 +9,7 @@ use futures_util::{Stream, stream};
99 use serde::Deserialize;
1010 use tokio::sync::watch;
1111 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};
12+use topcoat::context::{Cx, context};
1313 use topcoat::router::content::Form;
1414 use topcoat::router::content::sse::Event;
1515 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
@@ -98,10 +98,10 @@ struct PackageQuery {
9898 /// The package page: the head with the install snippet, then one tab of README or versions.
9999 #[page("/{owner}/-/packages/{*pkg}")]
100100 async fn package_page(cx: &Cx) -> Result<impl View> {
101- let owner_name = path_param::<Owner>(cx);
102- let pkg_name = path_param::<Pkg>(cx).collect::<Vec<_>>().join("/");
101+ let owner_name = owner(cx);
102+ let pkg_name = pkg(cx).collect::<Vec<_>>().join("/");
103103 let pkg_name = pkg_name.as_str();
104- let state = app_context::<AppState>(cx);
104+ let state = context::<AppState>(cx);
105105 let viewer = current_user(cx).await?;
106106 let query = query_params::<PackageQuery>(cx)?;
107107 let actor = viewer.as_ref().map(|(u, _)| u);
@@ -202,7 +202,7 @@ async fn package_page(cx: &Cx) -> Result<impl View> {
202202 version_rows,
203203 lang,
204204 };
205- Ok(view! { cx =>
205+ Ok(view! {
206206 shell(title: title.as_str(), viewer: viewer.as_ref(),
207207 if let Some(page) = oci {
208208 oci_package_view(page: page)
@@ -228,8 +228,8 @@ struct TagDeleteForm {
228228 #[route(POST "/{owner}/-/packages/tags/delete")]
229229 async fn tag_delete(cx: &Cx, Form(form): Form<TagDeleteForm>) -> Result<SeeOther> {
230230 let (viewer, _) = require_csrf(cx, &form.csrf).await?;
231- let owner_name = path_param::<Owner>(cx);
232- let state = app_context::<AppState>(cx);
231+ let owner_name = owner(cx);
232+ let state = context::<AppState>(cx);
233233 let Some(owner) = state.store.user_by_username(owner_name).await? else {
234234 return Err(not_found().into());
235235 };
@@ -272,7 +272,7 @@ struct PackagePage {
272272
273273 /// The package page body.
274274 #[component]
275-async fn package_view(page: PackagePage) -> Result<impl View> {
275+async fn package_view(cx: &Cx, page: PackagePage) -> Result<impl View> {
276276 let lang = page.lang;
277277 let PackagePage {
278278 owner_name,
@@ -393,8 +393,8 @@ async fn package_view(page: PackagePage) -> Result<impl View> {
393393 /// on connect, since the page was just rendered.
394394 #[route(GET "/{owner}/-/packages/events")]
395395 async fn packages_events(cx: &Cx) -> Result<Response> {
396- let owner_name = path_param::<Owner>(cx);
397- let state = app_context::<AppState>(cx);
396+ let owner_name = owner(cx);
397+ let state = context::<AppState>(cx);
398398 let Some(owner) = state.store.user_by_username(owner_name).await? else {
399399 return Err(not_found().into());
400400 };
@@ -452,7 +452,7 @@ pub async fn repo_package_links(
452452
453453 /// The Packages card of a repo's sidebar: the packages linked to this repo.
454454 #[component]
455-pub async fn repo_packages_card(links: Vec<PackageLink>, lang: Lang) -> Result<impl View> {
455+pub async fn repo_packages_card(cx: &Cx, links: Vec<PackageLink>, lang: Lang) -> Result<impl View> {
456456 let heading = pk::t(lang, K::TabPackages);
457457 Ok(view! {
458458 <section class="sec repo-packages">
crates/forge-web/src/pages/packages_oci.rsmodified+2 -1
@@ -5,6 +5,7 @@
55 use forge_core::User;
66 use forge_core::packages::{OciTag, Package};
77 use topcoat::Result;
8+use topcoat::context::Cx;
89 use topcoat::view::{View, component, view};
910
1011 use crate::i18n::Lang;
@@ -72,7 +73,7 @@ fn short_digest(digest: &str) -> String {
7273
7374 /// The container package page body.
7475 #[component]
75-pub async fn oci_package_view(page: OciPage) -> Result<impl View> {
76+pub async fn oci_package_view(cx: &Cx, page: OciPage) -> Result<impl View> {
7677 let lang = page.lang;
7778 let OciPage {
7879 owner_name,
crates/forge-web/src/pages/palette.rsmodified+2 -2
@@ -21,7 +21,7 @@ use forge_core::store::orgs::OrgMemberRole;
2121 use http::header::{CACHE_CONTROL, CONTENT_TYPE, X_CONTENT_TYPE_OPTIONS};
2222 use serde_json::{Value, json};
2323 use topcoat::Result;
24-use topcoat::context::{Cx, app_context};
24+use topcoat::context::{Cx, context};
2525 use topcoat::router::response::Response;
2626 use topcoat::router::{Body, HeaderValue, StatusCode, route};
2727
@@ -379,7 +379,7 @@ async fn palette(cx: &Cx) -> Result<Response> {
379379 *res.status_mut() = StatusCode::UNAUTHORIZED;
380380 return Ok(res);
381381 };
382- let state = app_context::<AppState>(cx);
382+ let state = context::<AppState>(cx);
383383 let lang = i18n::lang(cx, Some(&user));
384384 let orgs = state.store.orgs_for_user(&user.id).await?;
385385
crates/forge-web/src/pages/passkeys.rsmodified+14 -9
@@ -19,7 +19,7 @@ use http::header::{HeaderValue, RETRY_AFTER};
1919 use serde::Deserialize;
2020 use serde_json::json;
2121 use topcoat::Result;
22-use topcoat::context::{Cx, app_context};
22+use topcoat::context::{Cx, context};
2323 use topcoat::router::content::Form;
2424 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
2525 use topcoat::router::response::Response;
@@ -250,7 +250,7 @@ struct LoginFinishForm {
250250 #[route(POST "/settings/security/passkeys/register/begin")]
251251 async fn register_begin(cx: &Cx, Form(form): Form<BeginForm>) -> Result<Response> {
252252 let viewer = require_csrf(cx, &form.csrf).await?;
253- let state = app_context::<AppState>(cx);
253+ let state = context::<AppState>(cx);
254254 let lang = i18n::lang(cx, Some(&viewer.0));
255255 let user = &viewer.0;
256256 let webauthn = match relying_party(&state.live().base_url) {
@@ -317,7 +317,7 @@ async fn register_begin(cx: &Cx, Form(form): Form<BeginForm>) -> Result<Response
317317 #[route(POST "/settings/security/passkeys/register/finish")]
318318 async fn register_finish(cx: &Cx, Form(form): Form<FinishForm>) -> Result<Response> {
319319 let viewer = require_csrf(cx, &form.csrf).await?;
320- let state = app_context::<AppState>(cx);
320+ let state = context::<AppState>(cx);
321321 let lang = i18n::lang(cx, Some(&viewer.0));
322322 let user = &viewer.0;
323323 let webauthn = match relying_party(&state.live().base_url) {
@@ -392,7 +392,7 @@ async fn register_finish(cx: &Cx, Form(form): Form<FinishForm>) -> Result<Respon
392392 #[route(POST "/settings/security/passkeys/{passkey_id}/rename")]
393393 async fn rename(cx: &Cx, Form(form): Form<RenameForm>) -> Result<SeeOther> {
394394 let (user, _session) = require_csrf(cx, &form.csrf).await?;
395- let state = app_context::<AppState>(cx);
395+ let state = context::<AppState>(cx);
396396 let id = path_param_segment(cx, "passkey_id").to_owned();
397397 let Ok(name) = clean_name(&form.name) else {
398398 return Ok(see_other("/settings/security?saved=passkey-bad-name"));
@@ -415,7 +415,7 @@ async fn rename(cx: &Cx, Form(form): Form<RenameForm>) -> Result<SeeOther> {
415415 #[route(POST "/settings/security/passkeys/{passkey_id}/delete")]
416416 async fn delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
417417 let (user, _session) = require_csrf(cx, &form.csrf).await?;
418- let state = app_context::<AppState>(cx);
418+ let state = context::<AppState>(cx);
419419 let id = path_param_segment(cx, "passkey_id").to_owned();
420420 // Only the owner's own list is searched, so another account's id looks like a missing one.
421421 let Some(row) = state
@@ -462,7 +462,7 @@ async fn login_begin(cx: &Cx, Form(form): Form<LoginBeginForm>) -> Result<Respon
462462 if !check_pre_csrf(cx, &form.precsrf) {
463463 return Err(forbidden().into());
464464 }
465- let state = app_context::<AppState>(cx);
465+ let state = context::<AppState>(cx);
466466 let lang = i18n::lang(cx, None);
467467 let ip_key = throttle::ip_key("passkey-ip", client_ip(cx));
468468 if let Some(retry) = state
@@ -502,7 +502,7 @@ async fn login_finish(cx: &Cx, Form(form): Form<LoginFinishForm>) -> Result<Resp
502502 if !check_pre_csrf(cx, &form.precsrf) {
503503 return Err(forbidden().into());
504504 }
505- let state = app_context::<AppState>(cx);
505+ let state = context::<AppState>(cx);
506506 let lang = i18n::lang(cx, None);
507507 let now = Instant::now();
508508 let ip_key = throttle::ip_key("passkey-ip", client_ip(cx));
@@ -650,7 +650,12 @@ pub async fn build_panel(state: &AppState, user_id: &str) -> forge_core::Result<
650650 /// The Passkeys topic of the security page: the list, rename and delete, and the add form that
651651 /// `nav.js` drives. The add form stays hidden until the browser proves it supports passkeys.
652652 #[component]
653-pub async fn passkeys_panel(lang: Lang, csrf: &str, panel: PasskeyPanel) -> Result<impl View> {
653+pub async fn passkeys_panel(
654+ cx: &Cx,
655+ lang: Lang,
656+ csrf: &str,
657+ panel: PasskeyPanel,
658+) -> Result<impl View> {
654659 let PasskeyPanel { items, problem } = panel;
655660 let empty = items.is_empty();
656661 let count_text = format!("{} {}", items.len(), s(lang, "passkeys", "geçiş anahtarı"));
@@ -721,7 +726,7 @@ pub async fn passkeys_panel(lang: Lang, csrf: &str, panel: PasskeyPanel) -> Resu
721726 /// The passkey button and its error line for the login page. Hidden until the browser proves it
722727 /// supports passkeys.
723728 #[component]
724-pub async fn login_passkey(lang: Lang) -> Result<impl View> {
729+pub async fn login_passkey(cx: &Cx, lang: Lang) -> Result<impl View> {
725730 Ok(view! {
726731 <div class="passkey-login" data-passkey-login="" hidden=(true)>
727732 <p class="passkey-or hint">(s(lang, "or", "veya"))</p>
crates/forge-web/src/pages/passkeys_tests.rsmodified+4 -1
@@ -598,7 +598,10 @@ async fn passkey_pages_show_the_ui_and_admins_remove_all_passkeys() {
598598 let page = send(&fx.router, "GET", &detail, session_cookie(ADMIN_TOKEN), &[]).await;
599599 assert_eq!(page.status, 200);
600600 assert!(page.body.contains("Remove every passkey of this user?"));
601- assert!(page.body.contains(&format!("action=\"{detail}/remove-passkeys\"")));
601+ assert!(
602+ page.body
603+ .contains(&format!("action=\"{detail}/remove-passkeys\""))
604+ );
602605
603606 let uri = format!("{detail}/remove-passkeys");
604607 let denied = send(
crates/forge-web/src/pages/profile.rsmodified+22 -9
@@ -14,7 +14,7 @@ use forge_core::store::repo_listing::RepoScope;
1414 use forge_core::tz::local_time_now;
1515 use forge_core::{Repo, User, Visibility};
1616 use topcoat::Result;
17-use topcoat::context::{Cx, app_context};
17+use topcoat::context::{Cx, context};
1818 use topcoat::router::error::not_found;
1919 use topcoat::router::response::Response;
2020 use topcoat::router::{page, path_param, query_params, route};
@@ -98,8 +98,8 @@ fn sort_key(raw: Option<&str>) -> &'static str {
9898
9999 #[page("/{username}")]
100100 async fn profile_page(cx: &Cx) -> Result<impl View> {
101- let name = path_param::<Username>(cx);
102- let state = app_context::<AppState>(cx);
101+ let name = username(cx);
102+ let state = context::<AppState>(cx);
103103 let viewer = current_user(cx).await?;
104104 let query = query_params::<ProfileQuery>(cx)?;
105105
@@ -234,7 +234,13 @@ async fn profile_page(cx: &Cx) -> Result<impl View> {
234234 let snippet_pages = snippet_total.div_ceil(PER_PAGE).max(1);
235235 let snippet_page = page.min(snippet_pages);
236236 let snippet_pager = pager_links(snippet_page, snippet_pages, |n| {
237- profile_href(&user.username, "snippets", &Finder::default(), SORTS[0].0, n)
237+ profile_href(
238+ &user.username,
239+ "snippets",
240+ &Finder::default(),
241+ SORTS[0].0,
242+ n,
243+ )
238244 });
239245 let snippets: Vec<ListRow> = snippets
240246 .into_iter()
@@ -370,7 +376,7 @@ async fn profile_page(cx: &Cx) -> Result<impl View> {
370376 // A repo deleted just before this redirect here shows its one-line notice once.
371377 let notice = take_notice(cx);
372378 let title = user.username.clone();
373- Ok(view! { cx =>
379+ Ok(view! {
374380 shell(title: title.as_str(), viewer: viewer.as_ref(),
375381 notice_banner_for(lang: lang, title: notice)
376382 profile_card(user: user, avatar: avatar, about_html: about_html, local_time: local_time,
@@ -390,8 +396,8 @@ async fn profile_page(cx: &Cx) -> Result<impl View> {
390396 /// comes from the session, so what it sends is what that viewer may read. An unknown name is 404.
391397 #[route(GET "/users/{username}/events")]
392398 async fn profile_events(cx: &Cx) -> Result<Response> {
393- let name = path_param::<Username>(cx);
394- let state = app_context::<AppState>(cx).clone();
399+ let name = username(cx);
400+ let state = context::<AppState>(cx).clone();
395401 let Some(user) = state.store.user_by_username(name).await? else {
396402 return Err(not_found().into());
397403 };
@@ -601,6 +607,7 @@ async fn readable(
601607
602608 #[component]
603609 async fn profile_card(
610+ cx: &Cx,
604611 user: User,
605612 avatar: Option<String>,
606613 about_html: String,
@@ -875,10 +882,15 @@ async fn profile_card(
875882 /// The viewer's own profile tabs on a page that makes something of theirs (a repository, a
876883 /// snippet, an organization): the same tabs and counts as their profile, with `current` marked.
877884 #[component]
878-pub async fn own_profile_tabs(lang: Lang, username: String, current: String) -> Result<impl View> {
885+pub async fn own_profile_tabs(
886+ cx: &Cx,
887+ lang: Lang,
888+ username: String,
889+ current: String,
890+) -> Result<impl View> {
879891 let items = crate::views::profile_items(lang, &username, false, true, false);
880892 let mut counts = Vec::new();
881- if let Some(state) = topcoat::context::try_app_context::<AppState>(__cx)
893+ if let Some(state) = topcoat::context::try_context::<AppState>(cx)
882894 && let Some(user) = state.store.user_by_username(&username).await?
883895 {
884896 let actor = Some(&user);
@@ -913,6 +925,7 @@ pub async fn own_profile_tabs(lang: Lang, username: String, current: String) ->
913925 /// organization's member pages all render it.
914926 #[component]
915927 pub async fn profile_tabs(
928+ cx: &Cx,
916929 username: String,
917930 items: Vec<NavItem>,
918931 current: String,
crates/forge-web/src/pages/profile_pins.rsmodified+6 -5
@@ -5,7 +5,7 @@
55 use forge_core::store::profile_pins::MAX_PROFILE_PINS;
66 use forge_core::{Repo, Store, User};
77 use topcoat::Result;
8-use topcoat::context::{Cx, app_context};
8+use topcoat::context::{Cx, context};
99 use topcoat::router::content::RawForm;
1010 use topcoat::router::error::{SeeOther, see_other};
1111 use topcoat::router::{path_param, route};
@@ -60,6 +60,7 @@ fn selection(raw: Vec<String>) -> Vec<String> {
6060 /// the result after the redirect.
6161 #[component]
6262 pub(crate) async fn pins_menu(
63+ cx: &Cx,
6364 lang: Lang,
6465 action: String,
6566 csrf: String,
@@ -117,13 +118,13 @@ async fn pins_save(cx: &Cx, RawForm(raw): RawForm) -> Result<SeeOther> {
117118 let chosen = selection(form_all(&pairs, "repo"));
118119 let back = format!("/{}", viewer.0.username);
119120 let owner = viewer.0.clone();
120- save_pins(app_context::<AppState>(cx), owner, chosen, back).await
121+ save_pins(context::<AppState>(cx), owner, chosen, back).await
121122 }
122123
123124 /// Pins are picked on the profile; an old link lands there. Owners only, as the form was.
124125 #[route(GET "/org/{org}/settings/pins")]
125126 async fn org_pins_page(cx: &Cx) -> Result<SeeOther> {
126- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
127+ let ctx = load_org(cx, org(cx)).await?;
127128 require_owner(&ctx)?;
128129 Err(see_other(format!("/{}", ctx.org.username)).into())
129130 }
@@ -131,13 +132,13 @@ async fn org_pins_page(cx: &Cx) -> Result<SeeOther> {
131132 /// Saves an organization's pins, then back to the org profile. Owners only.
132133 #[route(POST "/org/{org}/settings/pins")]
133134 async fn org_pins_save(cx: &Cx, RawForm(raw): RawForm) -> Result<SeeOther> {
134- let ctx = load_org(cx, path_param::<Org>(cx)).await?;
135+ let ctx = load_org(cx, org(cx)).await?;
135136 let pairs = form_pairs(&raw[..]);
136137 require_form_csrf(&ctx, &form_field(&pairs, "csrf"))?;
137138 require_owner(&ctx)?;
138139 let chosen = selection(form_all(&pairs, "repo"));
139140 let back = format!("/{}", ctx.org.username);
140- save_pins(app_context::<AppState>(cx), ctx.org, chosen, back).await
141+ save_pins(context::<AppState>(cx), ctx.org, chosen, back).await
141142 }
142143
143144 #[cfg(test)]
crates/forge-web/src/pages/pull_branch.rsmodified+5 -4
@@ -17,7 +17,7 @@ use forge_git::repo::repo_path;
1717 use serde::Deserialize;
1818 use serde_json::json;
1919 use topcoat::Result;
20-use topcoat::context::{Cx, app_context};
20+use topcoat::context::{Cx, context};
2121 use topcoat::router::content::Form;
2222 use topcoat::router::error::{forbidden, not_found, see_other};
2323 use topcoat::router::request::uri;
@@ -81,10 +81,10 @@ async fn restore_branch_post(cx: &Cx, Form(form): Form<BranchForm>) -> Result<Re
8181 }
8282
8383 async fn branch_post(cx: &Cx, csrf: &str, op: Op) -> Result<Response> {
84- let number = parse_number(path_param::<Number>(cx))?;
85- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
84+ let number = parse_number(number(cx))?;
85+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
8686 let (user, _) = require_csrf(cx, csrf).await?;
87- let state = app_context::<AppState>(cx);
87+ let state = context::<AppState>(cx);
8888 let Some(pr) = state.store.pull_by_number(&ctx.repo.id, number).await? else {
8989 return Err(not_found().into());
9090 };
@@ -374,6 +374,7 @@ pub(crate) fn branch_error_from(cx: &Cx, lang: Lang) -> Option<String> {
374374 /// when the viewer may act, the delete or restore tool.
375375 #[component]
376376 pub(crate) async fn branch_box(
377+ cx: &Cx,
377378 lang: Lang,
378379 action: Option<BranchAction>,
379380 error: Option<String>,
crates/forge-web/src/pages/pull_files.rsmodified+16 -14
@@ -13,7 +13,7 @@ use forge_git::history::{CommitDiff, DiffStatus, FileDiff};
1313 use forge_git::pulls::{blob_at, range_diff_files_ws};
1414 use serde::Deserialize;
1515 use topcoat::Result;
16-use topcoat::context::{Cx, app_context};
16+use topcoat::context::{Cx, context};
1717 use topcoat::router::content::Form;
1818 use topcoat::router::error::{SeeOther, not_found, see_other};
1919 use topcoat::router::request::uri;
@@ -26,9 +26,7 @@ use crate::i18n::pulls as review_strings;
2626 use crate::i18n::pulls::{self as g, K};
2727 use crate::i18n::{self, Lang};
2828 use crate::pages::edit_history::thread_edit_counts;
29-use crate::pages::issue_parts::{
30- check_write, csrf_of, may_converse, parse_number, triage, viewer,
31-};
29+use crate::pages::issue_parts::{check_write, csrf_of, may_converse, parse_number, triage, viewer};
3230 use crate::pages::passkeys;
3331 use crate::pages::pull_reviews::{error_text_in, pull_diff, suggest_states};
3432 use crate::pages::pull_view::{commits_of, frame_in, is_merged, pull_header};
@@ -206,6 +204,7 @@ struct RailFile {
206204 /// toggle, and a changed file says so.
207205 #[component]
208206 async fn files_rail(
207+ cx: &Cx,
209208 lang: Lang,
210209 rows: Vec<RailFile>,
211210 done_text: String,
@@ -253,6 +252,7 @@ async fn files_rail(
253252 /// The diff pane's top row: Unified or Split, and whitespace. Its links are the toolbar's own.
254253 #[component]
255254 async fn diff_top(
255+ cx: &Cx,
256256 lang: Lang,
257257 unified: String,
258258 split: String,
@@ -286,11 +286,11 @@ struct ViewedForm {
286286 /// unreadable repo answers with the same not-found.
287287 #[route(POST "/{owner}/{repo}/pulls/{number}/viewed")]
288288 async fn viewed_post(cx: &Cx, Form(form): Form<ViewedForm>) -> Result<SeeOther> {
289- let number = parse_number(path_param::<Number>(cx))?;
290- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
289+ let number = parse_number(number(cx))?;
290+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
291291 let (user, session) = require_user(cx).await?;
292292 check_write(&ctx, &session, &form.csrf)?;
293- let state = app_context::<AppState>(cx);
293+ let state = context::<AppState>(cx);
294294 let pr = match state.store.pull_by_number(&ctx.repo.id, number).await? {
295295 Some(pr) => pr,
296296 None => return Err(not_found().into()),
@@ -334,6 +334,7 @@ async fn viewed_post(cx: &Cx, Form(form): Form<ViewedForm>) -> Result<SeeOther>
334334 /// Request changes in the pull's head submit the same form.
335335 #[component]
336336 async fn review_bar(
337+ cx: &Cx,
337338 lang: Lang,
338339 pr_href: String,
339340 csrf: String,
@@ -413,9 +414,9 @@ fn file_param(cx: &Cx) -> Option<usize> {
413414
414415 #[page("/{owner}/{repo}/pulls/{number}/files")]
415416 async fn pull_files(cx: &Cx) -> Result<impl View> {
416- let number = parse_number(path_param::<Number>(cx))?;
417- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
418- let state = app_context::<AppState>(cx);
417+ let number = parse_number(number(cx))?;
418+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
419+ let state = context::<AppState>(cx);
419420 let pr = match state.store.pull_by_number(&ctx.repo.id, number).await? {
420421 Some(pr) => pr,
421422 None => return Err(not_found().into()),
@@ -568,7 +569,10 @@ async fn pull_files(cx: &Cx) -> Result<impl View> {
568569 .as_ref()
569570 .map(|c| format!("{}/viewed", c.pr_href))
570571 .unwrap_or_default();
571- let panel_csrf = controls.as_ref().map(|c| c.csrf.clone()).unwrap_or_default();
572+ let panel_csrf = controls
573+ .as_ref()
574+ .map(|c| c.csrf.clone())
575+ .unwrap_or_default();
572576
573577 let done = rows
574578 .iter()
@@ -653,9 +657,7 @@ async fn pull_files(cx: &Cx) -> Result<impl View> {
653657 }
654658 .to_owned(),
655659 tick,
656- href: row
657- .index
658- .map(|i| format!("?file={i}#file-{}", i + 1)),
660+ href: row.index.map(|i| format!("?file={i}#file-{}", i + 1)),
659661 path: row.path,
660662 label: row.label,
661663 state: row.state,
crates/forge-web/src/pages/pull_flow.rsmodified+11 -11
@@ -13,7 +13,7 @@
1313 use forge_core::{Action, IssueState, MergeStyle, PullRequest, authorize};
1414 use serde::Deserialize;
1515 use topcoat::Result;
16-use topcoat::context::{Cx, app_context};
16+use topcoat::context::{Cx, context};
1717 use topcoat::router::content::Form;
1818 use topcoat::router::error::{bad_request, forbidden, not_found, see_other};
1919 use topcoat::router::response::Response;
@@ -54,7 +54,7 @@ fn can_write(ctx: &RepoCtx, user: &forge_core::User) -> bool {
5454 }
5555
5656 async fn load(cx: &Cx, ctx: &RepoCtx, number: i64) -> Result<PullRequest> {
57- let state = app_context::<AppState>(cx);
57+ let state = context::<AppState>(cx);
5858 match state.store.pull_by_number(&ctx.repo.id, number).await? {
5959 Some(pr) => Ok(pr),
6060 None => Err(not_found().into()),
@@ -72,10 +72,10 @@ async fn draft_post(cx: &Cx, Form(form): Form<FlowForm>) -> Result<Response> {
7272 }
7373
7474 async fn set_draft(cx: &Cx, csrf: &str, draft: bool) -> Result<Response> {
75- let number = parse_number(path_param::<Number>(cx))?;
76- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
75+ let number = parse_number(number(cx))?;
76+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
7777 let (user, _) = require_csrf(cx, csrf).await?;
78- let state = app_context::<AppState>(cx);
78+ let state = context::<AppState>(cx);
7979 let pr = load(cx, &ctx, number).await?;
8080 if ctx.repo.archived || !(can_write(&ctx, &user) || user.id == pr.issue.author_id) {
8181 return Err(forbidden().into());
@@ -118,13 +118,13 @@ async fn set_draft(cx: &Cx, csrf: &str, draft: bool) -> Result<Response> {
118118
119119 #[route(POST "/{owner}/{repo}/pulls/{number}/auto-merge")]
120120 async fn auto_merge_enable(cx: &Cx, Form(form): Form<FlowForm>) -> Result<Response> {
121- let number = parse_number(path_param::<Number>(cx))?;
122- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
121+ let number = parse_number(number(cx))?;
122+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
123123 let (user, _) = require_csrf(cx, &form.csrf).await?;
124124 if ctx.repo.archived || !can_write(&ctx, &user) {
125125 return Err(forbidden().into());
126126 }
127- let state = app_context::<AppState>(cx);
127+ let state = context::<AppState>(cx);
128128 let pr = load(cx, &ctx, number).await?;
129129 let style = form
130130 .style
@@ -149,13 +149,13 @@ async fn auto_merge_enable(cx: &Cx, Form(form): Form<FlowForm>) -> Result<Respon
149149
150150 #[route(POST "/{owner}/{repo}/pulls/{number}/auto-merge/disable")]
151151 async fn auto_merge_disable(cx: &Cx, Form(form): Form<FlowForm>) -> Result<Response> {
152- let number = parse_number(path_param::<Number>(cx))?;
153- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
152+ let number = parse_number(number(cx))?;
153+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
154154 let (user, _) = require_csrf(cx, &form.csrf).await?;
155155 if ctx.repo.archived || !can_write(&ctx, &user) {
156156 return Err(forbidden().into());
157157 }
158- let state = app_context::<AppState>(cx);
158+ let state = context::<AppState>(cx);
159159 let pr = load(cx, &ctx, number).await?;
160160 state
161161 .store
crates/forge-web/src/pages/pull_live.rsmodified+7 -7
@@ -18,7 +18,7 @@ use forge_core::PullRequest;
1818 use forge_core::reactions::ReactionTarget;
1919 use forge_core::store::Store;
2020 use topcoat::Result;
21-use topcoat::context::{Cx, app_context};
21+use topcoat::context::{Cx, context};
2222 use topcoat::router::request::{method, uri};
2323 use topcoat::router::response::Response;
2424 use topcoat::router::{Body, Layer, LayerFuture, Method, Next, Path, path_param, route};
@@ -202,8 +202,8 @@ pub fn pull_live_url(owner: &str, repo: &str, number: i64) -> String {
202202 /// The pull list's change stream. Auth is the repo read check of the list page.
203203 #[route(GET "/{owner}/{repo}/pulls/events")]
204204 async fn pulls_events(cx: &Cx) -> Result<Response> {
205- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
206- let state = app_context::<AppState>(cx);
205+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
206+ let state = context::<AppState>(cx);
207207 let topic = Topic::PullList(ctx.repo.id.clone());
208208 let store = state.store.clone();
209209 let repo_id = ctx.repo.id.clone();
@@ -220,9 +220,9 @@ async fn pulls_events(cx: &Cx) -> Result<Response> {
220220 /// One pull request's change stream. Auth is the page's: the repo read check, then the pull.
221221 #[route(GET "/{owner}/{repo}/pulls/{number}/events")]
222222 async fn pull_events(cx: &Cx) -> Result<Response> {
223- let number = parse_number(path_param::<Number>(cx))?;
224- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
225- let state = app_context::<AppState>(cx);
223+ let number = parse_number(number(cx))?;
224+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
225+ let state = context::<AppState>(cx);
226226 let Some(pr) = state.store.pull_by_number(&ctx.repo.id, number).await? else {
227227 return Err(topcoat::router::error::not_found().into());
228228 };
@@ -284,7 +284,7 @@ async fn bump_after_write(cx: &Cx, body: Body, next: Next<'_>) -> topcoat::Resul
284284 let target = written(cx);
285285 let result = next.run(cx, body).await;
286286 if let Some(target) = target {
287- bump_written(app_context::<AppState>(cx), target).await;
287+ bump_written(context::<AppState>(cx), target).await;
288288 }
289289 result
290290 }
crates/forge-web/src/pages/pull_reviews.rsmodified+40 -40
@@ -20,7 +20,7 @@ use forge_git::history::{CommitDiff, DiffStatus, FileDiff, LineKind};
2020 use forge_git::pulls::{FileEdit, Signature, commit_file_edit, range_diff_files};
2121 use serde::Deserialize;
2222 use topcoat::Result;
23-use topcoat::context::{Cx, app_context};
23+use topcoat::context::{Cx, context};
2424 use topcoat::router::content::Form;
2525 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
2626 use topcoat::router::request::uri;
@@ -341,11 +341,11 @@ fn signature_of(state: &AppState, user: &User) -> Signature {
341341 /// request must name the head the form was rendered for, and the line must be on that diff.
342342 #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments")]
343343 async fn review_comment_post(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {
344- let number = parse_number(path_param::<Number>(cx))?;
345- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
344+ let number = parse_number(number(cx))?;
345+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
346346 let (user, session) = require_user(cx).await?;
347347 check_write(&ctx, &session, &form.csrf)?;
348- let state = app_context::<AppState>(cx);
348+ let state = context::<AppState>(cx);
349349 let pr = pull_for(state, &ctx, number).await?;
350350 if !may_converse(&ctx, &pr.issue) {
351351 return Err(forbidden().into());
@@ -411,16 +411,16 @@ async fn review_comment_post(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<Se
411411 /// Replies in the thread of a root comment. Replies post at once, even on a closed pull request.
412412 #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/reply")]
413413 async fn review_comment_reply(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {
414- let number = parse_number(path_param::<Number>(cx))?;
415- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
414+ let number = parse_number(number(cx))?;
415+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
416416 let (user, session) = require_user(cx).await?;
417417 check_write(&ctx, &session, &form.csrf)?;
418- let state = app_context::<AppState>(cx);
418+ let state = context::<AppState>(cx);
419419 let pr = pull_for(state, &ctx, number).await?;
420420 if !may_converse(&ctx, &pr.issue) {
421421 return Err(forbidden().into());
422422 }
423- let parent = comment_on_pull(state, &pr, &user, path_param::<CommentId>(cx)).await?;
423+ let parent = comment_on_pull(state, &pr, &user, comment_id(cx)).await?;
424424 let root = root_of(&parent);
425425 let tab = tab_url(&ctx, number, &form.ret);
426426 let anchor = format!("#rc-{root}");
@@ -441,13 +441,13 @@ async fn review_comment_reply(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<S
441441 /// The edit form for a comment. Only its author may open it.
442442 #[page("/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/edit")]
443443 async fn review_comment_edit_form(cx: &Cx) -> Result<impl View> {
444- let number = parse_number(path_param::<Number>(cx))?;
445- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
444+ let number = parse_number(number(cx))?;
445+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
446446 let (user, _) = require_user(cx).await?;
447447 let lang = i18n::lang(cx, Some(&user));
448- let state = app_context::<AppState>(cx);
448+ let state = context::<AppState>(cx);
449449 let pr = pull_for(state, &ctx, number).await?;
450- let comment = comment_on_pull(state, &pr, &user, path_param::<CommentId>(cx)).await?;
450+ let comment = comment_on_pull(state, &pr, &user, comment_id(cx)).await?;
451451 if comment.author_id != user.id {
452452 return Err(forbidden().into());
453453 }
@@ -464,7 +464,7 @@ async fn edit_page(
464464 error: Option<&'static str>,
465465 lang: Lang,
466466 ) -> Result<impl View> {
467- let state = app_context::<AppState>(cx);
467+ let state = context::<AppState>(cx);
468468 let owner = ctx.repo.owner_name.clone();
469469 let name = ctx.repo.name.clone();
470470 let csrf = csrf_of(&ctx);
@@ -481,7 +481,7 @@ async fn edit_page(
481481 let save_label = g::t(lang, K::SaveComment);
482482 let cancel_label = g::t(lang, K::CancelButton);
483483 let header = ctx.head(state, "pulls").await?;
484- Ok(view! { cx =>
484+ Ok(view! {
485485 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(),
486486 repo_head(head: header, title: Some(heading.to_owned()))
487487 <div class="sheet fit">
@@ -507,13 +507,13 @@ async fn edit_page(
507507 /// Saves an edited comment. Only its author; the store records the previous body.
508508 #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/edit")]
509509 async fn review_comment_edit_save(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {
510- let number = parse_number(path_param::<Number>(cx))?;
511- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
510+ let number = parse_number(number(cx))?;
511+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
512512 let (user, session) = require_user(cx).await?;
513513 check_write(&ctx, &session, &form.csrf)?;
514- let state = app_context::<AppState>(cx);
514+ let state = context::<AppState>(cx);
515515 let pr = pull_for(state, &ctx, number).await?;
516- let comment = comment_on_pull(state, &pr, &user, path_param::<CommentId>(cx)).await?;
516+ let comment = comment_on_pull(state, &pr, &user, comment_id(cx)).await?;
517517 if comment.author_id != user.id {
518518 return Err(forbidden().into());
519519 }
@@ -543,13 +543,13 @@ async fn review_comment_edit_save(cx: &Cx, Form(form): Form<ReviewForm>) -> Resu
543543 /// Deletes a comment. Its author or Triage. Deleting a root deletes its replies.
544544 #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/delete")]
545545 async fn review_comment_delete(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {
546- let number = parse_number(path_param::<Number>(cx))?;
547- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
546+ let number = parse_number(number(cx))?;
547+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
548548 let (user, session) = require_user(cx).await?;
549549 check_write(&ctx, &session, &form.csrf)?;
550- let state = app_context::<AppState>(cx);
550+ let state = context::<AppState>(cx);
551551 let pr = pull_for(state, &ctx, number).await?;
552- let comment = comment_on_pull(state, &pr, &user, path_param::<CommentId>(cx)).await?;
552+ let comment = comment_on_pull(state, &pr, &user, comment_id(cx)).await?;
553553 if !may_change(&ctx, &comment.author_id) {
554554 return Err(forbidden().into());
555555 }
@@ -565,13 +565,13 @@ async fn review_comment_delete(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<
565565 /// Resolves or unresolves a thread (`resolved=1|0`). The PR author or Write.
566566 #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/resolve")]
567567 async fn review_comment_resolve(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {
568- let number = parse_number(path_param::<Number>(cx))?;
569- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
568+ let number = parse_number(number(cx))?;
569+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
570570 let (user, session) = require_user(cx).await?;
571571 check_write(&ctx, &session, &form.csrf)?;
572- let state = app_context::<AppState>(cx);
572+ let state = context::<AppState>(cx);
573573 let pr = pull_for(state, &ctx, number).await?;
574- let comment = comment_on_pull(state, &pr, &user, path_param::<CommentId>(cx)).await?;
574+ let comment = comment_on_pull(state, &pr, &user, comment_id(cx)).await?;
575575 let is_pr_author = pr.issue.author_id == user.id;
576576 if !is_pr_author
577577 && authorize(
@@ -607,13 +607,13 @@ async fn review_comment_resolve(cx: &Cx, Form(form): Form<ReviewForm>) -> Result
607607 /// suggestion was written against.
608608 #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/apply")]
609609 async fn review_comment_apply(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {
610- let number = parse_number(path_param::<Number>(cx))?;
611- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
610+ let number = parse_number(number(cx))?;
611+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
612612 let (user, session) = require_user(cx).await?;
613613 check_write(&ctx, &session, &form.csrf)?;
614- let state = app_context::<AppState>(cx);
614+ let state = context::<AppState>(cx);
615615 let pr = pull_for(state, &ctx, number).await?;
616- let comment = comment_on_pull(state, &pr, &user, path_param::<CommentId>(cx)).await?;
616+ let comment = comment_on_pull(state, &pr, &user, comment_id(cx)).await?;
617617 let files = tab_url(&ctx, number, &form.ret);
618618 let anchor = format!("#rc-{}", comment.id);
619619 if comment.reply_to.is_some() || comment.pending || comment.side != Side::New {
@@ -697,11 +697,11 @@ async fn review_comment_apply(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<S
697697 /// cannot approve or request changes on their own pull request. Closed pull requests refuse it.
698698 #[route(POST "/{owner}/{repo}/pulls/{number}/reviews")]
699699 async fn review_submit(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {
700- let number = parse_number(path_param::<Number>(cx))?;
701- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
700+ let number = parse_number(number(cx))?;
701+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
702702 let (user, session) = require_user(cx).await?;
703703 check_write(&ctx, &session, &form.csrf)?;
704- let state = app_context::<AppState>(cx);
704+ let state = context::<AppState>(cx);
705705 let pr = pull_for(state, &ctx, number).await?;
706706 if !may_converse(&ctx, &pr.issue) {
707707 return Err(forbidden().into());
@@ -772,11 +772,11 @@ async fn review_text(
772772 /// Discards the viewer's pending review and its draft comments.
773773 #[route(POST "/{owner}/{repo}/pulls/{number}/reviews/discard")]
774774 async fn review_discard(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {
775- let number = parse_number(path_param::<Number>(cx))?;
776- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
775+ let number = parse_number(number(cx))?;
776+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
777777 let (user, session) = require_user(cx).await?;
778778 check_write(&ctx, &session, &form.csrf)?;
779- let state = app_context::<AppState>(cx);
779+ let state = context::<AppState>(cx);
780780 let pr = pull_for(state, &ctx, number).await?;
781781 state
782782 .store
@@ -788,8 +788,8 @@ async fn review_discard(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOthe
788788 /// Dismisses an approval or a change request with a reason. Write only.
789789 #[route(POST "/{owner}/{repo}/pulls/{number}/reviews/{review_id}/dismiss")]
790790 async fn review_dismiss(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {
791- let number = parse_number(path_param::<Number>(cx))?;
792- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
791+ let number = parse_number(number(cx))?;
792+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
793793 let (user, session) = require_user(cx).await?;
794794 check_write(&ctx, &session, &form.csrf)?;
795795 if authorize(
@@ -803,9 +803,9 @@ async fn review_dismiss(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOthe
803803 {
804804 return Err(forbidden().into());
805805 }
806- let state = app_context::<AppState>(cx);
806+ let state = context::<AppState>(cx);
807807 let pr = pull_for(state, &ctx, number).await?;
808- let wanted = path_param::<ReviewId>(cx);
808+ let wanted = review_id(cx);
809809 let Some(review) = state
810810 .store
811811 .list_reviews(&pr.issue.id)
crates/forge-web/src/pages/pull_view.rsmodified+21 -20
@@ -12,7 +12,7 @@ use forge_git::browse::CommitInfo;
1212 use forge_git::history::CommitDiff;
1313 use forge_git::pulls::{is_ancestor, range_diff_files, range_log};
1414 use topcoat::Result;
15-use topcoat::context::{Cx, app_context};
15+use topcoat::context::{Cx, context};
1616 use topcoat::router::content::Form;
1717 use topcoat::router::error::{not_found, see_other};
1818 use topcoat::router::request::uri;
@@ -69,9 +69,9 @@ async fn pull_for(state: &AppState, ctx: &RepoCtx, number: i64) -> Result<PullRe
6969
7070 /// The repo and pull request for a request whose path names `{owner}/{repo}/pulls/{number}`.
7171 async fn load_pull(cx: &Cx) -> Result<(RepoCtx, PullRequest)> {
72- let number = parse_number(path_param::<Number>(cx))?;
73- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
74- let pr = pull_for(app_context::<AppState>(cx), &ctx, number).await?;
72+ let number = parse_number(number(cx))?;
73+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
74+ let pr = pull_for(context::<AppState>(cx), &ctx, number).await?;
7575 Ok((ctx, pr))
7676 }
7777
@@ -192,6 +192,7 @@ pub(crate) async fn frame_in(
192192 /// then the pull request's tabs. `active` names the tab that is open.
193193 #[component]
194194 pub(crate) async fn pull_header(
195+ cx: &Cx,
195196 frame: Frame,
196197 active: String,
197198 #[default] child: Child<'_>,
@@ -317,6 +318,7 @@ struct FlowView {
317318 /// `ok`, `bad` or `muted` and picks the box colors.
318319 #[component]
319320 async fn merge_box(
321+ cx: &Cx,
320322 headline: String,
321323 tone: String,
322324 conflicts: Vec<String>,
@@ -458,6 +460,7 @@ async fn merge_box(
458460 /// The note that replaces the merge box once the pull request is merged.
459461 #[component]
460462 async fn merged_notice(
463+ cx: &Cx,
461464 who: String,
462465 when: When,
463466 commit: String,
@@ -500,6 +503,7 @@ struct DismissRow {
500503 /// holders. Either summary line may be absent.
501504 #[component]
502505 async fn review_box(
506+ cx: &Cx,
503507 approved: Option<String>,
504508 approved_before: Option<String>,
505509 changes: Option<String>,
@@ -571,7 +575,7 @@ async fn head_checks(
571575 }
572576
573577 #[component]
574-async fn commit_list(rows: Vec<CommitRow>, lang: Lang) -> Result<impl View> {
578+async fn commit_list(cx: &Cx, rows: Vec<CommitRow>, lang: Lang) -> Result<impl View> {
575579 let empty = rows.is_empty();
576580 let no_commits = g::t(lang, K::NoCommits);
577581 let committed = g::t(lang, K::Committed);
@@ -612,7 +616,7 @@ async fn pull_conversation(
612616 error: Option<String>,
613617 merge_error: Option<String>,
614618 ) -> Result<impl View> {
615- let state = app_context::<AppState>(cx);
619+ let state = context::<AppState>(cx);
616620 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
617621 let commit_count = commits_of(state, &ctx, &pr).await?.len();
618622 let file_count = diff_of(state, &ctx, &pr).await?.files.len();
@@ -899,7 +903,7 @@ async fn pull_conversation(
899903 let labels_href = repo_href(&owner, &name, "labels.css", "");
900904 // The conversation follows the pull request's event stream: a change re-renders it.
901905 let live = format!("{href}/events");
902- Ok(view! { cx =>
906+ Ok(view! {
903907 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(), extra_stylesheet: Some(labels_href.as_str()),
904908 pull_header(frame: frame.clone(), active: "conversation".to_owned(),
905909 item_head_tools(lang: lang, close: close, notify: notify)
@@ -1005,7 +1009,7 @@ async fn pull_show(cx: &Cx) -> Result<impl View> {
10051009 #[page("/{owner}/{repo}/pulls/{number}/commits")]
10061010 async fn pull_commits(cx: &Cx) -> Result<impl View> {
10071011 let (ctx, pr) = load_pull(cx).await?;
1008- let state = app_context::<AppState>(cx);
1012+ let state = context::<AppState>(cx);
10091013 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
10101014 let commits = commits_of(state, &ctx, &pr).await?;
10111015 let file_count = diff_of(state, &ctx, &pr).await?.files.len();
@@ -1042,11 +1046,11 @@ async fn pull_commits(cx: &Cx) -> Result<impl View> {
10421046 /// routes. A merged pull request's state cannot change, and a refused comment re-renders the
10431047 /// Conversation with its text.
10441048 async fn pull_post(cx: &Cx, form: CommentForm) -> Result<impl View> {
1045- let number = parse_number(path_param::<Number>(cx))?;
1046- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
1049+ let number = parse_number(number(cx))?;
1050+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
10471051 let (user, session) = require_user(cx).await?;
10481052 check_write(&ctx, &session, &form.csrf)?;
1049- let state = app_context::<AppState>(cx);
1053+ let state = context::<AppState>(cx);
10501054 let pr = pull_for(state, &ctx, number).await?;
10511055 let lang = i18n::lang(cx, Some(&user));
10521056
@@ -1301,10 +1305,7 @@ mod tests {
13011305 assert_eq!(status, 200, "clean");
13021306 assert!(body.contains("Add feature"), "clean: {body}");
13031307 assert!(body.contains("issue-badge-open\">Open<"), "clean: {body}");
1304- assert!(
1305- body.contains("Ready to merge"),
1306- "clean: {body}"
1307- );
1308+ assert!(body.contains("Ready to merge"), "clean: {body}");
13081309 assert!(
13091310 body.contains(&format!("action=\"{uri}/merge\"")),
13101311 "clean: {body}"
@@ -1320,10 +1321,7 @@ mod tests {
13201321 // A reader sees the clean status but no merge form.
13211322 let (status, _, body) = send(&fx.router, "GET", &uri, Some("bob-token"), None).await;
13221323 assert_eq!(status, 200, "reader");
1323- assert!(
1324- body.contains("Ready to merge"),
1325- "reader: {body}"
1326- );
1324+ assert!(body.contains("Ready to merge"), "reader: {body}");
13271325 assert!(!body.contains("name=\"style\""), "reader: {body}");
13281326 assert!(!body.contains("Merge pull request"), "reader: {body}");
13291327
@@ -1723,7 +1721,10 @@ mod tests {
17231721 assert!(body.contains("Please rename this"), "approval: {body}");
17241722 assert!(body.contains("feat.txt:1"), "approval: {body}");
17251723 assert!(body.contains("@@ -0,0 +1 @@"), "approval: {body}");
1726- assert!(body.contains("<span class=\"badge\">Outdated</span>"), "approval: {body}");
1724+ assert!(
1725+ body.contains("<span class=\"badge\">Outdated</span>"),
1726+ "approval: {body}"
1727+ );
17271728 assert!(body.contains("Approved by bob"), "approval: {body}");
17281729
17291730 fx.store
crates/forge-web/src/pages/pulls_list.rsmodified+16 -10
@@ -8,7 +8,7 @@ use std::collections::HashMap;
88 use forge_core::tz::format_in_tz;
99 use forge_core::{IssueListItem, IssueState};
1010 use topcoat::Result;
11-use topcoat::context::{Cx, app_context};
11+use topcoat::context::{Cx, context};
1212 use topcoat::router::{page, path_param, query_params};
1313 use topcoat::view::{View, view};
1414
@@ -16,13 +16,12 @@ use crate::i18n::merge_queue as mq;
1616 use crate::i18n::pulls::{self as g, K};
1717 use crate::i18n::{self, Lang};
1818 use crate::pages::issues_list::{
19- AssigneeView, LabelView, ListQuery, MilestoneView, Selection, SortOption, list_href,
20- stamp_unix,
19+ AssigneeView, LabelView, ListQuery, MilestoneView, Selection, SortOption, list_href, stamp_unix,
2120 };
21+use crate::pages::passkeys::s;
2222 use crate::pages::repo::repo_head;
2323 use crate::pages::repo_ctx::load_repo;
2424 use crate::state::AppState;
25-use crate::pages::passkeys::s;
2625 use crate::views::parts::{RailItem, SubPart, rail};
2726 use crate::views::{
2827 avatar_url_unknown, iso_time, now_unix, relative_time, repo_href, shell, user_link,
@@ -64,9 +63,15 @@ fn state_parts(lang: Lang, open: bool, merged: bool) -> (&'static str, &'static
6463 if open {
6564 (g::t(lang, K::PrStateOpenLabel), g::t(lang, K::StateOpen))
6665 } else if merged {
67- (g::t(lang, K::PrStateMergedLabel), g::t(lang, K::StateMerged))
66+ (
67+ g::t(lang, K::PrStateMergedLabel),
68+ g::t(lang, K::StateMerged),
69+ )
6870 } else {
69- (g::t(lang, K::PrStateClosedLabel), g::t(lang, K::StateClosed))
71+ (
72+ g::t(lang, K::PrStateClosedLabel),
73+ g::t(lang, K::StateClosed),
74+ )
7075 }
7176 }
7277
@@ -150,11 +155,11 @@ fn row_view(
150155
151156 #[page("/{owner}/{repo}/pulls")]
152157 async fn pulls_list_page(cx: &Cx) -> Result<impl View> {
153- let owner = path_param::<Owner>(cx);
154- let name = path_param::<Repo>(cx);
158+ let owner = owner(cx);
159+ let name = repo(cx);
155160 let query = query_params::<ListQuery>(cx)?;
156161 let ctx = load_repo(cx, owner, name).await?;
157- let state = app_context::<AppState>(cx);
162+ let state = context::<AppState>(cx);
158163 let mut sel = Selection::parse(query);
159164 sel.resolve_me(ctx.viewer.as_ref().map(|(user, _)| user.username.as_str()));
160165 let search_value = sel.search_text();
@@ -411,7 +416,8 @@ mod tests {
411416 }
412417
413418 fn rows(html: &str) -> usize {
414- html.matches("class=\"line issue-row\" data-kb-row=\"\"").count()
419+ html.matches("class=\"line issue-row\" data-kb-row=\"\"")
420+ .count()
415421 }
416422
417423 const HEAD_OID: &str = "1111111111111111111111111111111111111111";
crates/forge-web/src/pages/pulls_merge.rsmodified+4 -4
@@ -25,7 +25,7 @@ use http::HeaderValue;
2525 use http::header::CONTENT_TYPE;
2626 use serde::Deserialize;
2727 use topcoat::Result;
28-use topcoat::context::{Cx, app_context};
28+use topcoat::context::{Cx, context};
2929 use topcoat::router::content::Form;
3030 use topcoat::router::error::{bad_request, forbidden, not_found, see_other};
3131 use topcoat::router::response::Response;
@@ -110,8 +110,8 @@ pub enum MergeOutcome {
110110
111111 #[route(POST "/{owner}/{repo}/pulls/{number}/merge")]
112112 async fn merge_post(cx: &Cx, Form(form): Form<MergeForm>) -> Result<Response> {
113- let number = parse_number(path_param::<Number>(cx))?;
114- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
113+ let number = parse_number(number(cx))?;
114+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
115115 let (user, _) = require_csrf(cx, &form.csrf).await?;
116116 if ctx.repo.archived
117117 || authorize(
@@ -125,7 +125,7 @@ async fn merge_post(cx: &Cx, Form(form): Form<MergeForm>) -> Result<Response> {
125125 {
126126 return Err(forbidden().into());
127127 }
128- let state = app_context::<AppState>(cx);
128+ let state = context::<AppState>(cx);
129129 let Some(pr) = state.store.pull_by_number(&ctx.repo.id, number).await? else {
130130 return Err(not_found().into());
131131 };
crates/forge-web/src/pages/push.rsmodified+12 -12
@@ -17,7 +17,7 @@ use serde::Deserialize;
1717 use serde_json::json;
1818 use tokio::sync::broadcast::error::RecvError;
1919 use topcoat::Result;
20-use topcoat::context::{Cx, app_context};
20+use topcoat::context::{Cx, context};
2121 use topcoat::router::content::Form;
2222 use topcoat::router::content::sse::Event;
2323 use topcoat::router::error::{SeeOther, see_other};
@@ -117,7 +117,7 @@ fn no_content() -> Response {
117117 #[route(GET "/push/vapid-key")]
118118 async fn vapid_key(cx: &Cx) -> Result<Response> {
119119 require_user(cx).await?;
120- let state = app_context::<AppState>(cx);
120+ let state = context::<AppState>(cx);
121121 let keys = web_push::vapid_keys(state).await?;
122122 Ok(json(StatusCode::OK, &json!({ "public_key": keys.public })))
123123 }
@@ -126,7 +126,7 @@ async fn vapid_key(cx: &Cx) -> Result<Response> {
126126 #[route(POST "/push/subscribe")]
127127 async fn subscribe(cx: &Cx, Form(form): Form<SubscribeForm>) -> Result<Response> {
128128 let (user, _) = require_csrf(cx, &form.csrf).await?;
129- let state = app_context::<AppState>(cx);
129+ let state = context::<AppState>(cx);
130130 let policy = crate::mirrors::policy(state);
131131 if let Err(e) =
132132 check_endpoint(&form.endpoint, &policy).and_then(|()| check_keys(&form.p256dh, &form.auth))
@@ -156,7 +156,7 @@ async fn subscribe(cx: &Cx, Form(form): Form<SubscribeForm>) -> Result<Response>
156156 #[route(POST "/push/unsubscribe")]
157157 async fn unsubscribe(cx: &Cx, Form(form): Form<EndpointForm>) -> Result<Response> {
158158 let (user, _) = require_csrf(cx, &form.csrf).await?;
159- let state = app_context::<AppState>(cx);
159+ let state = context::<AppState>(cx);
160160 if state
161161 .store
162162 .delete_push_subscription_by_endpoint(&user.id, &form.endpoint)
@@ -171,7 +171,7 @@ async fn unsubscribe(cx: &Cx, Form(form): Form<EndpointForm>) -> Result<Response
171171 #[route(POST "/settings/notifications/push/remove")]
172172 async fn remove_device(cx: &Cx, Form(form): Form<DeviceForm>) -> Result<SeeOther> {
173173 let (user, _) = require_csrf(cx, &form.csrf).await?;
174- let state = app_context::<AppState>(cx);
174+ let state = context::<AppState>(cx);
175175 if state
176176 .store
177177 .delete_push_subscription(&user.id, &form.id)
@@ -187,7 +187,7 @@ async fn remove_device(cx: &Cx, Form(form): Form<DeviceForm>) -> Result<SeeOther
187187 #[route(POST "/settings/notifications/push/test")]
188188 async fn send_test(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
189189 let (user, _) = require_csrf(cx, &form.csrf).await?;
190- let state = app_context::<AppState>(cx);
190+ let state = context::<AppState>(cx);
191191 let devices = state.store.push_subscriptions(&user.id).await?.len();
192192 if devices > 0 {
193193 web_push::queue(state, &user.id, Alert::Test);
@@ -204,7 +204,7 @@ async fn push_events(cx: &Cx) -> Result<Response> {
204204 *res.status_mut() = StatusCode::UNAUTHORIZED;
205205 return Ok(res);
206206 };
207- let state = app_context::<AppState>(cx);
207+ let state = context::<AppState>(cx);
208208 let rx = state.push_live.subscribe();
209209 let changes = stream::unfold((rx, user.id), |(mut rx, user_id)| async move {
210210 loop {
@@ -263,31 +263,31 @@ fn static_headers(content_type: &'static str, cache: &'static str) -> HeaderMap
263263 }
264264
265265 #[route(GET "/sw.js")]
266-async fn service_worker() -> Result<(StatusCode, HeaderMap, &'static str)> {
266+async fn service_worker(cx: &Cx) -> Result<(StatusCode, HeaderMap, &'static str)> {
267267 let headers = static_headers("text/javascript; charset=utf-8", "no-cache");
268268 Ok((StatusCode::OK, headers, SW_JS))
269269 }
270270
271271 #[route(GET "/manifest.webmanifest")]
272-async fn manifest() -> Result<(StatusCode, HeaderMap, &'static str)> {
272+async fn manifest(cx: &Cx) -> Result<(StatusCode, HeaderMap, &'static str)> {
273273 let headers = static_headers("application/manifest+json", "public, max-age=3600");
274274 Ok((StatusCode::OK, headers, MANIFEST))
275275 }
276276
277277 #[route(GET "/assets/icons/icon-192.png")]
278-async fn icon_192() -> Result<(StatusCode, HeaderMap, &'static [u8])> {
278+async fn icon_192(cx: &Cx) -> Result<(StatusCode, HeaderMap, &'static [u8])> {
279279 let headers = static_headers("image/png", "public, max-age=604800");
280280 Ok((StatusCode::OK, headers, ICON_192))
281281 }
282282
283283 #[route(GET "/assets/icons/icon-512.png")]
284-async fn icon_512() -> Result<(StatusCode, HeaderMap, &'static [u8])> {
284+async fn icon_512(cx: &Cx) -> Result<(StatusCode, HeaderMap, &'static [u8])> {
285285 let headers = static_headers("image/png", "public, max-age=604800");
286286 Ok((StatusCode::OK, headers, ICON_512))
287287 }
288288
289289 #[route(GET "/assets/icons/apple-touch-icon.png")]
290-async fn apple_touch_icon() -> Result<(StatusCode, HeaderMap, &'static [u8])> {
290+async fn apple_touch_icon(cx: &Cx) -> Result<(StatusCode, HeaderMap, &'static [u8])> {
291291 let headers = static_headers("image/png", "public, max-age=604800");
292292 Ok((StatusCode::OK, headers, APPLE_TOUCH_ICON))
293293 }
crates/forge-web/src/pages/reactions.rsmodified+4 -4
@@ -7,7 +7,7 @@
77 use forge_core::{Reaction, ReactionTarget};
88 use serde::Deserialize;
99 use topcoat::Result;
10-use topcoat::context::{Cx, app_context};
10+use topcoat::context::{Cx, context};
1111 use topcoat::router::content::Form;
1212 use topcoat::router::error::{SeeOther, bad_request, forbidden, not_found, see_other};
1313 use topcoat::router::{path_param, route};
@@ -47,13 +47,13 @@ async fn pull_reaction(cx: &Cx, Form(form): Form<ReactionForm>) -> Result<SeeOth
4747 }
4848
4949 async fn react(cx: &Cx, kind: ItemKind, form: ReactionForm) -> Result<SeeOther> {
50- let number = parse_number(path_param::<Number>(cx))?;
51- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
50+ let number = parse_number(number(cx))?;
51+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
5252 let (user, _) = require_csrf(cx, &form.csrf).await?;
5353 if ctx.repo.archived {
5454 return Err(forbidden().into());
5555 }
56- let state = app_context::<AppState>(cx);
56+ let state = context::<AppState>(cx);
5757 let item = item_for(state, &ctx, kind, number).await?;
5858 if !may_converse(&ctx, &item) {
5959 return Err(forbidden().into());
crates/forge-web/src/pages/ref_live.rsmodified+4 -4
@@ -9,7 +9,7 @@
99 //! the commits they show, and a soft re-read is cheap.
1010
1111 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};
12+use topcoat::context::{Cx, context};
1313 use topcoat::router::response::Response;
1414 use topcoat::router::{path_param, route};
1515
@@ -38,10 +38,10 @@ pub fn topics(repo: &forge_core::Repo) -> [Topic; 3] {
3838 /// who cannot read the repo gets the same 404 as the page.
3939 #[route(GET "/{owner}/{repo}/refs/events")]
4040 async fn ref_events(cx: &Cx) -> Result<Response> {
41- let owner = path_param::<Owner>(cx);
42- let name = path_param::<Repo>(cx);
41+ let owner = owner(cx);
42+ let name = repo(cx);
4343 let ctx = load_repo(cx, owner, name).await?;
44- let hub: &LiveHub = &app_context::<AppState>(cx).live;
44+ let hub: &LiveHub = &context::<AppState>(cx).live;
4545 stream_wakes(cx, hub, &topics(&ctx.repo))
4646 }
4747
crates/forge-web/src/pages/refs.rsmodified+5 -5
@@ -8,7 +8,7 @@ use crate::state::AppState;
88 use forge_core::Repo as RepoRow;
99 use forge_git::browse::{self, CommitInfo, RefInfo, RefKind};
1010 use topcoat::Result;
11-use topcoat::context::{Cx, app_context};
11+use topcoat::context::{Cx, context};
1212 use topcoat::router::{page, path_param};
1313 use topcoat::view::{View, component, view};
1414
@@ -105,7 +105,7 @@ pub(crate) async fn ref_rows(
105105 }
106106
107107 #[component]
108-async fn refs_table(rows: Vec<RefRow>, lang: Lang) -> Result<impl View> {
108+async fn refs_table(cx: &Cx, rows: Vec<RefRow>, lang: Lang) -> Result<impl View> {
109109 let empty = rows.is_empty();
110110 Ok(view! {
111111 if empty {
@@ -142,8 +142,8 @@ struct RefsPage {
142142 }
143143
144144 async fn refs_data(cx: &Cx, kind: RefKind) -> Result<RefsPage> {
145- let owner = path_param::<Owner>(cx);
146- let name = path_param::<Repo>(cx);
145+ let owner = owner(cx);
146+ let name = repo(cx);
147147 let ctx = load_repo(cx, owner, name).await?;
148148 let now = now_unix();
149149 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
@@ -174,7 +174,7 @@ async fn tags_page(cx: &Cx) -> Result<impl View> {
174174 ctx.repo.name,
175175 g::t(lang, K::TagsTitle)
176176 );
177- let mut header = ctx.head(app_context::<AppState>(cx), "tags").await?;
177+ let mut header = ctx.head(context::<AppState>(cx), "tags").await?;
178178 header.live = ref_live::live_url(&ctx.repo.owner_name, &ctx.repo.name);
179179 Ok(view! {
180180 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),
crates/forge-web/src/pages/register.rsmodified+7 -5
@@ -9,7 +9,7 @@ use forge_core::store::validate_email;
99 use forge_core::{AuditAction, Registration, User};
1010 use serde::Deserialize;
1111 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};
12+use topcoat::context::{Cx, context};
1313 use topcoat::router::content::Form;
1414 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
1515 use topcoat::router::{page, path_param_segment, query_params, route};
@@ -120,6 +120,7 @@ fn gate_for(mode: &Registration, invite: &str, invite_valid: bool) -> Gate {
120120
121121 #[component]
122122 async fn register_form(
123+ cx: &Cx,
123124 lang: Lang,
124125 gate: Gate,
125126 invite: &str,
@@ -179,7 +180,7 @@ async fn register_form(
179180
180181 #[page("/register")]
181182 async fn register_page(cx: &Cx) -> Result<impl View> {
182- let state = app_context::<AppState>(cx);
183+ let state = context::<AppState>(cx);
183184 if state.live().registration == Registration::Closed {
184185 return Err(not_found().into());
185186 }
@@ -260,7 +261,7 @@ async fn create_account(
260261
261262 #[page(POST "/register")]
262263 async fn register_submit(cx: &Cx, Form(form): Form<RegisterForm>) -> Result<impl View> {
263- let state = app_context::<AppState>(cx);
264+ let state = context::<AppState>(cx);
264265 if state.live().registration == Registration::Closed {
265266 return Err(not_found().into());
266267 }
@@ -343,6 +344,7 @@ async fn register_submit(cx: &Cx, Form(form): Form<RegisterForm>) -> Result<impl
343344
344345 #[component]
345346 async fn verify_body(
347+ cx: &Cx,
346348 lang: Lang,
347349 token: &str,
348350 precsrf: &str,
@@ -382,7 +384,7 @@ async fn verify_submit(cx: &Cx, Form(form): Form<VerifyForm>) -> Result<impl Vie
382384 if !check_pre_csrf(cx, &form.precsrf) {
383385 return Err(forbidden().into());
384386 }
385- let state = app_context::<AppState>(cx);
387+ let state = context::<AppState>(cx);
386388 let lang = i18n::lang(cx, None);
387389 let token = path_param_segment(cx, "token").to_owned();
388390 let mode = match state.store.redeem_verify_token(&token).await? {
@@ -415,7 +417,7 @@ async fn verify_submit(cx: &Cx, Form(form): Form<VerifyForm>) -> Result<impl Vie
415417 #[route(POST "/settings/security/email/resend")]
416418 async fn verify_resend(cx: &Cx, Form(form): Form<ResendForm>) -> Result<SeeOther> {
417419 let viewer = require_csrf(cx, &form.csrf).await?;
418- let state = app_context::<AppState>(cx);
420+ let state = context::<AppState>(cx);
419421 if !mail_can_send(state).await {
420422 return Ok(see_other("/settings/security?saved=verify_wait"));
421423 }
crates/forge-web/src/pages/releases.rsmodified+45 -40
@@ -20,7 +20,7 @@ use http_body::Frame;
2020 use http_body_util::StreamBody;
2121 use serde::Deserialize;
2222 use topcoat::Result;
23-use topcoat::context::{Cx, app_context};
23+use topcoat::context::{Cx, context};
2424 use topcoat::router::content::Form;
2525 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
2626 use topcoat::router::request::headers;
@@ -344,6 +344,7 @@ fn check_title_body(lang: Lang, title: &str, body: &str) -> std::result::Result<
344344 /// Release-form list of branches and the form itself, shared by the new and edit pages.
345345 #[component]
346346 async fn release_form(
347+ cx: &Cx,
347348 action: String,
348349 csrf: String,
349350 lang: Lang,
@@ -413,6 +414,7 @@ async fn release_form(
413414 /// The assets table on the edit page. `delete_actions` holds one form action per asset.
414415 #[component]
415416 async fn asset_rows(
417+ cx: &Cx,
416418 assets: Vec<AssetLink>,
417419 delete_actions: Vec<String>,
418420 upload_action: String,
@@ -464,6 +466,7 @@ async fn asset_rows(
464466 /// The list page body.
465467 #[component]
466468 async fn list_body(
469+ cx: &Cx,
467470 head: crate::pages::repo_ctx::RepoHead,
468471 lang: Lang,
469472 notice: Option<(&'static str, bool)>,
@@ -537,12 +540,12 @@ async fn list_body(
537540 /// Lists the repo's releases, newest first. Drafts appear only for writers.
538541 #[page("/{owner}/{repo}/releases")]
539542 async fn releases_list_page(cx: &Cx) -> Result<impl View> {
540- let owner = path_param::<Owner>(cx);
541- let name = path_param::<Repo>(cx);
543+ let owner = owner(cx);
544+ let name = repo(cx);
542545 let query = query_params::<ReleasesQuery>(cx)?;
543546 let ctx = load_repo(cx, owner, name).await?;
544547 let lang = i18n::lang(cx, viewer_user(&ctx));
545- let state = app_context::<AppState>(cx);
548+ let state = context::<AppState>(cx);
546549 let writer = can_write(&ctx);
547550 let latest_id = state
548551 .store
@@ -605,6 +608,7 @@ async fn new_form_data(state: &AppState, ctx: &RepoCtx) -> Result<(RepoHead, Vec
605608 /// The new-release form body, below the repo header.
606609 #[component]
607610 async fn new_form_body(
611+ cx: &Cx,
608612 head: RepoHead,
609613 lang: Lang,
610614 action: String,
@@ -626,12 +630,12 @@ async fn new_form_body(
626630 /// The new-release form.
627631 #[page("/{owner}/{repo}/releases/new")]
628632 async fn release_new_page(cx: &Cx) -> Result<impl View> {
629- let owner = path_param::<Owner>(cx);
630- let name = path_param::<Repo>(cx);
633+ let owner = owner(cx);
634+ let name = repo(cx);
631635 let ctx = load_repo(cx, owner, name).await?;
632636 require_write(&ctx)?;
633637 let lang = i18n::lang(cx, viewer_user(&ctx));
634- let state = app_context::<AppState>(cx);
638+ let state = context::<AppState>(cx);
635639 let csrf = match crate::auth::current_user(cx).await? {
636640 Some((_, session)) => session.csrf_token.clone(),
637641 None => String::new(),
@@ -653,13 +657,13 @@ async fn release_new_page(cx: &Cx) -> Result<impl View> {
653657 /// Creates a release. The tag is created at the target branch's head when it does not exist.
654658 #[page(POST "/{owner}/{repo}/releases/new")]
655659 async fn release_create(cx: &Cx, Form(form): Form<CreateForm>) -> Result<impl View> {
656- let owner = path_param::<Owner>(cx);
657- let name = path_param::<Repo>(cx);
660+ let owner = owner(cx);
661+ let name = repo(cx);
658662 let ctx = load_repo(cx, owner, name).await?;
659663 let (user, session) = require_csrf(cx, &form.csrf).await?;
660664 require_write(&ctx)?;
661665 let lang = i18n::lang(cx, viewer_user(&ctx));
662- let state = app_context::<AppState>(cx);
666+ let state = context::<AppState>(cx);
663667 let draft = FormDraft {
664668 tag: form.tag.trim().to_owned(),
665669 target: form.target.trim().to_owned(),
@@ -733,12 +737,12 @@ async fn create_checked(
733737 /// The public view of one release: notes, assets and the source archive links.
734738 #[page("/{owner}/{repo}/releases/tag/{tag}")]
735739 async fn release_tag_page(cx: &Cx) -> Result<impl View> {
736- let owner = path_param::<Owner>(cx);
737- let name = path_param::<Repo>(cx);
738- let tag_param = path_param::<Tag>(cx).to_owned();
740+ let owner = owner(cx);
741+ let name = repo(cx);
742+ let tag_param = tag(cx).to_owned();
739743 let ctx = load_repo(cx, owner, name).await?;
740744 let lang = i18n::lang(cx, viewer_user(&ctx));
741- let state = app_context::<AppState>(cx);
745+ let state = context::<AppState>(cx);
742746 let writer = can_write(&ctx);
743747 let Some(release) = state.store.release_by_tag(&ctx.repo.id, &tag_param).await? else {
744748 return Err(not_found().into());
@@ -864,6 +868,7 @@ async fn release_tag_page(cx: &Cx) -> Result<impl View> {
864868 /// which shows the typed values again.
865869 #[component]
866870 async fn edit_body(
871+ cx: &Cx,
867872 head: RepoHead,
868873 lang: Lang,
869874 notice: Option<(&'static str, bool)>,
@@ -976,13 +981,13 @@ async fn edit_parts(
976981 /// The edit page: the release fields, its assets, and the upload form.
977982 #[page("/{owner}/{repo}/releases/{release_id}/edit")]
978983 async fn release_edit_page(cx: &Cx) -> Result<impl View> {
979- let owner = path_param::<Owner>(cx);
980- let name = path_param::<Repo>(cx);
981- let id = path_param::<ReleaseId>(cx).to_owned();
984+ let owner = owner(cx);
985+ let name = repo(cx);
986+ let id = release_id(cx).to_owned();
982987 let ctx = load_repo(cx, owner, name).await?;
983988 require_write(&ctx)?;
984989 let lang = i18n::lang(cx, viewer_user(&ctx));
985- let state = app_context::<AppState>(cx);
990+ let state = context::<AppState>(cx);
986991 let Some(release) = state.store.release(&id).await? else {
987992 return Err(not_found().into());
988993 };
@@ -1016,14 +1021,14 @@ async fn release_edit_page(cx: &Cx) -> Result<impl View> {
10161021 /// unchanged tag keeps the tag. A refused save shows its message and keeps the typed values.
10171022 #[page(POST "/{owner}/{repo}/releases/{release_id}/edit")]
10181023 async fn release_update(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View> {
1019- let owner = path_param::<Owner>(cx);
1020- let name = path_param::<Repo>(cx);
1021- let id = path_param::<ReleaseId>(cx).to_owned();
1024+ let owner = owner(cx);
1025+ let name = repo(cx);
1026+ let id = release_id(cx).to_owned();
10221027 let ctx = load_repo(cx, owner, name).await?;
10231028 let (user, session) = require_csrf(cx, &form.csrf).await?;
10241029 require_write(&ctx)?;
10251030 let lang = i18n::lang(cx, viewer_user(&ctx));
1026- let state = app_context::<AppState>(cx);
1031+ let state = context::<AppState>(cx);
10271032 let Some(before) = state.store.release(&id).await? else {
10281033 return Err(not_found().into());
10291034 };
@@ -1072,9 +1077,9 @@ async fn release_update(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View
10721077 /// Deletes a release and its assets, then their blobs. The git tag is kept. Requires the confirm box.
10731078 #[route(POST "/{owner}/{repo}/releases/{release_id}/delete")]
10741079 async fn release_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<Response> {
1075- let owner = path_param::<Owner>(cx);
1076- let name = path_param::<Repo>(cx);
1077- let id = path_param::<ReleaseId>(cx).to_owned();
1080+ let owner = owner(cx);
1081+ let name = repo(cx);
1082+ let id = release_id(cx).to_owned();
10781083 let ctx = load_repo(cx, owner, name).await?;
10791084 let (user, _) = require_csrf(cx, &form.csrf).await?;
10801085 require_write(&ctx)?;
@@ -1083,7 +1088,7 @@ async fn release_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<Response>
10831088 let href = release_edit_href(&title, &id);
10841089 return Err(notice_redirect(&href, "confirm").into());
10851090 }
1086- let state = app_context::<AppState>(cx);
1091+ let state = context::<AppState>(cx);
10871092 let Some(release) = state.store.release(&id).await? else {
10881093 return Err(not_found().into());
10891094 };
@@ -1097,14 +1102,14 @@ async fn release_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<Response>
10971102 /// Deletes one asset row and its blob.
10981103 #[route(POST "/{owner}/{repo}/releases/{release_id}/assets/{asset_id}/delete")]
10991104 async fn asset_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<Response> {
1100- let owner = path_param::<Owner>(cx);
1101- let name = path_param::<Repo>(cx);
1102- let release_id = path_param::<ReleaseId>(cx).to_owned();
1103- let asset = path_param::<AssetId>(cx).to_owned();
1105+ let owner = owner(cx);
1106+ let name = repo(cx);
1107+ let release_id = release_id(cx).to_owned();
1108+ let asset = asset_id(cx).to_owned();
11041109 let ctx = load_repo(cx, owner, name).await?;
11051110 require_csrf(cx, &form.csrf).await?;
11061111 require_write(&ctx)?;
1107- let state = app_context::<AppState>(cx);
1112+ let state = context::<AppState>(cx);
11081113 let Some(release) = state.store.release(&release_id).await? else {
11091114 return Err(not_found().into());
11101115 };
@@ -1123,11 +1128,11 @@ async fn asset_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<Response> {
11231128 /// `assets/<id>` only when it is complete and the row is stored.
11241129 #[route(POST "/{owner}/{repo}/releases/{release_id}/assets")]
11251130 async fn asset_upload(cx: &Cx, body: Body) -> Result<Response> {
1126- let owner = path_param::<Owner>(cx);
1127- let name = path_param::<Repo>(cx);
1128- let id = path_param::<ReleaseId>(cx).to_owned();
1131+ let owner = owner(cx);
1132+ let name = repo(cx);
1133+ let id = release_id(cx).to_owned();
11291134 let ctx = load_repo(cx, owner, name).await?;
1130- let state = app_context::<AppState>(cx);
1135+ let state = context::<AppState>(cx);
11311136 let href = release_edit_href(&title_of(&ctx), &id);
11321137 let max_bytes = state
11331138 .config
@@ -1255,11 +1260,11 @@ async fn store_upload(
12551260 /// people who can write; anyone else gets a 404.
12561261 #[route(GET "/{owner}/{repo}/releases/download/{tag}/{name}")]
12571262 async fn asset_download(cx: &Cx) -> Result<Response> {
1258- let owner = path_param::<Owner>(cx);
1259- let repo_name = path_param::<Repo>(cx);
1260- let tag_param = path_param::<Tag>(cx).to_owned();
1261- let file_name = path_param::<Name>(cx).to_owned();
1262- let state = app_context::<AppState>(cx);
1263+ let owner = owner(cx);
1264+ let repo_name = repo(cx);
1265+ let tag_param = tag(cx).to_owned();
1266+ let file_name = name(cx).to_owned();
1267+ let state = context::<AppState>(cx);
12631268 // A caller that sends credentials (a Gitea or Forgejo server migrating this repo) is judged by
12641269 // its token, with the same rules as the API. Everyone else goes through the session.
12651270 if headers(cx).contains_key(http::header::AUTHORIZATION) {
crates/forge-web/src/pages/releases_live.rsmodified+6 -6
@@ -11,7 +11,7 @@
1111
1212 use forge_core::store::Store;
1313 use topcoat::Result;
14-use topcoat::context::{Cx, app_context};
14+use topcoat::context::{Cx, context};
1515 use topcoat::router::error::not_found;
1616 use topcoat::router::response::Response;
1717 use topcoat::router::{path_param, route};
@@ -85,8 +85,8 @@ pub(crate) async fn release_fingerprint(
8585 /// The release list's change stream.
8686 #[route(GET "/{owner}/{repo}/releases/events")]
8787 async fn releases_events(cx: &Cx) -> Result<Response> {
88- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
89- let state = app_context::<AppState>(cx);
88+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
89+ let state = context::<AppState>(cx);
9090 let writer = can_write(&ctx);
9191 let topic = Topic::RepoReleases(ctx.repo.id.clone());
9292 let store = state.store.clone();
@@ -102,9 +102,9 @@ async fn releases_events(cx: &Cx) -> Result<Response> {
102102 /// One release page's change stream. A release the viewer cannot open gets the page's 404.
103103 #[route(GET "/{owner}/{repo}/releases/tag/{tag}/events")]
104104 async fn release_events(cx: &Cx) -> Result<Response> {
105- let tag = path_param::<Tag>(cx).to_owned();
106- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
107- let state = app_context::<AppState>(cx);
105+ let tag = tag(cx).to_owned();
106+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
107+ let state = context::<AppState>(cx);
108108 let writer = can_write(&ctx);
109109 let visible = match state.store.release_by_tag(&ctx.repo.id, &tag).await? {
110110 Some(release) => writer || !release.draft,
crates/forge-web/src/pages/repo.rsmodified+14 -6
@@ -12,7 +12,7 @@ use forge_core::time::stamp_before;
1212 use forge_git::browse;
1313 use forge_git::repo::repo_path;
1414 use topcoat::Result;
15-use topcoat::context::{Cx, app_context};
15+use topcoat::context::{Cx, context};
1616 use topcoat::router::error::not_found;
1717 use topcoat::router::{page, path_param, route};
1818 use topcoat::view::{Child, View, ViewExt, component, view};
@@ -84,6 +84,7 @@ pub(crate) fn tab_title(lang: Lang, active: &str, repo: &str) -> String {
8484 /// `RepoCtx::head`; every repo page passes one.
8585 #[component]
8686 pub async fn repo_head(
87+ cx: &Cx,
8788 head: RepoHead,
8889 #[default] title: Option<String>,
8990 #[default] sub: Vec<SubPart>,
@@ -228,6 +229,7 @@ pub async fn repo_head(
228229 /// the branch has a commit, links to its archive (`downloads`: the zip and tar.gz hrefs).
229230 #[component]
230231 async fn clone_popover(
232+ cx: &Cx,
231233 https: String,
232234 ssh: String,
233235 downloads: Option<(String, String)>,
@@ -258,6 +260,7 @@ async fn clone_popover(
258260 /// or push instructions when there are none.
259261 #[component]
260262 async fn branches_card(
263+ cx: &Cx,
261264 branches: Vec<String>,
262265 push_https: String,
263266 push_ssh: String,
@@ -408,7 +411,12 @@ async fn recent_push_banners(
408411
409412 /// The "had recent pushes" banners above the code tab.
410413 #[component]
411-async fn recent_pushes(banners: Vec<PushBanner>, now: i64, lang: Lang) -> Result<impl View> {
414+async fn recent_pushes(
415+ cx: &Cx,
416+ banners: Vec<PushBanner>,
417+ now: i64,
418+ lang: Lang,
419+) -> Result<impl View> {
412420 Ok(view! {
413421 <section class="recent-pushes" aria-label=(g::t(lang, K::RecentPushes))>
414422 for banner in banners.into_iter() {
@@ -426,10 +434,10 @@ async fn recent_pushes(banners: Vec<PushBanner>, now: i64, lang: Lang) -> Result
426434
427435 #[page("/{owner}/{repo}")]
428436 async fn repo_page(cx: &Cx) -> Result<impl View> {
429- let owner = path_param::<Owner>(cx);
430- let name = path_param::<Repo>(cx);
437+ let owner = owner(cx);
438+ let name = repo(cx);
431439 let ctx = load_repo(cx, owner, name).await?;
432- let state = app_context::<AppState>(cx);
440+ let state = context::<AppState>(cx);
433441 let lang = ctx.lang;
434442 let repo = &ctx.repo;
435443 let branch = repo.default_branch.clone();
@@ -530,7 +538,7 @@ async fn repo_page(cx: &Cx) -> Result<impl View> {
530538
531539 /// Other methods on a repo path get a plain 404, not a 405 that would reveal the route shape.
532540 #[route(* "/{owner}/{repo}")]
533-async fn repo_other_methods() -> Result<&'static str> {
541+async fn repo_other_methods(cx: &Cx) -> Result<&'static str> {
534542 Err(not_found().into())
535543 }
536544
crates/forge-web/src/pages/repo_collaborators.rsmodified+14 -13
@@ -14,7 +14,7 @@ use forge_core::store::orgs::OrgMemberRole;
1414 use forge_core::{AuditAction, Role, User};
1515 use serde::Deserialize;
1616 use topcoat::Result;
17-use topcoat::context::{Cx, app_context};
17+use topcoat::context::{Cx, context};
1818 use topcoat::cookie::{Cookie, Cookies, SameSite, cookies};
1919 use topcoat::router::content::Form;
2020 use topcoat::router::error::{SeeOther, forbidden, see_other};
@@ -159,6 +159,7 @@ impl FrameData {
159159 /// The page body: repo header with Settings active, the notice, then the collaborators topic.
160160 #[component]
161161 async fn collaborators_body(
162+ cx: &Cx,
162163 lang: Lang,
163164 frame: FrameData,
164165 rows: Vec<PersonRow>,
@@ -230,15 +231,15 @@ async fn collaborators_body(
230231 /// and signed-in viewers who may not manage the repo get 403.
231232 #[page("/{owner}/{repo}/settings/collaborators")]
232233 async fn collaborators_page(cx: &Cx) -> Result<impl View> {
233- let owner = path_param::<Owner>(cx);
234- let name = path_param::<Repo>(cx);
234+ let owner = owner(cx);
235+ let name = repo(cx);
235236 let ctx = load_repo(cx, owner, name).await?;
236237 let (user, session) = require_user(cx).await?;
237238 if !ctx.can_admin() {
238239 return Err(forbidden().into());
239240 }
240241 let lang = i18n::lang(cx, Some(&user));
241- let state = app_context::<AppState>(cx);
242+ let state = context::<AppState>(cx);
242243 let collaborators = state.store.list_collaborators(&ctx.repo.id).await?;
243244 let viewer_id = user.id.clone();
244245 let rows = collaborators
@@ -275,15 +276,15 @@ async fn collaborators_page(cx: &Cx) -> Result<impl View> {
275276 /// Adds a collaborator or updates an existing one's role. Admin grants need the owner or an instance admin.
276277 #[route(POST "/{owner}/{repo}/settings/collaborators/add")]
277278 async fn collaborators_add(cx: &Cx, Form(form): Form<AddForm>) -> Result<SeeOther> {
278- let owner = path_param::<Owner>(cx);
279- let name = path_param::<Repo>(cx);
279+ let owner = owner(cx);
280+ let name = repo(cx);
280281 let ctx = load_repo(cx, owner, name).await?;
281282 let (actor, _) = require_csrf(cx, &form.csrf).await?;
282283 if !ctx.can_admin() {
283284 return Err(forbidden().into());
284285 }
285286 let title = title_of(&ctx);
286- let state = app_context::<AppState>(cx);
287+ let state = context::<AppState>(cx);
287288
288289 let Ok(role) = form.role.trim().parse::<Role>() else {
289290 set_notice(cx, "invalid_role");
@@ -361,15 +362,15 @@ async fn collaborators_add(cx: &Cx, Form(form): Form<AddForm>) -> Result<SeeOthe
361362 /// Changes an existing collaborator's role. Only existing collaborators can be changed here.
362363 #[route(POST "/{owner}/{repo}/settings/collaborators/role")]
363364 async fn collaborators_role(cx: &Cx, Form(form): Form<RoleForm>) -> Result<SeeOther> {
364- let owner = path_param::<Owner>(cx);
365- let name = path_param::<Repo>(cx);
365+ let owner = owner(cx);
366+ let name = repo(cx);
366367 let ctx = load_repo(cx, owner, name).await?;
367368 let (actor, _) = require_csrf(cx, &form.csrf).await?;
368369 if !ctx.can_admin() {
369370 return Err(forbidden().into());
370371 }
371372 let title = title_of(&ctx);
372- let state = app_context::<AppState>(cx);
373+ let state = context::<AppState>(cx);
373374
374375 let Ok(role) = form.role.trim().parse::<Role>() else {
375376 set_notice(cx, "invalid_role");
@@ -422,15 +423,15 @@ async fn collaborators_role(cx: &Cx, Form(form): Form<RoleForm>) -> Result<SeeOt
422423 /// yourself is allowed and redirects to the repo home page.
423424 #[route(POST "/{owner}/{repo}/settings/collaborators/remove")]
424425 async fn collaborators_remove(cx: &Cx, Form(form): Form<RemoveForm>) -> Result<SeeOther> {
425- let owner = path_param::<Owner>(cx);
426- let name = path_param::<Repo>(cx);
426+ let owner = owner(cx);
427+ let name = repo(cx);
427428 let ctx = load_repo(cx, owner, name).await?;
428429 let (actor, _) = require_csrf(cx, &form.csrf).await?;
429430 if !ctx.can_admin() {
430431 return Err(forbidden().into());
431432 }
432433 let title = title_of(&ctx);
433- let state = app_context::<AppState>(cx);
434+ let state = context::<AppState>(cx);
434435 let target_id = form.user_id.trim();
435436 let self_removal = target_id == actor.id;
436437
crates/forge-web/src/pages/repo_ctx.rsmodified+6 -3
@@ -8,9 +8,12 @@ use std::path::PathBuf;
88 use forge_core::authz::{Action, authorize};
99 use forge_core::{Repo, Role, Session, Store, User, Visibility, WatchLevel};
1010 use forge_git::repo::repo_path;
11-use http::{HeaderValue, header::{CACHE_CONTROL, LOCATION}};
11+use http::{
12+ HeaderValue,
13+ header::{CACHE_CONTROL, LOCATION},
14+};
1215 use topcoat::Result;
13-use topcoat::context::{Cx, app_context};
16+use topcoat::context::{Cx, context};
1417 use topcoat::router::error::not_found;
1518 use topcoat::router::request::uri;
1619 use topcoat::router::response::Response;
@@ -306,7 +309,7 @@ pub async fn fork_count(state: &AppState, repo_id: &str) -> Result<u64> {
306309 }
307310
308311 pub async fn load_repo(cx: &Cx, owner: &str, name: &str) -> Result<RepoCtx> {
309- let state = app_context::<AppState>(cx);
312+ let state = context::<AppState>(cx);
310313 let viewer = current_user(cx).await?;
311314
312315 let Some(repo) = state.store.repo_by_owner_and_name(owner, name).await? else {
crates/forge-web/src/pages/repo_mirrors.rsmodified+27 -23
@@ -16,7 +16,7 @@ use serde::Deserialize;
1616 use time::OffsetDateTime;
1717 use time::format_description::well_known::Rfc3339;
1818 use topcoat::Result;
19-use topcoat::context::{Cx, app_context};
19+use topcoat::context::{Cx, context};
2020 use topcoat::router::content::Form;
2121 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
2222 use topcoat::router::request::uri;
@@ -391,6 +391,7 @@ async fn rows_of(state: &AppState, ctx: &RepoCtx, frame: &Frame) -> Result<Vec<M
391391 /// mirror's redacted URL on its own page.
392392 #[component]
393393 async fn frame_top(
394+ cx: &Cx,
394395 head: RepoHead,
395396 title: String,
396397 heading: String,
@@ -421,6 +422,7 @@ async fn frame_top(
421422 /// `direction` is sent as a hidden field by the add-pull form only (empty for the others).
422423 #[component]
423424 async fn mirror_form(
425+ cx: &Cx,
424426 action: String,
425427 csrf: String,
426428 prefix: &'static str,
@@ -494,6 +496,7 @@ async fn mirror_form(
494496 /// Archived repos show no add rows.
495497 #[component]
496498 async fn mirrors_list_body(
499+ cx: &Cx,
497500 head: RepoHead,
498501 title: String,
499502 notice: Option<(&'static str, bool)>,
@@ -575,14 +578,14 @@ async fn mirrors_list_body(
575578 /// Lists the repo's mirrors. Admins only: anyone else gets 404.
576579 #[page("/{owner}/{repo}/settings/mirrors")]
577580 async fn mirrors_list_page(cx: &Cx) -> Result<impl View> {
578- let owner = path_param::<Owner>(cx);
579- let name = path_param::<Repo>(cx);
581+ let owner = owner(cx);
582+ let name = repo(cx);
580583 let ctx = load_repo(cx, owner, name).await?;
581584 let (_, session) = require_user(cx).await?;
582585 if !ctx.can_admin() {
583586 return Err(not_found().into());
584587 }
585- let state = app_context::<AppState>(cx);
588+ let state = context::<AppState>(cx);
586589 let lang = lang_of(cx, &ctx);
587590 let frame = Frame::new(&ctx, state, lang).await?;
588591 let rows = rows_of(state, &ctx, &frame).await?;
@@ -690,8 +693,8 @@ async fn add_pull_mirror(
690693 /// before anything is stored.
691694 #[page(POST "/{owner}/{repo}/settings/mirrors")]
692695 async fn mirror_create(cx: &Cx, Form(form): Form<PushForm>) -> Result<impl View> {
693- let owner = path_param::<Owner>(cx);
694- let name = path_param::<Repo>(cx);
696+ let owner = owner(cx);
697+ let name = repo(cx);
695698 let ctx = load_repo(cx, owner, name).await?;
696699 let (user, session) = require_csrf(cx, &form.csrf).await?;
697700 if !ctx.can_admin() {
@@ -700,7 +703,7 @@ async fn mirror_create(cx: &Cx, Form(form): Form<PushForm>) -> Result<impl View>
700703 if ctx.repo.archived {
701704 return Err(forbidden().into());
702705 }
703- let state = app_context::<AppState>(cx);
706+ let state = context::<AppState>(cx);
704707 let lang = lang_of(cx, &ctx);
705708 let pull = form.direction == "pull";
706709 let stored = if pull {
@@ -768,6 +771,7 @@ async fn repo_mirror(state: &AppState, ctx: &RepoCtx, id: &str) -> Result<Mirror
768771 /// The edit page body: the form, the sync and delete controls.
769772 #[component]
770773 async fn mirror_body(
774+ cx: &Cx,
771775 head: RepoHead,
772776 title: String,
773777 notice: Option<(&'static str, bool)>,
@@ -844,15 +848,15 @@ impl EditDraft {
844848 /// The edit page for one mirror.
845849 #[page("/{owner}/{repo}/settings/mirrors/{mirror_id}")]
846850 async fn mirror_page(cx: &Cx) -> Result<impl View> {
847- let owner = path_param::<Owner>(cx);
848- let name = path_param::<Repo>(cx);
849- let id = path_param::<MirrorId>(cx);
851+ let owner = owner(cx);
852+ let name = repo(cx);
853+ let id = mirror_id(cx);
850854 let ctx = load_repo(cx, owner, name).await?;
851855 let (_, session) = require_user(cx).await?;
852856 if !ctx.can_admin() {
853857 return Err(not_found().into());
854858 }
855- let state = app_context::<AppState>(cx);
859+ let state = context::<AppState>(cx);
856860 let mirror = repo_mirror(state, &ctx, id).await?;
857861 let lang = lang_of(cx, &ctx);
858862 let frame = Frame::new(&ctx, state, lang).await?;
@@ -872,9 +876,9 @@ async fn mirror_page(cx: &Cx) -> Result<impl View> {
872876 /// the clear box removes it. A refused form shows the error on the edit page.
873877 #[page(POST "/{owner}/{repo}/settings/mirrors/{mirror_id}")]
874878 async fn mirror_update(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View> {
875- let owner = path_param::<Owner>(cx);
876- let name = path_param::<Repo>(cx);
877- let id = path_param::<MirrorId>(cx);
879+ let owner = owner(cx);
880+ let name = repo(cx);
881+ let id = mirror_id(cx);
878882 let ctx = load_repo(cx, owner, name).await?;
879883 let (user, session) = require_csrf(cx, &form.csrf).await?;
880884 if !ctx.can_admin() {
@@ -883,7 +887,7 @@ async fn mirror_update(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View>
883887 if ctx.repo.archived {
884888 return Err(forbidden().into());
885889 }
886- let state = app_context::<AppState>(cx);
890+ let state = context::<AppState>(cx);
887891 let mirror = repo_mirror(state, &ctx, id).await?;
888892 let url = if form.url.trim().is_empty() {
889893 mirror.url.clone()
@@ -966,9 +970,9 @@ async fn mirror_update(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View>
966970 /// Queues a sync now: the mirror is due at the current time and the worker is woken.
967971 #[route(POST "/{owner}/{repo}/settings/mirrors/{mirror_id}/sync")]
968972 async fn mirror_sync(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
969- let owner = path_param::<Owner>(cx);
970- let name = path_param::<Repo>(cx);
971- let id = path_param::<MirrorId>(cx);
973+ let owner = owner(cx);
974+ let name = repo(cx);
975+ let id = mirror_id(cx);
972976 let ctx = load_repo(cx, owner, name).await?;
973977 require_csrf(cx, &form.csrf).await?;
974978 if !ctx.can_admin() {
@@ -977,7 +981,7 @@ async fn mirror_sync(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
977981 if ctx.repo.archived {
978982 return Err(forbidden().into());
979983 }
980- let state = app_context::<AppState>(cx);
984+ let state = context::<AppState>(cx);
981985 let mirror = repo_mirror(state, &ctx, id).await?;
982986 state
983987 .store
@@ -990,9 +994,9 @@ async fn mirror_sync(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
990994 /// Deletes a mirror. The box must be ticked. Deleting the pull mirror makes the repo a normal one.
991995 #[route(POST "/{owner}/{repo}/settings/mirrors/{mirror_id}/delete")]
992996 async fn mirror_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther> {
993- let owner = path_param::<Owner>(cx);
994- let name = path_param::<Repo>(cx);
995- let id = path_param::<MirrorId>(cx);
997+ let owner = owner(cx);
998+ let name = repo(cx);
999+ let id = mirror_id(cx);
9961000 let ctx = load_repo(cx, owner, name).await?;
9971001 let (user, _) = require_csrf(cx, &form.csrf).await?;
9981002 if !ctx.can_admin() {
@@ -1001,7 +1005,7 @@ async fn mirror_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther
10011005 if ctx.repo.archived {
10021006 return Err(forbidden().into());
10031007 }
1004- let state = app_context::<AppState>(cx);
1008+ let state = context::<AppState>(cx);
10051009 let mirror = repo_mirror(state, &ctx, id).await?;
10061010 let title = title_of(&ctx);
10071011 if form.confirm.is_none() {
crates/forge-web/src/pages/repo_rename.rsmodified+15 -15
@@ -10,7 +10,7 @@ use forge_core::store::orgs::OrgMemberRole;
1010 use forge_core::{AuditAction, Error as CoreError};
1111 use serde::Deserialize;
1212 use topcoat::Result;
13-use topcoat::context::{Cx, app_context};
13+use topcoat::context::{Cx, context};
1414 use topcoat::router::content::Form;
1515 use topcoat::router::error::{SeeOther, forbidden, see_other};
1616 use topcoat::router::{page, path_param, route};
@@ -51,6 +51,7 @@ struct TransferForm {
5151 /// form opens with it and keeps the typed `name`.
5252 #[component]
5353 pub(crate) async fn rename_section(
54+ cx: &Cx,
5455 lang: Lang,
5556 title: String,
5657 csrf: String,
@@ -84,17 +85,19 @@ pub(crate) async fn rename_section(
8485 /// The rename form moved into the danger zone; the old address goes there.
8586 #[route(GET "/{owner}/{repo}/settings/rename")]
8687 async fn rename_get(cx: &Cx) -> Result<SeeOther> {
87- let owner = path_param::<Owner>(cx);
88- let name = path_param::<Repo>(cx);
89- Ok(see_other(format!("/{owner}/{name}/settings?section=danger")))
88+ let owner = owner(cx);
89+ let name = repo(cx);
90+ Ok(see_other(format!(
91+ "/{owner}/{name}/settings?section=danger"
92+ )))
9093 }
9194
9295 /// Renames the repo. The store validates the name with `validate_name`; an invalid name or a name
9396 /// taken by another repo of the owner re-renders the danger zone with the message.
9497 #[page(POST "/{owner}/{repo}/settings/rename")]
9598 async fn rename_post(cx: &Cx, Form(form): Form<RenameForm>) -> Result<impl View> {
96- let owner = path_param::<Owner>(cx);
97- let name = path_param::<Repo>(cx);
99+ let owner = owner(cx);
100+ let name = repo(cx);
98101 let ctx = load_repo(cx, owner, name).await?;
99102 let (user, session) = require_csrf(cx, &form.csrf).await?;
100103 if !ctx.can_admin() {
@@ -107,7 +110,7 @@ async fn rename_post(cx: &Cx, Form(form): Form<RenameForm>) -> Result<impl View>
107110 .chars()
108111 .all(|c| c.is_ascii_alphanumeric() || matches!(c, '.' | '_' | '-'))
109112 {
110- let state = app_context::<AppState>(cx);
113+ let state = context::<AppState>(cx);
111114 state
112115 .store
113116 .rename_repo(&ctx.repo.id, &new_name)
@@ -127,7 +130,7 @@ async fn rename_post(cx: &Cx, Form(form): Form<RenameForm>) -> Result<impl View>
127130 "repository renamed"
128131 );
129132 audit::record(
130- &app_context::<AppState>(cx).store,
133+ &context::<AppState>(cx).store,
131134 Some(cx),
132135 Actor::User(&user),
133136 AuditAction::RepoRenamed,
@@ -170,8 +173,8 @@ async fn rename_post(cx: &Cx, Form(form): Form<RenameForm>) -> Result<impl View>
170173 /// `owner/name` confirmation. The store removes the new owner's collaborator row.
171174 #[page(POST "/{owner}/{repo}/settings/transfer")]
172175 async fn transfer_post(cx: &Cx, Form(form): Form<TransferForm>) -> Result<impl View> {
173- let owner = path_param::<Owner>(cx);
174- let name = path_param::<Repo>(cx);
176+ let owner = owner(cx);
177+ let name = repo(cx);
175178 let ctx = load_repo(cx, owner, name).await?;
176179 let (user, session) = require_csrf(cx, &form.csrf).await?;
177180 if !ctx.can_delete() {
@@ -180,7 +183,7 @@ async fn transfer_post(cx: &Cx, Form(form): Form<TransferForm>) -> Result<impl V
180183 let lang = i18n::lang(cx, Some(&user));
181184 let title = format!("{}/{}", ctx.repo.owner_name, ctx.repo.name);
182185 let target = form.new_owner.trim().to_owned();
183- let state = app_context::<AppState>(cx);
186+ let state = context::<AppState>(cx);
184187
185188 let error: Option<String> = 'attempt: {
186189 if form.confirm.trim() != title {
@@ -226,10 +229,7 @@ async fn transfer_post(cx: &Cx, Form(form): Form<TransferForm>) -> Result<impl V
226229 serde_json::json!({ "to": new_owner.username }),
227230 )
228231 .await;
229- return Err(see_other(format!(
230- "/{title}/settings?section=danger"
231- ))
232- .into());
232+ return Err(see_other(format!("/{title}/settings?section=danger")).into());
233233 }
234234 Err(CoreError::Conflict(message)) => break 'attempt Some(message),
235235 Err(other) => return Err(other.into()),
crates/forge-web/src/pages/repo_scrub.rsmodified+6 -6
@@ -12,7 +12,7 @@ use std::sync::{Arc, Mutex};
1212 use forge_core::Repo as RepoRow;
1313 use forge_git::browse;
1414 use topcoat::Result;
15-use topcoat::context::{Cx, app_context};
15+use topcoat::context::{Cx, context};
1616 use topcoat::router::error::not_found;
1717 use topcoat::router::{page, path_param};
1818 use topcoat::view::{View, component, view};
@@ -162,7 +162,7 @@ async fn scrub_parts(state: &AppState, ctx: &RepoCtx, oid: &str) -> Result<Optio
162162
163163 /// The listing rows. Names link to their entry at the commit; directories get the folder icon.
164164 #[component]
165-async fn scrub_table(rows: Vec<ScrubRow>, lang: Lang) -> Result<impl View> {
165+async fn scrub_table(cx: &Cx, rows: Vec<ScrubRow>, lang: Lang) -> Result<impl View> {
166166 Ok(view! {
167167 for row in rows.into_iter() {
168168 <div class="tree-entry">
@@ -187,14 +187,14 @@ async fn scrub_table(rows: Vec<ScrubRow>, lang: Lang) -> Result<impl View> {
187187
188188 #[page("/{owner}/{repo}/scrub/{oid}")]
189189 async fn scrub_page(cx: &Cx) -> Result<impl View> {
190- let owner = path_param::<Owner>(cx);
191- let name = path_param::<Repo>(cx);
192- let oid = path_param::<Oid>(cx);
190+ let owner = owner(cx);
191+ let name = repo(cx);
192+ let oid = oid(cx);
193193 let ctx = load_repo(cx, owner, name).await?;
194194 if !is_full_oid(&oid) {
195195 return Err(not_found().into());
196196 }
197- let state = app_context::<AppState>(cx);
197+ let state = context::<AppState>(cx);
198198 let Some(parts) = scrub_parts(state, &ctx, &oid).await? else {
199199 return Err(not_found().into());
200200 };
crates/forge-web/src/pages/repo_secrets.rsmodified+12 -10
@@ -7,7 +7,7 @@
77 use forge_core::AuditAction;
88 use serde::Deserialize;
99 use topcoat::Result;
10-use topcoat::context::{Cx, app_context};
10+use topcoat::context::{Cx, context};
1111 use topcoat::router::content::Form;
1212 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
1313 use topcoat::router::request::uri;
@@ -151,6 +151,7 @@ impl SecretsData {
151151 /// Header, the rail and the one-line notice.
152152 #[component]
153153 async fn frame_top(
154+ cx: &Cx,
154155 lang: Lang,
155156 head: RepoHead,
156157 title: String,
@@ -182,6 +183,7 @@ async fn frame_top(
182183 /// value is never passed back, so the textarea is always empty.
183184 #[component]
184185 async fn secrets_body(
186+ cx: &Cx,
185187 lang: Lang,
186188 head: RepoHead,
187189 title: String,
@@ -252,15 +254,15 @@ async fn secrets_body(
252254 /// Lists the repo's CI secret names. Admins only: anyone else gets 404.
253255 #[page("/{owner}/{repo}/settings/secrets")]
254256 async fn secrets_list_page(cx: &Cx) -> Result<impl View> {
255- let owner = path_param::<Owner>(cx);
256- let name = path_param::<Repo>(cx);
257+ let owner = owner(cx);
258+ let name = repo(cx);
257259 let ctx = load_repo(cx, owner, name).await?;
258260 let (user, session) = require_user(cx).await?;
259261 if !ctx.can_admin() {
260262 return Err(not_found().into());
261263 }
262264 let lang = i18n::lang(cx, Some(&user));
263- let state = app_context::<AppState>(cx);
265+ let state = context::<AppState>(cx);
264266 let data = SecretsData::load(state, &ctx, lang).await?;
265267 let csrf = session.csrf_token.clone();
266268 let notice = notice_from_query(cx);
@@ -276,8 +278,8 @@ async fn secrets_list_page(cx: &Cx) -> Result<impl View> {
276278 /// is dropped, not sent back.
277279 #[page(POST "/{owner}/{repo}/settings/secrets")]
278280 async fn secret_set(cx: &Cx, Form(form): Form<SetForm>) -> Result<impl View> {
279- let owner = path_param::<Owner>(cx);
280- let name = path_param::<Repo>(cx);
281+ let owner = owner(cx);
282+ let name = repo(cx);
281283 let ctx = load_repo(cx, owner, name).await?;
282284 let (user, session) = require_csrf(cx, &form.csrf).await?;
283285 if !ctx.can_admin() {
@@ -287,7 +289,7 @@ async fn secret_set(cx: &Cx, Form(form): Form<SetForm>) -> Result<impl View> {
287289 return Err(forbidden().into());
288290 }
289291 let lang = i18n::lang(cx, Some(&user));
290- let state = app_context::<AppState>(cx);
292+ let state = context::<AppState>(cx);
291293 let secret_name = form.name.trim().to_owned();
292294 if let Err(message) = check_secret(lang, &secret_name, &form.value) {
293295 let data = SecretsData::load(state, &ctx, lang).await?;
@@ -323,8 +325,8 @@ async fn secret_set(cx: &Cx, Form(form): Form<SetForm>) -> Result<impl View> {
323325 /// Deletes a secret by name. A name that is not stored is refused with a notice.
324326 #[route(POST "/{owner}/{repo}/settings/secrets/delete")]
325327 async fn secret_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther> {
326- let owner = path_param::<Owner>(cx);
327- let name = path_param::<Repo>(cx);
328+ let owner = owner(cx);
329+ let name = repo(cx);
328330 let ctx = load_repo(cx, owner, name).await?;
329331 let (user, _) = require_csrf(cx, &form.csrf).await?;
330332 if !ctx.can_admin() {
@@ -333,7 +335,7 @@ async fn secret_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther
333335 if ctx.repo.archived {
334336 return Err(forbidden().into());
335337 }
336- let state = app_context::<AppState>(cx);
338+ let state = context::<AppState>(cx);
337339 let title = title_of(&ctx);
338340 let secret_name = form.name.trim().to_owned();
339341 if !valid_name(&secret_name)
crates/forge-web/src/pages/repo_security.rsmodified+8 -7
@@ -9,7 +9,7 @@ use forge_core::{Action, AuditAction, authorize};
99 use serde::Deserialize;
1010 use serde_json::json;
1111 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};
12+use topcoat::context::{Cx, context};
1313 use topcoat::router::content::Form;
1414 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
1515 use topcoat::router::{page, path_param, route};
@@ -112,6 +112,7 @@ fn row_of(alert: &Alert, title: &str, lang: Lang) -> AlertRow {
112112
113113 #[component]
114114 async fn security_body(
115+ cx: &Cx,
115116 lang: Lang,
116117 head: RepoHead,
117118 enabled: bool,
@@ -156,15 +157,15 @@ async fn security_body(
156157 /// The security page. Write on the repo or 404.
157158 #[page("/{owner}/{repo}/security")]
158159 async fn security_page(cx: &Cx) -> Result<impl View> {
159- let owner = path_param::<Owner>(cx);
160- let name = path_param::<Repo>(cx);
160+ let owner = owner(cx);
161+ let name = repo(cx);
161162 let ctx = load_repo(cx, owner, name).await?;
162163 let (user, session) = require_user(cx).await?;
163164 if !can_write(&ctx) {
164165 return Err(not_found().into());
165166 }
166167 let lang = i18n::lang(cx, Some(&user));
167- let state = app_context::<AppState>(cx);
168+ let state = context::<AppState>(cx);
168169 let title = title_of(&ctx);
169170 let mut head = ctx.head(state, "security").await?;
170171 head.live = security_live_url(&ctx.repo.owner_name, &ctx.repo.name);
@@ -195,8 +196,8 @@ async fn change_alert(
195196 to: AlertState,
196197 action: AuditAction,
197198 ) -> Result<SeeOther> {
198- let owner = path_param::<Owner>(cx);
199- let name = path_param::<Repo>(cx);
199+ let owner = owner(cx);
200+ let name = repo(cx);
200201 let ctx = load_repo(cx, owner, name).await?;
201202 let (user, _) = require_csrf(cx, &form.csrf).await?;
202203 if !can_write(&ctx) {
@@ -205,7 +206,7 @@ async fn change_alert(
205206 if ctx.repo.archived {
206207 return Err(forbidden().into());
207208 }
208- let state = app_context::<AppState>(cx);
209+ let state = context::<AppState>(cx);
209210 let key = AlertKey {
210211 advisory_id: form.advisory.clone(),
211212 ecosystem: form.ecosystem.clone(),
crates/forge-web/src/pages/repo_settings.rsmodified+87 -41
@@ -22,7 +22,7 @@ use forge_git::repo::{
2222 };
2323 use serde::Deserialize;
2424 use topcoat::Result;
25-use topcoat::context::{Cx, app_context};
25+use topcoat::context::{Cx, context};
2626 use topcoat::cookie::{Cookie, Cookies, SameSite, cookies};
2727 use topcoat::router::content::Form;
2828 use topcoat::router::error::{SeeOther, forbidden, see_other};
@@ -261,7 +261,7 @@ async fn load_branch_names(ctx: &RepoCtx) -> Result<Vec<String>> {
261261
262262 /// The one-line notice on the profile page after a delete.
263263 #[component]
264-pub async fn notice_banner_for(lang: Lang, title: Option<String>) -> Result<impl View> {
264+pub async fn notice_banner_for(cx: &Cx, lang: Lang, title: Option<String>) -> Result<impl View> {
265265 Ok(view! {
266266 if let Some(title) = title {
267267 <p class="state" role="status">
@@ -296,6 +296,7 @@ impl DangerForms {
296296 /// The Visibility topic: the current value as a line, and the other side behind a confirm.
297297 #[component]
298298 async fn visibility_section(
299+ cx: &Cx,
299300 lang: Lang,
300301 title: String,
301302 csrf: String,
@@ -334,6 +335,7 @@ async fn visibility_section(
334335 /// The Archive topic: what archiving does, and the one action for the repo's state.
335336 #[component]
336337 async fn archive_section(
338+ cx: &Cx,
337339 lang: Lang,
338340 title: String,
339341 csrf: String,
@@ -363,6 +365,7 @@ async fn archive_section(
363365 /// action is a small pill that opens its form or confirm in place.
364366 #[component]
365367 async fn danger_section(
368+ cx: &Cx,
366369 lang: Lang,
367370 title: String,
368371 csrf: String,
@@ -396,6 +399,7 @@ async fn danger_section(
396399 /// The Delete topic: what deleting does, and the confirmation form, which opens in place.
397400 #[component]
398401 async fn delete_section(
402+ cx: &Cx,
399403 lang: Lang,
400404 csrf: String,
401405 title: String,
@@ -437,6 +441,7 @@ async fn delete_section(
437441 /// page is for a repo admin, so the Danger zone is always listed.
438442 #[component]
439443 pub async fn settings_frame(
444+ cx: &Cx,
440445 lang: Lang,
441446 title: String,
442447 current: &'static str,
@@ -449,13 +454,41 @@ pub async fn settings_frame(
449454 current: on,
450455 };
451456 let items = vec![
452- item(g::t(lang, K::General), format!("/{title}/settings"), current == "general"),
453- item(g::t(lang, K::Collaborators), format!("/{title}/settings/collaborators"), current == "collaborators"),
454- item(g::t(lang, K::BranchProtection), format!("/{title}/settings?section=branches"), current == "branches"),
455- item(g::t(lang, K::Webhooks), format!("/{title}/settings/hooks"), current == "webhooks"),
456- item(g::t(lang, K::Mirrors), format!("/{title}/settings/mirrors"), current == "mirrors"),
457- item(g::t(lang, K::Secrets), format!("/{title}/settings/secrets"), current == "secrets"),
458- item(g::t(lang, K::DangerZone), format!("/{title}/settings?section=danger"), current == "danger"),
457+ item(
458+ g::t(lang, K::General),
459+ format!("/{title}/settings"),
460+ current == "general",
461+ ),
462+ item(
463+ g::t(lang, K::Collaborators),
464+ format!("/{title}/settings/collaborators"),
465+ current == "collaborators",
466+ ),
467+ item(
468+ g::t(lang, K::BranchProtection),
469+ format!("/{title}/settings?section=branches"),
470+ current == "branches",
471+ ),
472+ item(
473+ g::t(lang, K::Webhooks),
474+ format!("/{title}/settings/hooks"),
475+ current == "webhooks",
476+ ),
477+ item(
478+ g::t(lang, K::Mirrors),
479+ format!("/{title}/settings/mirrors"),
480+ current == "mirrors",
481+ ),
482+ item(
483+ g::t(lang, K::Secrets),
484+ format!("/{title}/settings/secrets"),
485+ current == "secrets",
486+ ),
487+ item(
488+ g::t(lang, K::DangerZone),
489+ format!("/{title}/settings?section=danger"),
490+ current == "danger",
491+ ),
459492 ];
460493 Ok(view! {
461494 <div class="work">
@@ -467,12 +500,12 @@ pub async fn settings_frame(
467500 })
468501 }
469502
470-
471503 /// The General section: description and default branch in one form, under no heading (the page's
472504 /// head names it), then the Features topic with one switch per feature. Each form carries its own
473505 /// CSRF token. An empty repo shows "No branches yet" and no selector.
474506 #[component]
475507 async fn general_section(
508+ cx: &Cx,
476509 lang: Lang,
477510 title: String,
478511 csrf: String,
@@ -617,6 +650,7 @@ struct RuleCard {
617650 /// opens with the draft when no rule takes it. The rows share one `name`, so opening one closes the rest.
618651 #[component]
619652 async fn branch_rule_cards(
653+ cx: &Cx,
620654 lang: Lang,
621655 cards: Vec<RuleCard>,
622656 builtin_row: bool,
@@ -673,6 +707,7 @@ async fn branch_rule_cards(
673707 /// an existing rule's Remove action is a confirm_act beside them, on the same row.
674708 #[component]
675709 async fn branch_rule_form(
710+ cx: &Cx,
676711 lang: Lang,
677712 csrf: String,
678713 save_action: String,
@@ -700,7 +735,11 @@ async fn branch_rule_form(
700735 || require_up_to_date
701736 || require_merge_queue
702737 || !required_checks.trim().is_empty();
703- let pr_class = if pr_saved { "rule-pr rule-pr-set" } else { "rule-pr" };
738+ let pr_class = if pr_saved {
739+ "rule-pr rule-pr-set"
740+ } else {
741+ "rule-pr"
742+ };
704743 // Field ids are per rule, so two open rule forms never share an id.
705744 let prefix = match &rule_id {
706745 Some(id) => format!("rule-{id}"),
@@ -896,7 +935,7 @@ pub(crate) async fn render_settings(
896935 lang: Lang,
897936 shown: Shown,
898937 ) -> Result<impl View> {
899- let state = app_context::<AppState>(cx);
938+ let state = context::<AppState>(cx);
900939 let Shown {
901940 section,
902941 notice,
@@ -915,14 +954,11 @@ pub(crate) async fn render_settings(
915954 danger,
916955 transfer,
917956 wiki_on: state.store.wiki_enabled(&ctx.repo.id).await?,
918- contexts: state
919- .store
920- .recent_status_contexts(&ctx.repo.id, 20)
921- .await?,
957+ contexts: state.store.recent_status_contexts(&ctx.repo.id, 20).await?,
922958 };
923959 let frame = SettingsFrame::new(&ctx, state, lang).await?;
924960 let branches = load_branch_names(&ctx).await?;
925- Ok(view! { cx =>
961+ Ok(view! {
926962 shell(title: frame.page_title.as_str(), viewer: ctx.viewer.as_ref(),
927963 settings_body(lang: lang, head: frame.head, default_branch: frame.default_branch, archived: frame.archived,
928964 branches: branches, title: frame.title, csrf: csrf,
@@ -934,6 +970,7 @@ pub(crate) async fn render_settings(
934970 /// general, branches or danger) in the sheet.
935971 #[component]
936972 async fn settings_body(
973+ cx: &Cx,
937974 lang: Lang,
938975 head: RepoHead,
939976 default_branch: String,
@@ -1057,8 +1094,8 @@ impl SettingsFrame {
10571094 /// visible repos go to login, and signed-in viewers who may not manage the repo get 403.
10581095 #[page("/{owner}/{repo}/settings")]
10591096 async fn settings_page(cx: &Cx) -> Result<impl View> {
1060- let owner = path_param::<Owner>(cx);
1061- let name = path_param::<Repo>(cx);
1097+ let owner = owner(cx);
1098+ let name = repo(cx);
10621099 let ctx = load_repo(cx, owner, name).await?;
10631100 let (user, session) = require_user(cx).await?;
10641101 if !ctx.can_admin() {
@@ -1080,15 +1117,15 @@ async fn settings_page(cx: &Cx) -> Result<impl View> {
10801117 /// and the database changes only when that succeeds. A failed database write puts HEAD back.
10811118 #[route(POST "/{owner}/{repo}/settings/general")]
10821119 async fn settings_general_save(cx: &Cx, Form(form): Form<GeneralForm>) -> Result<SeeOther> {
1083- let owner = path_param::<Owner>(cx);
1084- let name = path_param::<Repo>(cx);
1120+ let owner = owner(cx);
1121+ let name = repo(cx);
10851122 let ctx = load_repo(cx, owner, name).await?;
10861123 let (user, _) = require_csrf(cx, &form.csrf).await?;
10871124 if !ctx.can_admin() {
10881125 return Err(forbidden().into());
10891126 }
10901127 let title = format!("{}/{}", ctx.repo.owner_name, ctx.repo.name);
1091- let state = app_context::<AppState>(cx);
1128+ let state = context::<AppState>(cx);
10921129
10931130 let description = clean_description(&form.description);
10941131 if description.chars().count() > MAX_DESCRIPTION_CHARS {
@@ -1149,8 +1186,8 @@ async fn settings_general_save(cx: &Cx, Form(form): Form<GeneralForm>) -> Result
11491186 /// changes nothing.
11501187 #[route(POST "/{owner}/{repo}/settings/visibility")]
11511188 async fn settings_visibility_save(cx: &Cx, Form(form): Form<VisibilityForm>) -> Result<SeeOther> {
1152- let owner = path_param::<Owner>(cx);
1153- let name = path_param::<Repo>(cx);
1189+ let owner = owner(cx);
1190+ let name = repo(cx);
11541191 let ctx = load_repo(cx, owner, name).await?;
11551192 let (user, _) = require_csrf(cx, &form.csrf).await?;
11561193 if !ctx.can_admin() {
@@ -1166,7 +1203,7 @@ async fn settings_visibility_save(cx: &Cx, Form(form): Form<VisibilityForm>) ->
11661203 set_settings_notice(cx, "understand");
11671204 return Ok(back_to_section(&title, "danger"));
11681205 }
1169- let state = app_context::<AppState>(cx);
1206+ let state = context::<AppState>(cx);
11701207 state
11711208 .store
11721209 .set_repo_visibility(&ctx.repo.id, target)
@@ -1201,8 +1238,8 @@ async fn settings_visibility_save(cx: &Cx, Form(form): Form<VisibilityForm>) ->
12011238 /// the archived flag does not block Admin.
12021239 #[route(POST "/{owner}/{repo}/settings/archive")]
12031240 async fn settings_archive_save(cx: &Cx, Form(form): Form<ArchiveForm>) -> Result<SeeOther> {
1204- let owner = path_param::<Owner>(cx);
1205- let name = path_param::<Repo>(cx);
1241+ let owner = owner(cx);
1242+ let name = repo(cx);
12061243 let ctx = load_repo(cx, owner, name).await?;
12071244 let (user, _) = require_csrf(cx, &form.csrf).await?;
12081245 if !ctx.can_admin() {
@@ -1217,7 +1254,7 @@ async fn settings_archive_save(cx: &Cx, Form(form): Form<ArchiveForm>) -> Result
12171254 return Ok(back_to_section(&title, "danger"));
12181255 }
12191256 };
1220- let state = app_context::<AppState>(cx);
1257+ let state = context::<AppState>(cx);
12211258 state
12221259 .store
12231260 .set_repo_archived(&ctx.repo.id, archived)
@@ -1258,8 +1295,8 @@ async fn settings_archive_save(cx: &Cx, Form(form): Form<ArchiveForm>) -> Result
12581295 /// A wrong confirmation re-renders the page with an error and changes nothing.
12591296 #[page(POST "/{owner}/{repo}/settings/delete")]
12601297 async fn settings_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<impl View> {
1261- let owner = path_param::<Owner>(cx);
1262- let name = path_param::<Repo>(cx);
1298+ let owner = owner(cx);
1299+ let name = repo(cx);
12631300 let ctx = load_repo(cx, owner, name).await?;
12641301 let (user, session) = require_csrf(cx, &form.csrf).await?;
12651302 if !ctx.can_delete() {
@@ -1274,7 +1311,7 @@ async fn settings_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<impl V
12741311 };
12751312
12761313 if error.is_none() {
1277- let state = app_context::<AppState>(cx);
1314+ let state = context::<AppState>(cx);
12781315 let repo: &RepoRow = &ctx.repo;
12791316 let data_dir = &state.config.data_dir;
12801317 // A missing directory (already removed by hand) has nothing to trash, so only the rows go.
@@ -1378,8 +1415,8 @@ async fn settings_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<impl V
13781415 /// `Action::Admin` first. An invalid pattern re-renders the page with the error next to the form.
13791416 #[page(POST "/{owner}/{repo}/settings/branches")]
13801417 async fn settings_branch_save(cx: &Cx, Form(form): Form<BranchForm>) -> Result<impl View> {
1381- let owner = path_param::<Owner>(cx);
1382- let name = path_param::<Repo>(cx);
1418+ let owner = owner(cx);
1419+ let name = repo(cx);
13831420 let ctx = load_repo(cx, owner, name).await?;
13841421 let (user, session) = require_csrf(cx, &form.csrf).await?;
13851422 if !ctx.can_admin() {
@@ -1391,7 +1428,7 @@ async fn settings_branch_save(cx: &Cx, Form(form): Form<BranchForm>) -> Result<i
13911428
13921429 let is_new = form.existing.is_none();
13931430 let taken = is_new
1394- && app_context::<AppState>(cx)
1431+ && context::<AppState>(cx)
13951432 .store
13961433 .list_branch_rules(&ctx.repo.id)
13971434 .await?
@@ -1433,7 +1470,7 @@ async fn settings_branch_save(cx: &Cx, Form(form): Form<BranchForm>) -> Result<i
14331470 }
14341471 };
14351472
1436- let state = app_context::<AppState>(cx);
1473+ let state = context::<AppState>(cx);
14371474 state
14381475 .store
14391476 .upsert_branch_rule(&ctx.repo.id, &pattern, flags.clone())
@@ -1458,14 +1495,14 @@ async fn settings_branch_save(cx: &Cx, Form(form): Form<BranchForm>) -> Result<i
14581495 /// Removes a branch rule by id, scoped to this repo. Same checks as the save form.
14591496 #[route(POST "/{owner}/{repo}/settings/branches/delete")]
14601497 async fn settings_branch_delete(cx: &Cx, Form(form): Form<BranchDeleteForm>) -> Result<SeeOther> {
1461- let owner = path_param::<Owner>(cx);
1462- let name = path_param::<Repo>(cx);
1498+ let owner = owner(cx);
1499+ let name = repo(cx);
14631500 let ctx = load_repo(cx, owner, name).await?;
14641501 let (user, _) = require_csrf(cx, &form.csrf).await?;
14651502 if !ctx.can_admin() {
14661503 return Err(forbidden().into());
14671504 }
1468- let state = app_context::<AppState>(cx);
1505+ let state = context::<AppState>(cx);
14691506 state
14701507 .store
14711508 .delete_branch_rule(&ctx.repo.id, &form.rule_id)
@@ -1568,7 +1605,11 @@ mod tests {
15681605 let (status, _) = post_rule(
15691606 &app,
15701607 &cookie,
1571- &[("pattern", "main"), ("existing", "1"), ("required_approvals", "")],
1608+ &[
1609+ ("pattern", "main"),
1610+ ("existing", "1"),
1611+ ("required_approvals", ""),
1612+ ],
15721613 )
15731614 .await;
15741615 assert_eq!(status, 303);
@@ -1583,7 +1624,8 @@ mod tests {
15831624 &app,
15841625 &cookie,
15851626 &[
1586- ("pattern", "main"), ("existing", "1"),
1627+ ("pattern", "main"),
1628+ ("existing", "1"),
15871629 ("required_approvals", "21"),
15881630 ("restrict_push", "on"),
15891631 ],
@@ -1602,7 +1644,11 @@ mod tests {
16021644 let (status, body) = post_rule(
16031645 &app,
16041646 &cookie,
1605- &[("pattern", "main"), ("existing", "1"), ("required_approvals", "two")],
1647+ &[
1648+ ("pattern", "main"),
1649+ ("existing", "1"),
1650+ ("required_approvals", "two"),
1651+ ],
16061652 )
16071653 .await;
16081654 assert_eq!(status, 200);
crates/forge-web/src/pages/repo_settings_live.rsmodified+7 -7
@@ -15,7 +15,7 @@
1515 //! security and transfer streams for the signed-in viewers their pages admit.
1616
1717 use topcoat::Result;
18-use topcoat::context::{Cx, app_context};
18+use topcoat::context::{Cx, context};
1919 use topcoat::router::error::forbidden;
2020 use topcoat::router::request::{method, uri};
2121 use topcoat::router::response::Response;
@@ -56,11 +56,11 @@ pub fn bump_settings(hub: &LiveHub, repo_id: &str) {
5656 /// as the settings page is.
5757 #[route(GET "/{owner}/{repo}/settings/live")]
5858 async fn settings_live(cx: &Cx) -> Result<Response> {
59- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
59+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
6060 if !ctx.can_admin() {
6161 return Err(forbidden().into());
6262 }
63- let state = app_context::<AppState>(cx);
63+ let state = context::<AppState>(cx);
6464 let topics = [
6565 Topic::RepoSettings(ctx.repo.id.clone()),
6666 Topic::RepoRefs(ctx.repo.id.clone()),
@@ -72,9 +72,9 @@ async fn settings_live(cx: &Cx) -> Result<Response> {
7272 /// read the repo.
7373 #[route(GET "/{owner}/{repo}/security/live")]
7474 async fn security_live(cx: &Cx) -> Result<Response> {
75- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
75+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
7676 require_user(cx).await?;
77- let state = app_context::<AppState>(cx);
77+ let state = context::<AppState>(cx);
7878 stream_wakes(cx, &state.live, &[Topic::RepoSettings(ctx.repo.id.clone())])
7979 }
8080
@@ -115,7 +115,7 @@ fn written(cx: &Cx) -> Option<(String, String)> {
115115 async fn bump_after_write(cx: &Cx, body: Body, next: Next<'_>) -> Result<Response> {
116116 let repo_id = match written(cx) {
117117 Some((owner, name)) => {
118- let state = app_context::<AppState>(cx);
118+ let state = context::<AppState>(cx);
119119 match state.store.repo_by_owner_and_name(&owner, &name).await {
120120 Ok(repo) => repo.map(|repo| repo.id),
121121 Err(e) => {
@@ -128,7 +128,7 @@ async fn bump_after_write(cx: &Cx, body: Body, next: Next<'_>) -> Result<Respons
128128 };
129129 let result = next.run(cx, body).await;
130130 if let Some(repo_id) = repo_id {
131- let state = app_context::<AppState>(cx);
131+ let state = context::<AppState>(cx);
132132 bump_settings(&state.live, &repo_id);
133133 // The repo header shows settings too (the mirror line, the archived notice, the tabs); its
134134 // stream sends nothing when its fingerprint holds.
crates/forge-web/src/pages/repo_side.rsmodified+3 -2
@@ -256,7 +256,9 @@ pub fn code_sub(
256256 parts.push(SubPart::text(lang_name(lang, share)));
257257 }
258258 if let Some((file, id)) = facts.license.as_ref() {
259- parts.push(SubPart::text(if id.is_empty() { file } else { id }.as_str()));
259+ parts.push(SubPart::text(
260+ if id.is_empty() { file } else { id }.as_str(),
261+ ));
260262 }
261263 if facts.size > 0 {
262264 parts.push(SubPart::text(human_size(lang, facts.size)));
@@ -329,4 +331,3 @@ fn lang_name(lang: Lang, share: &LangShare) -> String {
329331 s(lang, "Other", "Diğer").to_owned()
330332 }
331333 }
332-
crates/forge-web/src/pages/repo_transfer.rsmodified+14 -10
@@ -12,7 +12,7 @@ use forge_core::store::transfers::PendingTransfer;
1212 use forge_core::{AuditAction, Error as CoreError};
1313 use serde::Deserialize;
1414 use topcoat::Result;
15-use topcoat::context::{Cx, app_context};
15+use topcoat::context::{Cx, context};
1616 use topcoat::router::content::Form;
1717 use topcoat::router::error::{SeeOther, forbidden, see_other};
1818 use topcoat::router::{path_param, route};
@@ -94,6 +94,7 @@ pub(crate) async fn transfer_status(
9494 /// with an error opens with it.
9595 #[component]
9696 pub(crate) async fn transfer_section(
97+ cx: &Cx,
9798 lang: Lang,
9899 title: String,
99100 csrf: String,
@@ -146,9 +147,11 @@ pub(crate) async fn transfer_section(
146147 /// The transfer page moved into the danger zone; the old address goes there.
147148 #[route(GET "/{owner}/{repo}/transfer")]
148149 async fn transfer_get(cx: &Cx) -> Result<SeeOther> {
149- let owner = path_param::<Owner>(cx);
150- let repo = path_param::<Repo>(cx);
151- Ok(see_other(format!("/{owner}/{repo}/settings?section=danger")))
150+ let owner = owner(cx);
151+ let repo = repo(cx);
152+ Ok(see_other(format!(
153+ "/{owner}/{repo}/settings?section=danger"
154+ )))
152155 }
153156
154157 /// The open transfer `repo_id`, or `NotFound`.
@@ -163,9 +166,9 @@ async fn open_transfer(state: &AppState, repo_id: &str) -> Result<PendingTransfe
163166 /// Accepts the transfer as the target and moves the repo. Then goes to the repo at its new owner.
164167 #[route(POST "/-/transfers/{transfer}/accept")]
165168 async fn accept_post(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther> {
166- let repo_id = path_param::<Transfer>(cx).to_owned();
169+ let repo_id = transfer(cx).to_owned();
167170 let (user, _) = require_csrf(cx, &form.csrf).await?;
168- let state = app_context::<AppState>(cx);
171+ let state = context::<AppState>(cx);
169172 let pending = open_transfer(state, &repo_id).await?;
170173 let from_owner = state
171174 .store
@@ -201,9 +204,9 @@ async fn accept_post(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther>
201204 /// Declines the transfer as one of its target's owners. The repo stays where it is.
202205 #[route(POST "/-/transfers/{transfer}/decline")]
203206 async fn decline_post(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther> {
204- let repo_id = path_param::<Transfer>(cx).to_owned();
207+ let repo_id = transfer(cx).to_owned();
205208 let (user, _) = require_csrf(cx, &form.csrf).await?;
206- let state = app_context::<AppState>(cx);
209+ let state = context::<AppState>(cx);
207210 let pending = open_transfer(state, &repo_id).await?;
208211 state.store.decline_transfer(&repo_id, &user.id).await?;
209212 bump_settings(&state.live, &repo_id);
@@ -226,9 +229,9 @@ async fn decline_post(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther>
226229 /// Cancels the transfer. The initiator may, and so may anyone who may delete the repo.
227230 #[route(POST "/-/transfers/{transfer}/cancel")]
228231 async fn cancel_post(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther> {
229- let repo_id = path_param::<Transfer>(cx).to_owned();
232+ let repo_id = transfer(cx).to_owned();
230233 let (user, _) = require_csrf(cx, &form.csrf).await?;
231- let state = app_context::<AppState>(cx);
234+ let state = context::<AppState>(cx);
232235 let pending = open_transfer(state, &repo_id).await?;
233236 let repo = state
234237 .store
@@ -276,6 +279,7 @@ struct InboxRow {
276279 /// private repo.
277280 #[component]
278281 pub(crate) async fn transfer_list_for(
282+ cx: &Cx,
279283 lang: Lang,
280284 transfers: Vec<PendingTransfer>,
281285 csrf: String,
crates/forge-web/src/pages/repo_webhooks.rsmodified+37 -31
@@ -13,7 +13,7 @@ use serde_json::Value;
1313 use time::OffsetDateTime;
1414 use time::format_description::well_known::Rfc3339;
1515 use topcoat::Result;
16-use topcoat::context::{Cx, app_context};
16+use topcoat::context::{Cx, context};
1717 use topcoat::router::content::Form;
1818 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
1919 use topcoat::router::request::uri;
@@ -490,6 +490,7 @@ impl Frame {
490490 /// list's name, or the hook's URL); `action` is the head's main action as (href, label), if any.
491491 #[component]
492492 async fn frame_top(
493+ cx: &Cx,
493494 head: RepoHead,
494495 title: String,
495496 heading: String,
@@ -524,6 +525,7 @@ async fn frame_top(
524525 /// The add or edit form. `secret_hint` says what the secret field does for this form.
525526 #[component]
526527 async fn hook_form(
528+ cx: &Cx,
527529 action: String,
528530 csrf: String,
529531 url: String,
@@ -584,6 +586,7 @@ async fn hook_form(
584586
585587 #[component]
586588 async fn hooks_list_body(
589+ cx: &Cx,
587590 head: RepoHead,
588591 title: String,
589592 notice: Option<(&'static str, bool)>,
@@ -628,6 +631,7 @@ async fn hooks_list_body(
628631
629632 #[component]
630633 async fn delivery_list(
634+ cx: &Cx,
631635 deliveries: Vec<DeliveryRow>,
632636 csrf: String,
633637 archived: bool,
@@ -671,6 +675,7 @@ async fn delivery_list(
671675
672676 #[component]
673677 async fn hook_body(
678+ cx: &Cx,
674679 head: RepoHead,
675680 title: String,
676681 notice: Option<(&'static str, bool)>,
@@ -731,14 +736,14 @@ async fn hook_body(
731736 /// Lists the repo's hooks. Admins only: a hidden repo is 404, any other viewer is 403.
732737 #[page("/{owner}/{repo}/settings/hooks")]
733738 async fn hooks_list_page(cx: &Cx) -> Result<impl View> {
734- let owner = path_param::<Owner>(cx);
735- let name = path_param::<Repo>(cx);
739+ let owner = owner(cx);
740+ let name = repo(cx);
736741 let ctx = load_repo(cx, owner, name).await?;
737742 require_user(cx).await?;
738743 if !ctx.can_admin() {
739744 return Err(forbidden().into());
740745 }
741- let state = app_context::<AppState>(cx);
746+ let state = context::<AppState>(cx);
742747 let hooks = state.store.list_webhooks(&ctx.repo.id).await?;
743748 let lang = lang_of(cx, &ctx);
744749 let frame = Frame::new(&ctx, state, lang).await?;
@@ -771,14 +776,14 @@ async fn hooks_list_page(cx: &Cx) -> Result<impl View> {
771776 /// The add form.
772777 #[page("/{owner}/{repo}/settings/hooks/new")]
773778 async fn hook_new_page(cx: &Cx) -> Result<impl View> {
774- let owner = path_param::<Owner>(cx);
775- let name = path_param::<Repo>(cx);
779+ let owner = owner(cx);
780+ let name = repo(cx);
776781 let ctx = load_repo(cx, owner, name).await?;
777782 let (_, session) = require_user(cx).await?;
778783 if !ctx.can_admin() {
779784 return Err(forbidden().into());
780785 }
781- let state = app_context::<AppState>(cx);
786+ let state = context::<AppState>(cx);
782787 let lang = lang_of(cx, &ctx);
783788 let frame = Frame::new(&ctx, state, lang).await?;
784789 let csrf = session.csrf_token.clone();
@@ -793,6 +798,7 @@ async fn hook_new_page(cx: &Cx) -> Result<impl View> {
793798
794799 #[component]
795800 async fn hook_new_body(
801+ cx: &Cx,
796802 head: RepoHead,
797803 title: String,
798804 archived: bool,
@@ -820,14 +826,14 @@ async fn hook_new_body(
820826 /// Creates a hook. The secret is sealed before it is stored. A ping is queued on success.
821827 #[page(POST "/{owner}/{repo}/settings/hooks/new")]
822828 async fn hook_create(cx: &Cx, Form(form): Form<HookForm>) -> Result<impl View> {
823- let owner = path_param::<Owner>(cx);
824- let name = path_param::<Repo>(cx);
829+ let owner = owner(cx);
830+ let name = repo(cx);
825831 let ctx = load_repo(cx, owner, name).await?;
826832 let (user, session) = require_csrf(cx, &form.csrf).await?;
827833 if !ctx.can_admin() || ctx.repo.archived {
828834 return Err(forbidden().into());
829835 }
830- let state = app_context::<AppState>(cx);
836+ let state = context::<AppState>(cx);
831837 let url = form.url.trim().to_owned();
832838 let events = form.events();
833839 let lang = lang_of(cx, &ctx);
@@ -970,15 +976,15 @@ async fn hook_page_data(
970976 /// The hook page: its form, a test button, the last deliveries and the delete form.
971977 #[page("/{owner}/{repo}/settings/hooks/{hook_id}")]
972978 async fn hook_page(cx: &Cx) -> Result<impl View> {
973- let owner = path_param::<Owner>(cx);
974- let name = path_param::<Repo>(cx);
975- let id = path_param::<HookId>(cx);
979+ let owner = owner(cx);
980+ let name = repo(cx);
981+ let id = hook_id(cx);
976982 let ctx = load_repo(cx, owner, name).await?;
977983 let (_, session) = require_user(cx).await?;
978984 if !ctx.can_admin() {
979985 return Err(forbidden().into());
980986 }
981- let state = app_context::<AppState>(cx);
987+ let state = context::<AppState>(cx);
982988 let hook = repo_hook(state, &ctx, id).await?;
983989 let draft = HookDraft::of_hook(&hook);
984990 let csrf = session.csrf_token.clone();
@@ -998,15 +1004,15 @@ async fn hook_page(cx: &Cx) -> Result<impl View> {
9981004 /// page with the submitted values.
9991005 #[page(POST "/{owner}/{repo}/settings/hooks/{hook_id}")]
10001006 async fn hook_update(cx: &Cx, Form(form): Form<HookForm>) -> Result<impl View> {
1001- let owner = path_param::<Owner>(cx);
1002- let name = path_param::<Repo>(cx);
1003- let id = path_param::<HookId>(cx);
1007+ let owner = owner(cx);
1008+ let name = repo(cx);
1009+ let id = hook_id(cx);
10041010 let ctx = load_repo(cx, owner, name).await?;
10051011 let (user, session) = require_csrf(cx, &form.csrf).await?;
10061012 if !ctx.can_admin() || ctx.repo.archived {
10071013 return Err(forbidden().into());
10081014 }
1009- let state = app_context::<AppState>(cx);
1015+ let state = context::<AppState>(cx);
10101016 let hook = repo_hook(state, &ctx, id).await?;
10111017 let url = form.url.trim().to_owned();
10121018 let events = form.events();
@@ -1064,15 +1070,15 @@ async fn hook_update(cx: &Cx, Form(form): Form<HookForm>) -> Result<impl View> {
10641070 /// Sends a ping to the hook now.
10651071 #[route(POST "/{owner}/{repo}/settings/hooks/{hook_id}/test")]
10661072 async fn hook_test(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
1067- let owner = path_param::<Owner>(cx);
1068- let name = path_param::<Repo>(cx);
1069- let id = path_param::<HookId>(cx);
1073+ let owner = owner(cx);
1074+ let name = repo(cx);
1075+ let id = hook_id(cx);
10701076 let ctx = load_repo(cx, owner, name).await?;
10711077 require_csrf(cx, &form.csrf).await?;
10721078 if !ctx.can_admin() || ctx.repo.archived {
10731079 return Err(forbidden().into());
10741080 }
1075- let state = app_context::<AppState>(cx);
1081+ let state = context::<AppState>(cx);
10761082 let hook = repo_hook(state, &ctx, id).await?;
10771083 emit_ping(state, &hook).await?;
10781084 Ok(back_to_hook(&title_of(&ctx), &hook.id, "tested"))
@@ -1081,16 +1087,16 @@ async fn hook_test(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
10811087 /// Queues a new delivery with the same payload as an earlier one, then wakes the worker.
10821088 #[route(POST "/{owner}/{repo}/settings/hooks/{hook_id}/deliveries/{delivery_id}/redeliver")]
10831089 async fn hook_redeliver(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
1084- let owner = path_param::<Owner>(cx);
1085- let name = path_param::<Repo>(cx);
1086- let id = path_param::<HookId>(cx);
1087- let delivery = path_param::<DeliveryId>(cx);
1090+ let owner = owner(cx);
1091+ let name = repo(cx);
1092+ let id = hook_id(cx);
1093+ let delivery = delivery_id(cx);
10881094 let ctx = load_repo(cx, owner, name).await?;
10891095 require_csrf(cx, &form.csrf).await?;
10901096 if !ctx.can_admin() || ctx.repo.archived {
10911097 return Err(forbidden().into());
10921098 }
1093- let state = app_context::<AppState>(cx);
1099+ let state = context::<AppState>(cx);
10941100 let hook = repo_hook(state, &ctx, id).await?;
10951101 match state.store.delivery(delivery).await? {
10961102 Some(original) if original.hook_id == hook.id => {}
@@ -1104,15 +1110,15 @@ async fn hook_redeliver(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther>
11041110 /// Deletes a hook and its deliveries. The box must be ticked.
11051111 #[route(POST "/{owner}/{repo}/settings/hooks/{hook_id}/delete")]
11061112 async fn hook_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther> {
1107- let owner = path_param::<Owner>(cx);
1108- let name = path_param::<Repo>(cx);
1109- let id = path_param::<HookId>(cx);
1113+ let owner = owner(cx);
1114+ let name = repo(cx);
1115+ let id = hook_id(cx);
11101116 let ctx = load_repo(cx, owner, name).await?;
11111117 let (user, _) = require_csrf(cx, &form.csrf).await?;
11121118 if !ctx.can_admin() || ctx.repo.archived {
11131119 return Err(forbidden().into());
11141120 }
1115- let state = app_context::<AppState>(cx);
1121+ let state = context::<AppState>(cx);
11161122 let hook = repo_hook(state, &ctx, id).await?;
11171123 let title = title_of(&ctx);
11181124 if form.confirm.is_none() {
crates/forge-web/src/pages/review_requests.rsmodified+11 -7
@@ -7,7 +7,7 @@
77 use forge_core::authz::{Action, authorize};
88 use serde::Deserialize;
99 use topcoat::Result;
10-use topcoat::context::{Cx, app_context};
10+use topcoat::context::{Cx, context};
1111 use topcoat::router::content::Form;
1212 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
1313 use topcoat::router::request::uri;
@@ -76,7 +76,7 @@ async fn review_requests_events(cx: &Cx) -> Result<Response> {
7676 *res.status_mut() = StatusCode::UNAUTHORIZED;
7777 return Ok(res);
7878 };
79- let state = app_context::<AppState>(cx);
79+ let state = context::<AppState>(cx);
8080 stream_wakes(cx, &state.live, &[Topic::ReviewRequests(user.id)])
8181 }
8282
@@ -87,11 +87,11 @@ fn refusal(code: &str, href: &str) -> SeeOther {
8787
8888 #[route(POST "/{owner}/{repo}/pulls/{number}/reviewers")]
8989 async fn reviewers_save(cx: &Cx, Form(form): Form<ReviewerForm>) -> Result<SeeOther> {
90- let number = parse_number(path_param::<Number>(cx))?;
91- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
90+ let number = parse_number(number(cx))?;
91+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
9292 let (user, session) = require_user(cx).await?;
9393 check_write(&ctx, &session, &form.csrf)?;
94- let state = app_context::<AppState>(cx);
94+ let state = context::<AppState>(cx);
9595 let Some(pr) = state.store.pull_by_number(&ctx.repo.id, number).await? else {
9696 return Err(not_found().into());
9797 };
@@ -201,7 +201,11 @@ fn error_text(lang: Lang, code: &str) -> &'static str {
201201 }
202202
203203 #[component]
204-pub(crate) async fn reviewers_box(lang: Lang, reviewers: ReviewersView) -> Result<impl View> {
204+pub(crate) async fn reviewers_box(
205+ cx: &Cx,
206+ lang: Lang,
207+ reviewers: ReviewersView,
208+) -> Result<impl View> {
205209 let ReviewersView {
206210 action,
207211 csrf,
@@ -251,7 +255,7 @@ pub(crate) async fn reviewers_box(lang: Lang, reviewers: ReviewersView) -> Resul
251255 #[page("/review-requests")]
252256 async fn review_requests(cx: &Cx) -> Result<impl View> {
253257 let viewer = require_user(cx).await?;
254- let state = app_context::<AppState>(cx);
258+ let state = context::<AppState>(cx);
255259 let user = &viewer.0;
256260 let lang = i18n::lang(cx, Some(user));
257261 let items = state.store.review_requests_for_user(&user.id).await?;
crates/forge-web/src/pages/settings_appearance.rsmodified+6 -6
@@ -11,7 +11,7 @@ use forge_core::store::user_prefs::{SOUND, SOUND_VALUES};
1111 use forge_core::{Error as CoreError, Session, Store, User};
1212 use serde::{Deserialize, Deserializer};
1313 use topcoat::Result;
14-use topcoat::context::{Cx, app_context};
14+use topcoat::context::{Cx, context};
1515 use topcoat::router::content::Form;
1616 use topcoat::router::error::{SeeOther, see_other};
1717 use topcoat::router::{page, route};
@@ -289,7 +289,7 @@ fn colour_group(lang: Lang, dark: bool, base: &str, accent_id: &str) -> ColourGr
289289 /// vividness slider and a hex box. The Custom radio carries `hue-H-vV`, and nav.js keeps it, the
290290 /// sliders and the hex box in step while the row is used.
291291 #[component]
292-async fn colour_row(row: ColourRow) -> Result<impl View> {
292+async fn colour_row(cx: &Cx, row: ColourRow) -> Result<impl View> {
293293 let ColourRow {
294294 dark,
295295 base,
@@ -358,7 +358,7 @@ async fn colour_row(row: ColourRow) -> Result<impl View> {
358358
359359 /// One theme's panel: a Background row and an Accent row.
360360 #[component]
361-async fn colour_panel(group: ColourGroup) -> Result<impl View> {
361+async fn colour_panel(cx: &Cx, group: ColourGroup) -> Result<impl View> {
362362 let ColourGroup {
363363 dark,
364364 background,
@@ -408,7 +408,7 @@ async fn colour_panel(group: ColourGroup) -> Result<impl View> {
408408 }
409409
410410 #[component]
411-async fn appearance_body(page: AppearancePage) -> Result<impl View> {
411+async fn appearance_body(cx: &Cx, page: AppearancePage) -> Result<impl View> {
412412 let AppearancePage {
413413 lang,
414414 csrf,
@@ -591,7 +591,7 @@ fn pref_choice(
591591 async fn appearance_page(cx: &Cx) -> Result<impl View> {
592592 let viewer = require_user(cx).await?;
593593 let lang = i18n::lang(cx, Some(&viewer.0));
594- let prefs = app_context::<AppState>(cx)
594+ let prefs = context::<AppState>(cx)
595595 .store
596596 .user_prefs(&viewer.0.id)
597597 .await?;
@@ -609,7 +609,7 @@ async fn appearance_page(cx: &Cx) -> Result<impl View> {
609609 async fn appearance_save(cx: &Cx, Form(form): Form<AppearanceForm>) -> Result<SeeOther> {
610610 let viewer = require_csrf(cx, &form.csrf).await?;
611611 let lang = i18n::lang(cx, Some(&viewer.0));
612- let store: &Store = &app_context::<AppState>(cx).store;
612+ let store: &Store = &context::<AppState>(cx).store;
613613 let user = &viewer.0;
614614
615615 check_choice(lang, &form.theme, &form.language)?;
crates/forge-web/src/pages/settings_export.rsmodified+27 -13
@@ -16,7 +16,7 @@ use http_body_util::StreamBody;
1616 use serde::Deserialize;
1717 use tokio_util::io::ReaderStream;
1818 use topcoat::Result;
19-use topcoat::context::{Cx, app_context};
19+use topcoat::context::{Cx, context};
2020 use topcoat::router::content::Form;
2121 use topcoat::router::error::{SeeOther, not_found, see_other};
2222 use topcoat::router::response::Response;
@@ -79,7 +79,12 @@ fn data_rail_items(lang: Lang, delete: bool) -> Vec<RailItem> {
7979
8080 /// The archives sheet: the request's state, and each archive with its download and delete.
8181 #[component]
82-async fn export_sheet(lang: Lang, csrf: &str, exports: Vec<DataExport>) -> Result<impl View> {
82+async fn export_sheet(
83+ cx: &Cx,
84+ lang: Lang,
85+ csrf: &str,
86+ exports: Vec<DataExport>,
87+) -> Result<impl View> {
8388 let building = exports.iter().any(|e| e.state == ExportState::Building);
8489 let live = building.then(|| {
8590 format!(
@@ -139,6 +144,7 @@ async fn export_sheet(lang: Lang, csrf: &str, exports: Vec<DataExport>) -> Resul
139144 /// username, in one reveal. Repositories still owned by the user block it, and are listed.
140145 #[component]
141146 async fn delete_sheet(
147+ cx: &Cx,
142148 lang: Lang,
143149 csrf: &str,
144150 two_factor_on: bool,
@@ -196,6 +202,7 @@ async fn delete_sheet(
196202 /// The Data page body: the head of the topic, then the rail beside its sheet.
197203 #[component]
198204 async fn data_body(
205+ cx: &Cx,
199206 lang: Lang,
200207 csrf: &str,
201208 delete: bool,
@@ -239,7 +246,7 @@ async fn page_view(
239246 delete_error: Option<String>,
240247 throttled: Option<Duration>,
241248 ) -> Result<impl View> {
242- let state = app_context::<AppState>(cx);
249+ let state = context::<AppState>(cx);
243250 let lang = i18n::lang(cx, Some(&viewer.0));
244251 let user_id = viewer.0.id.clone();
245252 let exports = state.store.list_exports(&user_id).await?;
@@ -260,9 +267,9 @@ async fn page_view(
260267 None => StatusCode::OK,
261268 };
262269 let csrf = viewer.1.csrf_token.clone();
263- // `view!` expects the `__cx` binding that `#[page]` and `#[component]` provide. This plain
270+ // `view!` expects the `cx` binding that `#[page]` and `#[component]` provide. This plain
264271 // helper has to bind it itself.
265- let __cx = cx;
272+ let cx = cx;
266273 Ok(view! {
267274 (status)
268275 (headers)
@@ -286,16 +293,23 @@ pub(crate) async fn respond_delete(
286293 #[page("/settings/export")]
287294 async fn export_page(cx: &Cx) -> Result<impl View> {
288295 let viewer = require_user(cx).await?;
289- let state = app_context::<AppState>(cx);
296+ let state = context::<AppState>(cx);
290297 exporter::sweep_expired(state).await;
291298 let query = query_params::<TopicQuery>(cx)?;
292- page_view(cx, viewer, query.part.as_deref() == Some("delete"), None, None).await
299+ page_view(
300+ cx,
301+ viewer,
302+ query.part.as_deref() == Some("delete"),
303+ None,
304+ None,
305+ )
306+ .await
293307 }
294308
295309 #[route(POST "/settings/export")]
296310 async fn export_request(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
297311 let viewer = require_csrf(cx, &form.csrf).await?;
298- let state = app_context::<AppState>(cx);
312+ let state = context::<AppState>(cx);
299313 exporter::start(state, &viewer.0).await?;
300314 Err(see_other("/settings/export").into())
301315 }
@@ -304,8 +318,8 @@ async fn export_request(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther>
304318 #[route(POST "/settings/export/{export_id}/delete")]
305319 async fn export_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
306320 let viewer = require_csrf(cx, &form.csrf).await?;
307- let id = path_param::<ExportId>(cx).to_owned();
308- let state = app_context::<AppState>(cx);
321+ let id = export_id(cx).to_owned();
322+ let state = context::<AppState>(cx);
309323 let export = match state.store.data_export(&id).await? {
310324 Some(e) if e.user_id == viewer.0.id && e.state != ExportState::Building => e,
311325 _ => return Err(not_found().into()),
@@ -320,7 +334,7 @@ async fn export_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther>
320334 async fn export_events(cx: &Cx) -> Result<Response> {
321335 let viewer = require_user(cx).await?;
322336 let query = query_params::<SeenQuery>(cx)?;
323- let state = app_context::<AppState>(cx);
337+ let state = context::<AppState>(cx);
324338 let user_id = viewer.0.id.clone();
325339 let wake = exporter::subscribe(&user_id);
326340 let store = state.store.clone();
@@ -354,8 +368,8 @@ async fn export_events(cx: &Cx) -> Result<Response> {
354368 #[route(GET "/settings/export/{export_id}/download")]
355369 async fn export_download(cx: &Cx) -> Result<Response> {
356370 let viewer = require_user(cx).await?;
357- let id = path_param::<ExportId>(cx).to_owned();
358- let state = app_context::<AppState>(cx);
371+ let id = export_id(cx).to_owned();
372+ let state = context::<AppState>(cx);
359373 exporter::sweep_expired(state).await;
360374 let export = match state.store.data_export(&id).await? {
361375 Some(e) if e.user_id == viewer.0.id && e.state == ExportState::Ready => e,
crates/forge-web/src/pages/settings_gpg.rsmodified+5 -4
@@ -5,7 +5,7 @@ use forge_core::AuditAction;
55 use forge_core::store::signatures::GpgKey;
66 use serde::Deserialize;
77 use topcoat::Result;
8-use topcoat::context::{Cx, app_context};
8+use topcoat::context::{Cx, context};
99 use topcoat::router::content::Form;
1010 use topcoat::router::error::{SeeOther, not_found, see_other};
1111 use topcoat::router::{page, query_params, route};
@@ -39,6 +39,7 @@ struct DeleteKeyForm {
3939
4040 #[component]
4141 pub(crate) async fn gpg_section(
42+ cx: &Cx,
4243 lang: Lang,
4344 csrf: &str,
4445 keys: Vec<GpgKey>,
@@ -87,7 +88,7 @@ pub(crate) async fn gpg_section(
8788 async fn gpg_page(cx: &Cx) -> Result<impl View> {
8889 let viewer = require_user(cx).await?;
8990 let lang = i18n::lang(cx, Some(&viewer.0));
90- let state = app_context::<AppState>(cx);
91+ let state = context::<AppState>(cx);
9192 let draft = KeysDraft {
9293 add: query_params::<AddQuery>(cx)?.add.is_some(),
9394 ..KeysDraft::default()
@@ -101,7 +102,7 @@ async fn gpg_page(cx: &Cx) -> Result<impl View> {
101102 async fn gpg_add(cx: &Cx, Form(form): Form<AddKeyForm>) -> Result<impl View> {
102103 let viewer = require_csrf(cx, &form.csrf).await?;
103104 let lang = i18n::lang(cx, Some(&viewer.0));
104- let state = app_context::<AppState>(cx);
105+ let state = context::<AppState>(cx);
105106
106107 let message: String = match signatures::import_gpg_key(state, &form.armored).await {
107108 Err(message) => message,
@@ -149,7 +150,7 @@ async fn gpg_add(cx: &Cx, Form(form): Form<AddKeyForm>) -> Result<impl View> {
149150 #[route(POST "/settings/gpg/delete")]
150151 async fn gpg_delete(cx: &Cx, Form(form): Form<DeleteKeyForm>) -> Result<SeeOther> {
151152 let (user, _) = require_csrf(cx, &form.csrf).await?;
152- let state = app_context::<AppState>(cx);
153+ let state = context::<AppState>(cx);
153154 // `delete_gpg_key` only matches the viewer's own keys, so anything else is a 404.
154155 let Some(key) = state.store.delete_gpg_key(&user.id, &form.id).await? else {
155156 return Err(not_found().into());
crates/forge-web/src/pages/settings_keys.rsmodified+6 -4
@@ -6,7 +6,7 @@ use forge_core::{AuditAction, Session, SshKey, User};
66 use serde::Deserialize;
77 use sha2::{Digest, Sha256};
88 use topcoat::Result;
9-use topcoat::context::{Cx, app_context};
9+use topcoat::context::{Cx, context};
1010 use topcoat::router::content::Form;
1111 use topcoat::router::error::{SeeOther, see_other};
1212 use topcoat::router::{page, query_params, route};
@@ -195,6 +195,7 @@ pub(crate) struct AddQuery {
195195 /// The keys page for the viewer, one kind at a time, with what a form sent back.
196196 #[component]
197197 pub(crate) async fn keys_page_view(
198+ cx: &Cx,
198199 lang: Lang,
199200 state: &AppState,
200201 viewer: &(User, Session),
@@ -255,6 +256,7 @@ fn pk_title(lang: Lang) -> &'static str {
255256
256257 #[component]
257258 async fn ssh_section(
259+ cx: &Cx,
258260 lang: Lang,
259261 csrf: &str,
260262 keys: Vec<SshKey>,
@@ -303,7 +305,7 @@ async fn ssh_section(
303305 async fn keys_page(cx: &Cx) -> Result<impl View> {
304306 let viewer = require_user(cx).await?;
305307 let lang = i18n::lang(cx, Some(&viewer.0));
306- let state = app_context::<AppState>(cx);
308+ let state = context::<AppState>(cx);
307309 let draft = KeysDraft {
308310 add: query_params::<AddQuery>(cx)?.add.is_some(),
309311 ..KeysDraft::default()
@@ -317,7 +319,7 @@ async fn keys_page(cx: &Cx) -> Result<impl View> {
317319 async fn keys_add(cx: &Cx, Form(form): Form<AddKeyForm>) -> Result<impl View> {
318320 let viewer = require_csrf(cx, &form.csrf).await?;
319321 let lang = i18n::lang(cx, Some(&viewer.0));
320- let state = app_context::<AppState>(cx);
322+ let state = context::<AppState>(cx);
321323 let store = &state.store;
322324
323325 let outcome: std::result::Result<(), String> = match parse_public_key(&form.public_key) {
@@ -375,7 +377,7 @@ async fn keys_add(cx: &Cx, Form(form): Form<AddKeyForm>) -> Result<impl View> {
375377 #[route(POST "/settings/keys/delete")]
376378 async fn keys_delete(cx: &Cx, Form(form): Form<DeleteKeyForm>) -> Result<SeeOther> {
377379 let (user, _) = require_csrf(cx, &form.csrf).await?;
378- let state = app_context::<AppState>(cx);
380+ let state = context::<AppState>(cx);
379381 if state.store.delete_ssh_key(&user.id, &form.id).await? {
380382 audit::record(
381383 &state.store,
crates/forge-web/src/pages/settings_live.rsmodified+4 -4
@@ -27,7 +27,7 @@ use forge_core::server_settings::{self, FIELDS, Kind};
2727 use futures_util::stream::{self, BoxStream, StreamExt};
2828 use tokio::sync::watch;
2929 use topcoat::Result;
30-use topcoat::context::{Cx, app_context, try_app_context};
30+use topcoat::context::{Cx, context, try_context};
3131 use topcoat::router::content::sse::Event;
3232 use topcoat::router::request::{method, uri};
3333 use topcoat::router::response::Response;
@@ -52,7 +52,7 @@ async fn settings_events(cx: &Cx) -> Result<Response> {
5252 *res.status_mut() = StatusCode::UNAUTHORIZED;
5353 return Ok(res);
5454 };
55- let hub: &LiveHub = &app_context::<AppState>(cx).live;
55+ let hub: &LiveHub = &context::<AppState>(cx).live;
5656 stream_wakes(cx, hub, &[Topic::Account(user.id)])
5757 }
5858
@@ -166,7 +166,7 @@ async fn wait_account(account: &mut Option<AccountFollow>) -> bool {
166166 /// means the server is back.
167167 pub async fn alive_response(cx: &Cx) -> Result<Response> {
168168 // A router with no app state (the asset tests) has nothing to follow: the stream only stays open.
169- let Some(state) = try_app_context::<AppState>(cx).cloned() else {
169+ let Some(state) = try_context::<AppState>(cx).cloned() else {
170170 return events_response(cx, stream::pending::<Result<Event>>());
171171 };
172172 let viewer = current_user(cx)
@@ -305,7 +305,7 @@ async fn bump_after_settings_write(cx: &Cx, body: Body, next: Next<'_>) -> Resul
305305 .map(|(user, _)| user.id);
306306 let result = next.run(cx, body).await;
307307 if let Some(user_id) = viewer {
308- bump_account(app_context::<AppState>(cx), &user_id);
308+ bump_account(context::<AppState>(cx), &user_id);
309309 }
310310 result
311311 }
crates/forge-web/src/pages/settings_notifications.rsmodified+4 -4
@@ -8,7 +8,7 @@ use forge_core::store::web_push::PushSubscription;
88 use forge_core::{Session, Store, User};
99 use serde::Deserialize;
1010 use topcoat::Result;
11-use topcoat::context::{Cx, app_context};
11+use topcoat::context::{Cx, context};
1212 use topcoat::router::content::Form;
1313 use topcoat::router::error::{SeeOther, see_other};
1414 use topcoat::router::{page, query_params, route};
@@ -56,7 +56,7 @@ struct NotificationsPage {
5656 }
5757
5858 #[component]
59-async fn notifications_body(page: NotificationsPage) -> Result<impl View> {
59+async fn notifications_body(cx: &Cx, page: NotificationsPage) -> Result<impl View> {
6060 let NotificationsPage {
6161 lang,
6262 csrf,
@@ -166,7 +166,7 @@ async fn page_for(
166166 #[page("/settings/notifications")]
167167 async fn notifications_page(cx: &Cx) -> Result<impl View> {
168168 let viewer = require_user(cx).await?;
169- let store: &Store = &app_context::<AppState>(cx).store;
169+ let store: &Store = &context::<AppState>(cx).store;
170170 let lang = i18n::lang(cx, Some(&viewer.0));
171171 let query = query_params::<NotificationsQuery>(cx)?;
172172 let notice = if query.saved.as_deref() == Some("1") {
@@ -191,7 +191,7 @@ async fn notifications_page(cx: &Cx) -> Result<impl View> {
191191 #[route(POST "/settings/notifications")]
192192 async fn notifications_save(cx: &Cx, Form(form): Form<NotificationsForm>) -> Result<SeeOther> {
193193 let viewer = require_csrf(cx, &form.csrf).await?;
194- let store: &Store = &app_context::<AppState>(cx).store;
194+ let store: &Store = &context::<AppState>(cx).store;
195195 store
196196 .set_email_notifications(&viewer.0.id, form.email_notifications.is_some())
197197 .await?;
crates/forge-web/src/pages/settings_profile.rsmodified+10 -18
@@ -12,7 +12,7 @@ use forge_core::{Session, Store, User, avatar::MAX_UPLOAD_BYTES, avatar::process
1212 use serde::Deserialize;
1313 use tokio::sync::Semaphore;
1414 use topcoat::Result;
15-use topcoat::context::{Cx, app_context};
15+use topcoat::context::{Cx, context};
1616 use topcoat::router::content::Form;
1717 use topcoat::router::content::multipart::Multipart;
1818 use topcoat::router::error::{SeeOther, see_other};
@@ -33,16 +33,8 @@ pub const MAX_ABOUT_CHARS: usize = 2000;
3333 /// Multipart framing overhead allowed on top of the image itself.
3434 const MULTIPART_OVERHEAD: usize = 64 * 1024;
3535
36-/// Body limit for the avatar upload route. The default 2 MiB is too small for a 5 MiB image.
37-pub fn avatar_body_limit() -> BodyLimit {
38- BodyLimit::max(MAX_UPLOAD_BYTES + MULTIPART_OVERHEAD).at("/settings/profile/avatar")
39-}
40-
41-/// Body limit for the org avatar upload route. A `{org}` segment in a layer path matches any
42-/// org name, as it does in the route path itself.
43-pub fn org_avatar_body_limit() -> BodyLimit {
44- BodyLimit::max(MAX_UPLOAD_BYTES + MULTIPART_OVERHEAD).at("/org/{org}/settings/avatar")
45-}
36+/// Body limit for the avatar upload routes. The default 2 MiB is too small for a 5 MiB image.
37+pub const AVATAR_BODY_LIMIT: usize = MAX_UPLOAD_BYTES + MULTIPART_OVERHEAD;
4638
4739 #[query_params(error = bad_request)]
4840 struct ProfileQuery {
@@ -127,7 +119,7 @@ struct ProfilePage {
127119 }
128120
129121 #[component]
130-async fn profile_body(page: ProfilePage) -> Result<impl View> {
122+async fn profile_body(cx: &Cx, page: ProfilePage) -> Result<impl View> {
131123 let ProfilePage {
132124 lang,
133125 csrf,
@@ -352,7 +344,7 @@ async fn profile_page(cx: &Cx) -> Result<impl View> {
352344 async fn profile_save(cx: &Cx, Form(form): Form<ProfileForm>) -> Result<impl View> {
353345 let viewer = require_csrf(cx, &form.csrf).await?;
354346 let lang = i18n::lang(cx, Some(&viewer.0));
355- let store = &app_context::<AppState>(cx).store;
347+ let store = &context::<AppState>(cx).store;
356348 let about = form.about.replace("\r\n", "\n");
357349
358350 let mut errors = Errors::default();
@@ -413,14 +405,14 @@ async fn profile_save(cx: &Cx, Form(form): Form<ProfileForm>) -> Result<impl Vie
413405 }
414406 // The public profile shows the name, the username and the about text: its viewers follow the
415407 // user's topic too.
416- app_context::<AppState>(cx)
408+ context::<AppState>(cx)
417409 .live
418410 .bump(&Topic::User(viewer.0.id.clone()));
419411 Err(see_other("/settings/profile?saved=1").into())
420412 }
421413
422414 /// Reads the multipart body. The CSRF field is checked before the image is decoded.
423-#[page(POST "/settings/profile/avatar")]
415+#[page(POST "/settings/profile/avatar", with(BodyLimit::max(AVATAR_BODY_LIMIT)))]
424416 async fn avatar_upload(cx: &Cx, mut multipart: Multipart) -> Result<impl View> {
425417 let mut csrf = String::new();
426418 let mut image = None;
@@ -434,11 +426,11 @@ async fn avatar_upload(cx: &Cx, mut multipart: Multipart) -> Result<impl View> {
434426 }
435427 let viewer = require_csrf(cx, &csrf).await?;
436428 let lang = i18n::lang(cx, Some(&viewer.0));
437- let store = &app_context::<AppState>(cx).store;
429+ let store = &context::<AppState>(cx).store;
438430
439431 let message = match store_avatar(store, &viewer.0.id, image, lang).await {
440432 Ok(()) => {
441- app_context::<AppState>(cx)
433+ context::<AppState>(cx)
442434 .live
443435 .bump(&Topic::User(viewer.0.id.clone()));
444436 return Err(see_other("/settings/profile?saved=avatar").into());
@@ -461,7 +453,7 @@ async fn avatar_upload(cx: &Cx, mut multipart: Multipart) -> Result<impl View> {
461453 #[route(POST "/settings/profile/avatar/delete")]
462454 async fn avatar_remove(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
463455 let viewer = require_csrf(cx, &form.csrf).await?;
464- let state = app_context::<AppState>(cx);
456+ let state = context::<AppState>(cx);
465457 state.store.delete_avatar(&viewer.0.id).await?;
466458 state.live.bump(&Topic::User(viewer.0.id.clone()));
467459 Ok(see_other("/settings/profile?saved=avatar-removed"))
crates/forge-web/src/pages/settings_security.rsmodified+15 -15
@@ -11,7 +11,7 @@ use forge_core::{AuditAction, Session, User, secret};
1111 use http::header::{HeaderValue, RETRY_AFTER};
1212 use serde::Deserialize;
1313 use topcoat::Result;
14-use topcoat::context::{Cx, app_context};
14+use topcoat::context::{Cx, context};
1515 use topcoat::router::content::Form;
1616 use topcoat::router::error::{SeeOther, see_other};
1717 use topcoat::router::{HeaderMap, StatusCode, page, query_params, route};
@@ -274,7 +274,7 @@ pub(crate) async fn security_rail_for(
274274 }
275275
276276 #[component]
277-async fn security_body(page: SecurityPage, csrf: &str) -> Result<impl View> {
277+async fn security_body(cx: &Cx, page: SecurityPage, csrf: &str) -> Result<impl View> {
278278 let SecurityPage {
279279 lang,
280280 email,
@@ -656,10 +656,10 @@ async fn build_page(
656656
657657 /// Renders the page. A throttled check answers 429 with `Retry-After`.
658658 async fn respond(cx: &Cx, viewer: (User, Session), shown: Shown) -> Result<impl View> {
659- let state = app_context::<AppState>(cx);
660- // `view!` expects the `__cx` binding that `#[page]` and `#[component]` provide. This plain
659+ let state = context::<AppState>(cx);
660+ // `view!` expects the `cx` binding that `#[page]` and `#[component]` provide. This plain
661661 // helper has to bind it itself.
662- let __cx = cx;
662+ let cx = cx;
663663 let mut headers = HeaderMap::new();
664664 let status = match shown.throttled {
665665 Some(retry) => {
@@ -779,7 +779,7 @@ async fn security_page(cx: &Cx) -> Result<impl View> {
779779 async fn password_change(cx: &Cx, Form(form): Form<PasswordForm>) -> Result<impl View> {
780780 let viewer = require_csrf(cx, &form.csrf).await?;
781781 let lang = i18n::lang(cx, Some(&viewer.0));
782- let state = app_context::<AppState>(cx);
782+ let state = context::<AppState>(cx);
783783 let mut shown = Shown::default();
784784 if let Err(refused) = require_password(lang, state, &viewer.0, &form.current_password).await? {
785785 shown.password_error = Some(refused.message.into());
@@ -822,7 +822,7 @@ async fn password_change(cx: &Cx, Form(form): Form<PasswordForm>) -> Result<impl
822822 async fn email_change(cx: &Cx, Form(form): Form<EmailForm>) -> Result<impl View> {
823823 let viewer = require_csrf(cx, &form.csrf).await?;
824824 let lang = i18n::lang(cx, Some(&viewer.0));
825- let state = app_context::<AppState>(cx);
825+ let state = context::<AppState>(cx);
826826 let email = form.email.trim().to_owned();
827827 let mut shown = Shown {
828828 email_draft: Some(email.clone()),
@@ -865,7 +865,7 @@ async fn email_change(cx: &Cx, Form(form): Form<EmailForm>) -> Result<impl View>
865865 #[route(POST "/settings/security/2fa/enable")]
866866 async fn two_factor_enable(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
867867 let (user, _session) = require_csrf(cx, &form.csrf).await?;
868- let state = app_context::<AppState>(cx);
868+ let state = context::<AppState>(cx);
869869 if !two_factor_enabled(&state.store, &user.id).await? {
870870 // A new enrollment replaces any unconfirmed secret.
871871 let sealed = secret::seal(&state.key, &totp::new_secret())?;
@@ -878,7 +878,7 @@ async fn two_factor_enable(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOth
878878 async fn two_factor_confirm(cx: &Cx, Form(form): Form<EnrollForm>) -> Result<impl View> {
879879 let viewer = require_csrf(cx, &form.csrf).await?;
880880 let lang = i18n::lang(cx, Some(&viewer.0));
881- let state = app_context::<AppState>(cx);
881+ let state = context::<AppState>(cx);
882882 let user_id = viewer.0.id.clone();
883883 let Some(totp_state) = state.store.totp_state(&user_id).await? else {
884884 return Err(see_other("/settings/security").into());
@@ -938,7 +938,7 @@ async fn two_factor_confirm(cx: &Cx, Form(form): Form<EnrollForm>) -> Result<imp
938938 async fn two_factor_disable(cx: &Cx, Form(form): Form<DisableForm>) -> Result<impl View> {
939939 let viewer = require_csrf(cx, &form.csrf).await?;
940940 let lang = i18n::lang(cx, Some(&viewer.0));
941- let state = app_context::<AppState>(cx);
941+ let state = context::<AppState>(cx);
942942 let user_id = viewer.0.id.clone();
943943 if !two_factor_enabled(&state.store, &user_id).await? {
944944 return Err(see_other("/settings/security").into());
@@ -981,7 +981,7 @@ async fn two_factor_disable(cx: &Cx, Form(form): Form<DisableForm>) -> Result<im
981981 async fn account_delete(cx: &Cx, Form(form): Form<DeleteAccountForm>) -> Result<impl View> {
982982 let viewer = require_csrf(cx, &form.csrf).await?;
983983 let lang = i18n::lang(cx, Some(&viewer.0));
984- let state = app_context::<AppState>(cx);
984+ let state = context::<AppState>(cx);
985985 let user_id = viewer.0.id.clone();
986986 if form.confirm_username != viewer.0.username {
987987 let error = Some(t(lang, Key::ErrConfirmUsername).into());
@@ -1036,7 +1036,7 @@ async fn account_delete(cx: &Cx, Form(form): Form<DeleteAccountForm>) -> Result<
10361036 async fn two_factor_recovery(cx: &Cx, Form(form): Form<CodeForm>) -> Result<impl View> {
10371037 let viewer = require_csrf(cx, &form.csrf).await?;
10381038 let lang = i18n::lang(cx, Some(&viewer.0));
1039- let state = app_context::<AppState>(cx);
1039+ let state = context::<AppState>(cx);
10401040 let user_id = viewer.0.id.clone();
10411041 if !two_factor_enabled(&state.store, &user_id).await? {
10421042 return Err(see_other("/settings/security").into());
@@ -1089,7 +1089,7 @@ mod tests {
10891089 use forge_core::token::hash_token;
10901090 use forge_core::{Config, Registration, Store, User, secret, totp};
10911091 use forge_git::GitEnv;
1092- use topcoat::cookie::RouterBuilderCookieExt;
1092+ use topcoat::cookie::CookieLayer;
10931093 use topcoat::router::request::Request;
10941094 use topcoat::router::{Body, Router, RouterBuilderDiscoverExt, to_bytes};
10951095
@@ -1184,8 +1184,8 @@ mod tests {
11841184 .unwrap();
11851185 let router = Router::builder()
11861186 .discover()
1187- .cookies()
1188- .app_context(state.clone())
1187+ .layer(CookieLayer::new())
1188+ .with(state.clone())
11891189 .build();
11901190 Fixture {
11911191 router,
crates/forge-web/src/pages/settings_sessions.rsmodified+4 -4
@@ -5,7 +5,7 @@
55 use forge_core::{AuditAction, Session};
66 use serde::Deserialize;
77 use topcoat::Result;
8-use topcoat::context::{Cx, app_context};
8+use topcoat::context::{Cx, context};
99 use topcoat::router::content::Form;
1010 use topcoat::router::error::{SeeOther, see_other};
1111 use topcoat::router::route;
@@ -55,7 +55,7 @@ async fn sessions_revoke(cx: &Cx, Form(form): Form<RevokeForm>) -> Result<SeeOth
5555 let (user, current) = require_csrf(cx, &form.csrf).await?;
5656 if form.id == current.id {
5757 audit::record(
58- &app_context::<AppState>(cx).store,
58+ &context::<AppState>(cx).store,
5959 Some(cx),
6060 Actor::User(&user),
6161 AuditAction::SessionRevoked,
@@ -70,7 +70,7 @@ async fn sessions_revoke(cx: &Cx, Form(form): Form<RevokeForm>) -> Result<SeeOth
7070 logout(cx, &current).await?;
7171 return Ok(see_other("/"));
7272 }
73- let store = &app_context::<AppState>(cx).store;
73+ let store = &context::<AppState>(cx).store;
7474 // Only revoke sessions that belong to the signed-in user.
7575 let owned = store.list_sessions(&user.id).await?;
7676 if owned.iter().any(|s| s.id == form.id) {
@@ -95,7 +95,7 @@ async fn sessions_revoke(cx: &Cx, Form(form): Form<RevokeForm>) -> Result<SeeOth
9595 #[route(POST "/settings/sessions/revoke-others")]
9696 async fn sessions_revoke_others(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
9797 let (user, current) = require_csrf(cx, &form.csrf).await?;
98- let store = &app_context::<AppState>(cx).store;
98+ let store = &context::<AppState>(cx).store;
9999 let mut revoked = 0_u64;
100100 for session in store.list_sessions(&user.id).await? {
101101 if session.id != current.id {
crates/forge-web/src/pages/settings_tokens.rsmodified+5 -4
@@ -9,7 +9,7 @@ use http::HeaderValue;
99 use http::header::CACHE_CONTROL;
1010 use serde::Deserialize;
1111 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};
12+use topcoat::context::{Cx, context};
1313 use topcoat::router::content::Form;
1414 use topcoat::router::error::{SeeOther, see_other};
1515 use topcoat::router::response::response_headers;
@@ -66,6 +66,7 @@ fn expiry_days(choice: &str) -> Option<u64> {
6666
6767 #[component]
6868 pub(crate) async fn tokens_section(
69+ cx: &Cx,
6970 lang: Lang,
7071 csrf: &str,
7172 tokens: Vec<AccessToken>,
@@ -133,7 +134,7 @@ pub(crate) async fn tokens_section(
133134 async fn tokens_page(cx: &Cx) -> Result<impl View> {
134135 let viewer = require_user(cx).await?;
135136 let lang = i18n::lang(cx, Some(&viewer.0));
136- let state = app_context::<AppState>(cx);
137+ let state = context::<AppState>(cx);
137138 let draft = KeysDraft {
138139 add: query_params::<AddQuery>(cx)?.add.is_some(),
139140 ..KeysDraft::default()
@@ -147,7 +148,7 @@ async fn tokens_page(cx: &Cx) -> Result<impl View> {
147148 async fn tokens_create(cx: &Cx, Form(form): Form<CreateTokenForm>) -> Result<impl View> {
148149 let viewer = require_csrf(cx, &form.csrf).await?;
149150 let lang = i18n::lang(cx, Some(&viewer.0));
150- let state = app_context::<AppState>(cx);
151+ let state = context::<AppState>(cx);
151152 let store = &state.store;
152153 let name = form.name.trim();
153154
@@ -211,7 +212,7 @@ async fn tokens_create(cx: &Cx, Form(form): Form<CreateTokenForm>) -> Result<imp
211212 #[route(POST "/settings/tokens/delete")]
212213 async fn tokens_delete(cx: &Cx, Form(form): Form<DeleteTokenForm>) -> Result<SeeOther> {
213214 let (user, _) = require_csrf(cx, &form.csrf).await?;
214- let state = app_context::<AppState>(cx);
215+ let state = context::<AppState>(cx);
215216 if state.store.delete_token(&user.id, &form.id).await? {
216217 audit::record(
217218 &state.store,
crates/forge-web/src/pages/setup.rsmodified+4 -3
@@ -4,7 +4,7 @@ use forge_core::AuditAction;
44 use forge_core::names::validate_username;
55 use serde::Deserialize;
66 use topcoat::Result;
7-use topcoat::context::{Cx, app_context};
7+use topcoat::context::{Cx, context};
88 use topcoat::router::content::Form;
99 use topcoat::router::error::{forbidden, not_found, see_other};
1010 use topcoat::router::page;
@@ -36,6 +36,7 @@ struct SetupForm {
3636
3737 #[component]
3838 async fn setup_form(
39+ cx: &Cx,
3940 lang: Lang,
4041 username: &str,
4142 email: &str,
@@ -75,7 +76,7 @@ async fn setup_form(
7576
7677 #[page("/setup")]
7778 async fn setup_page(cx: &Cx) -> Result<impl View> {
78- let state = app_context::<AppState>(cx);
79+ let state = context::<AppState>(cx);
7980 if state.store.user_count().await? != 0 {
8081 return Err(not_found().into());
8182 }
@@ -92,7 +93,7 @@ async fn setup_submit(cx: &Cx, Form(form): Form<SetupForm>) -> Result<impl View>
9293 if !check_pre_csrf(cx, &form.precsrf) {
9394 return Err(forbidden().into());
9495 }
95- let state = app_context::<AppState>(cx);
96+ let state = context::<AppState>(cx);
9697 if state.store.user_count().await? != 0 {
9798 return Err(not_found().into());
9899 }
crates/forge-web/src/pages/shell_events.rsmodified+2 -2
@@ -12,7 +12,7 @@
1212 use futures_util::StreamExt;
1313 use futures_util::stream::{self, BoxStream};
1414 use topcoat::Result;
15-use topcoat::context::{Cx, try_app_context};
15+use topcoat::context::{Cx, try_context};
1616 use topcoat::router::content::sse::Event;
1717 use topcoat::router::response::Response;
1818 use topcoat::router::route;
@@ -29,7 +29,7 @@ use crate::state::AppState;
2929 #[route(GET "/-/shell/events")]
3030 async fn shell_events(cx: &Cx) -> Result<Response> {
3131 // A router with no app state (the asset tests) has nothing to follow: the stream only stays open.
32- let Some(state) = try_app_context::<AppState>(cx).cloned() else {
32+ let Some(state) = try_context::<AppState>(cx).cloned() else {
3333 return events_response(cx, stream::pending::<Result<Event>>());
3434 };
3535 let viewer = current_user(cx).await?;
crates/forge-web/src/pages/snippet_raw.rsmodified+2 -2
@@ -7,7 +7,7 @@ use forge_core::raw_token::{sign_raw, verify_raw};
77 use forge_core::store::snippets::{Snippet, SnippetVisibility};
88 use serde::Deserialize;
99 use sha2::{Digest, Sha256};
10-use topcoat::context::{Cx, app_context};
10+use topcoat::context::{Cx, context};
1111 use topcoat::router::request::{headers, method};
1212 use topcoat::router::response::Response;
1313 use topcoat::router::{
@@ -66,7 +66,7 @@ fn content_type(file_name: &str) -> &'static str {
6666
6767 /// Serves one file. Every failure is turned into a response here, so the route never errors.
6868 async fn serve(cx: &Cx) -> Response {
69- let state = app_context::<AppState>(cx).clone();
69+ let state = context::<AppState>(cx).clone();
7070 let id = path_param_segment(cx, "id").to_owned();
7171 let segments: Vec<&str> = path_param_segments(cx, "rest").collect();
7272 let [name] = segments.as_slice() else {
crates/forge-web/src/pages/snippets.rsmodified+24 -18
@@ -12,7 +12,7 @@ use forge_core::store::snippets::{
1212 };
1313 use forge_core::{AuditAction, Session, User};
1414 use topcoat::Result;
15-use topcoat::context::{Cx, app_context};
15+use topcoat::context::{Cx, context};
1616 use topcoat::router::content::Form;
1717 use topcoat::router::error::{SeeOther, not_found, see_other};
1818 use topcoat::router::{page, path_param, route};
@@ -257,7 +257,7 @@ pub(crate) async fn readable(
257257 viewer_id: Option<&str>,
258258 snippet_id: &str,
259259 ) -> Result<Snippet> {
260- let store = &app_context::<AppState>(cx).store;
260+ let store = &context::<AppState>(cx).store;
261261 match store.get_snippet(snippet_id).await? {
262262 Some(snippet) if snippet.is_visible_to(viewer_id) => Ok(snippet),
263263 _ => Err(not_found().into()),
@@ -266,7 +266,7 @@ pub(crate) async fn readable(
266266
267267 /// The snippet if the user owns it, else 404. Edits and deletes go through this check.
268268 async fn owned(cx: &Cx, user: &User, snippet_id: &str) -> Result<Snippet> {
269- let store = &app_context::<AppState>(cx).store;
269+ let store = &context::<AppState>(cx).store;
270270 match store.get_snippet(snippet_id).await? {
271271 Some(snippet) if snippet.owner_id == user.id => Ok(snippet),
272272 _ => Err(not_found().into()),
@@ -275,7 +275,7 @@ async fn owned(cx: &Cx, user: &User, snippet_id: &str) -> Result<Snippet> {
275275
276276 /// The snippet rows, one linked line each: title, owner, visibility, file count and update time.
277277 #[component]
278-pub(crate) async fn snippet_rows(lang: Lang, rows: Vec<ListRow>) -> Result<impl View> {
278+pub(crate) async fn snippet_rows(cx: &Cx, lang: Lang, rows: Vec<ListRow>) -> Result<impl View> {
279279 Ok(view! {
280280 <div class="snippet-list">
281281 for row in rows.into_iter() {
@@ -290,6 +290,7 @@ pub(crate) async fn snippet_rows(lang: Lang, rows: Vec<ListRow>) -> Result<impl
290290
291291 #[component]
292292 async fn snippet_list_body(
293+ cx: &Cx,
293294 lang: Lang,
294295 rows: Vec<ListRow>,
295296 signed_in: bool,
@@ -317,6 +318,7 @@ async fn snippet_list_body(
317318 /// The panel's remove button is shown only when there is more than one file.
318319 #[component]
319320 async fn snippet_files(
321+ cx: &Cx,
320322 lang: Lang,
321323 slots: Vec<Slot>,
322324 active: usize,
@@ -389,6 +391,7 @@ async fn snippet_files(
389391 /// and the remove buttons submit the same form with `formnovalidate` and never save.
390392 #[component]
391393 async fn snippet_form(
394+ cx: &Cx,
392395 lang: Lang,
393396 csrf: &str,
394397 action: &str,
@@ -452,6 +455,7 @@ async fn snippet_form(
452455
453456 #[component]
454457 async fn snippet_body(
458+ cx: &Cx,
455459 lang: Lang,
456460 snippet_id: &str,
457461 title: &str,
@@ -508,6 +512,7 @@ async fn snippet_body(
508512
509513 #[component]
510514 async fn revisions_body(
515+ cx: &Cx,
511516 lang: Lang,
512517 snippet_id: &str,
513518 title: &str,
@@ -541,6 +546,7 @@ async fn revisions_body(
541546
542547 #[component]
543548 async fn snippet_form_page(
549+ cx: &Cx,
544550 lang: Lang,
545551 viewer: &(User, Session),
546552 heading: &str,
@@ -573,7 +579,7 @@ async fn snippets_list(cx: &Cx) -> Result<impl View> {
573579 let viewer = current_user(cx).await?;
574580 let lang = i18n::lang(cx, viewer.as_ref().map(|(user, _)| user));
575581 let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone());
576- let summaries: Vec<SnippetSummary> = app_context::<AppState>(cx)
582+ let summaries: Vec<SnippetSummary> = context::<AppState>(cx)
577583 .store
578584 .list_snippets(viewer_id.as_deref())
579585 .await?;
@@ -605,7 +611,7 @@ async fn snippet_create(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> R
605611 let mut error = None;
606612 let step = apply_slot_step(&mut draft, &form);
607613 if step.is_none() {
608- let store = &app_context::<AppState>(cx).store;
614+ let store = &context::<AppState>(cx).store;
609615 let files = draft.saved_files();
610616 let saved = match SnippetVisibility::parse(&draft.visibility) {
611617 None => Err(g::t(lang, K::ChooseVisibility).to_owned()),
@@ -641,7 +647,7 @@ async fn snippet_create(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> R
641647 serde_json::Value::Null,
642648 )
643649 .await;
644- bump_snippet(app_context::<AppState>(cx), &snippet.id);
650+ bump_snippet(context::<AppState>(cx), &snippet.id);
645651 return Err(see_other(format!("/snippets/{}", snippet.id)).into());
646652 }
647653 Err(message) => error = Some(message),
@@ -657,12 +663,12 @@ async fn snippet_create(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> R
657663
658664 #[page("/snippets/{id}")]
659665 async fn snippet_view(cx: &Cx) -> Result<impl View> {
660- let snippet_id = path_param::<Id>(cx).to_owned();
666+ let snippet_id = id(cx).to_owned();
661667 let viewer = current_user(cx).await?;
662668 let lang = i18n::lang(cx, viewer.as_ref().map(|(user, _)| user));
663669 let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone());
664670 let snippet = readable(cx, viewer_id.as_deref(), &snippet_id).await?;
665- let state = app_context::<AppState>(cx);
671+ let state = context::<AppState>(cx);
666672 let files: Vec<FileView> = snippet
667673 .files
668674 .iter()
@@ -685,7 +691,7 @@ async fn snippet_view(cx: &Cx) -> Result<impl View> {
685691
686692 #[page("/snippets/{id}/edit")]
687693 async fn snippet_edit(cx: &Cx) -> Result<impl View> {
688- let snippet_id = path_param::<Id>(cx).to_owned();
694+ let snippet_id = id(cx).to_owned();
689695 let viewer = require_user(cx).await?;
690696 let lang = i18n::lang(cx, Some(&viewer.0));
691697 let snippet = owned(cx, &viewer.0, &snippet_id).await?;
@@ -699,7 +705,7 @@ async fn snippet_edit(cx: &Cx) -> Result<impl View> {
699705
700706 #[page(POST "/snippets/{id}/edit")]
701707 async fn snippet_update(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> Result<impl View> {
702- let snippet_id = path_param::<Id>(cx).to_owned();
708+ let snippet_id = id(cx).to_owned();
703709 let (user, _) = require_csrf(cx, form.get("csrf").map_or("", String::as_str)).await?;
704710 let lang = i18n::lang(cx, Some(&user));
705711 owned(cx, &user, &snippet_id).await?;
@@ -707,7 +713,7 @@ async fn snippet_update(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> R
707713 let mut error = None;
708714 let step = apply_slot_step(&mut draft, &form);
709715 if step.is_none() {
710- let store = &app_context::<AppState>(cx).store;
716+ let store = &context::<AppState>(cx).store;
711717 let files = draft.saved_files();
712718 let saved = match SnippetVisibility::parse(&draft.visibility) {
713719 None => Err(g::t(lang, K::ChooseVisibility).to_owned()),
@@ -744,7 +750,7 @@ async fn snippet_update(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> R
744750 serde_json::Value::Null,
745751 )
746752 .await;
747- bump_snippet(app_context::<AppState>(cx), &snippet.id);
753+ bump_snippet(context::<AppState>(cx), &snippet.id);
748754 return Err(see_other(format!("/snippets/{}", snippet.id)).into());
749755 }
750756 Err(message) => error = Some(message),
@@ -761,12 +767,12 @@ async fn snippet_update(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> R
761767
762768 #[page("/snippets/{id}/revisions")]
763769 async fn snippet_revisions(cx: &Cx) -> Result<impl View> {
764- let snippet_id = path_param::<Id>(cx).to_owned();
770+ let snippet_id = id(cx).to_owned();
765771 let viewer = current_user(cx).await?;
766772 let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone());
767773 let snippet = readable(cx, viewer_id.as_deref(), &snippet_id).await?;
768774 let lang = i18n::lang(cx, viewer.as_ref().map(|(user, _)| user));
769- let store = &app_context::<AppState>(cx).store;
775+ let store = &context::<AppState>(cx).store;
770776 let revisions: Vec<SnippetRevision> = store.list_snippet_revisions(&snippet.id).await?;
771777 // Stored oldest first; the page shows the newest first with its number.
772778 let rows: Vec<RevisionView> = revisions
@@ -796,10 +802,10 @@ async fn snippet_revisions(cx: &Cx) -> Result<impl View> {
796802
797803 #[route(POST "/snippets/{id}/delete")]
798804 async fn snippet_delete(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> Result<SeeOther> {
799- let snippet_id = path_param::<Id>(cx).to_owned();
805+ let snippet_id = id(cx).to_owned();
800806 let (user, _) = require_csrf(cx, form.get("csrf").map_or("", String::as_str)).await?;
801807 let snippet = owned(cx, &user, &snippet_id).await?;
802- let store = &app_context::<AppState>(cx).store;
808+ let store = &context::<AppState>(cx).store;
803809 if store.delete_snippet(&user.id, &snippet.id).await? {
804810 audit::record(
805811 store,
@@ -814,7 +820,7 @@ async fn snippet_delete(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> R
814820 serde_json::Value::Null,
815821 )
816822 .await;
817- bump_snippet(app_context::<AppState>(cx), &snippet.id);
823+ bump_snippet(context::<AppState>(cx), &snippet.id);
818824 }
819825 Ok(see_other("/snippets"))
820826 }
crates/forge-web/src/pages/snippets_live.rsmodified+4 -4
@@ -12,7 +12,7 @@
1212 use forge_core::store::Store;
1313 use forge_core::store::snippets::{Snippet, SnippetSummary};
1414 use topcoat::Result;
15-use topcoat::context::{Cx, app_context};
15+use topcoat::context::{Cx, context};
1616 use topcoat::router::response::Response;
1717 use topcoat::router::{path_param, route};
1818
@@ -87,7 +87,7 @@ fn snippet_fingerprint(viewer_id: Option<&str>, snippet: Option<Snippet>) -> Str
8787 async fn snippets_events(cx: &Cx) -> Result<Response> {
8888 let viewer = current_user(cx).await?;
8989 let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone());
90- let state = app_context::<AppState>(cx);
90+ let state = context::<AppState>(cx);
9191 let store = state.store.clone();
9292 stream_changes(cx, &state.live, &[Topic::Snippets], move || {
9393 let store = store.clone();
@@ -101,11 +101,11 @@ async fn snippets_events(cx: &Cx) -> Result<Response> {
101101 /// must be readable by the viewer.
102102 #[route(GET "/snippets/{id}/events")]
103103 async fn snippet_events(cx: &Cx) -> Result<Response> {
104- let snippet_id = path_param::<Id>(cx).to_owned();
104+ let snippet_id = id(cx).to_owned();
105105 let viewer = current_user(cx).await?;
106106 let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone());
107107 readable(cx, viewer_id.as_deref(), &snippet_id).await?;
108- let state = app_context::<AppState>(cx);
108+ let state = context::<AppState>(cx);
109109 let store = state.store.clone();
110110 stream_changes(
111111 cx,
crates/forge-web/src/pages/star.rsmodified+4 -4
@@ -6,7 +6,7 @@
66 use http::header::{HOST, REFERER};
77 use serde::Deserialize;
88 use topcoat::Result;
9-use topcoat::context::{Cx, app_context};
9+use topcoat::context::{Cx, context};
1010 use topcoat::router::content::Form;
1111 use topcoat::router::error::{SeeOther, see_other};
1212 use topcoat::router::request::headers;
@@ -37,11 +37,11 @@ async fn unstar_post(cx: &Cx, Form(form): Form<StarForm>) -> Result<SeeOther> {
3737 }
3838
3939 async fn set_starred(cx: &Cx, csrf: &str, starred: bool) -> Result<SeeOther> {
40- let owner = path_param::<Owner>(cx);
41- let name = path_param::<Repo>(cx);
40+ let owner = owner(cx);
41+ let name = repo(cx);
4242 let ctx = load_repo(cx, owner, name).await?;
4343 let (user, _) = require_csrf(cx, csrf).await?;
44- let state = app_context::<AppState>(cx);
44+ let state = context::<AppState>(cx);
4545 if starred {
4646 state.store.star(&user.id, &ctx.repo.id).await?;
4747 } else {
crates/forge-web/src/pages/theme_cookie.rsmodified+2 -2
@@ -5,7 +5,7 @@
55
66 use serde::Deserialize;
77 use topcoat::Result;
8-use topcoat::context::{Cx, app_context};
8+use topcoat::context::{Cx, context};
99 use topcoat::router::content::Form;
1010 use topcoat::router::error::{SeeOther, see_other};
1111 use topcoat::router::route;
@@ -54,7 +54,7 @@ async fn set_theme(cx: &Cx, Form(form): Form<ThemeForm>) -> Result<SeeOther> {
5454 if !THEMES.contains(&form.theme.as_str()) {
5555 return Err(forge_core::Error::Invalid("theme".into()).into());
5656 }
57- let store: &Store = &app_context::<AppState>(cx).store;
57+ let store: &Store = &context::<AppState>(cx).store;
5858 store
5959 .set_ui_prefs(&viewer.0.id, &form.theme, &viewer.0.language)
6060 .await?;
crates/forge-web/src/pages/tree.rsmodified+16 -10
@@ -10,7 +10,7 @@ use forge_core::tz::format_in_tz;
1010 use forge_git::browse::{self, BlobData, CommitInfo, EntryKind, RefInfo, TreeEntry};
1111 use forge_git::history;
1212 use topcoat::Result;
13-use topcoat::context::{Cx, app_context};
13+use topcoat::context::{Cx, context};
1414 use topcoat::router::error::not_found;
1515 use topcoat::router::{page, path_param};
1616 use topcoat::view::{Unescaped, View, component, view};
@@ -24,9 +24,7 @@ use crate::pages::passkeys::s;
2424 use crate::pages::refs::{load_refs, ref_links};
2525 use crate::pages::repo::repo_head;
2626 use crate::pages::repo_ctx::load_repo;
27-use crate::pages::repo_side::{
28- code_sub, commit_strip, run_pips, run_rows, tree_facts,
29-};
27+use crate::pages::repo_side::{code_sub, commit_strip, run_pips, run_rows, tree_facts};
3028 use crate::raw::raw_url;
3129 use crate::render::emoji::emojify;
3230 use crate::render::markdown::{LinkContext, render_markdown};
@@ -351,6 +349,7 @@ pub async fn load_readme(
351349 /// Submodules have no page, so their row shows the short sha. A long folder scrolls here alone.
352350 #[component]
353351 pub async fn tree_table(
352+ cx: &Cx,
354353 rows: Vec<EntryRow>,
355354 lang: Lang,
356355 #[default] current: Option<String>,
@@ -381,6 +380,7 @@ pub async fn tree_table(
381380 /// The sheet beside a folder: its README, with Source, History and Raw as tools, or `none`.
382381 #[component]
383382 pub async fn readme_sheet(
383+ cx: &Cx,
384384 lang: Lang,
385385 owner: String,
386386 repo: String,
@@ -404,7 +404,13 @@ pub async fn readme_sheet(
404404 )
405405 });
406406 // The tools row names what is shown: the README, or the folder (the repo name at the root).
407- let shown = readme_name.unwrap_or_else(|| if dir.is_empty() { repo.clone() } else { dir.clone() });
407+ let shown = readme_name.unwrap_or_else(|| {
408+ if dir.is_empty() {
409+ repo.clone()
410+ } else {
411+ dir.clone()
412+ }
413+ });
408414 Ok(view! {
409415 <div class="sheet">
410416 <div class="sheet-tools">
@@ -427,7 +433,7 @@ pub async fn readme_sheet(
427433 /// README body. Markdown HTML is embedded only from `render_markdown`; plain text is escaped. The
428434 /// file name is for screen readers: the pane head shows it.
429435 #[component]
430-pub async fn readme_card(name: String, markdown: bool, body: String) -> Result<impl View> {
436+pub async fn readme_card(cx: &Cx, name: String, markdown: bool, body: String) -> Result<impl View> {
431437 Ok(view! {
432438 <section class="readme">
433439 <p class="sr-only">(name)</p>
@@ -442,11 +448,11 @@ pub async fn readme_card(name: String, markdown: bool, body: String) -> Result<i
442448
443449 #[page("/{owner}/{repo}/tree/{*rest}")]
444450 async fn tree_page(cx: &Cx) -> Result<impl View> {
445- let owner = path_param::<Owner>(cx);
446- let name = path_param::<Repo>(cx);
447- let rest = path_param::<Rest>(cx).collect::<Vec<_>>().join("/");
451+ let owner = owner(cx);
452+ let name = repo(cx);
453+ let rest = rest(cx).collect::<Vec<_>>().join("/");
448454 let ctx = load_repo(cx, owner, name).await?;
449- let state = app_context::<AppState>(cx);
455+ let state = context::<AppState>(cx);
450456 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
451457 let repo = &ctx.repo;
452458
crates/forge-web/src/pages/user_prefs.rsmodified+2 -2
@@ -5,7 +5,7 @@
55 use http::StatusCode;
66 use serde::Deserialize;
77 use topcoat::Result;
8-use topcoat::context::{Cx, app_context};
8+use topcoat::context::{Cx, context};
99 use topcoat::router::content::Form;
1010 use topcoat::router::error::bad_request;
1111 use topcoat::router::response::Response;
@@ -43,7 +43,7 @@ pub fn clean_pref(key: &str, value: &str) -> std::result::Result<Option<String>,
4343 #[route(POST "/-/prefs")]
4444 async fn set_pref(cx: &Cx, Form(form): Form<PrefForm>) -> Result<Response> {
4545 let (user, _) = require_csrf(cx, &form.csrf).await?;
46- let store = &app_context::<AppState>(cx).store;
46+ let store = &context::<AppState>(cx).store;
4747 match clean_pref(&form.key, &form.value) {
4848 Err(message) => return Err(bad_request(message).into()),
4949 Ok(None) => store.delete_user_pref(&user.id, &form.key).await?,
crates/forge-web/src/pages/wiki.rsmodified+49 -43
@@ -13,7 +13,7 @@ use forge_git::repo::wiki_path;
1313 use forge_git::wiki::{self, MAX_PAGE_BYTES, PageEdit, PageRevision, valid_page_name};
1414 use serde::Deserialize;
1515 use topcoat::Result;
16-use topcoat::context::{Cx, app_context};
16+use topcoat::context::{Cx, context};
1717 use topcoat::router::content::Form;
1818 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
1919 use topcoat::router::{page, path_param, route};
@@ -179,6 +179,7 @@ fn wiki_links(
179179 /// The page list beside a wiki page: every page, the one on screen marked.
180180 #[component]
181181 async fn wiki_rail(
182+ cx: &Cx,
182183 lang: Lang,
183184 owner: String,
184185 repo: String,
@@ -203,6 +204,7 @@ async fn wiki_rail(
203204 /// the screen follows.
204205 #[component]
205206 async fn wiki_sheet(
207+ cx: &Cx,
206208 #[default] title: Option<String>,
207209 links: Vec<(String, String)>,
208210 #[default] live: Option<String>,
@@ -251,7 +253,7 @@ fn page_links(
251253 }
252254
253255 #[component]
254-async fn wiki_view_body(html: String) -> Result<impl View> {
256+async fn wiki_view_body(cx: &Cx, html: String) -> Result<impl View> {
255257 Ok(view! {
256258 <section class="sec wiki-page">
257259 <div class="markdown-body">(Unescaped::new_unchecked(html))</div>
@@ -261,6 +263,7 @@ async fn wiki_view_body(html: String) -> Result<impl View> {
261263
262264 #[component]
263265 async fn wiki_empty_body(
266+ cx: &Cx,
264267 lang: Lang,
265268 owner: String,
266269 repo: String,
@@ -278,6 +281,7 @@ async fn wiki_empty_body(
278281
279282 #[component]
280283 async fn wiki_list_body(
284+ cx: &Cx,
281285 lang: Lang,
282286 owner: String,
283287 repo: String,
@@ -304,7 +308,7 @@ async fn wiki_list_body(
304308 }
305309
306310 #[component]
307-async fn wiki_history_body(lang: Lang, rows: Vec<RevisionRow>) -> Result<impl View> {
311+async fn wiki_history_body(cx: &Cx, lang: Lang, rows: Vec<RevisionRow>) -> Result<impl View> {
308312 Ok(view! {
309313 if rows.is_empty() {
310314 empty_state(title: g::t(lang, K::NoChangesYet))
@@ -321,6 +325,7 @@ async fn wiki_history_body(lang: Lang, rows: Vec<RevisionRow>) -> Result<impl Vi
321325
322326 #[component]
323327 async fn wiki_edit_body(
328+ cx: &Cx,
324329 lang: Lang,
325330 action: String,
326331 csrf: String,
@@ -370,10 +375,10 @@ async fn load_page(dir: PathBuf, name: String) -> Result<(Option<String>, Option
370375
371376 #[page("/{owner}/{repo}/wiki")]
372377 async fn wiki_home(cx: &Cx) -> Result<impl View> {
373- let owner = path_param::<Owner>(cx);
374- let name = path_param::<Repo>(cx);
378+ let owner = owner(cx);
379+ let name = repo(cx);
375380 let ctx = load_repo(cx, owner, name).await?;
376- let state = app_context::<AppState>(cx);
381+ let state = context::<AppState>(cx);
377382 ensure_enabled(state, &ctx).await?;
378383 let dir = wiki_dir(state, &ctx)?;
379384 let names = page_names(dir.clone()).await?;
@@ -401,7 +406,7 @@ async fn wiki_home(cx: &Cx) -> Result<impl View> {
401406 };
402407 let links = wiki_links(lang, &owner_name, &repo_name, can_write, extra);
403408 let header = ctx.head(state, "wiki").await?;
404- Ok(view! { cx =>
409+ Ok(view! {
405410 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),
406411 repo_head(head: header, title: head_title)
407412 <div class="work">
@@ -421,10 +426,10 @@ async fn wiki_home(cx: &Cx) -> Result<impl View> {
421426
422427 #[page("/{owner}/{repo}/wiki/-/pages")]
423428 async fn wiki_pages(cx: &Cx) -> Result<impl View> {
424- let owner = path_param::<Owner>(cx);
425- let name = path_param::<Repo>(cx);
429+ let owner = owner(cx);
430+ let name = repo(cx);
426431 let ctx = load_repo(cx, owner, name).await?;
427- let state = app_context::<AppState>(cx);
432+ let state = context::<AppState>(cx);
428433 ensure_enabled(state, &ctx).await?;
429434 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
430435 let dir = wiki_dir(state, &ctx)?;
@@ -440,7 +445,7 @@ async fn wiki_pages(cx: &Cx) -> Result<impl View> {
440445 );
441446 let links = wiki_links(lang, &owner_name, &repo_name, can_write, Vec::new());
442447 let header = ctx.head(state, "wiki").await?;
443- Ok(view! { cx =>
448+ Ok(view! {
444449 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),
445450 repo_head(head: header, title: Some(g::t(lang, K::AllPages).to_owned()))
446451 wiki_sheet(links: links, live: Some(wiki_live_url(&owner_name, &repo_name)),
@@ -452,11 +457,11 @@ async fn wiki_pages(cx: &Cx) -> Result<impl View> {
452457
453458 #[page("/{owner}/{repo}/wiki/{wiki_page}")]
454459 async fn wiki_page_view(cx: &Cx) -> Result<impl View> {
455- let owner = path_param::<Owner>(cx);
456- let repo_param = path_param::<Repo>(cx);
457- let page_name = path_param::<WikiPage>(cx).to_owned();
460+ let owner = owner(cx);
461+ let repo_param = repo(cx);
462+ let page_name = wiki_page(cx).to_owned();
458463 let ctx = load_repo(cx, owner, repo_param).await?;
459- let state = app_context::<AppState>(cx);
464+ let state = context::<AppState>(cx);
460465 ensure_enabled(state, &ctx).await?;
461466 if !valid_page_name(&page_name) {
462467 return Err(not_found().into());
@@ -486,7 +491,7 @@ async fn wiki_page_view(cx: &Cx) -> Result<impl View> {
486491 page_links(lang, &owner_name, &repo_name, &page_name, can_write),
487492 );
488493 let header = ctx.head(state, "wiki").await?;
489- Ok(view! { cx =>
494+ Ok(view! {
490495 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),
491496 repo_head(head: header, title: Some(page_name.replace('-', " ")))
492497 <div class="work">
@@ -501,11 +506,11 @@ async fn wiki_page_view(cx: &Cx) -> Result<impl View> {
501506
502507 #[page("/{owner}/{repo}/wiki/{wiki_page}/history")]
503508 async fn wiki_page_history(cx: &Cx) -> Result<impl View> {
504- let owner = path_param::<Owner>(cx);
505- let repo_param = path_param::<Repo>(cx);
506- let page_name = path_param::<WikiPage>(cx).to_owned();
509+ let owner = owner(cx);
510+ let repo_param = repo(cx);
511+ let page_name = wiki_page(cx).to_owned();
507512 let ctx = load_repo(cx, owner, repo_param).await?;
508- let state = app_context::<AppState>(cx);
513+ let state = context::<AppState>(cx);
509514 ensure_enabled(state, &ctx).await?;
510515 if !valid_page_name(&page_name) {
511516 return Err(not_found().into());
@@ -536,7 +541,7 @@ async fn wiki_page_history(cx: &Cx) -> Result<impl View> {
536541 )],
537542 );
538543 let header = ctx.head(state, "wiki").await?;
539- Ok(view! { cx =>
544+ Ok(view! {
540545 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),
541546 repo_head(head: header, title: Some(format!("{} \u{b7} {}", page_name.replace('-', " "), g::t(lang, K::History))))
542547 <div class="work">
@@ -558,7 +563,7 @@ async fn edit_screen(
558563 content: String,
559564 error: Option<String>,
560565 ) -> Result<impl View> {
561- let state = app_context::<AppState>(cx);
566+ let state = context::<AppState>(cx);
562567 let (user, session) = require_user(cx).await?;
563568 let lang = i18n::lang(cx, Some(&user));
564569 let dir = wiki_dir(state, &ctx)?;
@@ -599,7 +604,7 @@ async fn edit_screen(
599604 )]
600605 };
601606 let links = wiki_links(lang, &owner_name, &repo_name, !is_new, back_links);
602- Ok(view! { cx =>
607+ Ok(view! {
603608 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),
604609 repo_head(head: header, title: Some(head_title))
605610 <div class="work">
@@ -614,10 +619,10 @@ async fn edit_screen(
614619
615620 #[page("/{owner}/{repo}/wiki/-/new")]
616621 async fn wiki_new_page(cx: &Cx) -> Result<impl View> {
617- let owner = path_param::<Owner>(cx);
618- let repo_param = path_param::<Repo>(cx);
622+ let owner = owner(cx);
623+ let repo_param = repo(cx);
619624 let ctx = load_repo(cx, owner, repo_param).await?;
620- let state = app_context::<AppState>(cx);
625+ let state = context::<AppState>(cx);
621626 ensure_enabled(state, &ctx).await?;
622627 if !ctx.can_write() {
623628 return Err(forbidden().into());
@@ -627,11 +632,11 @@ async fn wiki_new_page(cx: &Cx) -> Result<impl View> {
627632
628633 #[page("/{owner}/{repo}/wiki/{wiki_page}/edit")]
629634 async fn wiki_edit_page(cx: &Cx) -> Result<impl View> {
630- let owner = path_param::<Owner>(cx);
631- let repo_param = path_param::<Repo>(cx);
632- let page_name = path_param::<WikiPage>(cx).to_owned();
635+ let owner = owner(cx);
636+ let repo_param = repo(cx);
637+ let page_name = wiki_page(cx).to_owned();
633638 let ctx = load_repo(cx, owner, repo_param).await?;
634- let state = app_context::<AppState>(cx);
639+ let state = context::<AppState>(cx);
635640 ensure_enabled(state, &ctx).await?;
636641 if !ctx.can_write() {
637642 return Err(forbidden().into());
@@ -646,10 +651,10 @@ async fn wiki_edit_page(cx: &Cx) -> Result<impl View> {
646651
647652 #[page(POST "/{owner}/{repo}/wiki/-/new")]
648653 async fn wiki_new_post(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View> {
649- let owner = path_param::<Owner>(cx);
650- let repo_param = path_param::<Repo>(cx);
654+ let owner = owner(cx);
655+ let repo_param = repo(cx);
651656 let ctx = load_repo(cx, owner, repo_param).await?;
652- let state = app_context::<AppState>(cx);
657+ let state = context::<AppState>(cx);
653658 ensure_enabled(state, &ctx).await?;
654659 if !ctx.can_write() {
655660 return Err(forbidden().into());
@@ -680,11 +685,11 @@ async fn wiki_new_post(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View>
680685
681686 #[page(POST "/{owner}/{repo}/wiki/{wiki_page}/edit")]
682687 async fn wiki_edit_post(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View> {
683- let owner = path_param::<Owner>(cx);
684- let repo_param = path_param::<Repo>(cx);
685- let page_name = path_param::<WikiPage>(cx).to_owned();
688+ let owner = owner(cx);
689+ let repo_param = repo(cx);
690+ let page_name = wiki_page(cx).to_owned();
686691 let ctx = load_repo(cx, owner, repo_param).await?;
687- let state = app_context::<AppState>(cx);
692+ let state = context::<AppState>(cx);
688693 ensure_enabled(state, &ctx).await?;
689694 if !ctx.can_write() {
690695 return Err(forbidden().into());
@@ -709,7 +714,7 @@ enum SaveOutcome {
709714 /// Writes the page as a commit guarded by the form's `base`. A conflicting or invalid save is
710715 /// refused with a message, and the caller shows the edit screen again with the typed text.
711716 async fn save(cx: &Cx, ctx: &RepoCtx, form: &EditForm, name: &str) -> Result<SaveOutcome> {
712- let state = app_context::<AppState>(cx);
717+ let state = context::<AppState>(cx);
713718 let (user, _) = require_user(cx).await?;
714719 let lang = i18n::lang(cx, Some(&user));
715720 if form.content.len() > MAX_PAGE_BYTES {
@@ -765,6 +770,7 @@ async fn save(cx: &Cx, ctx: &RepoCtx, form: &EditForm, name: &str) -> Result<Sav
765770 /// change (`data-autosubmit`), then its hint. `enabled` is the current state.
766771 #[component]
767772 pub(crate) async fn wiki_switch(
773+ cx: &Cx,
768774 action: String,
769775 csrf: String,
770776 enabled: bool,
@@ -783,8 +789,8 @@ pub(crate) async fn wiki_switch(
783789 /// The wiki switch moved to the General settings page; the old address goes there.
784790 #[route(GET "/{owner}/{repo}/settings/wiki")]
785791 async fn wiki_settings_page(cx: &Cx) -> Result<SeeOther> {
786- let owner = path_param::<Owner>(cx);
787- let repo_param = path_param::<Repo>(cx);
792+ let owner = owner(cx);
793+ let repo_param = repo(cx);
788794 Ok(see_other(repo_href(owner, repo_param, "settings", "")))
789795 }
790796
@@ -798,14 +804,14 @@ struct WikiSettingsForm {
798804
799805 #[route(POST "/{owner}/{repo}/settings/wiki")]
800806 async fn wiki_settings_post(cx: &Cx, Form(form): Form<WikiSettingsForm>) -> Result<SeeOther> {
801- let owner = path_param::<Owner>(cx);
802- let repo_param = path_param::<Repo>(cx);
807+ let owner = owner(cx);
808+ let repo_param = repo(cx);
803809 let ctx = load_repo(cx, owner, repo_param).await?;
804810 let (user, _) = require_csrf(cx, &form.csrf).await?;
805811 if !ctx.can_admin() {
806812 return Err(forbidden().into());
807813 }
808- let state = app_context::<AppState>(cx);
814+ let state = context::<AppState>(cx);
809815 let enable = form.enabled.is_some();
810816 let before = state.store.wiki_enabled(&ctx.repo.id).await?;
811817 state.store.set_wiki_enabled(&ctx.repo.id, enable).await?;
crates/forge-web/src/pages/wiki_live.rsmodified+6 -6
@@ -15,7 +15,7 @@ use std::path::{Path, PathBuf};
1515 use forge_git::GitEnv;
1616 use forge_git::wiki::{self, valid_page_name};
1717 use topcoat::Result;
18-use topcoat::context::{Cx, app_context};
18+use topcoat::context::{Cx, context};
1919 use topcoat::router::error::not_found;
2020 use topcoat::router::response::Response;
2121 use topcoat::router::{path_param, route};
@@ -66,8 +66,8 @@ async fn page_fingerprint(git: &GitEnv, dir: &Path, name: &str) -> Result<String
6666 /// wiki's on switch.
6767 #[route(GET "/{owner}/{repo}/wiki/-/events")]
6868 async fn wiki_events(cx: &Cx) -> Result<Response> {
69- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
70- let state = app_context::<AppState>(cx);
69+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
70+ let state = context::<AppState>(cx);
7171 ensure_enabled(state, &ctx).await?;
7272 let dir = wiki_dir(state, &ctx)?;
7373 let topic = Topic::Wiki(ctx.repo.id.clone());
@@ -80,9 +80,9 @@ async fn wiki_events(cx: &Cx) -> Result<Response> {
8080 /// The change stream of one wiki page, its page view and its history.
8181 #[route(GET "/{owner}/{repo}/wiki/{wiki_page}/events")]
8282 async fn wiki_page_events(cx: &Cx) -> Result<Response> {
83- let page_name = path_param::<WikiPage>(cx).to_owned();
84- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
85- let state = app_context::<AppState>(cx);
83+ let page_name = wiki_page(cx).to_owned();
84+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
85+ let state = context::<AppState>(cx);
8686 ensure_enabled(state, &ctx).await?;
8787 if !valid_page_name(&page_name) {
8888 return Err(not_found().into());
crates/forge-web/src/raw.rsmodified+4 -4
@@ -17,7 +17,7 @@ use serde::Deserialize;
1717 use tokio::io::AsyncReadExt;
1818 use tokio::process::Child;
1919 use tokio_util::io::ReaderStream;
20-use topcoat::context::{Cx, app_context};
20+use topcoat::context::{Cx, context};
2121 use topcoat::router::request::{headers, method};
2222 use topcoat::router::response::Response;
2323 use topcoat::router::{
@@ -113,8 +113,8 @@ pub fn router(state: AppState) -> Router {
113113 ))
114114 .route(RouteFn::new(Method::GET, "/healthz", healthz))
115115 // Responses must match the bytes behind the ETag and Content-Length.
116- .compression(Compression::off())
117- .app_context(state)
116+ .with(Compression::disable())
117+ .with(state)
118118 .build()
119119 }
120120
@@ -137,7 +137,7 @@ fn raw_file(cx: &Cx, _body: topcoat::router::Body) -> RouteFuture<'_> {
137137
138138 /// Serves one file. Every failure is turned into a response here, so the route never errors.
139139 async fn serve(cx: &Cx) -> Response {
140- let state = app_context::<AppState>(cx).clone();
140+ let state = context::<AppState>(cx).clone();
141141 let owner = path_param_segment(cx, "owner").to_owned();
142142 let name = path_param_segment(cx, "repo").to_owned();
143143 let rest = path_param_segments(cx, "rest")
crates/forge-web/src/test_support.rsmodified+4 -7
@@ -13,12 +13,11 @@ use forge_core::token::hash_token;
1313 use forge_core::{Config, Registration, Store};
1414 use forge_git::GitEnv;
1515 use tokio::sync::Notify;
16-use topcoat::cookie::RouterBuilderCookieExt;
16+use topcoat::cookie::CookieLayer;
1717 use topcoat::router::tower::TowerLayer;
1818 use topcoat::router::{Compression, Router, RouterBuilderDiscoverExt};
1919
2020 use crate::pages::repo_ctx::RepoMovedLayer;
21-use crate::pages::settings_profile::{avatar_body_limit, org_avatar_body_limit};
2221 use crate::state::AppState;
2322 use crate::throttle::Throttle;
2423
@@ -105,18 +104,16 @@ pub async fn test_state(dir: &Path) -> AppState {
105104 pub fn app_router(state: AppState) -> Router {
106105 Router::builder()
107106 .discover()
108- .app_context(state)
107+ .with(state)
109108 .layer(crate::pages::settings_live::AccountWriteLayer)
110- .cookies()
111- .layer(avatar_body_limit())
112- .layer(org_avatar_body_limit())
109+ .layer(CookieLayer::new())
113110 .layer(RepoMovedLayer)
114111 .layer(crate::pages::repo_settings_live::RepoSettingsWriteLayer)
115112 .layer(crate::pages::pull_live::PullWriteLayer)
116113 .layer(crate::pages::discussion_live::DiscussionWriteLayer)
117114 .layer(crate::pages::org_live::OrgWriteLayer)
118115 .layer(TowerLayer::new(crate::compression::ResponseCompression))
119- .compression(Compression::off())
116+ .with(Compression::disable())
120117 .build()
121118 }
122119
crates/forge-web/src/views/commit_line.rsmodified+2 -1
@@ -3,6 +3,7 @@
33 //! subject as written, like GitHub. The full subject is the `title` attribute.
44
55 use topcoat::Result;
6+use topcoat::context::Cx;
67 use topcoat::view::{View, component, view};
78
89 use crate::render::emoji::emojify;
@@ -10,7 +11,7 @@ use crate::render::emoji::emojify;
1011 /// One subject on one line as it was written, header included, truncated by CSS. The full subject
1112 /// is the `title` attribute.
1213 #[component]
13-pub async fn commit_line(subject: String) -> Result<impl View> {
14+pub async fn commit_line(cx: &Cx, subject: String) -> Result<impl View> {
1415 let text = emojify(&subject).into_owned();
1516 Ok(view! {
1617 <span class="commit-line" title=(text.as_str())>
crates/forge-web/src/views/commit_status.rsmodified+4 -1
@@ -4,6 +4,7 @@
44
55 use forge_core::store::commit_status::{CommitStatus, StatusState, combine};
66 use topcoat::Result;
7+use topcoat::context::Cx;
78 use topcoat::view::{View, component, view};
89
910 use crate::i18n::Lang;
@@ -88,6 +89,7 @@ pub fn css(state: StatusState) -> &'static str {
8889 /// no statuses.
8990 #[component]
9091 pub async fn commit_status(
92+ cx: &Cx,
9193 summary: StatusSummary,
9294 #[default] lang: StatusLang,
9395 ) -> Result<impl View> {
@@ -118,6 +120,7 @@ pub async fn commit_status(
118120 /// the contexts beneath it.
119121 #[component]
120122 pub async fn checks_summary(
123+ cx: &Cx,
121124 summary: StatusSummary,
122125 #[default] lang: StatusLang,
123126 ) -> Result<impl View> {
@@ -167,7 +170,7 @@ fn description_text(lang: Lang, text: &str) -> &str {
167170
168171 /// The contexts of one commit: icon, context name, description and a details link.
169172 #[component]
170-pub async fn status_list(items: Vec<StatusItem>, lang: Lang) -> Result<impl View> {
173+pub async fn status_list(cx: &Cx, items: Vec<StatusItem>, lang: Lang) -> Result<impl View> {
171174 Ok(view! {
172175 <ul class="status-list">
173176 for item in items.iter() {
crates/forge-web/src/views/diff.rsmodified+20 -8
@@ -13,7 +13,7 @@ use std::collections::HashMap;
1313 use forge_core::{Side, Thread};
1414 use forge_git::history::{CommitDiff, DiffLimits, DiffStatus, FileDiff, LineKind};
1515 use topcoat::Result;
16-use topcoat::context::{Cx, app_context};
16+use topcoat::context::{Cx, context};
1717 use topcoat::cookie::{Cookie, Cookies, SameSite, cookies, time};
1818 use topcoat::router::request::uri;
1919 use topcoat::view::{View, component, view};
@@ -111,7 +111,7 @@ impl DiffOpts {
111111 }
112112 let split = match current_user(cx).await? {
113113 Some((user, _)) => {
114- let state = app_context::<AppState>(cx);
114+ let state = context::<AppState>(cx);
115115 let stored = state.store.user_prefs(&user.id).await?.remove(DIFF_VIEW);
116116 match view_param.as_deref() {
117117 Some(v @ ("split" | "unified")) => {
@@ -511,6 +511,7 @@ struct NavItem {
511511 #[allow(clippy::too_many_arguments)]
512512 #[component]
513513 pub async fn diff_section(
514+ cx: &Cx,
514515 diff: &CommitDiff,
515516 owner: &str,
516517 repo: &str,
@@ -529,7 +530,12 @@ pub async fn diff_section(
529530 .files
530531 .iter()
531532 .enumerate()
532- .map(|(i, file)| (i, FileView::new(i, file, oid, parent, owner, repo, lang, &mut comments)))
533+ .map(|(i, file)| {
534+ (
535+ i,
536+ FileView::new(i, file, oid, parent, owner, repo, lang, &mut comments),
537+ )
538+ })
533539 .filter(|(i, _)| opts.only.is_none_or(|only| only == *i))
534540 .map(|(_, file)| file)
535541 .collect();
@@ -605,7 +611,7 @@ pub async fn diff_section(
605611
606612 /// Unified or split, ignore whitespace, and the patch and diff downloads.
607613 #[component]
608-async fn diff_toolbar(bar: Toolbar, lang: Lang) -> Result<impl View> {
614+async fn diff_toolbar(cx: &Cx, bar: Toolbar, lang: Lang) -> Result<impl View> {
609615 let unified_on = if bar.split { "false" } else { "true" };
610616 let split_on = if bar.split { "true" } else { "false" };
611617 let ws_on = if bar.ignore_ws { "true" } else { "false" };
@@ -623,7 +629,13 @@ async fn diff_toolbar(bar: Toolbar, lang: Lang) -> Result<impl View> {
623629 }
624630
625631 #[component]
626-async fn diff_file(file: FileView, lang: Lang, split: bool, anchored: bool) -> Result<impl View> {
632+async fn diff_file(
633+ cx: &Cx,
634+ file: FileView,
635+ lang: Lang,
636+ split: bool,
637+ anchored: bool,
638+) -> Result<impl View> {
627639 let add_label = format!("+{}", file.additions);
628640 let del_label = format!("-{}", file.deletions);
629641 let rows = file.rows;
@@ -683,7 +695,7 @@ async fn diff_file(file: FileView, lang: Lang, split: bool, anchored: bool) -> R
683695 /// One split row as a `<tbody>`: the two sides, then, when either has threads or an open form, a
684696 /// full-width row holding them. A hunk header spans the table.
685697 #[component]
686-async fn diff_split_line(row: SplitRow, lang: Lang, anchored: bool) -> Result<impl View> {
698+async fn diff_split_line(cx: &Cx, row: SplitRow, lang: Lang, anchored: bool) -> Result<impl View> {
687699 let SplitRow {
688700 hunk,
689701 left,
@@ -752,7 +764,7 @@ async fn diff_split_line(row: SplitRow, lang: Lang, anchored: bool) -> Result<im
752764 /// One diff line as a `<tbody>`: the line itself, then, when it has threads or an open form, a
753765 /// full-width row holding them.
754766 #[component]
755-async fn diff_line(row: DiffRow, lang: Lang) -> Result<impl View> {
767+async fn diff_line(cx: &Cx, row: DiffRow, lang: Lang) -> Result<impl View> {
756768 let DiffRow {
757769 class,
758770 old,
@@ -803,7 +815,7 @@ async fn diff_line(row: DiffRow, lang: Lang) -> Result<impl View> {
803815 /// The inline comment form under a line. "Add single comment" posts one comment; the review
804816 /// button starts a review, or adds to the pending one.
805817 #[component]
806-async fn inline_comment_form(form: InlineForm, lang: Lang) -> Result<impl View> {
818+async fn inline_comment_form(cx: &Cx, form: InlineForm, lang: Lang) -> Result<impl View> {
807819 let InlineForm {
808820 action,
809821 cancel_href,
crates/forge-web/src/views/find.rsmodified+2 -0
@@ -5,6 +5,7 @@
55 //! word as typed.
66
77 use topcoat::Result;
8+use topcoat::context::Cx;
89 use topcoat::view::{View, component, view};
910
1011 use crate::i18n::Lang;
@@ -160,6 +161,7 @@ fn distance(a: &[char], b: &[char]) -> usize {
160161 /// searches as you type; an option applies the moment it is ticked.
161162 #[component]
162163 pub async fn finder_field(
164+ cx: &Cx,
163165 lang: Lang,
164166 finder: Finder,
165167 placeholder: &str,
crates/forge-web/src/views/heatmap.rsmodified+2 -0
@@ -8,6 +8,7 @@
88 //! that day's contributions under the calendar, and clicking the selected day again clears it.
99
1010 use std::collections::HashMap;
11+use topcoat::context::Cx;
1112
1213 use forge_core::store::contributions::{ContributionItem, ContributionKind};
1314 use forge_core::time::stamp_to_unix;
@@ -346,6 +347,7 @@ fn day_entries(lang: Lang, items: &[ContributionItem], now: i64) -> Vec<DayEntry
346347 /// is the stream URL the card re-renders on; it is set on a person's overview only.
347348 #[component]
348349 pub async fn contribution_calendar(
350+ cx: &Cx,
349351 calendar: Calendar,
350352 selected: Option<DayDetail>,
351353 lang: Lang,
crates/forge-web/src/views/mod.rsmodified+26 -19
@@ -23,7 +23,7 @@ use http::header::{
2323 use http::{HeaderValue, Uri};
2424 use sha2::{Digest, Sha256};
2525 use topcoat::Result;
26-use topcoat::context::{Cx, try_app_context};
26+use topcoat::context::{Cx, try_context};
2727 use topcoat::router::request::uri;
2828 use topcoat::router::response::{Response, response_headers};
2929 use topcoat::router::{Body, Next, layer};
@@ -495,7 +495,7 @@ struct ProfileCorner {
495495 /// waits. Its menu holds the name, notifications with their count, the settings and admin links and
496496 /// log out.
497497 #[component]
498-async fn profile_corner(lang: Lang, corner: ProfileCorner) -> Result<impl View> {
498+async fn profile_corner(cx: &Cx, lang: Lang, corner: ProfileCorner) -> Result<impl View> {
499499 let profile_href = user_href(&corner.username);
500500 let profile_label = mi::t(lang, MK::YourProfile);
501501 let settings_label = o::t(lang, OK::Settings);
@@ -542,6 +542,7 @@ async fn profile_corner(lang: Lang, corner: ProfileCorner) -> Result<impl View>
542542 /// more stylesheet link to the head (such as a repo's generated label colors).
543543 #[component]
544544 pub async fn shell(
545+ cx: &Cx,
545546 title: &str,
546547 viewer: Option<&(User, Session)>,
547548 #[default] extra_stylesheet: Option<&str>,
@@ -552,7 +553,7 @@ pub async fn shell(
552553 // The unread count, the profile corner's inbox counts, their CI runs and the items waiting on
553554 // them. Signed-in only.
554555 let (unread, inbox, runs) = match viewer {
555- Some((user, _)) => match try_app_context::<AppState>(__cx) {
556+ Some((user, _)) => match try_context::<AppState>(cx) {
556557 Some(state) => (
557558 state.store.unread_count(&user.id).await?,
558559 state.store.inbox_kind_counts(&user.id).await?,
@@ -567,26 +568,26 @@ pub async fn shell(
567568 // stored preference saved. Anonymous visitors get the cookie. Either way the browser comes
568569 // back to the page it was on.
569570 let theme_csrf = viewer.map(|(_, session)| session.csrf_token.clone());
570- let back = uri(__cx).path_and_query().map(|p| p.as_str().to_owned());
571- let lang = i18n::lang(__cx, viewer.map(|(user, _)| user));
571+ let back = uri(cx).path_and_query().map(|p| p.as_str().to_owned());
572+ let lang = i18n::lang(cx, viewer.map(|(user, _)| user));
572573 // A signed-in viewer's account preferences, read once for the banner, the tree width and the
573574 // profile corner. Signed-out visitors keep theirs in the browser.
574- let prefs = match (viewer, try_app_context::<AppState>(__cx)) {
575+ let prefs = match (viewer, try_context::<AppState>(cx)) {
575576 (Some((user, _)), Some(state)) => Some(state.store.user_prefs(&user.id).await?),
576577 _ => None,
577578 };
578- let banner = crate::pages::banner::current(__cx, prefs.as_ref());
579+ let banner = crate::pages::banner::current(cx, prefs.as_ref());
579580 let sound_attr = crate::pages::settings_appearance::sound_attr(prefs.as_ref());
580581 let banner_back = back.clone().unwrap_or_else(|| "/".to_owned());
581582 let dismiss_label = crate::i18n::accounts::t(lang, crate::i18n::accounts::A::Dismiss);
582583 // The admin area and the user settings swap the global links for their own list. Signed-in only.
583584 let section = if signed_in {
584- section_for(lang, uri(__cx).path())
585+ section_for(lang, uri(cx).path())
585586 } else {
586587 None
587588 };
588- let width = page_width(uri(__cx).path());
589- let theme_attr = crate::theme::data_theme(__cx, viewer.map(|(user, _)| user));
589+ let width = page_width(uri(cx).path());
590+ let theme_attr = crate::theme::data_theme(cx, viewer.map(|(user, _)| user));
590591 // The relative-time wording and the server's clock, for nav.js to keep `<time data-rel>` labels current.
591592 let rel_words_attr = rel_words(lang);
592593 let rel_now_attr = now_unix().to_string();
@@ -627,7 +628,7 @@ pub async fn shell(
627628 };
628629 // The stored preference, "auto" included, drives the button: its icon, its label and the
629630 // value it posts (the next preference in the cycle auto, light, dark).
630- let theme_pref = crate::theme::preference(__cx, viewer.map(|(user, _)| user));
631+ let theme_pref = crate::theme::preference(cx, viewer.map(|(user, _)| user));
631632 let next_theme = crate::theme::next_preference(theme_pref);
632633 let theme_state = match theme_pref {
633634 "light" => mi::t(lang, MK::Light),
@@ -649,7 +650,7 @@ pub async fn shell(
649650 let explore_label = t(lang, Key::Explore);
650651 let home_label = o::t(lang, OK::Home);
651652 // The path bar: one segment per part of the request path, the last one unlinked.
652- let mut segments = path_segments(lang, uri(__cx).path(), title);
653+ let mut segments = path_segments(lang, uri(cx).path(), title);
653654 // A page with no place of its own in the path, such as settings, names its section and itself.
654655 // A page below one of the section's tabs (an account under Users) names that tab too.
655656 if segments.is_empty() {
@@ -658,7 +659,7 @@ pub async fn shell(
658659 if section.title != title {
659660 segments.push((section.title.clone(), first));
660661 }
661- let path = uri(__cx).path();
662+ let path = uri(cx).path();
662663 if let Some(item) = section.items.iter().find(|item| {
663664 path.strip_prefix(item.href.as_str())
664665 .is_some_and(|below| below.starts_with('/'))
@@ -1072,6 +1073,7 @@ pub fn section_for(lang: Lang, path: &str) -> Option<Section> {
10721073 /// One row of text tabs, with `aria-current="page"` on the current one.
10731074 #[component]
10741075 async fn section_tabs(
1076+ cx: &Cx,
10751077 key: &'static str,
10761078 label: &str,
10771079 items: Vec<NavItem>,
@@ -1132,7 +1134,7 @@ pub fn user_href(username: &str) -> String {
11321134 /// the text to display (it differs from `login` only for the ghost account). Both are escaped
11331135 /// like any other interpolation.
11341136 #[component]
1135-pub async fn user_link(shown: &str, login: &str) -> Result<impl View> {
1137+pub async fn user_link(cx: &Cx, shown: &str, login: &str) -> Result<impl View> {
11361138 let href = user_href(login);
11371139 Ok(view! {
11381140 <a href=(href.as_str())>(shown)</a>
@@ -1141,7 +1143,7 @@ pub async fn user_link(shown: &str, login: &str) -> Result<impl View> {
11411143
11421144 /// Hidden CSRF input for a POST form.
11431145 #[component]
1144-pub async fn csrf_field(token: &str) -> Result<impl View> {
1146+pub async fn csrf_field(cx: &Cx, token: &str) -> Result<impl View> {
11451147 Ok(view! {
11461148 <input type="hidden" name="csrf" value=(token)>
11471149 })
@@ -1149,7 +1151,7 @@ pub async fn csrf_field(token: &str) -> Result<impl View> {
11491151
11501152 /// Inline error box.
11511153 #[component]
1152-pub async fn alert(message: &str) -> Result<impl View> {
1154+pub async fn alert(cx: &Cx, message: &str) -> Result<impl View> {
11531155 Ok(view! {
11541156 <p class="alert" role="alert">(message)</p>
11551157 })
@@ -1160,6 +1162,7 @@ pub async fn alert(message: &str) -> Result<impl View> {
11601162 /// reads the same way.
11611163 #[component]
11621164 pub async fn empty_state(
1165+ cx: &Cx,
11631166 title: &str,
11641167 #[default] hint: Option<&str>,
11651168 #[default] child: Child<'_>,
@@ -1194,7 +1197,7 @@ pub async fn security_headers(cx: &Cx, body: Body, next: Next<'_>) -> Result<Res
11941197 headers.append(X_CONTENT_TYPE_OPTIONS, HeaderValue::from_static("nosniff"));
11951198 headers.append(REFERRER_POLICY, HeaderValue::from_static("same-origin"));
11961199 headers.append(X_FRAME_OPTIONS, HeaderValue::from_static("DENY"));
1197- let csp = match try_app_context::<AppState>(cx) {
1200+ let csp = match try_context::<AppState>(cx) {
11981201 Some(state) => APP_CSP
11991202 .get_or_init(|| csp_header(&state.config.user_content_base_url))
12001203 .clone(),
@@ -1327,7 +1330,7 @@ pub fn rel_words(lang: Lang) -> String {
13271330 /// A live relative time for an RFC 3339 stamp: a `<time data-rel>` that nav.js re-words as the
13281331 /// clock moves. A stamp that does not parse renders empty.
13291332 #[component]
1330-pub async fn rel_time(lang: Lang, stamp: &str) -> Result<impl View> {
1333+pub async fn rel_time(cx: &Cx, lang: Lang, stamp: &str) -> Result<impl View> {
13311334 let label = forge_core::time::stamp_to_unix(stamp)
13321335 .map_or_else(String::new, |unix| relative_time(lang, unix, now_unix()));
13331336 Ok(view! {
@@ -1337,7 +1340,7 @@ pub async fn rel_time(lang: Lang, stamp: &str) -> Result<impl View> {
13371340
13381341 /// A live relative time, or "never" when there is no stamp.
13391342 #[component]
1340-pub async fn rel_time_or_never(lang: Lang, stamp: Option<&str>) -> Result<impl View> {
1343+pub async fn rel_time_or_never(cx: &Cx, lang: Lang, stamp: Option<&str>) -> Result<impl View> {
13411344 Ok(view! {
13421345 if let Some(stamp) = stamp {
13431346 rel_time(lang: lang, stamp: stamp)
@@ -1351,6 +1354,7 @@ pub async fn rel_time_or_never(lang: Lang, stamp: Option<&str>) -> Result<impl V
13511354 /// stamp is left out.
13521355 #[component]
13531356 pub async fn added_status(
1357+ cx: &Cx,
13541358 lang: Lang,
13551359 added: Option<&str>,
13561360 used: Option<&str>,
@@ -1423,6 +1427,7 @@ fn tab_more_class(on: bool) -> &'static str {
14231427 /// counts shown on their tabs; a zero count (or `None`) shows the tab without one.
14241428 #[component]
14251429 pub async fn repo_tabs(
1430+ cx: &Cx,
14261431 owner: String,
14271432 repo: String,
14281433 default_branch: String,
@@ -1545,6 +1550,7 @@ const TAG_ICON: &str = r#"<svg viewBox="0 0 24 24"><path d="M20.6 13.4 13.4 20.6
15451550 /// is left out.
15461551 #[component]
15471552 async fn ref_group(
1553+ cx: &Cx,
15481554 lang: Lang,
15491555 kind: &'static str,
15501556 heading: &'static str,
@@ -1593,6 +1599,7 @@ async fn ref_group(
15931599 /// still lists the first entries of each section.
15941600 #[component]
15951601 pub async fn ref_selector(
1602+ cx: &Cx,
15961603 lang: Lang,
15971604 label: &'static str,
15981605 current: String,
crates/forge-web/src/views/parts.rsmodified+11 -2
@@ -2,6 +2,7 @@
22 //! `docs/ui-language.md`.
33
44 use topcoat::Result;
5+use topcoat::context::Cx;
56 use topcoat::view::{Child, View, ViewExt, component, view};
67
78 use crate::i18n::Lang;
@@ -10,7 +11,9 @@ use crate::pages::passkeys::s;
1011 /// The width class of a strip segment holding `part` of `total`: `fr1` to `fr40`, since a page may
1112 /// not set inline styles. A segment with nothing in it still shows.
1213 pub fn seg_fr(part: u64, total: u64) -> String {
13- let n = (part.saturating_mul(40) + total / 2).checked_div(total).unwrap_or(1);
14+ let n = (part.saturating_mul(40) + total / 2)
15+ .checked_div(total)
16+ .unwrap_or(1);
1417 format!("fr{}", n.clamp(1, 40))
1518 }
1619
@@ -18,6 +21,7 @@ pub fn seg_fr(part: u64, total: u64) -> String {
1821 /// starts it open, as a form sent back with an error must.
1922 #[component]
2023 pub async fn reveal(
24+ cx: &Cx,
2125 label: &str,
2226 #[default] id: Option<&str>,
2327 #[default] open: bool,
@@ -35,6 +39,7 @@ pub async fn reveal(
3539 /// `fields` are the form's hidden fields besides the CSRF token, `note` says what will be lost.
3640 #[component]
3741 pub async fn confirm_act(
42+ cx: &Cx,
3843 lang: Lang,
3944 label: &str,
4045 action: &str,
@@ -65,6 +70,7 @@ pub async fn confirm_act(
6570 /// One text link that posts at once, for actions that lose nothing.
6671 #[component]
6772 pub async fn post_act(
73+ cx: &Cx,
6874 label: &str,
6975 action: &str,
7076 csrf: &str,
@@ -132,7 +138,7 @@ pub struct PeopleList {
132138
133139 /// The people list and its add form. The caller puts it in a sheet.
134140 #[component]
135-pub async fn people_list(list: PeopleList) -> Result<impl View> {
141+pub async fn people_list(cx: &Cx, list: PeopleList) -> Result<impl View> {
136142 let PeopleList {
137143 lang,
138144 title,
@@ -287,6 +293,7 @@ impl SubPart {
287293 /// The line under a head's title. `pips` are recent runs, oldest first, as (href, title, class).
288294 #[component]
289295 pub async fn head_sub(
296+ cx: &Cx,
290297 parts: Vec<SubPart>,
291298 #[default] pips: Vec<(String, String, &'static str)>,
292299 ) -> Result<impl View> {
@@ -323,6 +330,7 @@ pub async fn head_sub(
323330 /// beside it (`child`), then the sub line. Every page starts with one. Section tabs follow it.
324331 #[component]
325332 pub async fn head(
333+ cx: &Cx,
326334 title: &str,
327335 #[default] sub: Vec<SubPart>,
328336 #[default] live: Option<&str>,
@@ -354,6 +362,7 @@ pub struct RailItem {
354362 /// for a filter.
355363 #[component]
356364 pub async fn rail(
365+ cx: &Cx,
357366 label: &str,
358367 items: Vec<RailItem>,
359368 #[default] heading: Option<&str>,
crates/forge-web/src/views/repo_list.rsmodified+6 -3
@@ -4,6 +4,7 @@
44 use forge_core::Visibility;
55 use forge_core::store::ListedRepo;
66 use topcoat::Result;
7+use topcoat::context::Cx;
78 use topcoat::view::{View, component, view};
89
910 use crate::i18n::orgs::{self as g, K};
@@ -14,7 +15,8 @@ use crate::views::repo_href;
1415 /// The fact a row leads with when the repo is private ("Private · "); public says nothing, it is
1516 /// the usual case.
1617 pub fn private_fact(lang: Lang, visibility: Visibility) -> Option<String> {
17- (visibility == Visibility::Private).then(|| format!("{} \u{b7} ", i18n::visibility_label(lang, visibility)))
18+ (visibility == Visibility::Private)
19+ .then(|| format!("{} \u{b7} ", i18n::visibility_label(lang, visibility)))
1820 }
1921
2022 /// One listed repo, formatted for display.
@@ -45,7 +47,7 @@ impl RepoRow {
4547
4648 /// The repo rows: name, a one-line description, then Private (when it is), stars and the last update.
4749 #[component]
48-pub async fn repo_rows(rows: Vec<RepoRow>, lang: Lang) -> Result<impl View> {
50+pub async fn repo_rows(cx: &Cx, rows: Vec<RepoRow>, lang: Lang) -> Result<impl View> {
4951 let (before, after) = g::updated_parts(lang);
5052 Ok(view! {
5153 <ul class="repo-list">
@@ -79,7 +81,7 @@ pub struct SortLink {
7981
8082 /// The "Sort by" chips.
8183 #[component]
82-pub async fn sort_chips(links: Vec<SortLink>, lang: Lang) -> Result<impl View> {
84+pub async fn sort_chips(cx: &Cx, links: Vec<SortLink>, lang: Lang) -> Result<impl View> {
8385 Ok(view! {
8486 <nav class="sort" aria-label=(g::t(lang, K::SortNav))>
8587 <span class="hint">(g::t(lang, K::SortBy))</span>
@@ -137,6 +139,7 @@ fn page_numbers(page: u64, pages: u64) -> Vec<Option<u64>> {
137139 /// page.
138140 #[component]
139141 pub async fn pager(
142+ cx: &Cx,
140143 page: u64,
141144 pages: u64,
142145 links: Vec<PageLink>,
crates/forge-web/src/views/review_thread.rsmodified+7 -2
@@ -5,6 +5,7 @@
55
66 use std::collections::HashMap;
77 use std::sync::Arc;
8+use topcoat::context::Cx;
89
910 use forge_core::suggestions::{Part, hunk_line, split_body};
1011 use forge_core::{ReviewComment, Thread};
@@ -167,6 +168,7 @@ fn comment_row(
167168 /// `conversation` and tells the POST routes which tab to redirect to.
168169 #[component]
169170 pub async fn review_thread(
171+ cx: &Cx,
170172 thread: Thread,
171173 ctx: ThreadCtx,
172174 show_hunk: bool,
@@ -181,6 +183,7 @@ pub async fn review_thread(
181183 /// One thread with its strings in `lang`. See `review_thread` for the arguments.
182184 #[component]
183185 pub async fn review_thread_in(
186+ cx: &Cx,
184187 lang: Lang,
185188 thread: Thread,
186189 ctx: ThreadCtx,
@@ -261,7 +264,7 @@ pub async fn review_thread_in(
261264 /// The diff hunk, the comments, then the thread's tools and reply form. Split into siblings so
262265 /// each component's view stays small enough to type-check.
263266 #[component]
264-async fn thread_parts(parts: ThreadParts) -> Result<impl View> {
267+async fn thread_parts(cx: &Cx, parts: ThreadParts) -> Result<impl View> {
265268 let ThreadParts {
266269 hunk,
267270 comments,
@@ -313,7 +316,7 @@ struct ThreadFooter {
313316 /// The resolve button, and Reply, which opens its form in place. Each is empty when the viewer
314317 /// may not use it.
315318 #[component]
316-async fn thread_footer(footer: ThreadFooter) -> Result<impl View> {
319+async fn thread_footer(cx: &Cx, footer: ThreadFooter) -> Result<impl View> {
317320 let ThreadFooter {
318321 resolve_action,
319322 resolve_value,
@@ -351,6 +354,7 @@ async fn thread_footer(footer: ThreadFooter) -> Result<impl View> {
351354
352355 #[component]
353356 async fn thread_comment(
357+ cx: &Cx,
354358 comment: CommentRow,
355359 csrf: String,
356360 return_to: String,
@@ -404,6 +408,7 @@ async fn thread_comment(
404408 /// lines, the Apply control when it applies, and a note when it is outdated.
405409 #[component]
406410 async fn comment_part(
411+ cx: &Cx,
407412 part: PartRow,
408413 csrf: String,
409414 return_to: String,
crates/forge-web/src/views/timeline.rsmodified+2 -0
@@ -4,6 +4,7 @@
44
55 use forge_core::ci::RunState;
66 use topcoat::Result;
7+use topcoat::context::Cx;
78 use topcoat::view::{View, component, view};
89
910 use super::{repo_href, short_oid};
@@ -54,6 +55,7 @@ struct BarView {
5455 /// counts the bars drawn.
5556 #[component]
5657 pub async fn history_strip(
58+ cx: &Cx,
5759 lang: Lang,
5860 owner: String,
5961 repo: String,