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"
242 source = "registry+https://github.com/rust-lang/crates.io-index"242 source = "registry+https://github.com/rust-lang/crates.io-index"
243 checksum = "2cb931c189b85683d69a5cfad41d4d418671e1ac413dd209f3f2fc31e3cfd902"243 checksum = "2cb931c189b85683d69a5cfad41d4d418671e1ac413dd209f3f2fc31e3cfd902"
244 244
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-
251 [[package]]245 [[package]]
252 name = "arc-swap"246 name = "arc-swap"
253 version = "1.9.5"247 version = "1.9.5"
@@ -3396,17 +3390,6 @@ dependencies = [
3396 "windows-sys 0.61.2",3390 "windows-sys 0.61.2",
3397 ]3391 ]
3398 3392
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-
3410 [[package]]3393 [[package]]
3411 name = "html5ever"3394 name = "html5ever"
3412 version = "0.40.1"3395 version = "0.40.1"
@@ -4146,7 +4129,6 @@ dependencies = [
4146 "fastrand",4129 "fastrand",
4147 "futures-io",4130 "futures-io",
4148 "futures-util",4131 "futures-util",
4149- "hostname",
4150 "httpdate",4132 "httpdate",
4151 "idna",4133 "idna",
4152 "mime",4134 "mime",
@@ -7180,9 +7162,9 @@ checksum = "009dbb7700f11c55ef83aebbe4c0e9cf1f1ac0844bd8d6f00dc38f302026e13a"
7180 7162
7181 [[package]]7163 [[package]]
7182 name = "topcoat"7164 name = "topcoat"
7183-version = "0.11.0"7165+version = "0.12.1"
7184 source = "registry+https://github.com/rust-lang/crates.io-index"7166 source = "registry+https://github.com/rust-lang/crates.io-index"
7185-checksum = "70b5093d8133b513742b7461a28d374107b8bf9168aa60f4f567ad89acd2ed9e"7167+checksum = "16bfbdbedee481dc7a9e89ed7c5be0a8fda008d6170fe9012c220590297eb4b9"
7186 dependencies = [7168 dependencies = [
7187 "futures-util",7169 "futures-util",
7188 "inventory",7170 "inventory",
@@ -7190,13 +7172,14 @@ dependencies = [
7190 "tokio",7172 "tokio",
7191 "tokio-tungstenite",7173 "tokio-tungstenite",
7192 "topcoat-asset",7174 "topcoat-asset",
7175+ "topcoat-asset-macro",
7193 "topcoat-cookie",7176 "topcoat-cookie",
7194 "topcoat-core",7177 "topcoat-core",
7195 "topcoat-core-macro",7178 "topcoat-core-macro",
7196 "topcoat-font",7179 "topcoat-font",
7197 "topcoat-font-macro",7180 "topcoat-font-macro",
7198 "topcoat-l10n",7181 "topcoat-l10n",
7199- "topcoat-mail",7182+ "topcoat-metadata",
7200 "topcoat-router",7183 "topcoat-router",
7201 "topcoat-router-macro",7184 "topcoat-router-macro",
7202 "topcoat-runtime",7185 "topcoat-runtime",
@@ -7208,9 +7191,9 @@ dependencies = [
7208 7191
7209 [[package]]7192 [[package]]
7210 name = "topcoat-asset"7193 name = "topcoat-asset"
7211-version = "0.11.0"7194+version = "0.12.1"
7212 source = "registry+https://github.com/rust-lang/crates.io-index"7195 source = "registry+https://github.com/rust-lang/crates.io-index"
7213-checksum = "ac70debf9eee62714ce45416eae27b283c3a44a0f9ebcb2ac088fda48b533f3e"7196+checksum = "14de3c5734f7bb8ffc85ae33baa00e7dafee22978d02ef13e2ce3ad992fb1bc8"
7214 dependencies = [7197 dependencies = [
7215 "http",7198 "http",
7216 "memchr",7199 "memchr",
@@ -7225,11 +7208,34 @@ dependencies = [
7225 "topcoat-view",7208 "topcoat-view",
7226 ]7209 ]
7227 7210
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+
7228 [[package]]7234 [[package]]
7229 name = "topcoat-cookie"7235 name = "topcoat-cookie"
7230-version = "0.11.0"7236+version = "0.12.1"
7231 source = "registry+https://github.com/rust-lang/crates.io-index"7237 source = "registry+https://github.com/rust-lang/crates.io-index"
7232-checksum = "df79aba10192abe21fbd01dfcb46bb04dab5ae64adb4432d9f078eb05f94e6a5"7238+checksum = "7fa34d585203cb080afce31749310bf5d9f238491636806d875726c7faebe10c"
7233 dependencies = [7239 dependencies = [
7234 "cookie",7240 "cookie",
7235 "getrandom 0.2.17",7241 "getrandom 0.2.17",
@@ -7242,11 +7248,10 @@ dependencies = [
7242 7248
7243 [[package]]7249 [[package]]
7244 name = "topcoat-core"7250 name = "topcoat-core"
7245-version = "0.11.0"7251+version = "0.12.1"
7246 source = "registry+https://github.com/rust-lang/crates.io-index"7252 source = "registry+https://github.com/rust-lang/crates.io-index"
7247-checksum = "ffff49b885744cdb89ee158c5d81cc8c619692bd9f4ab3cae92ad1adc0ce612e"7253+checksum = "121a7616ec29bc5525a4a580554c3d5330ce4314655a13d0d8d10cc1a083fc7a"
7248 dependencies = [7254 dependencies = [
7249- "anymap3",
7250 "base64 0.22.1",7255 "base64 0.22.1",
7251 "elsa",7256 "elsa",
7252 "http",7257 "http",
@@ -7258,9 +7263,9 @@ dependencies = [
7258 7263
7259 [[package]]7264 [[package]]
7260 name = "topcoat-core-grammar"7265 name = "topcoat-core-grammar"
7261-version = "0.11.0"7266+version = "0.12.1"
7262 source = "registry+https://github.com/rust-lang/crates.io-index"7267 source = "registry+https://github.com/rust-lang/crates.io-index"
7263-checksum = "b788a2010234cd29fc050268e52ceb393d2124b20f669a83d8f61a9dbf895bb6"7268+checksum = "6d2326406a37c4eb212d60bc421589f3b600f50ca440b8e39dbdb7f7d032cb8a"
7264 dependencies = [7269 dependencies = [
7265 "proc-macro-crate",7270 "proc-macro-crate",
7266 "proc-macro2",7271 "proc-macro2",
@@ -7270,9 +7275,9 @@ dependencies = [
7270 7275
7271 [[package]]7276 [[package]]
7272 name = "topcoat-core-macro"7277 name = "topcoat-core-macro"
7273-version = "0.11.0"7278+version = "0.12.1"
7274 source = "registry+https://github.com/rust-lang/crates.io-index"7279 source = "registry+https://github.com/rust-lang/crates.io-index"
7275-checksum = "3e3786bf2ee2c8b4f728d3fb53c41f639aa66583788b3135acbd63c11458b25b"7280+checksum = "020d81b3dfe852b7b5e44bbb2079c6b1346d6dfe50bc267e5d5a05c40bf5d9a4"
7276 dependencies = [7281 dependencies = [
7277 "quote",7282 "quote",
7278 "syn 3.0.10",7283 "syn 3.0.10",
@@ -7281,9 +7286,9 @@ dependencies = [
7281 7286
7282 [[package]]7287 [[package]]
7283 name = "topcoat-font"7288 name = "topcoat-font"
7284-version = "0.11.0"7289+version = "0.12.1"
7285 source = "registry+https://github.com/rust-lang/crates.io-index"7290 source = "registry+https://github.com/rust-lang/crates.io-index"
7286-checksum = "caa4656294aac116def1e7633f03117a84b65126c503242793ff4adc78577fb8"7291+checksum = "5e4382e452ddefff5b03cee1b3c84bcd36783e50afd2fea1e21fc9b41807142e"
7287 dependencies = [7292 dependencies = [
7288 "heck",7293 "heck",
7289 "inventory",7294 "inventory",
@@ -7298,9 +7303,9 @@ dependencies = [
7298 7303
7299 [[package]]7304 [[package]]
7300 name = "topcoat-font-grammar"7305 name = "topcoat-font-grammar"
7301-version = "0.11.0"7306+version = "0.12.1"
7302 source = "registry+https://github.com/rust-lang/crates.io-index"7307 source = "registry+https://github.com/rust-lang/crates.io-index"
7303-checksum = "b462fae28641a1bb24eab1fa9c473520389ca690331ca53fd6143d5b2746045e"7308+checksum = "d6159e8e361f19367ddb11de5e5ff9b04f92d91e0c46ef9b1a076404d83fcfe8"
7304 dependencies = [7309 dependencies = [
7305 "proc-macro2",7310 "proc-macro2",
7306 "quote",7311 "quote",
@@ -7311,9 +7316,9 @@ dependencies = [
7311 7316
7312 [[package]]7317 [[package]]
7313 name = "topcoat-font-macro"7318 name = "topcoat-font-macro"
7314-version = "0.11.0"7319+version = "0.12.1"
7315 source = "registry+https://github.com/rust-lang/crates.io-index"7320 source = "registry+https://github.com/rust-lang/crates.io-index"
7316-checksum = "40776cd3087aaea5e0c8b597126b1c09dbfb0d69833088d7f3b229305bbbb87f"7321+checksum = "7e3d3a71216cec0a27497716d4559e34245e61328f6e04fc2a2bac3b80679b31"
7317 dependencies = [7322 dependencies = [
7318 "quote",7323 "quote",
7319 "syn 3.0.10",7324 "syn 3.0.10",
@@ -7322,10 +7327,11 @@ dependencies = [
7322 7327
7323 [[package]]7328 [[package]]
7324 name = "topcoat-l10n"7329 name = "topcoat-l10n"
7325-version = "0.11.0"7330+version = "0.12.1"
7326 source = "registry+https://github.com/rust-lang/crates.io-index"7331 source = "registry+https://github.com/rust-lang/crates.io-index"
7327-checksum = "34da63b3a5aea3d6c243d9fa8c98ca79b181b985f6a0a042f630672f54d12e9e"7332+checksum = "d877822424504842f90d9f018dbaa61be2d52071653bc0f0921652ef925fdabd"
7328 dependencies = [7333 dependencies = [
7334+ "http",
7329 "icu_locale",7335 "icu_locale",
7330 "icu_locale_core",7336 "icu_locale_core",
7331 "topcoat-core",7337 "topcoat-core",
@@ -7333,24 +7339,24 @@ dependencies = [
7333 ]7339 ]
7334 7340
7335 [[package]]7341 [[package]]
7336-name = "topcoat-mail"7342+name = "topcoat-metadata"
7337-version = "0.11.0"7343+version = "0.12.1"
7338 source = "registry+https://github.com/rust-lang/crates.io-index"7344 source = "registry+https://github.com/rust-lang/crates.io-index"
7339-checksum = "54a13c10c6399d9eb9b0bde38bd3d947eba56ddfaea99d9a4f971b74b6a651db"7345+checksum = "bf250ddbaea17bd63c7d6f124ce8f883dee44ece584cfab979ec33a87a030875"
7340 dependencies = [7346 dependencies = [
7341- "lettre",7347+ "topcoat-asset",
7342- "thiserror 2.0.21",
7343- "time",
7344 "topcoat-core",7348 "topcoat-core",
7349+ "topcoat-core-macro",
7345 "topcoat-router",7350 "topcoat-router",
7346 "topcoat-view",7351 "topcoat-view",
7352+ "topcoat-view-macro",
7347 ]7353 ]
7348 7354
7349 [[package]]7355 [[package]]
7350 name = "topcoat-router"7356 name = "topcoat-router"
7351-version = "0.11.0"7357+version = "0.12.1"
7352 source = "registry+https://github.com/rust-lang/crates.io-index"7358 source = "registry+https://github.com/rust-lang/crates.io-index"
7353-checksum = "b9488065b08f293208b0f1aeb6667d5836b66c12dfced5e330f9a8f1d7f1ca1a"7359+checksum = "c86534384925992375ac979e9b5af7e4086119803b4586c6ac9bca814e814ed2"
7354 dependencies = [7360 dependencies = [
7355 "bytes",7361 "bytes",
7356 "form_urlencoded",7362 "form_urlencoded",
@@ -7384,11 +7390,10 @@ dependencies = [
7384 7390
7385 [[package]]7391 [[package]]
7386 name = "topcoat-router-grammar"7392 name = "topcoat-router-grammar"
7387-version = "0.11.0"7393+version = "0.12.1"
7388 source = "registry+https://github.com/rust-lang/crates.io-index"7394 source = "registry+https://github.com/rust-lang/crates.io-index"
7389-checksum = "ac3f51fa1a1e538bd34e02f88ebba554ac5931e55c688303a58a8e78123dfb04"7395+checksum = "0aa0f6bb59f921cdde73395cc526374d8a553d3285c3f4ac8086c40bedc5be3a"
7390 dependencies = [7396 dependencies = [
7391- "heck",
7392 "proc-macro2",7397 "proc-macro2",
7393 "quote",7398 "quote",
7394 "syn 3.0.10",7399 "syn 3.0.10",
@@ -7397,9 +7402,9 @@ dependencies = [
7397 7402
7398 [[package]]7403 [[package]]
7399 name = "topcoat-router-macro"7404 name = "topcoat-router-macro"
7400-version = "0.11.0"7405+version = "0.12.1"
7401 source = "registry+https://github.com/rust-lang/crates.io-index"7406 source = "registry+https://github.com/rust-lang/crates.io-index"
7402-checksum = "3c1b56d3bf19d54bddf300d6d57ca754531d7ad5481afca0b2302ac33f5d43af"7407+checksum = "71ddd5e527cdab30c73293f907e8f40ef16c421484bb7bad107ecd967a6b98c3"
7403 dependencies = [7408 dependencies = [
7404 "quote",7409 "quote",
7405 "syn 3.0.10",7410 "syn 3.0.10",
@@ -7408,9 +7413,9 @@ dependencies = [
7408 7413
7409 [[package]]7414 [[package]]
7410 name = "topcoat-runtime"7415 name = "topcoat-runtime"
7411-version = "0.11.0"7416+version = "0.12.1"
7412 source = "registry+https://github.com/rust-lang/crates.io-index"7417 source = "registry+https://github.com/rust-lang/crates.io-index"
7413-checksum = "03b22136b99694b349a950cd757387a04b080fdb131eecdd51d0511e1a45ebf5"7418+checksum = "3e8f8651d36f003dd85a6a36ff5e1161b01af1cc5ae5baa38e649bda3605037a"
7414 dependencies = [7419 dependencies = [
7415 "futures-util",7420 "futures-util",
7416 "pin-project-lite",7421 "pin-project-lite",
@@ -7419,6 +7424,7 @@ dependencies = [
7419 "serde_json",7424 "serde_json",
7420 "tokio",7425 "tokio",
7421 "topcoat-asset",7426 "topcoat-asset",
7427+ "topcoat-asset-macro",
7422 "topcoat-core",7428 "topcoat-core",
7423 "topcoat-router",7429 "topcoat-router",
7424 "topcoat-view",7430 "topcoat-view",
@@ -7427,9 +7433,9 @@ dependencies = [
7427 7433
7428 [[package]]7434 [[package]]
7429 name = "topcoat-runtime-grammar"7435 name = "topcoat-runtime-grammar"
7430-version = "0.11.0"7436+version = "0.12.1"
7431 source = "registry+https://github.com/rust-lang/crates.io-index"7437 source = "registry+https://github.com/rust-lang/crates.io-index"
7432-checksum = "ab93a83c38a045a4f541c2e548d30ba5dfdd3173c18de8b1c7b049709c29db97"7438+checksum = "1650432fe7adeab5aa815b84245c29c3ea5390a3b4a41d7cc2868e8f60f6277b"
7433 dependencies = [7439 dependencies = [
7434 "proc-macro2",7440 "proc-macro2",
7435 "quote",7441 "quote",
@@ -7443,9 +7449,9 @@ dependencies = [
7443 7449
7444 [[package]]7450 [[package]]
7445 name = "topcoat-runtime-macro"7451 name = "topcoat-runtime-macro"
7446-version = "0.11.0"7452+version = "0.12.1"
7447 source = "registry+https://github.com/rust-lang/crates.io-index"7453 source = "registry+https://github.com/rust-lang/crates.io-index"
7448-checksum = "5acb1db0bdba3c36e4f80f7ef530945779a1b0294b1087e7d877e33005da6283"7454+checksum = "f4ea7a5b61e948d702a5cb6727c38a3b0c934b630cc003971ca86a9262c16b0c"
7449 dependencies = [7455 dependencies = [
7450 "quote",7456 "quote",
7451 "syn 3.0.10",7457 "syn 3.0.10",
@@ -7454,9 +7460,9 @@ dependencies = [
7454 7460
7455 [[package]]7461 [[package]]
7456 name = "topcoat-session"7462 name = "topcoat-session"
7457-version = "0.11.0"7463+version = "0.12.1"
7458 source = "registry+https://github.com/rust-lang/crates.io-index"7464 source = "registry+https://github.com/rust-lang/crates.io-index"
7459-checksum = "2325c30a484b1b1b6f5012b50bc18994d37c33c6bd2f71be8ff509b591a17457"7465+checksum = "d705011dbdf07ea9e3f74397f177cf3224a2fa0ff600a2514c11837ef04e1858"
7460 dependencies = [7466 dependencies = [
7461 "base64 0.22.1",7467 "base64 0.22.1",
7462 "getrandom 0.4.3",7468 "getrandom 0.4.3",
@@ -7465,15 +7471,14 @@ dependencies = [
7465 "tokio",7471 "tokio",
7466 "topcoat-cookie",7472 "topcoat-cookie",
7467 "topcoat-core",7473 "topcoat-core",
7468- "topcoat-router",
7469 "web-time",7474 "web-time",
7470 ]7475 ]
7471 7476
7472 [[package]]7477 [[package]]
7473 name = "topcoat-view"7478 name = "topcoat-view"
7474-version = "0.11.0"7479+version = "0.12.1"
7475 source = "registry+https://github.com/rust-lang/crates.io-index"7480 source = "registry+https://github.com/rust-lang/crates.io-index"
7476-checksum = "db4553b91f30e30c71c2bd95ae8e931a33326c6ffb604663b9d214008f12947c"7481+checksum = "654e102f97a4c26ba9b7deb72bdac45c8587ced30480b431155a56a935d12e86"
7477 dependencies = [7482 dependencies = [
7478 "futures-core",7483 "futures-core",
7479 "futures-util",7484 "futures-util",
@@ -7487,9 +7492,9 @@ dependencies = [
7487 7492
7488 [[package]]7493 [[package]]
7489 name = "topcoat-view-grammar"7494 name = "topcoat-view-grammar"
7490-version = "0.11.0"7495+version = "0.12.1"
7491 source = "registry+https://github.com/rust-lang/crates.io-index"7496 source = "registry+https://github.com/rust-lang/crates.io-index"
7492-checksum = "75dd093ffc848370da4cce7670ccdfd4e98eab48e178d5d0da5509f747d85ca6"7497+checksum = "28e348a794d04565ee00e7899f215c02db9acf0711bb8eefbba2ffa14bc72a5c"
7493 dependencies = [7498 dependencies = [
7494 "heck",7499 "heck",
7495 "proc-macro2",7500 "proc-macro2",
@@ -7501,9 +7506,9 @@ dependencies = [
7501 7506
7502 [[package]]7507 [[package]]
7503 name = "topcoat-view-macro"7508 name = "topcoat-view-macro"
7504-version = "0.11.0"7509+version = "0.12.1"
7505 source = "registry+https://github.com/rust-lang/crates.io-index"7510 source = "registry+https://github.com/rust-lang/crates.io-index"
7506-checksum = "ffa1688d165704f08d58c03710453d0d39553292bea61b18be7959a996c3e39b"7511+checksum = "eed1edf71f2fe9f5edf9dcfa2ec3e55b9bae443c015497f80347f82cf6b7af8d"
7507 dependencies = [7512 dependencies = [
7508 "quote",7513 "quote",
7509 "syn 3.0.10",7514 "syn 3.0.10",
Cargo.tomlmodified+1 -1
@@ -82,7 +82,7 @@ multer = "3.1.0"
82 lettre = { version = "0.11.24", default-features = false, features = ["smtp-transport", "builder", "tokio1-rustls", "ring", "webpki-roots", "pool"] }82 lettre = { version = "0.11.24", default-features = false, features = ["smtp-transport", "builder", "tokio1-rustls", "ring", "webpki-roots", "pool"] }
83 83
84 # web framework84 # 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"] }
86 86
87 # ssh server87 # ssh server
88 russh = { version = "0.65.4", default-features = false, features = ["flate2", "aws-lc-rs"] }88 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)] = &[
117 include_str!("../../migrations/0070_pull_viewed_files.sql"),117 include_str!("../../migrations/0070_pull_viewed_files.sql"),
118 ),118 ),
119 (71, include_str!("../../migrations/0071_ci_job_steps.sql")),119 (71, include_str!("../../migrations/0071_ci_job_steps.sql")),
120- (72, include_str!("../../migrations/0072_ember_anvil_default.sql")),120+ (
121- (73, include_str!("../../migrations/0073_sage_ink_default.sql")),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+ ),
122 ];128 ];
123 129
124 /// The highest migration version this binary knows about.130 /// 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 {
23 /// it. `None` at the edge of the range jiff can represent. Unknown zones fall back to UTC.23 /// it. `None` at the edge of the range jiff can represent. Unknown zones fall back to UTC.
24 pub fn day_span(date: civil::Date, tz: &str) -> Option<(i64, i64)> {24 pub fn day_span(date: civil::Date, tz: &str) -> Option<(i64, i64)> {
25 let zone = zone_or_utc(tz);25 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();
27 let next = date31 let next = date
28 .tomorrow()32 .tomorrow()
29 .ok()?33 .ok()?
crates/forge-e2e/tests/e2e/browse_e2e.rsmodified+5 -1
@@ -127,7 +127,11 @@ fn element_texts(body: &str, selector: &str) -> Vec<String> {
127 /// Checks the latest commit in a repo page's head line: its short sha linking to the commit, no127 /// Checks the latest commit in a repo page's head line: its short sha linking to the commit, no
128 /// subject, and the commit count label.128 /// subject, and the commit count label.
129 fn assert_latest_bar(body: &str, what: &str, subject: &str, oid: &str, count: &str) {129 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+ );
131 let shas = element_texts(body, ".head-sub a.mono");135 let shas = element_texts(body, ".head-sub a.mono");
132 assert_eq!(shas.len(), 1, "{what}: the head line must show the sha");136 assert_eq!(shas.len(), 1, "{what}: the head line must show the sha");
133 assert_eq!(shas[0].trim(), &oid[..7], "{what}: short sha");137 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() {
50 assert_eq!(turkish.status().as_u16(), 200);50 assert_eq!(turkish.status().as_u16(), 200);
51 let body = turkish.text().await.expect("read body");51 let body = turkish.text().await.expect("read body");
52 assert!(body.contains("<html lang=\"tr\""), "html lang is tr");52 assert!(body.contains("<html lang=\"tr\""), "html lang is tr");
53- assert!(53+ assert!(body.contains("<h1>Parçacıklar</h1>"), "Turkish heading");
54- body.contains("<h1>Parçacıklar</h1>"),
55- "Turkish heading"
56- );
57 assert!(54 assert!(
58 body.contains("Gösterilecek parçacık yok."),55 body.contains("Gösterilecek parçacık yok."),
59 "Turkish empty state"56 "Turkish empty state"
@@ -67,9 +64,6 @@ async fn snippets_page_follows_the_browser_language() {
67 .await64 .await
68 .expect("GET /snippets (en)");65 .expect("GET /snippets (en)");
69 let body = english.text().await.expect("read body");66 let body = english.text().await.expect("read body");
70- assert!(67+ assert!(body.contains("<h1>Snippets</h1>"), "English heading");
71- body.contains("<h1>Snippets</h1>"),
72- "English heading"
73- );
74 assert!(body.contains("No snippets to show."), "English empty state");68 assert!(body.contains("No snippets to show."), "English empty state");
75 }69 }
crates/forge-e2e/tests/e2e/pulls_e2e.rsmodified+2 -1
@@ -23,7 +23,8 @@ const REPO_PATH: &str = "/tahinli/r";
23 /// Text of the first state badge on a page, e.g. `Open`, `Closed` or `Merged`.23 /// Text of the first state badge on a page, e.g. `Open`, `Closed` or `Merged`.
24 fn state_badge(body: &str) -> String {24 fn state_badge(body: &str) -> String {
25 let doc = scraper::Html::parse_document(body);25 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");
27 doc.select(&selector)28 doc.select(&selector)
28 .next()29 .next()
29 .map(|el| el.text().collect::<String>().trim().to_owned())30 .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() {
388 200,388 200,
389 "repo unchanged until accepted"389 "repo unchanged until accepted"
390 );390 );
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;
392 assert!(offered.body.contains("Pending transfer to carol"));394 assert!(offered.body.contains("Pending transfer to carol"));
393 let inbox = http.get("/notifications", Some(&carol)).await;395 let inbox = http.get("/notifications", Some(&carol)).await;
394 let accept_action = form_action(&inbox.body, "/accept");396 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() {
249 // The home page is the signed-in viewer's own page, not a redirect.249 // The home page is the signed-in viewer's own page, not a redirect.
250 let home = http.get("/", Some(&bob)).await;250 let home = http.get("/", Some(&bob)).await;
251 assert_eq!(home.status, 200, "home page for a signed-in viewer");251 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+ );
253 256
254 // An admin who does not own the repo can delete it.257 // An admin who does not own the repo can delete it.
255 let admin_page = http.get("/bob/priv/settings", Some(&tahinli)).await;258 let admin_page = http.get("/bob/priv/settings", Some(&tahinli)).await;
@@ -523,7 +526,11 @@ async fn branch_protection_end_to_end() {
523 let updated = http526 let updated = http
524 .post_form(527 .post_form(
525 "/bob/app/settings/branches",528 "/bob/app/settings/branches",
526- &[("csrf", &owner_csrf), ("pattern", "main"), ("existing", "1")],529+ &[
530+ ("csrf", &owner_csrf),
531+ ("pattern", "main"),
532+ ("existing", "1"),
533+ ],
527 Some(&bob),534 Some(&bob),
528 )535 )
529 .await;536 .await;
@@ -538,7 +545,10 @@ async fn branch_protection_end_to_end() {
538 )545 )
539 .await;546 .await;
540 assert_eq!(duplicate.status, 200, "duplicate rule re-renders the page");547 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+ );
542 let page = http552 let page = http
543 .get("/bob/app/settings?section=branches", Some(&bob))553 .get("/bob/app/settings?section=branches", Some(&bob))
544 .await;554 .await;
@@ -864,7 +874,10 @@ async fn general_settings_end_to_end() {
864 page.body874 page.body
865 .contains("href=\"/bob/gen/settings/collaborators\"")875 .contains("href=\"/bob/gen/settings/collaborators\"")
866 );876 );
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+ );
868 881
869 // Description: control characters are stripped and it shows on the repo header.882 // Description: control characters are stripped and it shows on the repo header.
870 let csrf = csrf_for(&http, &bob).await;883 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() {
148 offered.header(LOCATION).as_deref(),148 offered.header(LOCATION).as_deref(),
149 Some("/bob/priv/settings?section=danger")149 Some("/bob/priv/settings?section=danger")
150 );150 );
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;
152 assert!(status.body.contains("Pending transfer to carol"));154 assert!(status.body.contains("Pending transfer to carol"));
153 // Carol cannot read the private repo, yet the inbox offers her the actions.155 // Carol cannot read the private repo, yet the inbox offers her the actions.
154 assert_eq!(http.get("/bob/priv", Some(&carol)).await.status, 404);156 assert_eq!(http.get("/bob/priv", Some(&carol)).await.status, 404);
155 let declined = act_from(&http, &carol, "/notifications", "/decline").await;157 let declined = act_from(&http, &carol, "/notifications", "/decline").await;
156 assert_eq!(declined.status, 303, "decline: {}", declined.body);158 assert_eq!(declined.status, 303, "decline: {}", declined.body);
157 assert_eq!(declined.header(LOCATION).as_deref(), Some("/notifications"));159 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;
159 assert!(!after.body.contains("Pending transfer"));163 assert!(!after.body.contains("Pending transfer"));
160 assert_eq!(http.get("/bob/priv", Some(&bob)).await.status, 200);164 assert_eq!(http.get("/bob/priv", Some(&bob)).await.status, 200);
161 165
@@ -167,7 +171,9 @@ async fn repo_transfer_offers_declines_cancels_and_org_targets() {
167 cancelled.header(LOCATION).as_deref(),171 cancelled.header(LOCATION).as_deref(),
168 Some("/bob/priv/settings?section=danger")172 Some("/bob/priv/settings?section=danger")
169 );173 );
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;
171 assert!(!after.body.contains("Pending transfer"));177 assert!(!after.body.contains("Pending transfer"));
172 178
173 // A transfer to an org: plain members get no accept form, owners do.179 // 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 {
327 ] {327 ] {
328 assert!(!is_offered(id), "{id}");328 assert!(!is_offered(id), "{id}");
329 }329 }
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+ ] {
331 assert!(!is_offered_base(id), "{id}");339 assert!(!is_offered_base(id), "{id}");
332 }340 }
333 }341 }
crates/forge-web-base/src/compression.rsmodified+1 -1
@@ -200,7 +200,7 @@ mod tests {
200 ))200 ))
201 .route(RouteFn::new(Method::GET, "/tahinli/demo/blob.bin", binary))201 .route(RouteFn::new(Method::GET, "/tahinli/demo/blob.bin", binary))
202 .layer(TowerLayer::new(ResponseCompression))202 .layer(TowerLayer::new(ResponseCompression))
203- .compression(Compression::off())203+ .with(Compression::disable())
204 .build()204 .build()
205 }205 }
206 206
crates/forge-web-base/src/i18n/admin.rsmodified+2 -6
@@ -368,12 +368,8 @@ pub fn t(lang: Lang, key: K) -> &'static str {
368 (RunnerEnabledNotice, Tr) => "Çalıştırıcı etkinleştirildi.",368 (RunnerEnabledNotice, Tr) => "Çalıştırıcı etkinleştirildi.",
369 (Runners, En) => "Runners",369 (Runners, En) => "Runners",
370 (Runners, Tr) => "Çalıştırıcılar",370 (Runners, Tr) => "Çalıştırıcılar",
371- (ScheduledBackupsOff, En) => {371+ (ScheduledBackupsOff, En) => "Scheduled backups are off.",
372- "Scheduled backups are off."372+ (ScheduledBackupsOff, Tr) => "Zamanlanmış yedeklemeler kapalı.",
373- }
374- (ScheduledBackupsOff, Tr) => {
375- "Zamanlanmış yedeklemeler kapalı."
376- }
377 (SecurityLogTitle, En) => "Security log",373 (SecurityLogTitle, En) => "Security log",
378 (SecurityLogTitle, Tr) => "Güvenlik günlüğü",374 (SecurityLogTitle, Tr) => "Güvenlik günlüğü",
379 (SecurityNone, En) => "None (plain text)",375 (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 {
673 673
674 /// Several label additions in one run: "added labels a, b and c". `names` holds at least two.674 /// Several label additions in one run: "added labels a, b and c". `names` holds at least two.
675 pub fn event_labels_added(lang: Lang, names: &[String]) -> String {675 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));
677 let list = match lang {679 let list = match lang {
678 Lang::En => match rest.is_empty() {680 Lang::En => match rest.is_empty() {
679 true => last.to_owned(),681 true => last.to_owned(),
crates/forge-web-base/src/render/markdown.rsmodified+8 -2
@@ -390,12 +390,18 @@ fn text_with_links<'a>(
390 Some(n) => new_node(390 Some(n) => new_node(
391 arena,391 arena,
392 sourcepos,392 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+ ))),
394 ),397 ),
395 None => new_node(398 None => new_node(
396 arena,399 arena,
397 sourcepos,400 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+ ))),
399 ),405 ),
400 };406 };
401 link.append(new_node(407 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};
25 use http::HeaderMap;25 use http::HeaderMap;
26 use http::header::{AUTHORIZATION, HeaderName, HeaderValue};26 use http::header::{AUTHORIZATION, HeaderName, HeaderValue};
27 use serde_json::{Value, json};27 use serde_json::{Value, json};
28-use topcoat::context::{Cx, app_context};28+use topcoat::context::{Cx, context};
29 use topcoat::router::request::{headers, uri};29 use topcoat::router::request::{headers, uri};
30 use topcoat::router::response::Response;30 use topcoat::router::response::Response;
31 use topcoat::router::{StatusCode, path_param, route};31 use topcoat::router::{StatusCode, path_param, route};
@@ -108,7 +108,7 @@ fn effective_headers(cx: &Cx) -> HeaderMap {
108 108
109 /// Who is asking, and the raw token they used (for the clone URL of a private repo).109 /// Who is asking, and the raw token they used (for the clone URL of a private repo).
110 async fn caller(cx: &Cx) -> Result<(Option<User>, Option<String>), Refusal> {110 async fn caller(cx: &Cx) -> Result<(Option<User>, Option<String>), Refusal> {
111- let state = app_context::<AppState>(cx);111+ let state = context::<AppState>(cx);
112 let map = effective_headers(cx);112 let map = effective_headers(cx);
113 let actor = api::authenticate(state, client_ip(cx), &map).await?;113 let actor = api::authenticate(state, client_ip(cx), &map).await?;
114 let token = api::presented_token(&map).flatten();114 let token = api::presented_token(&map).flatten();
@@ -122,16 +122,9 @@ struct Ctx {
122 }122 }
123 123
124 async fn read_ctx(cx: &Cx) -> Result<Ctx, Refusal> {124 async fn read_ctx(cx: &Cx) -> Result<Ctx, Refusal> {
125- let state = app_context::<AppState>(cx);125+ let state = context::<AppState>(cx);
126 let (actor, token) = caller(cx).await?;126 let (actor, token) = caller(cx).await?;
127- let repo = api::load_repo(127+ let repo = api::load_repo(state, actor.as_ref(), owner(cx), repo(cx), Action::Read).await?;
128- state,
129- actor.as_ref(),
130- path_param::<Owner>(cx),
131- path_param::<Repo>(cx),
132- Action::Read,
133- )
134- .await?;
135 Ok(Ctx {128 Ok(Ctx {
136 repo,129 repo,
137 token: actor.and(token),130 token: actor.and(token),
@@ -178,7 +171,7 @@ pub fn slice<T>(items: Vec<T>, pg: &Paging) -> (Vec<T>, usize) {
178 pub fn page_response(cx: &Cx, items: Vec<Value>, total: usize, pg: &Paging) -> Response {171 pub fn page_response(cx: &Cx, items: Vec<Value>, total: usize, pg: &Paging) -> Response {
179 let mut res = api::json(StatusCode::OK, &Value::Array(items));172 let mut res = api::json(StatusCode::OK, &Value::Array(items));
180 let last = total.div_ceil(pg.limit.max(1)).max(1);173 let last = total.div_ceil(pg.limit.max(1)).max(1);
181- let state = app_context::<AppState>(cx);174+ let state = context::<AppState>(cx);
182 let base = state.config.base_url.trim_end_matches('/');175 let base = state.config.base_url.trim_end_matches('/');
183 let mut rest = String::new();176 let mut rest = String::new();
184 if let Some(query) = uri(cx).query() {177 if let Some(query) = uri(cx).query() {
@@ -230,7 +223,7 @@ fn internal(e: impl std::fmt::Display) -> Refusal {
230 }223 }
231 224
232 #[route(GET "/api/v1/version")]225 #[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> {
234 Ok(api::json(227 Ok(api::json(
235 StatusCode::OK,228 StatusCode::OK,
236 &json!({ "version": GITEA_VERSION }),229 &json!({ "version": GITEA_VERSION }),
@@ -238,7 +231,7 @@ async fn version_route(_cx: &Cx) -> topcoat::Result<Response> {
238 }231 }
239 232
240 #[route(GET "/api/v1/settings/api")]233 #[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> {
242 Ok(api::json(235 Ok(api::json(
243 StatusCode::OK,236 StatusCode::OK,
244 &json!({237 &json!({
@@ -302,7 +295,7 @@ pub async fn repo_json(
302 295
303 #[route(GET "/api/v1/repos/{owner}/{repo}")]296 #[route(GET "/api/v1/repos/{owner}/{repo}")]
304 async fn get_repo(cx: &Cx) -> topcoat::Result<Response> {297 async fn get_repo(cx: &Cx) -> topcoat::Result<Response> {
305- let state = app_context::<AppState>(cx);298+ let state = context::<AppState>(cx);
306 let ctx = match read_ctx(cx).await {299 let ctx = match read_ctx(cx).await {
307 Ok(ctx) => ctx,300 Ok(ctx) => ctx,
308 Err(res) => return Ok(*res),301 Err(res) => return Ok(*res),
@@ -336,7 +329,7 @@ fn label_json(base: &str, repo: &CoreRepo, label: &Label) -> Value {
336 329
337 #[route(GET "/api/v1/repos/{owner}/{repo}/labels")]330 #[route(GET "/api/v1/repos/{owner}/{repo}/labels")]
338 async fn list_labels_route(cx: &Cx) -> topcoat::Result<Response> {331 async fn list_labels_route(cx: &Cx) -> topcoat::Result<Response> {
339- let state = app_context::<AppState>(cx);332+ let state = context::<AppState>(cx);
340 let ctx = match read_ctx(cx).await {333 let ctx = match read_ctx(cx).await {
341 Ok(ctx) => ctx,334 Ok(ctx) => ctx,
342 Err(res) => return Ok(*res),335 Err(res) => return Ok(*res),
@@ -389,7 +382,7 @@ fn state_filter(cx: &Cx) -> Result<Option<IssueState>, Refusal> {
389 382
390 #[route(GET "/api/v1/repos/{owner}/{repo}/milestones")]383 #[route(GET "/api/v1/repos/{owner}/{repo}/milestones")]
391 async fn list_milestones_route(cx: &Cx) -> topcoat::Result<Response> {384 async fn list_milestones_route(cx: &Cx) -> topcoat::Result<Response> {
392- let state = app_context::<AppState>(cx);385+ let state = context::<AppState>(cx);
393 let ctx = match read_ctx(cx).await {386 let ctx = match read_ctx(cx).await {
394 Ok(ctx) => ctx,387 Ok(ctx) => ctx,
395 Err(res) => return Ok(*res),388 Err(res) => return Ok(*res),
@@ -495,7 +488,7 @@ fn filter_of(cx: &Cx, pg: &Paging) -> Result<IssueFilter, Refusal> {
495 488
496 #[route(GET "/api/v1/repos/{owner}/{repo}/issues")]489 #[route(GET "/api/v1/repos/{owner}/{repo}/issues")]
497 async fn list_issues_route(cx: &Cx) -> topcoat::Result<Response> {490 async fn list_issues_route(cx: &Cx) -> topcoat::Result<Response> {
498- let state = app_context::<AppState>(cx);491+ let state = context::<AppState>(cx);
499 let ctx = match read_ctx(cx).await {492 let ctx = match read_ctx(cx).await {
500 Ok(ctx) => ctx,493 Ok(ctx) => ctx,
501 Err(res) => return Ok(*res),494 Err(res) => return Ok(*res),
@@ -572,13 +565,13 @@ fn comment_json(
572 565
573 #[route(GET "/api/v1/repos/{owner}/{repo}/issues/{index}/comments")]566 #[route(GET "/api/v1/repos/{owner}/{repo}/issues/{index}/comments")]
574 async fn issue_comments(cx: &Cx) -> topcoat::Result<Response> {567 async fn issue_comments(cx: &Cx) -> topcoat::Result<Response> {
575- let state = app_context::<AppState>(cx);568+ let state = context::<AppState>(cx);
576 let ctx = match read_ctx(cx).await {569 let ctx = match read_ctx(cx).await {
577 Ok(ctx) => ctx,570 Ok(ctx) => ctx,
578 Err(res) => return Ok(*res),571 Err(res) => return Ok(*res),
579 };572 };
580 let result: Result<Response, Refusal> = async {573 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?;
582 let all = state575 let all = state
583 .store576 .store
584 .list_comments(&issue.id)577 .list_comments(&issue.id)
@@ -634,13 +627,13 @@ async fn reactions_json(
634 627
635 #[route(GET "/api/v1/repos/{owner}/{repo}/issues/{index}/reactions")]628 #[route(GET "/api/v1/repos/{owner}/{repo}/issues/{index}/reactions")]
636 async fn issue_reactions(cx: &Cx) -> topcoat::Result<Response> {629 async fn issue_reactions(cx: &Cx) -> topcoat::Result<Response> {
637- let state = app_context::<AppState>(cx);630+ let state = context::<AppState>(cx);
638 let ctx = match read_ctx(cx).await {631 let ctx = match read_ctx(cx).await {
639 Ok(ctx) => ctx,632 Ok(ctx) => ctx,
640 Err(res) => return Ok(*res),633 Err(res) => return Ok(*res),
641 };634 };
642 let result: Result<Response, Refusal> = async {635 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?;
644 let all = reactions_json(637 let all = reactions_json(
645 state,638 state,
646 &ctx,639 &ctx,
@@ -659,15 +652,13 @@ async fn issue_reactions(cx: &Cx) -> topcoat::Result<Response> {
659 652
660 #[route(GET "/api/v1/repos/{owner}/{repo}/issues/comments/{id}/reactions")]653 #[route(GET "/api/v1/repos/{owner}/{repo}/issues/comments/{id}/reactions")]
661 async fn comment_reactions(cx: &Cx) -> topcoat::Result<Response> {654 async fn comment_reactions(cx: &Cx) -> topcoat::Result<Response> {
662- let state = app_context::<AppState>(cx);655+ let state = context::<AppState>(cx);
663 let ctx = match read_ctx(cx).await {656 let ctx = match read_ctx(cx).await {
664 Ok(ctx) => ctx,657 Ok(ctx) => ctx,
665 Err(res) => return Ok(*res),658 Err(res) => return Ok(*res),
666 };659 };
667 let result: Result<Response, Refusal> = async {660 let result: Result<Response, Refusal> = async {
668- let id: i64 = path_param::<Id>(cx)661+ let id: i64 = id(cx).parse().map_err(|_| bad("invalid comment id"))?;
669- .parse()
670- .map_err(|_| bad("invalid comment id"))?;
671 let (number, position) =662 let (number, position) =
672 split_comment_id(id).ok_or_else(|| not_found("comment not found"))?;663 split_comment_id(id).ok_or_else(|| not_found("comment not found"))?;
673 let issue = issue_row(state, &ctx.repo, &number.to_string()).await?;664 let issue = issue_row(state, &ctx.repo, &number.to_string()).await?;
@@ -803,7 +794,7 @@ async fn pull_json(
803 794
804 #[route(GET "/api/v1/repos/{owner}/{repo}/pulls")]795 #[route(GET "/api/v1/repos/{owner}/{repo}/pulls")]
805 async fn list_pulls_route(cx: &Cx) -> topcoat::Result<Response> {796 async fn list_pulls_route(cx: &Cx) -> topcoat::Result<Response> {
806- let state = app_context::<AppState>(cx);797+ let state = context::<AppState>(cx);
807 let ctx = match read_ctx(cx).await {798 let ctx = match read_ctx(cx).await {
808 Ok(ctx) => ctx,799 Ok(ctx) => ctx,
809 Err(res) => return Ok(*res),800 Err(res) => return Ok(*res),
@@ -893,13 +884,13 @@ async fn review_comments(state: &AppState, issue_id: &str) -> Result<Vec<ReviewC
893 884
894 #[route(GET "/api/v1/repos/{owner}/{repo}/pulls/{index}/reviews")]885 #[route(GET "/api/v1/repos/{owner}/{repo}/pulls/{index}/reviews")]
895 async fn pull_reviews(cx: &Cx) -> topcoat::Result<Response> {886 async fn pull_reviews(cx: &Cx) -> topcoat::Result<Response> {
896- let state = app_context::<AppState>(cx);887+ let state = context::<AppState>(cx);
897 let ctx = match read_ctx(cx).await {888 let ctx = match read_ctx(cx).await {
898 Ok(ctx) => ctx,889 Ok(ctx) => ctx,
899 Err(res) => return Ok(*res),890 Err(res) => return Ok(*res),
900 };891 };
901 let result: Result<Response, Refusal> = async {892 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?;
903 let reviews = state894 let reviews = state
904 .store895 .store
905 .list_reviews(&issue.id)896 .list_reviews(&issue.id)
@@ -967,14 +958,14 @@ fn review_comment_json(ctx: &Ctx, number: i64, c: &ReviewComment) -> Value {
967 958
968 #[route(GET "/api/v1/repos/{owner}/{repo}/pulls/{index}/reviews/{review_id}/comments")]959 #[route(GET "/api/v1/repos/{owner}/{repo}/pulls/{index}/reviews/{review_id}/comments")]
969 async fn pull_review_comments(cx: &Cx) -> topcoat::Result<Response> {960 async fn pull_review_comments(cx: &Cx) -> topcoat::Result<Response> {
970- let state = app_context::<AppState>(cx);961+ let state = context::<AppState>(cx);
971 let ctx = match read_ctx(cx).await {962 let ctx = match read_ctx(cx).await {
972 Ok(ctx) => ctx,963 Ok(ctx) => ctx,
973 Err(res) => return Ok(*res),964 Err(res) => return Ok(*res),
974 };965 };
975 let result: Result<Response, Refusal> = async {966 let result: Result<Response, Refusal> = async {
976- let issue = pull_issue(state, &ctx.repo, path_param::<Index>(cx)).await?;967+ let issue = pull_issue(state, &ctx.repo, index(cx)).await?;
977- let raw = path_param::<ReviewId>(cx);968+ let raw = review_id(cx);
978 let reviews = state969 let reviews = state
979 .store970 .store
980 .list_reviews(&issue.id)971 .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};
13 use http_body::Frame;13 use http_body::Frame;
14 use http_body_util::StreamBody;14 use http_body_util::StreamBody;
15 use serde_json::{Value, json};15 use serde_json::{Value, json};
16-use topcoat::context::{Cx, app_context};16+use topcoat::context::{Cx, context};
17 use topcoat::router::request::headers;17 use topcoat::router::request::headers;
18 use topcoat::router::response::Response;18 use topcoat::router::response::Response;
19 use topcoat::router::{Body, StatusCode, path_param, route};19 use topcoat::router::{Body, StatusCode, path_param, route};
@@ -33,7 +33,7 @@ path_param!(version);
33 /// The caller of a registry request. Reads with a token that lacks the scope are served as33 /// The caller of a registry request. Reads with a token that lacks the scope are served as
34 /// anonymous, so a token made for another purpose cannot break a public install. Writes refuse.34 /// anonymous, so a token made for another purpose cannot break a public install. Writes refuse.
35 async fn caller(cx: &Cx, scope_required: bool) -> Result<Option<User>, Refusal> {35 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);
37 let normalized = bare_token_as_bearer(headers(cx));37 let normalized = bare_token_as_bearer(headers(cx));
38 let (user, token_id, scopes) =38 let (user, token_id, scopes) =
39 match api::authenticate_token(state, client_ip(cx), &normalized).await {39 match api::authenticate_token(state, client_ip(cx), &normalized).await {
@@ -120,8 +120,8 @@ fn text(body: String) -> Response {
120 120
121 /// Loads the registry owner named in the path, as the caller may see it. A missing owner is 404.121 /// Loads the registry owner named in the path, as the caller may see it. A missing owner is 404.
122 async fn owner_of(cx: &Cx) -> Result<User, Refusal> {122 async fn owner_of(cx: &Cx) -> Result<User, Refusal> {
123- let state = app_context::<AppState>(cx);123+ let state = context::<AppState>(cx);
124- match package_ops::owner_named(state, path_param::<Owner>(cx)).await {124+ match package_ops::owner_named(state, owner(cx)).await {
125 Ok(Some(found)) => Ok(found),125 Ok(Some(found)) => Ok(found),
126 Ok(_) => Err(Box::new(failure(PackageError::NotFound))),126 Ok(_) => Err(Box::new(failure(PackageError::NotFound))),
127 Err(e) => Err(Box::new(failure(e))),127 Err(e) => Err(Box::new(failure(e))),
@@ -130,7 +130,7 @@ async fn owner_of(cx: &Cx) -> Result<User, Refusal> {
130 130
131 #[route(GET "/api/packages/{owner}/cargo/config.json")]131 #[route(GET "/api/packages/{owner}/cargo/config.json")]
132 async fn config(cx: &Cx) -> topcoat::Result<Response> {132 async fn config(cx: &Cx) -> topcoat::Result<Response> {
133- let state = app_context::<AppState>(cx);133+ let state = context::<AppState>(cx);
134 if let Err(res) = caller(cx, false).await {134 if let Err(res) = caller(cx, false).await {
135 return Ok(*res);135 return Ok(*res);
136 }136 }
@@ -164,7 +164,7 @@ async fn index_long(cx: &Cx) -> topcoat::Result<Response> {
164 }164 }
165 165
166 async fn index_response(cx: &Cx) -> Response {166 async fn index_response(cx: &Cx) -> Response {
167- let state = app_context::<AppState>(cx);167+ let state = context::<AppState>(cx);
168 let actor = match caller(cx, false).await {168 let actor = match caller(cx, false).await {
169 Ok(actor) => actor,169 Ok(actor) => actor,
170 Err(res) => return *res,170 Err(res) => return *res,
@@ -173,13 +173,11 @@ async fn index_response(cx: &Cx) -> Response {
173 Ok(owner) => owner,173 Ok(owner) => owner,
174 Err(res) => return *res,174 Err(res) => return *res,
175 };175 };
176- let package =176+ let package = match package_ops::readable_package(state, actor.as_ref(), &owner, name(cx)).await
177- match package_ops::readable_package(state, actor.as_ref(), &owner, path_param::<Name>(cx))177+ {
178- .await178+ Ok(package) => package,
179- {179+ Err(e) => return failure(e),
180- Ok(package) => package,180+ };
181- Err(e) => return failure(e),
182- };
183 match package_ops::index_file(state, &package).await {181 match package_ops::index_file(state, &package).await {
184 Ok(body) => text(body),182 Ok(body) => text(body),
185 Err(e) => failure(e),183 Err(e) => failure(e),
@@ -189,7 +187,7 @@ async fn index_response(cx: &Cx) -> Response {
189 /// The `.crate` file of one version, streamed from the blob store.187 /// The `.crate` file of one version, streamed from the blob store.
190 #[route(GET "/api/packages/{owner}/cargo/download/{name}/{version}")]188 #[route(GET "/api/packages/{owner}/cargo/download/{name}/{version}")]
191 async fn download(cx: &Cx) -> topcoat::Result<Response> {189 async fn download(cx: &Cx) -> topcoat::Result<Response> {
192- let state = app_context::<AppState>(cx);190+ let state = context::<AppState>(cx);
193 let actor = match caller(cx, false).await {191 let actor = match caller(cx, false).await {
194 Ok(actor) => actor,192 Ok(actor) => actor,
195 Err(res) => return Ok(*res),193 Err(res) => return Ok(*res),
@@ -198,18 +196,11 @@ async fn download(cx: &Cx) -> topcoat::Result<Response> {
198 Ok(owner) => owner,196 Ok(owner) => owner,
199 Err(res) => return Ok(*res),197 Err(res) => return Ok(*res),
200 };198 };
201- let read = match package_ops::download(199+ let read =
202- state,200+ match package_ops::download(state, actor.as_ref(), &owner, name(cx), version(cx)).await {
203- actor.as_ref(),201+ Ok(read) => read,
204- &owner,202+ Err(e) => return Ok(failure(e)),
205- path_param::<Name>(cx),203+ };
206- path_param::<Version>(cx),
207- )
208- .await
209- {
210- Ok(read) => read,
211- Err(e) => return Ok(failure(e)),
212- };
213 let chunks = read.stream.map(|chunk| chunk.map(Frame::data));204 let chunks = read.stream.map(|chunk| chunk.map(Frame::data));
214 let mut res = Response::new(Body::new(StreamBody::new(chunks)));205 let mut res = Response::new(Body::new(StreamBody::new(chunks)));
215 *res.status_mut() = StatusCode::OK;206 *res.status_mut() = StatusCode::OK;
@@ -226,7 +217,7 @@ async fn download(cx: &Cx) -> topcoat::Result<Response> {
226 /// length-prefixed `.crate`. It is read whole, up to the publish limit.217 /// length-prefixed `.crate`. It is read whole, up to the publish limit.
227 #[route(PUT "/api/packages/{owner}/cargo/api/v1/crates/new")]218 #[route(PUT "/api/packages/{owner}/cargo/api/v1/crates/new")]
228 async fn publish(cx: &Cx, body: Body) -> topcoat::Result<Response> {219 async fn publish(cx: &Cx, body: Body) -> topcoat::Result<Response> {
229- let state = app_context::<AppState>(cx);220+ let state = context::<AppState>(cx);
230 let actor = match caller(cx, true).await {221 let actor = match caller(cx, true).await {
231 Ok(Some(actor)) => actor,222 Ok(Some(actor)) => actor,
232 Ok(None) => {223 Ok(None) => {
@@ -271,7 +262,7 @@ async fn unyank(cx: &Cx) -> topcoat::Result<Response> {
271 }262 }
272 263
273 async fn set_yank(cx: &Cx, yanked: bool) -> topcoat::Result<Response> {264 async fn set_yank(cx: &Cx, yanked: bool) -> topcoat::Result<Response> {
274- let state = app_context::<AppState>(cx);265+ let state = context::<AppState>(cx);
275 let actor = match caller(cx, true).await {266 let actor = match caller(cx, true).await {
276 Ok(Some(actor)) => actor,267 Ok(Some(actor)) => actor,
277 Ok(None) => {268 Ok(None) => {
@@ -286,16 +277,7 @@ async fn set_yank(cx: &Cx, yanked: bool) -> topcoat::Result<Response> {
286 Ok(owner) => owner,277 Ok(owner) => owner,
287 Err(res) => return Ok(*res),278 Err(res) => return Ok(*res),
288 };279 };
289- match package_ops::set_yanked(280+ match package_ops::set_yanked(state, &owner, &actor, name(cx), version(cx), yanked).await {
290- state,
291- &owner,
292- &actor,
293- path_param::<Name>(cx),
294- path_param::<Version>(cx),
295- yanked,
296- )
297- .await
298- {
299 Ok(()) => Ok(api::json(StatusCode::OK, &json!({ "ok": true }))),281 Ok(()) => Ok(api::json(StatusCode::OK, &json!({ "ok": true }))),
300 Err(e) => Ok(failure(e)),282 Err(e) => Ok(failure(e)),
301 }283 }
@@ -305,7 +287,7 @@ async fn set_yank(cx: &Cx, yanked: bool) -> topcoat::Result<Response> {
305 /// an org, its owners. Read-only: adding or removing owners is done in the forge.287 /// an org, its owners. Read-only: adding or removing owners is done in the forge.
306 #[route(GET "/api/packages/{owner}/cargo/api/v1/crates/{name}/owners")]288 #[route(GET "/api/packages/{owner}/cargo/api/v1/crates/{name}/owners")]
307 async fn owners(cx: &Cx) -> topcoat::Result<Response> {289 async fn owners(cx: &Cx) -> topcoat::Result<Response> {
308- let state = app_context::<AppState>(cx);290+ let state = context::<AppState>(cx);
309 let actor = match caller(cx, false).await {291 let actor = match caller(cx, false).await {
310 Ok(actor) => actor,292 Ok(actor) => actor,
311 Err(res) => return Ok(*res),293 Err(res) => return Ok(*res),
@@ -314,9 +296,7 @@ async fn owners(cx: &Cx) -> topcoat::Result<Response> {
314 Ok(owner) => owner,296 Ok(owner) => owner,
315 Err(res) => return Ok(*res),297 Err(res) => return Ok(*res),
316 };298 };
317- if let Err(e) =299+ if let Err(e) = package_ops::readable_package(state, actor.as_ref(), &owner, name(cx)).await {
318- package_ops::readable_package(state, actor.as_ref(), &owner, path_param::<Name>(cx)).await
319- {
320 return Ok(failure(e));300 return Ok(failure(e));
321 }301 }
322 let people: Vec<User> = if owner.is_org() {302 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;
13 use http::header::CONTENT_TYPE;13 use http::header::CONTENT_TYPE;
14 use serde::Deserialize;14 use serde::Deserialize;
15 use serde_json::{Value, json};15 use serde_json::{Value, json};
16-use topcoat::context::{Cx, app_context};16+use topcoat::context::{Cx, context};
17 use topcoat::router::request::headers;17 use topcoat::router::request::headers;
18 use topcoat::router::response::Response;18 use topcoat::router::response::Response;
19 use topcoat::router::{Body, StatusCode, path_param, route};19 use topcoat::router::{Body, StatusCode, path_param, route};
@@ -55,7 +55,7 @@ struct PatchBody {
55 55
56 #[route(GET "/api/v1/repos/{owner}/{repo}/releases")]56 #[route(GET "/api/v1/repos/{owner}/{repo}/releases")]
57 async fn list_releases(cx: &Cx) -> topcoat::Result<Response> {57 async fn list_releases(cx: &Cx) -> topcoat::Result<Response> {
58- let state = app_context::<AppState>(cx);58+ let state = context::<AppState>(cx);
59 let (repo, can_write) = match read_context(cx).await {59 let (repo, can_write) = match read_context(cx).await {
60 Ok(found) => found,60 Ok(found) => found,
61 Err(res) => return Ok(*res),61 Err(res) => return Ok(*res),
@@ -82,17 +82,17 @@ async fn list_releases(cx: &Cx) -> topcoat::Result<Response> {
82 /// Gitea's `GET .../releases/{id}/assets/{attachment_id}`: one asset of one release.82 /// Gitea's `GET .../releases/{id}/assets/{attachment_id}`: one asset of one release.
83 #[route(GET "/api/v1/repos/{owner}/{repo}/releases/{id}/assets/{asset}")]83 #[route(GET "/api/v1/repos/{owner}/{repo}/releases/{id}/assets/{asset}")]
84 async fn get_asset(cx: &Cx) -> topcoat::Result<Response> {84 async fn get_asset(cx: &Cx) -> topcoat::Result<Response> {
85- let state = app_context::<AppState>(cx);85+ let state = context::<AppState>(cx);
86 let (repo, can_write) = match read_context(cx).await {86 let (repo, can_write) = match read_context(cx).await {
87 Ok(found) => found,87 Ok(found) => found,
88 Err(res) => return Ok(*res),88 Err(res) => return Ok(*res),
89 };89 };
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 {
91 Ok(release) if can_write || !release.draft => release,91 Ok(release) if can_write || !release.draft => release,
92 Ok(_) => return Ok(not_found()),92 Ok(_) => return Ok(not_found()),
93 Err(res) => return Ok(*res),93 Err(res) => return Ok(*res),
94 };94 };
95- let wanted = path_param::<Asset>(cx);95+ let wanted = asset(cx);
96 let assets = match state.store.list_release_assets(&release.id).await {96 let assets = match state.store.list_release_assets(&release.id).await {
97 Ok(assets) => assets,97 Ok(assets) => assets,
98 Err(e) => return Ok(*api::internal(e)),98 Err(e) => return Ok(*api::internal(e)),
@@ -112,12 +112,12 @@ async fn get_asset(cx: &Cx) -> topcoat::Result<Response> {
112 112
113 #[route(GET "/api/v1/repos/{owner}/{repo}/releases/tags/{tag}")]113 #[route(GET "/api/v1/repos/{owner}/{repo}/releases/tags/{tag}")]
114 async fn get_release_by_tag(cx: &Cx) -> topcoat::Result<Response> {114 async fn get_release_by_tag(cx: &Cx) -> topcoat::Result<Response> {
115- let state = app_context::<AppState>(cx);115+ let state = context::<AppState>(cx);
116 let (repo, can_write) = match read_context(cx).await {116 let (repo, can_write) = match read_context(cx).await {
117 Ok(found) => found,117 Ok(found) => found,
118 Err(res) => return Ok(*res),118 Err(res) => return Ok(*res),
119 };119 };
120- let tag_name = path_param::<Tag>(cx);120+ let tag_name = tag(cx);
121 let release = match state.store.release_by_tag(&repo.id, tag_name).await {121 let release = match state.store.release_by_tag(&repo.id, tag_name).await {
122 Ok(Some(release)) if can_write || !release.draft => release,122 Ok(Some(release)) if can_write || !release.draft => release,
123 Ok(_) => return Ok(not_found()),123 Ok(_) => return Ok(not_found()),
@@ -131,7 +131,7 @@ async fn get_release_by_tag(cx: &Cx) -> topcoat::Result<Response> {
131 131
132 #[route(POST "/api/v1/repos/{owner}/{repo}/releases")]132 #[route(POST "/api/v1/repos/{owner}/{repo}/releases")]
133 async fn create_release(cx: &Cx, body: Body) -> topcoat::Result<Response> {133 async fn create_release(cx: &Cx, body: Body) -> topcoat::Result<Response> {
134- let state = app_context::<AppState>(cx);134+ let state = context::<AppState>(cx);
135 let (repo, user) = match write_context(cx).await {135 let (repo, user) = match write_context(cx).await {
136 Ok(found) => found,136 Ok(found) => found,
137 Err(res) => return Ok(*res),137 Err(res) => return Ok(*res),
@@ -176,12 +176,12 @@ async fn create_release(cx: &Cx, body: Body) -> topcoat::Result<Response> {
176 176
177 #[route(PATCH "/api/v1/repos/{owner}/{repo}/releases/{id}")]177 #[route(PATCH "/api/v1/repos/{owner}/{repo}/releases/{id}")]
178 async fn edit_release(cx: &Cx, body: Body) -> topcoat::Result<Response> {178 async fn edit_release(cx: &Cx, body: Body) -> topcoat::Result<Response> {
179- let state = app_context::<AppState>(cx);179+ let state = context::<AppState>(cx);
180 let (repo, user) = match write_context(cx).await {180 let (repo, user) = match write_context(cx).await {
181 Ok(found) => found,181 Ok(found) => found,
182 Err(res) => return Ok(*res),182 Err(res) => return Ok(*res),
183 };183 };
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 {
185 Ok(release) => release,185 Ok(release) => release,
186 Err(res) => return Ok(*res),186 Err(res) => return Ok(*res),
187 };187 };
@@ -218,12 +218,12 @@ async fn edit_release(cx: &Cx, body: Body) -> topcoat::Result<Response> {
218 218
219 #[route(DELETE "/api/v1/repos/{owner}/{repo}/releases/{id}")]219 #[route(DELETE "/api/v1/repos/{owner}/{repo}/releases/{id}")]
220 async fn delete_release(cx: &Cx) -> topcoat::Result<Response> {220 async fn delete_release(cx: &Cx) -> topcoat::Result<Response> {
221- let state = app_context::<AppState>(cx);221+ let state = context::<AppState>(cx);
222 let (repo, user) = match write_context(cx).await {222 let (repo, user) = match write_context(cx).await {
223 Ok(found) => found,223 Ok(found) => found,
224 Err(res) => return Ok(*res),224 Err(res) => return Ok(*res),
225 };225 };
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 {
227 Ok(release) => release,227 Ok(release) => release,
228 Err(res) => return Ok(*res),228 Err(res) => return Ok(*res),
229 };229 };
@@ -236,12 +236,12 @@ async fn delete_release(cx: &Cx) -> topcoat::Result<Response> {
236 /// Streams the raw request body into an asset. `201` for a new name, `200` when it replaces one.236 /// Streams the raw request body into an asset. `201` for a new name, `200` when it replaces one.
237 #[route(PUT "/api/v1/repos/{owner}/{repo}/releases/{id}/assets/{asset}")]237 #[route(PUT "/api/v1/repos/{owner}/{repo}/releases/{id}/assets/{asset}")]
238 async fn upload_asset(cx: &Cx, body: Body) -> topcoat::Result<Response> {238 async fn upload_asset(cx: &Cx, body: Body) -> topcoat::Result<Response> {
239- let state = app_context::<AppState>(cx);239+ let state = context::<AppState>(cx);
240 let (repo, user) = match write_context(cx).await {240 let (repo, user) = match write_context(cx).await {
241 Ok(found) => found,241 Ok(found) => found,
242 Err(res) => return Ok(*res),242 Err(res) => return Ok(*res),
243 };243 };
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 {
245 Ok(release) => release,245 Ok(release) => release,
246 Err(res) => return Ok(*res),246 Err(res) => return Ok(*res),
247 };247 };
@@ -264,7 +264,7 @@ async fn upload_asset(cx: &Cx, body: Body) -> topcoat::Result<Response> {
264 &repo,264 &repo,
265 &release,265 &release,
266 &user,266 &user,
267- path_param::<Asset>(cx),267+ asset(cx),
268 content_type.as_deref(),268 content_type.as_deref(),
269 stream,269 stream,
270 max_bytes,270 max_bytes,
@@ -287,17 +287,17 @@ async fn upload_asset(cx: &Cx, body: Body) -> topcoat::Result<Response> {
287 287
288 #[route(DELETE "/api/v1/repos/{owner}/{repo}/releases/{id}/assets/{asset}")]288 #[route(DELETE "/api/v1/repos/{owner}/{repo}/releases/{id}/assets/{asset}")]
289 async fn delete_asset(cx: &Cx) -> topcoat::Result<Response> {289 async fn delete_asset(cx: &Cx) -> topcoat::Result<Response> {
290- let state = app_context::<AppState>(cx);290+ let state = context::<AppState>(cx);
291 let (repo, _user) = match write_context(cx).await {291 let (repo, _user) = match write_context(cx).await {
292 Ok(found) => found,292 Ok(found) => found,
293 Err(res) => return Ok(*res),293 Err(res) => return Ok(*res),
294 };294 };
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 {
296 Ok(release) => release,296 Ok(release) => release,
297 Err(res) => return Ok(*res),297 Err(res) => return Ok(*res),
298 };298 };
299 // The asset may be named by its forge id or by the integer shown as `id` in the JSON.299 // 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();
301 if gitea::is_numeric(&asset)301 if gitea::is_numeric(&asset)
302 && let Ok(assets) = state.store.list_release_assets(&release.id).await302 && let Ok(assets) = state.store.list_release_assets(&release.id).await
303 && let Some(found) = assets303 && let Some(found) = assets
@@ -318,21 +318,14 @@ const MAX_JSON_BYTES: usize = 64 * 1024;
318 /// Authenticates an optional caller and loads the repo for reading. Also reports whether the318 /// Authenticates an optional caller and loads the repo for reading. Also reports whether the
319 /// caller may write, which decides whether drafts are visible.319 /// caller may write, which decides whether drafts are visible.
320 async fn read_context(cx: &Cx) -> Result<(CoreRepo, bool), Refusal> {320 async fn read_context(cx: &Cx) -> Result<(CoreRepo, bool), Refusal> {
321- let state = app_context::<AppState>(cx);321+ let state = context::<AppState>(cx);
322 let actor = api::authenticate(state, client_ip(cx), headers(cx)).await?;322 let actor = api::authenticate(state, client_ip(cx), headers(cx)).await?;
323- let repo = api::load_repo(323+ let repo = api::load_repo(state, actor.as_ref(), owner(cx), repo(cx), Action::Read).await?;
324- state,
325- actor.as_ref(),
326- path_param::<Owner>(cx),
327- path_param::<Repo>(cx),
328- Action::Read,
329- )
330- .await?;
331 let can_write = api::load_repo(324 let can_write = api::load_repo(
332 state,325 state,
333 actor.as_ref(),326 actor.as_ref(),
334- path_param::<Owner>(cx),327+ owner(cx),
335- path_param::<Repo>(cx),328+ self::repo(cx),
336 Action::Write,329 Action::Write,
337 )330 )
338 .await331 .await
@@ -342,16 +335,9 @@ async fn read_context(cx: &Cx) -> Result<(CoreRepo, bool), Refusal> {
342 335
343 /// Authenticates a required caller with write access and loads the repo.336 /// Authenticates a required caller with write access and loads the repo.
344 async fn write_context(cx: &Cx) -> Result<(CoreRepo, User), Refusal> {337 async fn write_context(cx: &Cx) -> Result<(CoreRepo, User), Refusal> {
345- let state = app_context::<AppState>(cx);338+ let state = context::<AppState>(cx);
346 let actor = api::authenticate(state, client_ip(cx), headers(cx)).await?;339 let actor = api::authenticate(state, client_ip(cx), headers(cx)).await?;
347- let repo = api::load_repo(340+ let repo = api::load_repo(state, actor.as_ref(), owner(cx), repo(cx), Action::Write).await?;
348- state,
349- actor.as_ref(),
350- path_param::<Owner>(cx),
351- path_param::<Repo>(cx),
352- Action::Write,
353- )
354- .await?;
355 match actor {341 match actor {
356 Some(user) => Ok((repo, user)),342 Some(user) => Ok((repo, user)),
357 None => Err(Box::new(api::unauthorized())),343 None => Err(Box::new(api::unauthorized())),
crates/forge-web/src/api/statuses.rsmodified+7 -21
@@ -8,7 +8,7 @@ use forge_core::Action;
8 use forge_core::store::commit_status::{CommitStatus, DEFAULT_CONTEXT, StatusState, combine};8 use forge_core::store::commit_status::{CommitStatus, DEFAULT_CONTEXT, StatusState, combine};
9 use serde::Deserialize;9 use serde::Deserialize;
10 use serde_json::{Value, json};10 use serde_json::{Value, json};
11-use topcoat::context::{Cx, app_context};11+use topcoat::context::{Cx, context};
12 use topcoat::router::request::headers;12 use topcoat::router::request::headers;
13 use topcoat::router::response::Response;13 use topcoat::router::response::Response;
14 use topcoat::router::{Body, StatusCode, path_param, route};14 use topcoat::router::{Body, StatusCode, path_param, route};
@@ -35,19 +35,12 @@ struct ReportBody {
35 35
36 #[route(POST "/api/v1/repos/{owner}/{repo}/statuses/{sha}")]36 #[route(POST "/api/v1/repos/{owner}/{repo}/statuses/{sha}")]
37 async fn report_status(cx: &Cx, body: Body) -> topcoat::Result<Response> {37 async fn report_status(cx: &Cx, body: Body) -> topcoat::Result<Response> {
38- let state = app_context::<AppState>(cx);38+ let state = context::<AppState>(cx);
39 let actor = match api::authenticate(state, client_ip(cx), headers(cx)).await {39 let actor = match api::authenticate(state, client_ip(cx), headers(cx)).await {
40 Ok(actor) => actor,40 Ok(actor) => actor,
41 Err(res) => return Ok(*res),41 Err(res) => return Ok(*res),
42 };42 };
43- let repo = match api::load_repo(43+ let repo = match api::load_repo(state, actor.as_ref(), owner(cx), repo(cx), Action::Write).await
44- state,
45- actor.as_ref(),
46- path_param::<Owner>(cx),
47- path_param::<Repo>(cx),
48- Action::Write,
49- )
50- .await
51 {44 {
52 Ok(repo) => repo,45 Ok(repo) => repo,
53 Err(res) => return Ok(*res),46 Err(res) => return Ok(*res),
@@ -55,7 +48,7 @@ async fn report_status(cx: &Cx, body: Body) -> topcoat::Result<Response> {
55 let Some(user) = actor else {48 let Some(user) = actor else {
56 return Ok(api::unauthorized());49 return Ok(api::unauthorized());
57 };50 };
58- let Some(sha) = api::normalize_sha(path_param::<Sha>(cx)) else {51+ let Some(sha) = api::normalize_sha(sha(cx)) else {
59 return Ok(not_a_full_sha());52 return Ok(not_a_full_sha());
60 };53 };
61 let bytes = match api::read_body(body, MAX_BODY_BYTES).await {54 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> {
117 110
118 #[route(GET "/api/v1/repos/{owner}/{repo}/commits/{sha}/statuses")]111 #[route(GET "/api/v1/repos/{owner}/{repo}/commits/{sha}/statuses")]
119 async fn list_statuses(cx: &Cx) -> topcoat::Result<Response> {112 async fn list_statuses(cx: &Cx) -> topcoat::Result<Response> {
120- let state = app_context::<AppState>(cx);113+ let state = context::<AppState>(cx);
121 let actor = match api::authenticate(state, client_ip(cx), headers(cx)).await {114 let actor = match api::authenticate(state, client_ip(cx), headers(cx)).await {
122 Ok(actor) => actor,115 Ok(actor) => actor,
123 Err(res) => return Ok(*res),116 Err(res) => return Ok(*res),
124 };117 };
125- let repo = match api::load_repo(118+ let repo = match api::load_repo(state, actor.as_ref(), owner(cx), repo(cx), Action::Read).await
126- state,
127- actor.as_ref(),
128- path_param::<Owner>(cx),
129- path_param::<Repo>(cx),
130- Action::Read,
131- )
132- .await
133 {119 {
134 Ok(repo) => repo,120 Ok(repo) => repo,
135 Err(res) => return Ok(*res),121 Err(res) => return Ok(*res),
136 };122 };
137- let Some(sha) = api::normalize_sha(path_param::<Sha>(cx)) else {123+ let Some(sha) = api::normalize_sha(sha(cx)) else {
138 return Ok(not_a_full_sha());124 return Ok(not_a_full_sha());
139 };125 };
140 let path = match api::repo_dir(state, &repo) {126 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};
13 use forge_core::{Session, Store, User, secret, totp};13 use forge_core::{Session, Store, User, secret, totp};
14 use tokio::sync::Semaphore;14 use tokio::sync::Semaphore;
15 use topcoat::Result;15 use topcoat::Result;
16-use topcoat::context::{Cx, app_context};16+use topcoat::context::{Cx, context};
17 use topcoat::cookie::{Cookie, Cookies, SameSite, cookies, time};17 use topcoat::cookie::{Cookie, Cookies, SameSite, cookies, time};
18 use topcoat::router::error::{forbidden, see_other};18 use topcoat::router::error::{forbidden, see_other};
19 use topcoat::router::request::{headers, uri};19 use topcoat::router::request::{headers, uri};
@@ -54,7 +54,7 @@ pub async fn current_user(cx: &Cx) -> forge_core::Result<Option<(User, Session)>
54 let Some(cookie) = session_jar(cx).get(SESSION_COOKIE) else {54 let Some(cookie) = session_jar(cx).get(SESSION_COOKIE) else {
55 return Ok(None);55 return Ok(None);
56 };56 };
57- let store = &app_context::<AppState>(cx).store;57+ let store = &context::<AppState>(cx).store;
58 let Some(session) = store58 let Some(session) = store
59 .session_by_token_hash(&hash_token(cookie.value()))59 .session_by_token_hash(&hash_token(cookie.value()))
60 .await?60 .await?
@@ -76,7 +76,7 @@ pub async fn current_user(cx: &Cx) -> forge_core::Result<Option<(User, Session)>
76 76
77 /// Creates a session for `user` and sets the session cookie on the response.77 /// Creates a session for `user` and sets the session cookie on the response.
78 pub async fn login(cx: &Cx, user: &User) -> forge_core::Result<Session> {78 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;
80 let token = new_session_token();80 let token = new_session_token();
81 let addr = client_addr(cx).to_string();81 let addr = client_addr(cx).to_string();
82 let session = store82 let session = store
@@ -90,7 +90,7 @@ pub async fn login(cx: &Cx, user: &User) -> forge_core::Result<Session> {
90 )90 )
91 .await?;91 .await?;
92 // A new sign-in shows up in the user's session list in their other open tabs.92 // 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)
94 .live94 .live
95 .bump(&crate::live::Topic::Account(user.id.clone()));95 .bump(&crate::live::Topic::Account(user.id.clone()));
96 let max_age = time::Duration::seconds(i64::try_from(SESSION_TTL.as_secs()).unwrap_or(i64::MAX));96 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> {
108 108
109 /// Deletes the session row and clears the cookie.109 /// Deletes the session row and clears the cookie.
110 pub async fn logout(cx: &Cx, session: &Session) -> forge_core::Result<()> {110 pub async fn logout(cx: &Cx, session: &Session) -> forge_core::Result<()> {
111- let state = app_context::<AppState>(cx);111+ let state = context::<AppState>(cx);
112 state.store.delete_session(&session.id).await?;112 state.store.delete_session(&session.id).await?;
113 // The user's other tabs may show this session (a page that now leaves for the login page).113 // The user's other tabs may show this session (a page that now leaves for the login page).
114 crate::pages::settings_live::bump_account(state, &session.user_id);114 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};
18 use tokio::signal::unix::{SignalKind, signal};18 use tokio::signal::unix::{SignalKind, signal};
19 use tokio::sync::Notify;19 use tokio::sync::Notify;
20 use tokio::sync::watch;20 use tokio::sync::watch;
21-use topcoat::cookie::RouterBuilderCookieExt;21+use topcoat::cookie::CookieLayer;
22 use topcoat::router::tower::TowerLayer;22 use topcoat::router::tower::TowerLayer;
23 use topcoat::router::{Compression, Router, RouterBuilderDiscoverExt, RouterService};23 use topcoat::router::{Compression, Router, RouterBuilderDiscoverExt, RouterService};
24 24
@@ -169,11 +169,9 @@ pub async fn serve(
169 // `ResponseCompression` compresses text responses only and skips git, LFS, raw and archive paths.169 // `ResponseCompression` compresses text responses only and skips git, LFS, raw and archive paths.
170 let public: Router = Router::builder()170 let public: Router = Router::builder()
171 .discover()171 .discover()
172- .app_context(state.clone())172+ .with(state.clone())
173 .layer(crate::pages::settings_live::AccountWriteLayer)173 .layer(crate::pages::settings_live::AccountWriteLayer)
174- .cookies()174+ .layer(CookieLayer::new())
175- .layer(crate::pages::settings_profile::avatar_body_limit())
176- .layer(crate::pages::settings_profile::org_avatar_body_limit())
177 .layer(crate::pages::repo_ctx::RepoMovedLayer)175 .layer(crate::pages::repo_ctx::RepoMovedLayer)
178 .layer(crate::pages::pull_live::PullWriteLayer)176 .layer(crate::pages::pull_live::PullWriteLayer)
179 .layer(crate::pages::discussion_live::DiscussionWriteLayer)177 .layer(crate::pages::discussion_live::DiscussionWriteLayer)
@@ -181,7 +179,7 @@ pub async fn serve(
181 .layer(crate::pages::repo_settings_live::RepoSettingsWriteLayer)179 .layer(crate::pages::repo_settings_live::RepoSettingsWriteLayer)
182 .layer(crate::pages::not_found_page::NotFoundLayer)180 .layer(crate::pages::not_found_page::NotFoundLayer)
183 .layer(TowerLayer::new(crate::compression::ResponseCompression))181 .layer(TowerLayer::new(crate::compression::ResponseCompression))
184- .compression(Compression::off())182+ .with(Compression::disable())
185 .build();183 .build();
186 let internal_router = internal::router(state.clone());184 let internal_router = internal::router(state.clone());
187 let raw_router = raw::router(state.clone());185 let raw_router = raw::router(state.clone());
crates/forge-web/src/ci/api.rsmodified+19 -19
@@ -22,7 +22,7 @@ use futures_util::StreamExt;
22 use http::header::HeaderValue;22 use http::header::HeaderValue;
23 use serde_json::json;23 use serde_json::json;
24 use std::collections::BTreeMap;24 use std::collections::BTreeMap;
25-use topcoat::context::{Cx, app_context};25+use topcoat::context::{Cx, context};
26 use topcoat::router::request::headers;26 use topcoat::router::request::headers;
27 use topcoat::router::response::Response;27 use topcoat::router::response::Response;
28 use topcoat::router::{Body, HeaderMap, StatusCode, path_param, route};28 use topcoat::router::{Body, HeaderMap, StatusCode, path_param, route};
@@ -146,7 +146,7 @@ pub fn valid_artifact_name(name: &str) -> bool {
146 146
147 #[route(POST "/api/v1/ci/runners/register")]147 #[route(POST "/api/v1/ci/runners/register")]
148 async fn register(cx: &Cx, body: Body) -> topcoat::Result<Response> {148 async fn register(cx: &Cx, body: Body) -> topcoat::Result<Response> {
149- let state = app_context::<AppState>(cx);149+ let state = context::<AppState>(cx);
150 let request: RegisterRequest = match json_body(body).await {150 let request: RegisterRequest = match json_body(body).await {
151 Ok(request) => request,151 Ok(request) => request,
152 Err(res) => return Ok(*res),152 Err(res) => return Ok(*res),
@@ -189,7 +189,7 @@ async fn register(cx: &Cx, body: Body) -> topcoat::Result<Response> {
189 189
190 #[route(POST "/api/v1/ci/runners/claim")]190 #[route(POST "/api/v1/ci/runners/claim")]
191 async fn claim(cx: &Cx, body: Body) -> topcoat::Result<Response> {191 async fn claim(cx: &Cx, body: Body) -> topcoat::Result<Response> {
192- let state = app_context::<AppState>(cx);192+ let state = context::<AppState>(cx);
193 // The labels in the request are ignored: the labels stored at registration are used, plus the193 // The labels in the request are ignored: the labels stored at registration are used, plus the
194 // arch and OS the runner reports, so `runs_on = ["aarch64"]` needs no admin to type a label.194 // arch and OS the runner reports, so `runs_on = ["aarch64"]` needs no admin to type a label.
195 let mut runner = match runner_from(state, headers(cx)).await {195 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
330 /// number the forge wants for this boot id, so the runner resends what was lost.330 /// number the forge wants for this boot id, so the runner resends what was lost.
331 #[route(POST "/api/v1/ci/runners/log")]331 #[route(POST "/api/v1/ci/runners/log")]
332 async fn runner_log(cx: &Cx, body: Body) -> topcoat::Result<Response> {332 async fn runner_log(cx: &Cx, body: Body) -> topcoat::Result<Response> {
333- let state = app_context::<AppState>(cx);333+ let state = context::<AppState>(cx);
334 let runner = match runner_from(state, headers(cx)).await {334 let runner = match runner_from(state, headers(cx)).await {
335 Ok(runner) => runner,335 Ok(runner) => runner,
336 Err(res) => return Ok(*res),336 Err(res) => return Ok(*res),
@@ -364,7 +364,7 @@ async fn runner_log(cx: &Cx, body: Body) -> topcoat::Result<Response> {
364 /// page. Answers 204 with no body.364 /// page. Answers 204 with no body.
365 #[route(POST "/api/v1/ci/runners/metrics")]365 #[route(POST "/api/v1/ci/runners/metrics")]
366 async fn runner_metrics(cx: &Cx, body: Body) -> topcoat::Result<Response> {366 async fn runner_metrics(cx: &Cx, body: Body) -> topcoat::Result<Response> {
367- let state = app_context::<AppState>(cx);367+ let state = context::<AppState>(cx);
368 let runner = match runner_from(state, headers(cx)).await {368 let runner = match runner_from(state, headers(cx)).await {
369 Ok(runner) => runner,369 Ok(runner) => runner,
370 Err(res) => return Ok(*res),370 Err(res) => return Ok(*res),
@@ -397,7 +397,7 @@ async fn runner_metrics(cx: &Cx, body: Body) -> topcoat::Result<Response> {
397 /// starts, applies them to its in-memory config, then reports its effective config here.397 /// starts, applies them to its in-memory config, then reports its effective config here.
398 #[route(GET "/api/v1/ci/runners/config")]398 #[route(GET "/api/v1/ci/runners/config")]
399 async fn runner_config_get(cx: &Cx) -> topcoat::Result<Response> {399 async fn runner_config_get(cx: &Cx) -> topcoat::Result<Response> {
400- let state = app_context::<AppState>(cx);400+ let state = context::<AppState>(cx);
401 let runner = match runner_from(state, headers(cx)).await {401 let runner = match runner_from(state, headers(cx)).await {
402 Ok(runner) => runner,402 Ok(runner) => runner,
403 Err(res) => return Ok(*res),403 Err(res) => return Ok(*res),
@@ -407,7 +407,7 @@ async fn runner_config_get(cx: &Cx) -> topcoat::Result<Response> {
407 407
408 #[route(PUT "/api/v1/ci/runners/config")]408 #[route(PUT "/api/v1/ci/runners/config")]
409 async fn runner_config_put(cx: &Cx, body: Body) -> topcoat::Result<Response> {409 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);
411 let runner = match runner_from(state, headers(cx)).await {411 let runner = match runner_from(state, headers(cx)).await {
412 Ok(runner) => runner,412 Ok(runner) => runner,
413 Err(res) => return Ok(*res),413 Err(res) => return Ok(*res),
@@ -557,7 +557,7 @@ fn idle_text(skips: &QueueSkips, free: Option<u64>) -> Option<String> {
557 /// The running binary, for a runner that updates itself. 404 unless self-update is enabled.557 /// The running binary, for a runner that updates itself. 404 unless self-update is enabled.
558 #[route(GET "/api/v1/ci/runners/binary")]558 #[route(GET "/api/v1/ci/runners/binary")]
559 async fn runner_binary(cx: &Cx) -> topcoat::Result<Response> {559 async fn runner_binary(cx: &Cx) -> topcoat::Result<Response> {
560- let state = app_context::<AppState>(cx);560+ let state = context::<AppState>(cx);
561 if let Err(res) = runner_from(state, headers(cx)).await {561 if let Err(res) = runner_from(state, headers(cx)).await {
562 return Ok(*res);562 return Ok(*res);
563 }563 }
@@ -768,8 +768,8 @@ async fn is_fork_run(state: &AppState, run: &CiRun) -> Result<bool, Refusal> {
768 768
769 #[route(POST "/api/v1/ci/jobs/{job_id}/heartbeat")]769 #[route(POST "/api/v1/ci/jobs/{job_id}/heartbeat")]
770 async fn heartbeat(cx: &Cx) -> topcoat::Result<Response> {770 async fn heartbeat(cx: &Cx) -> topcoat::Result<Response> {
771- let state = app_context::<AppState>(cx);771+ let state = context::<AppState>(cx);
772- let job = match job_from(state, headers(cx), path_param::<JobId>(cx)).await {772+ let job = match job_from(state, headers(cx), job_id(cx)).await {
773 Ok(job) => job,773 Ok(job) => job,
774 Err(res) => return Ok(*res),774 Err(res) => return Ok(*res),
775 };775 };
@@ -845,9 +845,9 @@ enum LogWrite {
845 845
846 #[route(POST "/api/v1/ci/jobs/{job_id}/logs")]846 #[route(POST "/api/v1/ci/jobs/{job_id}/logs")]
847 async fn append_log(cx: &Cx, body: Body) -> topcoat::Result<Response> {847 async fn append_log(cx: &Cx, body: Body) -> topcoat::Result<Response> {
848- let state = app_context::<AppState>(cx);848+ let state = context::<AppState>(cx);
849 let headers = headers(cx);849 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 {
851 Ok(job) => job,851 Ok(job) => job,
852 Err(res) => return Ok(*res),852 Err(res) => return Ok(*res),
853 };853 };
@@ -1037,12 +1037,12 @@ async fn store_log_bytes(
1037 1037
1038 #[route(PUT "/api/v1/ci/jobs/{job_id}/artifacts/{artifact_name}")]1038 #[route(PUT "/api/v1/ci/jobs/{job_id}/artifacts/{artifact_name}")]
1039 async fn upload_artifact(cx: &Cx, body: Body) -> topcoat::Result<Response> {1039 async fn upload_artifact(cx: &Cx, body: Body) -> topcoat::Result<Response> {
1040- let state = app_context::<AppState>(cx);1040+ let state = context::<AppState>(cx);
1041- let job = match job_from(state, headers(cx), path_param::<JobId>(cx)).await {1041+ let job = match job_from(state, headers(cx), job_id(cx)).await {
1042 Ok(job) => job,1042 Ok(job) => job,
1043 Err(res) => return Ok(*res),1043 Err(res) => return Ok(*res),
1044 };1044 };
1045- let name = path_param::<ArtifactName>(cx);1045+ let name = artifact_name(cx);
1046 if !valid_artifact_name(name) {1046 if !valid_artifact_name(name) {
1047 return Ok(api::error(1047 return Ok(api::error(
1048 StatusCode::UNPROCESSABLE_ENTITY,1048 StatusCode::UNPROCESSABLE_ENTITY,
@@ -1187,8 +1187,8 @@ fn upload_failure(e: CoreError, interrupted: bool) -> Refusal {
1187 1187
1188 #[route(POST "/api/v1/ci/jobs/{job_id}/finish")]1188 #[route(POST "/api/v1/ci/jobs/{job_id}/finish")]
1189 async fn finish(cx: &Cx, body: Body) -> topcoat::Result<Response> {1189 async fn finish(cx: &Cx, body: Body) -> topcoat::Result<Response> {
1190- let state = app_context::<AppState>(cx);1190+ let state = context::<AppState>(cx);
1191- let job = match job_from(state, headers(cx), path_param::<JobId>(cx)).await {1191+ let job = match job_from(state, headers(cx), job_id(cx)).await {
1192 Ok(job) => job,1192 Ok(job) => job,
1193 Err(res) => return Ok(*res),1193 Err(res) => return Ok(*res),
1194 };1194 };
@@ -1210,8 +1210,8 @@ async fn finish(cx: &Cx, body: Body) -> topcoat::Result<Response> {
1210 1210
1211 #[route(POST "/api/v1/ci/jobs/{job_id}/requeue")]1211 #[route(POST "/api/v1/ci/jobs/{job_id}/requeue")]
1212 async fn requeue(cx: &Cx, body: Body) -> topcoat::Result<Response> {1212 async fn requeue(cx: &Cx, body: Body) -> topcoat::Result<Response> {
1213- let state = app_context::<AppState>(cx);1213+ let state = context::<AppState>(cx);
1214- let job = match job_from(state, headers(cx), path_param::<JobId>(cx)).await {1214+ let job = match job_from(state, headers(cx), job_id(cx)).await {
1215 Ok(job) => job,1215 Ok(job) => job,
1216 Err(res) => return Ok(*res),1216 Err(res) => return Ok(*res),
1217 };1217 };
crates/forge-web/src/client_ip.rsmodified+2 -2
@@ -8,7 +8,7 @@
8 use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};8 use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
9 9
10 use ipnet::IpNet;10 use ipnet::IpNet;
11-use topcoat::context::{Cx, app_context};11+use topcoat::context::{Cx, context};
12 use topcoat::router::request::{headers, remote_addr};12 use topcoat::router::request::{headers, remote_addr};
13 13
14 use crate::state::AppState;14 use crate::state::AppState;
@@ -24,7 +24,7 @@ pub fn client_ip(cx: &Cx) -> IpAddr {
24 /// The exact client address for this request, normalized but not bucketed, for display and audit.24 /// The exact client address for this request, normalized but not bucketed, for display and audit.
25 /// Unix-socket requests map to the unspecified address.25 /// Unix-socket requests map to the unspecified address.
26 pub fn client_addr(cx: &Cx) -> IpAddr {26 pub fn client_addr(cx: &Cx) -> IpAddr {
27- let live = app_context::<AppState>(cx).live();27+ let live = context::<AppState>(cx).live();
28 let trusted = &live.trusted_proxies;28 let trusted = &live.trusted_proxies;
29 let peer = remote_addr(cx).map(|addr| addr.ip());29 let peer = remote_addr(cx).map(|addr| addr.ip());
30 let forwarded = headers(cx)30 let forwarded = headers(cx)
crates/forge-web/src/git_http.rsmodified+8 -8
@@ -2,7 +2,7 @@
2 //! Streams bodies to and from `git <svc> --stateless-rpc`; gzip request bodies are decoded.2 //! Streams bodies to and from `git <svc> --stateless-rpc`; gzip request bodies are decoded.
3 //!3 //!
4 //! Compression must be off for these responses. Topcoat's compression is configured only on the4 //! 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.
6 6
7 use std::net::IpAddr;7 use std::net::IpAddr;
8 use std::time::Instant;8 use std::time::Instant;
@@ -20,7 +20,7 @@ use http_body_util::StreamBody;
20 use tokio::io::AsyncReadExt;20 use tokio::io::AsyncReadExt;
21 use tokio::process::{Child, ChildStdin};21 use tokio::process::{Child, ChildStdin};
22 use tokio_util::io::{ReaderStream, StreamReader};22 use tokio_util::io::{ReaderStream, StreamReader};
23-use topcoat::context::{Cx, app_context};23+use topcoat::context::{Cx, context};
24 use topcoat::router::request::headers;24 use topcoat::router::request::headers;
25 use topcoat::router::response::Response;25 use topcoat::router::response::Response;
26 use topcoat::router::{Body, HeaderMap, StatusCode, path_param, query_params, route};26 use topcoat::router::{Body, HeaderMap, StatusCode, path_param, query_params, route};
@@ -46,10 +46,10 @@ async fn info_refs(cx: &Cx) -> topcoat::Result<Response> {
46 return Ok(text(StatusCode::FORBIDDEN, "dumb protocol not supported"));46 return Ok(text(StatusCode::FORBIDDEN, "dumb protocol not supported"));
47 };47 };
48 48
49- let state = app_context::<AppState>(cx);49+ let state = context::<AppState>(cx);
50 let headers = headers(cx);50 let headers = headers(cx);
51- let owner = path_param::<Owner>(cx);51+ let owner = owner(cx);
52- let repo_name = path_param::<Repo>(cx);52+ let repo_name = repo(cx);
53 53
54 let (actor, repo, path) =54 let (actor, repo, path) =
55 match caller_repo(state, client_ip(cx), headers, owner, repo_name, service).await {55 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> {
102 /// Shared body of the two POST routes: authorize, spawn `git <svc> --stateless-rpc`, pipe the102 /// Shared body of the two POST routes: authorize, spawn `git <svc> --stateless-rpc`, pipe the
103 /// request body into its stdin and stream its stdout back.103 /// request body into its stdin and stream its stdout back.
104 async fn serve_rpc(cx: &Cx, service: GitService, body: Body) -> Response {104 async fn serve_rpc(cx: &Cx, service: GitService, body: Body) -> Response {
105- let state = app_context::<AppState>(cx);105+ let state = context::<AppState>(cx);
106 let headers = headers(cx);106 let headers = headers(cx);
107- let owner = path_param::<Owner>(cx);107+ let owner = owner(cx);
108- let repo_name = path_param::<Repo>(cx);108+ let repo_name = repo(cx);
109 109
110 let (actor, repo, path) =110 let (actor, repo, path) =
111 match caller_repo(state, client_ip(cx), headers, owner, repo_name, service).await {111 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;
14 use forge_core::{Repo, Role, Store};14 use forge_core::{Repo, Role, Store};
15 use forge_git::{GitCommand, GitEnv};15 use forge_git::{GitCommand, GitEnv};
16 use serde::{Deserialize, Serialize};16 use serde::{Deserialize, Serialize};
17-use topcoat::context::{Cx, app_context};17+use topcoat::context::{Cx, context};
18 use topcoat::router::content::Json;18 use topcoat::router::content::Json;
19 use topcoat::router::error::{bad_request, forbidden};19 use topcoat::router::error::{bad_request, forbidden};
20 use topcoat::router::request::headers;20 use topcoat::router::request::headers;
@@ -121,7 +121,7 @@ pub fn router(state: AppState) -> Router {
121 "/internal/admin/live",121 "/internal/admin/live",
122 admin_live,122 admin_live,
123 ))123 ))
124- .app_context(state)124+ .with(state)
125 .build()125 .build()
126 }126 }
127 127
@@ -144,7 +144,7 @@ async fn hook_endpoint(
144 body: Body,144 body: Body,
145 stage: Stage,145 stage: Stage,
146 ) -> topcoat::Result<topcoat::router::response::Response> {146 ) -> topcoat::Result<topcoat::router::response::Response> {
147- let state = app_context::<AppState>(cx);147+ let state = context::<AppState>(cx);
148 let presented = headers(cx)148 let presented = headers(cx)
149 .get(TOKEN_HEADER)149 .get(TOKEN_HEADER)
150 .and_then(|v| v.to_str().ok())150 .and_then(|v| v.to_str().ok())
@@ -219,7 +219,7 @@ struct AdminLiveRequest {
219 /// `POST /internal/admin/live`. Wakes the open pages of the running server for a write made by219 /// `POST /internal/admin/live`. Wakes the open pages of the running server for a write made by
220 /// another process (the admin CLI). The body is small and the answer carries no data.220 /// another process (the admin CLI). The body is small and the answer carries no data.
221 async fn admin_live_endpoint(cx: &Cx, body: Body) -> topcoat::Result<Response> {221 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);
223 if !admin_authorized(cx, state) {223 if !admin_authorized(cx, state) {
224 return Err(forbidden().into());224 return Err(forbidden().into());
225 }225 }
@@ -261,7 +261,7 @@ async fn admin_live_endpoint(cx: &Cx, body: Body) -> topcoat::Result<Response> {
261 261
262 /// `POST /internal/admin/lfs-gc`. The body is ignored.262 /// `POST /internal/admin/lfs-gc`. The body is ignored.
263 async fn admin_lfs_gc_endpoint(cx: &Cx, _body: Body) -> topcoat::Result<Response> {263 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);
265 if !admin_authorized(cx, state) {265 if !admin_authorized(cx, state) {
266 return Err(forbidden().into());266 return Err(forbidden().into());
267 }267 }
@@ -306,7 +306,7 @@ fn admin_authorized(cx: &Cx, state: &AppState) -> bool {
306 }306 }
307 307
308 async fn admin_backup_endpoint(cx: &Cx, body: Body) -> topcoat::Result<Response> {308 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);
310 if !admin_authorized(cx, state) {310 if !admin_authorized(cx, state) {
311 return Err(forbidden().into());311 return Err(forbidden().into());
312 }312 }
@@ -348,7 +348,7 @@ async fn admin_backup_endpoint(cx: &Cx, body: Body) -> topcoat::Result<Response>
348 }348 }
349 349
350 async fn admin_fsck_endpoint(cx: &Cx, body: Body) -> topcoat::Result<Response> {350 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);
352 if !admin_authorized(cx, state) {352 if !admin_authorized(cx, state) {
353 return Err(forbidden().into());353 return Err(forbidden().into());
354 }354 }
crates/forge-web/src/lfs/routes.rsmodified+15 -15
@@ -21,7 +21,7 @@ use serde_json::{Value, json};
21 use sha2::{Digest, Sha256};21 use sha2::{Digest, Sha256};
22 use tokio::io::AsyncWriteExt;22 use tokio::io::AsyncWriteExt;
23 use tokio_util::io::ReaderStream;23 use tokio_util::io::ReaderStream;
24-use topcoat::context::{Cx, app_context};24+use topcoat::context::{Cx, context};
25 use topcoat::router::request::headers;25 use topcoat::router::request::headers;
26 use topcoat::router::response::Response;26 use topcoat::router::response::Response;
27 use topcoat::router::{Body, HeaderMap, StatusCode, path_param, route, to_bytes};27 use topcoat::router::{Body, HeaderMap, StatusCode, path_param, route, to_bytes};
@@ -74,10 +74,10 @@ struct VerifyRequest {
74 74
75 #[route(POST "/{owner}/{repo}/info/lfs/objects/batch")]75 #[route(POST "/{owner}/{repo}/info/lfs/objects/batch")]
76 async fn batch(cx: &Cx, body: Body) -> topcoat::Result<Response> {76 async fn batch(cx: &Cx, body: Body) -> topcoat::Result<Response> {
77- let state = app_context::<AppState>(cx);77+ let state = context::<AppState>(cx);
78 let headers = headers(cx);78 let headers = headers(cx);
79- let owner = path_param::<Owner>(cx);79+ let owner = owner(cx);
80- let name = path_param::<Repo>(cx);80+ let name = repo(cx);
81 81
82 let bytes = to_bytes(body, MAX_BATCH_BYTES).await?;82 let bytes = to_bytes(body, MAX_BATCH_BYTES).await?;
83 let BatchPlan { request, action } = match parse_batch_operation(&bytes) {83 let BatchPlan { request, action } = match parse_batch_operation(&bytes) {
@@ -194,11 +194,11 @@ fn parse_batch_operation(bytes: &[u8]) -> Result<BatchPlan, Box<Response>> {
194 194
195 #[route(GET "/{owner}/{repo}/info/lfs/objects/{oid}")]195 #[route(GET "/{owner}/{repo}/info/lfs/objects/{oid}")]
196 async fn get_object(cx: &Cx) -> topcoat::Result<Response> {196 async fn get_object(cx: &Cx) -> topcoat::Result<Response> {
197- let state = app_context::<AppState>(cx);197+ let state = context::<AppState>(cx);
198 let headers = headers(cx);198 let headers = headers(cx);
199- let owner = path_param::<Owner>(cx);199+ let owner = owner(cx);
200- let name = path_param::<Repo>(cx);200+ let name = repo(cx);
201- let oid = path_param::<Oid>(cx);201+ let oid = oid(cx);
202 if !is_valid_oid(oid) {202 if !is_valid_oid(oid) {
203 return Ok(message(StatusCode::UNPROCESSABLE_ENTITY, "invalid oid"));203 return Ok(message(StatusCode::UNPROCESSABLE_ENTITY, "invalid oid"));
204 }204 }
@@ -234,11 +234,11 @@ async fn get_object(cx: &Cx) -> topcoat::Result<Response> {
234 234
235 #[route(PUT "/{owner}/{repo}/info/lfs/objects/{oid}")]235 #[route(PUT "/{owner}/{repo}/info/lfs/objects/{oid}")]
236 async fn put_object(cx: &Cx, body: Body) -> topcoat::Result<Response> {236 async fn put_object(cx: &Cx, body: Body) -> topcoat::Result<Response> {
237- let state = app_context::<AppState>(cx);237+ let state = context::<AppState>(cx);
238 let headers = headers(cx);238 let headers = headers(cx);
239- let owner = path_param::<Owner>(cx);239+ let owner = owner(cx);
240- let name = path_param::<Repo>(cx);240+ let name = repo(cx);
241- let oid = path_param::<Oid>(cx);241+ let oid = oid(cx);
242 if !is_valid_oid(oid) {242 if !is_valid_oid(oid) {
243 return Ok(message(StatusCode::UNPROCESSABLE_ENTITY, "invalid oid"));243 return Ok(message(StatusCode::UNPROCESSABLE_ENTITY, "invalid oid"));
244 }244 }
@@ -275,10 +275,10 @@ async fn put_object(cx: &Cx, body: Body) -> topcoat::Result<Response> {
275 275
276 #[route(POST "/{owner}/{repo}/info/lfs/objects/verify")]276 #[route(POST "/{owner}/{repo}/info/lfs/objects/verify")]
277 async fn verify(cx: &Cx, body: Body) -> topcoat::Result<Response> {277 async fn verify(cx: &Cx, body: Body) -> topcoat::Result<Response> {
278- let state = app_context::<AppState>(cx);278+ let state = context::<AppState>(cx);
279 let headers = headers(cx);279 let headers = headers(cx);
280- let owner = path_param::<Owner>(cx);280+ let owner = owner(cx);
281- let name = path_param::<Repo>(cx);281+ let name = repo(cx);
282 282
283 let repo = match authorize(state, client_ip(cx), headers, owner, name, Action::Write).await {283 let repo = match authorize(state, client_ip(cx), headers, owner, name, Action::Write).await {
284 Ok(repo) => repo,284 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
77 const DEFAULT_CONFIG: &str = "config/forge.toml";77 const DEFAULT_CONFIG: &str = "config/forge.toml";
78 78
79 #[route(GET "/healthz")]79 #[route(GET "/healthz")]
80-async fn healthz() -> Result<String, topcoat::Error> {80+async fn healthz(cx: &topcoat::context::Cx) -> Result<String, topcoat::Error> {
81 Ok(format!("ok {}", env!("FORGE_BUILD_SHA")))81 Ok(format!("ok {}", env!("FORGE_BUILD_SHA")))
82 }82 }
83 83
crates/forge-web/src/oci/auth.rsmodified+2 -2
@@ -9,7 +9,7 @@ use forge_core::User;
9 use forge_core::oci as rules;9 use forge_core::oci as rules;
10 use forge_core::packages::{KIND_OCI, Package};10 use forge_core::packages::{KIND_OCI, Package};
11 use http::header::{AUTHORIZATION, HeaderValue, WWW_AUTHENTICATE};11 use http::header::{AUTHORIZATION, HeaderValue, WWW_AUTHENTICATE};
12-use topcoat::context::{Cx, app_context};12+use topcoat::context::{Cx, context};
13 use topcoat::router::StatusCode;13 use topcoat::router::StatusCode;
14 use topcoat::router::request::headers;14 use topcoat::router::request::headers;
15 use topcoat::router::response::Response;15 use topcoat::router::response::Response;
@@ -42,7 +42,7 @@ pub struct Target {
42 /// verified here; anything else goes to the personal access token check the API uses. A bad42 /// verified here; anything else goes to the personal access token check the API uses. A bad
43 /// credential is a 401 with the challenge, so the client can ask again.43 /// credential is a 401 with the challenge, so the client can ask again.
44 pub async fn caller(cx: &Cx) -> Result<Caller, Refusal> {44 pub async fn caller(cx: &Cx) -> Result<Caller, Refusal> {
45- let state = app_context::<AppState>(cx);45+ let state = context::<AppState>(cx);
46 let headers = headers(cx);46 let headers = headers(cx);
47 let Some(value) = headers.get(AUTHORIZATION).and_then(|v| v.to_str().ok()) else {47 let Some(value) = headers.get(AUTHORIZATION).and_then(|v| v.to_str().ok()) else {
48 return Ok(Caller { user: None });48 return Ok(Caller { user: None });
crates/forge-web/src/oci/mod.rsmodified+5 -5
@@ -19,7 +19,7 @@ pub mod manifests;
19 use forge_core::oci as rules;19 use forge_core::oci as rules;
20 use http::header::{CONTENT_TYPE, HeaderValue};20 use http::header::{CONTENT_TYPE, HeaderValue};
21 use serde_json::{Value, json};21 use serde_json::{Value, json};
22-use topcoat::context::{Cx, app_context};22+use topcoat::context::{Cx, context};
23 use topcoat::router::request::{headers, method, uri};23 use topcoat::router::request::{headers, method, uri};
24 use topcoat::router::response::Response;24 use topcoat::router::response::Response;
25 use topcoat::router::{Body, StatusCode, path_param, route};25 use topcoat::router::{Body, StatusCode, path_param, route};
@@ -105,7 +105,7 @@ fn query_value(pairs: &[(String, String)], key: &str) -> Option<String> {
105 /// `GET /v2/`: the probe. A caller with valid credentials gets 200; anyone else the challenge.105 /// `GET /v2/`: the probe. A caller with valid credentials gets 200; anyone else the challenge.
106 #[route(GET "/v2/")]106 #[route(GET "/v2/")]
107 async fn root(cx: &Cx) -> topcoat::Result<Response> {107 async fn root(cx: &Cx) -> topcoat::Result<Response> {
108- let state = app_context::<AppState>(cx);108+ let state = context::<AppState>(cx);
109 Ok(match auth::caller(cx).await {109 Ok(match auth::caller(cx).await {
110 Ok(Caller { user: Some(_) }) => json_response(StatusCode::OK, &json!({})),110 Ok(Caller { user: Some(_) }) => json_response(StatusCode::OK, &json!({})),
111 Ok(_) => auth::challenge(state, None),111 Ok(_) => auth::challenge(state, None),
@@ -117,7 +117,7 @@ async fn root(cx: &Cx) -> topcoat::Result<Response> {
117 /// short-lived bearer token. Anonymous callers get an anonymous token, which reads public images.117 /// short-lived bearer token. Anonymous callers get an anonymous token, which reads public images.
118 #[route(GET "/v2/token")]118 #[route(GET "/v2/token")]
119 async fn token(cx: &Cx) -> topcoat::Result<Response> {119 async fn token(cx: &Cx) -> topcoat::Result<Response> {
120- let state = app_context::<AppState>(cx);120+ let state = context::<AppState>(cx);
121 let caller = match auth::caller(cx).await {121 let caller = match auth::caller(cx).await {
122 Ok(caller) => caller,122 Ok(caller) => caller,
123 Err(res) => return Ok(*res),123 Err(res) => return Ok(*res),
@@ -168,8 +168,8 @@ async fn delete_v2(cx: &Cx, body: Body) -> topcoat::Result<Response> {
168 /// Routes a request below `/v2/` to its operation. The caller is resolved first, so every answer168 /// Routes a request below `/v2/` to its operation. The caller is resolved first, so every answer
169 /// about a repository comes from the same identity.169 /// about a repository comes from the same identity.
170 async fn dispatch(cx: &Cx, body: Body) -> Response {170 async fn dispatch(cx: &Cx, body: Body) -> Response {
171- let state = app_context::<AppState>(cx);171+ let state = context::<AppState>(cx);
172- let segments: Vec<String> = path_param::<Rest>(cx).map(str::to_owned).collect();172+ let segments: Vec<String> = rest(cx).map(str::to_owned).collect();
173 let mut parts: Vec<&str> = segments.iter().map(String::as_str).collect();173 let mut parts: Vec<&str> = segments.iter().map(String::as_str).collect();
174 while parts.last() == Some(&"") {174 while parts.last() == Some(&"") {
175 parts.pop();175 parts.pop();
crates/forge-web/src/pages/activity.rsmodified+3 -3
@@ -9,7 +9,7 @@ use forge_core::{Reason, User};
9 use http::header::{CACHE_CONTROL, CONTENT_TYPE, X_CONTENT_TYPE_OPTIONS};9 use http::header::{CACHE_CONTROL, CONTENT_TYPE, X_CONTENT_TYPE_OPTIONS};
10 use serde_json::{Value, json};10 use serde_json::{Value, json};
11 use topcoat::Result;11 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};12+use topcoat::context::{Cx, context};
13 use topcoat::router::response::Response;13 use topcoat::router::response::Response;
14 use topcoat::router::{Body, HeaderValue, StatusCode, route};14 use topcoat::router::{Body, HeaderValue, StatusCode, route};
15 15
@@ -108,7 +108,7 @@ async fn activity(cx: &Cx) -> Result<Response> {
108 *res.status_mut() = StatusCode::UNAUTHORIZED;108 *res.status_mut() = StatusCode::UNAUTHORIZED;
109 return Ok(res);109 return Ok(res);
110 };110 };
111- let state = app_context::<AppState>(cx);111+ let state = context::<AppState>(cx);
112 let body = activity_json(state, &user).await?;112 let body = activity_json(state, &user).await?;
113 let mut response = Response::new(Body::from(body.to_string().into_bytes()));113 let mut response = Response::new(Body::from(body.to_string().into_bytes()));
114 let headers = response.headers_mut();114 let headers = response.headers_mut();
@@ -131,7 +131,7 @@ async fn activity_stream(cx: &Cx) -> Result<Response> {
131 *res.status_mut() = StatusCode::UNAUTHORIZED;131 *res.status_mut() = StatusCode::UNAUTHORIZED;
132 return Ok(res);132 return Ok(res);
133 };133 };
134- let state = app_context::<AppState>(cx).clone();134+ let state = context::<AppState>(cx).clone();
135 events_response(cx, activity_changes(state, user, "changed"))135 events_response(cx, activity_changes(state, user, "changed"))
136 }136 }
137 137
crates/forge-web/src/pages/admin_backups.rsmodified+11 -7
@@ -12,7 +12,7 @@ use forge_core::store::backup_runs::{BackupRun, RunKind};
12 use forge_core::{AuditAction, Error, Store, User};12 use forge_core::{AuditAction, Error, Store, User};
13 use serde::Deserialize;13 use serde::Deserialize;
14 use topcoat::Result;14 use topcoat::Result;
15-use topcoat::context::{Cx, app_context};15+use topcoat::context::{Cx, context};
16 use topcoat::router::content::Form;16 use topcoat::router::content::Form;
17 use topcoat::router::error::{forbidden, see_other};17 use topcoat::router::error::{forbidden, see_other};
18 use topcoat::router::response::Response;18 use topcoat::router::response::Response;
@@ -109,7 +109,7 @@ fn run_row(run: &BackupRun, lang: Lang) -> RunRow {
109 109
110 /// The rail of the Backups tab: Backups and Replication.110 /// The rail of the Backups tab: Backups and Replication.
111 #[component]111 #[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> {
113 let items = vec![113 let items = vec![
114 RailItem {114 RailItem {
115 name: g::t(lang, K::Backups).to_owned(),115 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
131 131
132 #[component]132 #[component]
133 async fn backups_view(133 async fn backups_view(
134+ cx: &Cx,
134 lang: Lang,135 lang: Lang,
135 csrf: String,136 csrf: String,
136 enabled: bool,137 enabled: bool,
@@ -213,7 +214,7 @@ async fn runs_fingerprint(store: &Store, running: Option<RunKind>) -> Result<Str
213 #[route(GET "/admin/backups/events")]214 #[route(GET "/admin/backups/events")]
214 async fn backups_events(cx: &Cx) -> Result<Response> {215 async fn backups_events(cx: &Cx) -> Result<Response> {
215 admin_only(cx).await?;216 admin_only(cx).await?;
216- let state = app_context::<AppState>(cx);217+ let state = context::<AppState>(cx);
217 let store = state.store.clone();218 let store = state.store.clone();
218 let jobs = state.jobs.clone();219 let jobs = state.jobs.clone();
219 stream_changes(220 stream_changes(
@@ -233,7 +234,7 @@ async fn backups_events(cx: &Cx) -> Result<Response> {
233 async fn backups_page(cx: &Cx) -> Result<impl View> {234 async fn backups_page(cx: &Cx) -> Result<impl View> {
234 let viewer = admin_only(cx).await?;235 let viewer = admin_only(cx).await?;
235 let query = query_params::<NoticeQuery>(cx)?;236 let query = query_params::<NoticeQuery>(cx)?;
236- let state = app_context::<AppState>(cx);237+ let state = context::<AppState>(cx);
237 let lang = i18n::lang(cx, Some(&viewer.0));238 let lang = i18n::lang(cx, Some(&viewer.0));
238 let runs = state.store.recent_runs(RUN_LIMIT).await?;239 let runs = state.store.recent_runs(RUN_LIMIT).await?;
239 let rows: Vec<RunRow> = runs.iter().map(|run| run_row(run, lang)).collect();240 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
255 return Err(forbidden().into());256 return Err(forbidden().into());
256 }257 }
257 let lang = i18n::lang(cx, Some(&viewer.0));258 let lang = i18n::lang(cx, Some(&viewer.0));
258- let state = app_context::<AppState>(cx);259+ let state = context::<AppState>(cx);
259 let notice = notice_of(260 let notice = notice_of(
260 lang,261 lang,
261 save_topic(262 save_topic(
@@ -289,7 +290,7 @@ async fn start_run(cx: &Cx, csrf: String, kind: RunKind) -> Result<Response> {
289 return Err(forbidden().into());290 return Err(forbidden().into());
290 }291 }
291 let lang = i18n::lang(cx, Some(&viewer.0));292 let lang = i18n::lang(cx, Some(&viewer.0));
292- let state = app_context::<AppState>(cx);293+ let state = context::<AppState>(cx);
293 let notice = match launch(cx, state, &viewer.0, kind, lang).await {294 let notice = match launch(cx, state, &viewer.0, kind, lang).await {
294 Ok(()) => g::started_notice(lang, kind),295 Ok(()) => g::started_notice(lang, kind),
295 Err(e) => match e {296 Err(e) => match e {
@@ -548,7 +549,10 @@ mod tests {
548 assert_eq!(status, 200);549 assert_eq!(status, 200);
549 assert!(body.contains("schedule"));550 assert!(body.contains("schedule"));
550 assert!(body.contains("disk full"));551 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+ );
552 assert!(556 assert!(
553 !body.contains("SECRET-TOKEN"),557 !body.contains("SECRET-TOKEN"),
554 "the healthcheck token must not be shown"558 "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;
14 use forge_core::time::stamp_to_unix;14 use forge_core::time::stamp_to_unix;
15 use tokio::process::Command;15 use tokio::process::Command;
16 use topcoat::Result;16 use topcoat::Result;
17-use topcoat::context::{Cx, app_context};17+use topcoat::context::{Cx, context};
18 use topcoat::router::response::Response;18 use topcoat::router::response::Response;
19 use topcoat::router::{page, query_params, route};19 use topcoat::router::{page, query_params, route};
20 use topcoat::view::{View, component, view};20 use topcoat::view::{View, component, view};
21 21
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+};
23 use crate::i18n::alerts as alert_text;25 use crate::i18n::alerts as alert_text;
24 use crate::i18n::{self, Lang};26 use crate::i18n::{self, Lang};
25 use crate::live::{Topic, stream_changes};27 use crate::live::{Topic, stream_changes};
@@ -464,7 +466,7 @@ async fn alert_rows(state: &AppState, lang: Lang) -> Result<Vec<AlertRow>> {
464 466
465 /// The alert's raised time as a live relative time, worded per language.467 /// The alert's raised time as a live relative time, worded per language.
466 #[component]468 #[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> {
468 Ok(view! {470 Ok(view! {
469 if matches!(lang, Lang::Tr) {471 if matches!(lang, Lang::Tr) {
470 rel_time(lang: lang, stamp: stamp) " başladı"472 rel_time(lang: lang, stamp: stamp) " başladı"
@@ -476,6 +478,7 @@ async fn since_line(lang: Lang, stamp: &str) -> Result<impl View> {
476 478
477 #[component]479 #[component]
478 async fn health_view(480 async fn health_view(
481+ cx: &Cx,
479 lang: Lang,482 lang: Lang,
480 health: Health,483 health: Health,
481 alerts: Vec<AlertRow>,484 alerts: Vec<AlertRow>,
@@ -579,7 +582,7 @@ async fn health_view(
579 async fn health_page(cx: &Cx) -> Result<impl View> {582 async fn health_page(cx: &Cx) -> Result<impl View> {
580 let viewer = admin_only(cx).await?;583 let viewer = admin_only(cx).await?;
581 let lang = i18n::lang(cx, Some(&viewer.0));584 let lang = i18n::lang(cx, Some(&viewer.0));
582- let state = app_context::<AppState>(cx);585+ let state = context::<AppState>(cx);
583 let query = query_params::<HealthQuery>(cx)?;586 let query = query_params::<HealthQuery>(cx)?;
584 let health = gather(state, lang).await?;587 let health = gather(state, lang).await?;
585 let all = alert_rows(state, lang).await?;588 let all = alert_rows(state, lang).await?;
@@ -644,7 +647,7 @@ async fn health_fingerprint(state: &AppState) -> Result<String> {
644 #[route(GET "/admin/health/events")]647 #[route(GET "/admin/health/events")]
645 async fn health_events(cx: &Cx) -> Result<Response> {648 async fn health_events(cx: &Cx) -> Result<Response> {
646 admin_only(cx).await?;649 admin_only(cx).await?;
647- let state = app_context::<AppState>(cx).clone();650+ let state = context::<AppState>(cx).clone();
648 stream_changes(cx, crate::live::admin(), &[Topic::AdminHealth], move || {651 stream_changes(cx, crate::live::admin(), &[Topic::AdminHealth], move || {
649 let state = state.clone();652 let state = state.clone();
650 async move { health_fingerprint(&state).await }653 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};
19 use serde::Deserialize;19 use serde::Deserialize;
20 use tokio::sync::watch;20 use tokio::sync::watch;
21 use topcoat::Result;21 use topcoat::Result;
22-use topcoat::context::{Cx, app_context};22+use topcoat::context::{Cx, context};
23 use topcoat::router::content::Form;23 use topcoat::router::content::Form;
24 use topcoat::router::content::sse::Event;24 use topcoat::router::content::sse::Event;
25 use topcoat::router::error::{forbidden, see_other};25 use topcoat::router::error::{forbidden, see_other};
@@ -199,6 +199,7 @@ async fn page_data(
199 199
200 #[component]200 #[component]
201 async fn mail_view(201 async fn mail_view(
202+ cx: &Cx,
202 lang: Lang,203 lang: Lang,
203 csrf: String,204 csrf: String,
204 data: PageData,205 data: PageData,
@@ -332,7 +333,7 @@ async fn mail_view(
332 async fn mail_page(cx: &Cx) -> Result<impl View> {333 async fn mail_page(cx: &Cx) -> Result<impl View> {
333 let viewer = admin_only(cx).await?;334 let viewer = admin_only(cx).await?;
334 let query = query_params::<NoticeQuery>(cx)?;335 let query = query_params::<NoticeQuery>(cx)?;
335- let state = app_context::<AppState>(cx);336+ let state = context::<AppState>(cx);
336 let lang = i18n::lang(cx, Some(&viewer.0));337 let lang = i18n::lang(cx, Some(&viewer.0));
337 let tab = if query.tab.as_deref() == Some("queue") {338 let tab = if query.tab.as_deref() == Some("queue") {
338 Tab::Queue339 Tab::Queue
@@ -398,7 +399,7 @@ async fn mail_save(cx: &Cx, Form(form): Form<SettingsForm>) -> Result<Response>
398 return Err(forbidden().into());399 return Err(forbidden().into());
399 }400 }
400 let lang = i18n::lang(cx, Some(&viewer.0));401 let lang = i18n::lang(cx, Some(&viewer.0));
401- let state = app_context::<AppState>(cx);402+ let state = context::<AppState>(cx);
402 let saved = save_settings(cx, state, &viewer.0, &form, lang).await;403 let saved = save_settings(cx, state, &viewer.0, &form, lang).await;
403 let transport = if form.transport.is_empty() {404 let transport = if form.transport.is_empty() {
404 Ok(None)405 Ok(None)
@@ -488,7 +489,7 @@ async fn mail_test(cx: &Cx, Form(form): Form<TestForm>) -> Result<Response> {
488 return Err(forbidden().into());489 return Err(forbidden().into());
489 }490 }
490 let lang = i18n::lang(cx, Some(&viewer.0));491 let lang = i18n::lang(cx, Some(&viewer.0));
491- let state = app_context::<AppState>(cx);492+ let state = context::<AppState>(cx);
492 let notice = match queue_test(cx, state, &viewer.0, lang).await {493 let notice = match queue_test(cx, state, &viewer.0, lang).await {
493 Ok(()) => g::t(lang, K::TestQueued).to_owned(),494 Ok(()) => g::t(lang, K::TestQueued).to_owned(),
494 Err(Error::Invalid(message)) => message,495 Err(Error::Invalid(message)) => message,
@@ -577,7 +578,7 @@ async fn queue_action(cx: &Cx, form: QueueForm, action: QueueAction) -> Result<R
577 return Err(forbidden().into());578 return Err(forbidden().into());
578 }579 }
579 let lang = i18n::lang(cx, Some(&viewer.0));580 let lang = i18n::lang(cx, Some(&viewer.0));
580- let state = app_context::<AppState>(cx);581+ let state = context::<AppState>(cx);
581 let now = now_stamp();582 let now = now_stamp();
582 let (done, notice) = match action {583 let (done, notice) = match action {
583 QueueAction::Retry => {584 QueueAction::Retry => {
crates/forge-web/src/pages/admin_replication.rsmodified+6 -5
@@ -16,7 +16,7 @@ use forge_core::time::stamp_ago;
16 use forge_core::{AuditAction, Error};16 use forge_core::{AuditAction, Error};
17 use serde::Deserialize;17 use serde::Deserialize;
18 use topcoat::Result;18 use topcoat::Result;
19-use topcoat::context::{Cx, app_context};19+use topcoat::context::{Cx, context};
20 use topcoat::router::content::Form;20 use topcoat::router::content::Form;
21 use topcoat::router::error::{forbidden, see_other};21 use topcoat::router::error::{forbidden, see_other};
22 use topcoat::router::response::Response;22 use topcoat::router::response::Response;
@@ -229,6 +229,7 @@ async fn page_data(state: &AppState, lang: Lang) -> forge_core::Result<PageData>
229 229
230 #[component]230 #[component]
231 async fn replication_view(231 async fn replication_view(
232+ cx: &Cx,
232 lang: Lang,233 lang: Lang,
233 csrf: String,234 csrf: String,
234 data: PageData,235 data: PageData,
@@ -352,7 +353,7 @@ async fn page_fingerprint(state: &AppState) -> Result<String> {
352 #[route(GET "/admin/replication/events")]353 #[route(GET "/admin/replication/events")]
353 async fn replication_events(cx: &Cx) -> Result<Response> {354 async fn replication_events(cx: &Cx) -> Result<Response> {
354 admin_only(cx).await?;355 admin_only(cx).await?;
355- let state = app_context::<AppState>(cx).clone();356+ let state = context::<AppState>(cx).clone();
356 stream_changes(357 stream_changes(
357 cx,358 cx,
358 crate::live::admin(),359 crate::live::admin(),
@@ -425,7 +426,7 @@ async fn replication_page(cx: &Cx) -> Result<impl View> {
425 let viewer = admin_only(cx).await?;426 let viewer = admin_only(cx).await?;
426 let query = query_params::<NoticeQuery>(cx)?;427 let query = query_params::<NoticeQuery>(cx)?;
427 let lang = i18n::lang(cx, Some(&viewer.0));428 let lang = i18n::lang(cx, Some(&viewer.0));
428- let state = app_context::<AppState>(cx);429+ let state = context::<AppState>(cx);
429 let mut data = page_data(state, lang).await?;430 let mut data = page_data(state, lang).await?;
430 let list = repo_list(&mut data, query);431 let list = repo_list(&mut data, query);
431 let settings = setting_rows(state, lang, REPLICATION_KEYS).await?;432 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>>) ->
444 return Err(forbidden().into());445 return Err(forbidden().into());
445 }446 }
446 let lang = i18n::lang(cx, Some(&viewer.0));447 let lang = i18n::lang(cx, Some(&viewer.0));
447- let state = app_context::<AppState>(cx);448+ let state = context::<AppState>(cx);
448 let notice = notice_of(449 let notice = notice_of(
449 lang,450 lang,
450 save_topic(451 save_topic(
@@ -474,7 +475,7 @@ async fn replication_reconcile(cx: &Cx, Form(form): Form<ReconcileForm>) -> Resu
474 return Err(forbidden().into());475 return Err(forbidden().into());
475 }476 }
476 let lang = i18n::lang(cx, Some(&viewer.0));477 let lang = i18n::lang(cx, Some(&viewer.0));
477- let state = app_context::<AppState>(cx);478+ let state = context::<AppState>(cx);
478 let notice = match reconcile_now(cx, state, &viewer.0, lang).await {479 let notice = match reconcile_now(cx, state, &viewer.0, lang).await {
479 Ok(()) => g::t(lang, K::ReconcileStarted).to_owned(),480 Ok(()) => g::t(lang, K::ReconcileStarted).to_owned(),
480 Err(Error::Config(message)) => message,481 Err(Error::Config(message)) => message,
crates/forge-web/src/pages/admin_runners.rsmodified+39 -37
@@ -17,7 +17,7 @@ use serde::Deserialize;
17 use time::OffsetDateTime;17 use time::OffsetDateTime;
18 use time::format_description::well_known::Rfc3339;18 use time::format_description::well_known::Rfc3339;
19 use topcoat::Result;19 use topcoat::Result;
20-use topcoat::context::{Cx, app_context};20+use topcoat::context::{Cx, context};
21 use topcoat::router::content::Form;21 use topcoat::router::content::Form;
22 use topcoat::router::error::{SeeOther, forbidden, see_other};22 use topcoat::router::error::{SeeOther, forbidden, see_other};
23 use topcoat::router::request::uri;23 use topcoat::router::request::uri;
@@ -62,18 +62,8 @@ fn s(lang: Lang, en: &'static str, tr: &'static str) -> &'static str {
62 62
63 /// Extra notice words: (word, English, Turkish, is an error).63 /// Extra notice words: (word, English, Turkish, is an error).
64 const EXTRA_NOTICES: [(&str, &str, &str, bool); 8] = [64 const EXTRA_NOTICES: [(&str, &str, &str, bool); 8] = [
65- (65+ ("saved", "Saved.", "Kaydedildi.", false),
66- "saved",66+ ("saved-restart", "Saved.", "Kaydedildi.", false),
67- "Saved.",
68- "Kaydedildi.",
69- false,
70- ),
71- (
72- "saved-restart",
73- "Saved.",
74- "Kaydedildi.",
75- false,
76- ),
77 (67 (
78 "reset",68 "reset",
79 "Override removed.",69 "Override removed.",
@@ -322,6 +312,7 @@ fn register_command(base_url: &str, token: &str) -> String {
322 312
323 #[component]313 #[component]
324 async fn runners_view(314 async fn runners_view(
315+ cx: &Cx,
325 lang: Lang,316 lang: Lang,
326 csrf: String,317 csrf: String,
327 rows: Vec<RunnerRow>,318 rows: Vec<RunnerRow>,
@@ -388,6 +379,7 @@ fn list_href(page: u64, notice: &str) -> String {
388 /// that are not destructive, so the confirm button is soft.379 /// that are not destructive, so the confirm button is soft.
389 #[component]380 #[component]
390 pub(crate) async fn confirm_post(381 pub(crate) async fn confirm_post(
382+ cx: &Cx,
391 lang: Lang,383 lang: Lang,
392 csrf: &str,384 csrf: &str,
393 action: &str,385 action: &str,
@@ -433,6 +425,7 @@ fn disable_message(lang: Lang, name: &str) -> String {
433 /// pending the control shows that instead, and the runner clears it by coming back with a new id.425 /// pending the control shows that instead, and the runner clears it by coming back with a new id.
434 #[component]426 #[component]
435 async fn restart_control(427 async fn restart_control(
428+ cx: &Cx,
436 lang: Lang,429 lang: Lang,
437 csrf: &str,430 csrf: &str,
438 action: &str,431 action: &str,
@@ -461,7 +454,7 @@ const PIP_MAX: u32 = 16;
461 454
462 /// The load of a runner: the jobs running, as a pip per concurrency slot, or a meter past `PIP_MAX`.455 /// The load of a runner: the jobs running, as a pip per concurrency slot, or a meter past `PIP_MAX`.
463 #[component]456 #[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> {
465 let running_text = running.to_string();458 let running_text = running.to_string();
466 let meter_max = max.max(1).to_string();459 let meter_max = max.max(1).to_string();
467 let use_pips = (1..=PIP_MAX).contains(&max);460 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> {
492 }485 }
493 486
494 #[component]487 #[component]
495-async fn token_view(488+async fn token_view(cx: &Cx, lang: Lang, token: String, command: String) -> Result<impl View> {
496- lang: Lang,
497- token: String,
498- command: String,
499-) -> Result<impl View> {
500 Ok(view! {489 Ok(view! {
501 head(title: g::t(lang, K::RegistrationToken))490 head(title: g::t(lang, K::RegistrationToken))
502 <p class="state" role="status"><strong>(g::t(lang, K::CopyTokenNow))</strong></p>491 <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> {
522 let viewer = admin_only(cx).await?;511 let viewer = admin_only(cx).await?;
523 let lang = i18n::lang(cx, Some(&viewer.0));512 let lang = i18n::lang(cx, Some(&viewer.0));
524 let query = query_params::<RunnersQuery>(cx)?;513 let query = query_params::<RunnersQuery>(cx)?;
525- let state = app_context::<AppState>(cx);514+ let state = context::<AppState>(cx);
526 let tz = viewer.0.timezone.clone();515 let tz = viewer.0.timezone.clone();
527 let now = now_unix();516 let now = now_unix();
528 let all: Vec<RunnerRow> = state517 let all: Vec<RunnerRow> = state
@@ -566,7 +555,7 @@ async fn runner_token_create(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<impl
566 if !check_csrf(&viewer.1, &form.csrf) {555 if !check_csrf(&viewer.1, &form.csrf) {
567 return Err(forbidden().into());556 return Err(forbidden().into());
568 }557 }
569- let state = app_context::<AppState>(cx);558+ let state = context::<AppState>(cx);
570 let lang = i18n::lang(cx, Some(&viewer.0));559 let lang = i18n::lang(cx, Some(&viewer.0));
571 let ttl_hours = state.live().ci.registration_token_hours;560 let ttl_hours = state.live().ci.registration_token_hours;
572 let token = match state561 let token = match state
@@ -617,8 +606,8 @@ async fn runner_set_disabled(cx: &Cx, Form(form): Form<DisableForm>) -> Result<S
617 if !check_csrf(&viewer.1, &form.csrf) {606 if !check_csrf(&viewer.1, &form.csrf) {
618 return Err(forbidden().into());607 return Err(forbidden().into());
619 }608 }
620- let id = path_param::<RunnerId>(cx);609+ let id = runner_id(cx);
621- let state = app_context::<AppState>(cx);610+ let state = context::<AppState>(cx);
622 if runner_named(state, id).await?.is_none() {611 if runner_named(state, id).await?.is_none() {
623 return Ok(back_to_list("missing"));612 return Ok(back_to_list("missing"));
624 }613 }
@@ -636,8 +625,8 @@ async fn runner_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther>
636 if !check_csrf(&viewer.1, &form.csrf) {625 if !check_csrf(&viewer.1, &form.csrf) {
637 return Err(forbidden().into());626 return Err(forbidden().into());
638 }627 }
639- let id = path_param::<RunnerId>(cx);628+ let id = runner_id(cx);
640- let state = app_context::<AppState>(cx);629+ let state = context::<AppState>(cx);
641 let Some(runner) = runner_named(state, id).await? else {630 let Some(runner) = runner_named(state, id).await? else {
642 return Ok(back_to_list("missing"));631 return Ok(back_to_list("missing"));
643 };632 };
@@ -816,10 +805,18 @@ fn field_text(lang: Lang, key: &str) -> &'static str {
816 "limits.cpus" => s(lang, "CPU limit", "CPU sınırı"),805 "limits.cpus" => s(lang, "CPU limit", "CPU sınırı"),
817 "limits.pids" => s(lang, "Process limit", "İşlem sınırı"),806 "limits.pids" => s(lang, "Process limit", "İşlem sınırı"),
818 "work_dir" => s(lang, "Work directory", "Çalışma dizini"),807 "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+ ),
820 "limits.job_disk_gb" => s(lang, "Disk per job (GB)", "İş başına disk (GB)"),813 "limits.job_disk_gb" => s(lang, "Disk per job (GB)", "İş başına disk (GB)"),
821 "images.keep_days" => s(lang, "Keep images (days)", "Kalıpları sakla (gün)"),814 "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+ ),
823 "sandbox.userns" => s(lang, "User namespaces", "Kullanıcı ad alanları"),820 "sandbox.userns" => s(lang, "User namespaces", "Kullanıcı ad alanları"),
824 "name" => s(lang, "Name", "Ad"),821 "name" => s(lang, "Name", "Ad"),
825 "url" => s(lang, "Forge URL", "Forge adresi"),822 "url" => s(lang, "Forge URL", "Forge adresi"),
@@ -1371,6 +1368,7 @@ fn current(on: bool) -> Option<&'static str> {
1371 1368
1372 #[component]1369 #[component]
1373 async fn runner_detail_view(1370 async fn runner_detail_view(
1371+ cx: &Cx,
1374 lang: Lang,1372 lang: Lang,
1375 csrf: String,1373 csrf: String,
1376 runner: CiRunner,1374 runner: CiRunner,
@@ -1418,7 +1416,11 @@ async fn runner_detail_view(
1418 let slots = row.concurrency.parse::<u32>().unwrap_or(0);1416 let slots = row.concurrency.parse::<u32>().unwrap_or(0);
1419 let mut sub = vec![SubPart::text(row.state_text)];1417 let mut sub = vec![SubPart::text(row.state_text)];
1420 if row.restart_pending.is_some() {1418 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+ )));
1422 }1424 }
1423 let jobs_href = format!("{}?tab=jobs", row.detail_href);1425 let jobs_href = format!("{}?tab=jobs", row.detail_href);
1424 let save_action = format!("{}/settings", row.detail_href);1426 let save_action = format!("{}/settings", row.detail_href);
@@ -1644,8 +1646,8 @@ async fn runner_detail_view(
1644 async fn runner_detail_page(cx: &Cx) -> Result<impl View> {1646 async fn runner_detail_page(cx: &Cx) -> Result<impl View> {
1645 let viewer = admin_only(cx).await?;1647 let viewer = admin_only(cx).await?;
1646 let lang = i18n::lang(cx, Some(&viewer.0));1648 let lang = i18n::lang(cx, Some(&viewer.0));
1647- let state = app_context::<AppState>(cx);1649+ let state = context::<AppState>(cx);
1648- let id = path_param::<RunnerId>(cx);1650+ let id = runner_id(cx);
1649 let Some(runner) = runner_named(state, id).await? else {1651 let Some(runner) = runner_named(state, id).await? else {
1650 return Err(back_to_list("missing").into());1652 return Err(back_to_list("missing").into());
1651 };1653 };
@@ -1683,8 +1685,8 @@ async fn runner_save_settings(
1683 if !check_csrf(&viewer.1, form.get("csrf").map_or("", String::as_str)) {1685 if !check_csrf(&viewer.1, form.get("csrf").map_or("", String::as_str)) {
1684 return Err(forbidden().into());1686 return Err(forbidden().into());
1685 }1687 }
1686- let id = path_param::<RunnerId>(cx);1688+ let id = runner_id(cx);
1687- let state = app_context::<AppState>(cx);1689+ let state = context::<AppState>(cx);
1688 let tab = tab_slug(form.get("tab").map(String::as_str));1690 let tab = tab_slug(form.get("tab").map(String::as_str));
1689 let back = |notice: &str| {1691 let back = |notice: &str| {
1690 see_other(format!(1692 see_other(format!(
@@ -1756,7 +1758,7 @@ async fn runner_save_settings(
1756 #[route(GET "/admin/runners/events")]1758 #[route(GET "/admin/runners/events")]
1757 async fn runners_events(cx: &Cx) -> Result<Response> {1759 async fn runners_events(cx: &Cx) -> Result<Response> {
1758 admin_only(cx).await?;1760 admin_only(cx).await?;
1759- let state = app_context::<AppState>(cx);1761+ let state = context::<AppState>(cx);
1760 let wake = state.ci_live.subscribe_runners();1762 let wake = state.ci_live.subscribe_runners();
1761 let events = futures_util::stream::unfold(wake, |mut wake| async move {1763 let events = futures_util::stream::unfold(wake, |mut wake| async move {
1762 wake.changed().await.ok()?;1764 wake.changed().await.ok()?;
@@ -1776,8 +1778,8 @@ async fn runner_set_config(cx: &Cx, Form(form): Form<ConfigForm>) -> Result<SeeO
1776 if !check_csrf(&viewer.1, &form.csrf) {1778 if !check_csrf(&viewer.1, &form.csrf) {
1777 return Err(forbidden().into());1779 return Err(forbidden().into());
1778 }1780 }
1779- let id = path_param::<RunnerId>(cx);1781+ let id = runner_id(cx);
1780- let state = app_context::<AppState>(cx);1782+ let state = context::<AppState>(cx);
1781 let back = |notice: &str| {1783 let back = |notice: &str| {
1782 if form.back == "detail" {1784 if form.back == "detail" {
1783 let tab = tab_slug(Some(form.tab.as_str()));1785 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
1851 if !check_csrf(&viewer.1, &form.csrf) {1853 if !check_csrf(&viewer.1, &form.csrf) {
1852 return Err(forbidden().into());1854 return Err(forbidden().into());
1853 }1855 }
1854- let id = path_param::<RunnerId>(cx);1856+ let id = runner_id(cx);
1855- let state = app_context::<AppState>(cx);1857+ let state = context::<AppState>(cx);
1856 let back = |notice: &str| {1858 let back = |notice: &str| {
1857 if form.back == "detail" {1859 if form.back == "detail" {
1858 see_other(format!("/admin/runners/{}?notice={}", enc(id), enc(notice)))1860 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};
21 use futures_util::StreamExt;21 use futures_util::StreamExt;
22 use serde::Deserialize;22 use serde::Deserialize;
23 use topcoat::Result;23 use topcoat::Result;
24-use topcoat::context::{Cx, app_context};24+use topcoat::context::{Cx, context};
25 use topcoat::router::content::Form;25 use topcoat::router::content::Form;
26 use topcoat::router::error::{forbidden, see_other};26 use topcoat::router::error::{forbidden, see_other};
27 use topcoat::router::response::Response;27 use topcoat::router::response::Response;
@@ -546,7 +546,7 @@ pub(crate) fn with_notice(back: &str, notice: &str) -> String {
546 /// The hidden form that resets one setting: the rows' "Reset to file value" buttons post to it by546 /// The hidden form that resets one setting: the rows' "Reset to file value" buttons post to it by
547 /// id. It goes outside the forms that save, since a form cannot hold another.547 /// id. It goes outside the forms that save, since a form cannot hold another.
548 #[component]548 #[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> {
550 Ok(view! {550 Ok(view! {
551 <form id="srv-reset" method="post" action="/admin/server/reset">551 <form id="srv-reset" method="post" action="/admin/server/reset">
552 <input type="hidden" name="csrf" value=(csrf.as_str())>552 <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>
557 557
558 /// The rows of a settings topic, one line each. The caller's form holds them.558 /// The rows of a settings topic, one line each. The caller's form holds them.
559 #[component]559 #[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> {
561 Ok(view! {561 Ok(view! {
562 for r in rows.iter() {562 for r in rows.iter() {
563 srv_row(lang: lang, row: r)563 srv_row(lang: lang, row: r)
@@ -584,7 +584,7 @@ async fn search_hits(
584 /// One setting on one line: its name, then its control (or its value when it cannot be changed584 /// One setting on one line: its name, then its control (or its value when it cannot be changed
585 /// here), then what to know about it. Every control is the same width, so the notes line up.585 /// here), then what to know about it. Every control is the same width, so the notes line up.
586 #[component]586 #[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> {
588 let id = format!("srv-{}", row.key);588 let id = format!("srv-{}", row.key);
589 let input = format!("srv-{}-in", row.key);589 let input = format!("srv-{}-in", row.key);
590 Ok(view! {590 Ok(view! {
@@ -619,7 +619,7 @@ async fn srv_row(lang: Lang, row: &Row) -> Result<impl View> {
619 619
620 /// The facts after a setting's control: its kind, whether a restart is needed, and its override.620 /// The facts after a setting's control: its kind, whether a restart is needed, and its override.
621 #[component]621 #[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> {
623 Ok(view! {623 Ok(view! {
624 <span class="srv-hints">624 <span class="srv-hints">
625 if !row.kind_label.is_empty() {625 if !row.kind_label.is_empty() {
@@ -644,6 +644,7 @@ async fn srv_hints(lang: Lang, row: &Row) -> Result<impl View> {
644 644
645 #[component]645 #[component]
646 async fn server_view(646 async fn server_view(
647+ cx: &Cx,
647 lang: Lang,648 lang: Lang,
648 csrf: String,649 csrf: String,
649 page: &'static SrvPage,650 page: &'static SrvPage,
@@ -738,7 +739,7 @@ async fn server_view(
738 async fn server_page(cx: &Cx) -> Result<impl View> {739 async fn server_page(cx: &Cx) -> Result<impl View> {
739 let viewer = admin_only(cx).await?;740 let viewer = admin_only(cx).await?;
740 let query = query_params::<ServerQuery>(cx)?;741 let query = query_params::<ServerQuery>(cx)?;
741- let state = app_context::<AppState>(cx);742+ let state = context::<AppState>(cx);
742 let lang = i18n::lang(cx, Some(&viewer.0));743 let lang = i18n::lang(cx, Some(&viewer.0));
743 let slug = query.cat.as_deref().or(query.tab.as_deref()).unwrap_or("");744 let slug = query.cat.as_deref().or(query.tab.as_deref()).unwrap_or("");
744 if let Some(to) = moved_slug(slug) {745 if let Some(to) = moved_slug(slug) {
@@ -769,7 +770,7 @@ async fn server_save(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> Resu
769 return Err(forbidden().into());770 return Err(forbidden().into());
770 }771 }
771 let lang = i18n::lang(cx, Some(&viewer.0));772 let lang = i18n::lang(cx, Some(&viewer.0));
772- let state = app_context::<AppState>(cx);773+ let state = context::<AppState>(cx);
773 let page = form774 let page = form
774 .get("tab")775 .get("tab")
775 .and_then(|t| page_by_slug(t))776 .and_then(|t| page_by_slug(t))
@@ -841,7 +842,7 @@ async fn server_restart(cx: &Cx, Form(form): Form<RestartForm>) -> Result<Respon
841 if !check_csrf(&viewer.1, &form.csrf) {842 if !check_csrf(&viewer.1, &form.csrf) {
842 return Err(forbidden().into());843 return Err(forbidden().into());
843 }844 }
844- let state = app_context::<AppState>(cx);845+ let state = context::<AppState>(cx);
845 let group = Group::parse(&form.tab).unwrap_or(Group::General);846 let group = Group::parse(&form.tab).unwrap_or(Group::General);
846 audit::record(847 audit::record(
847 &state.store,848 &state.store,
@@ -909,7 +910,7 @@ async fn server_reset(cx: &Cx, Form(form): Form<ResetForm>) -> Result<Response>
909 return Err(forbidden().into());910 return Err(forbidden().into());
910 }911 }
911 let lang = i18n::lang(cx, Some(&viewer.0));912 let lang = i18n::lang(cx, Some(&viewer.0));
912- let state = app_context::<AppState>(cx);913+ let state = context::<AppState>(cx);
913 let notice = match reset(cx, state, &viewer.0, &form.key).await {914 let notice = match reset(cx, state, &viewer.0, &form.key).await {
914 Ok(()) => g::t(lang, K::SrvResetDone).to_owned(),915 Ok(()) => g::t(lang, K::SrvResetDone).to_owned(),
915 Err(Error::Invalid(message)) => message,916 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;
10 use forge_core::{AuditAction, Store, User};10 use forge_core::{AuditAction, Store, User};
11 use serde::Deserialize;11 use serde::Deserialize;
12 use topcoat::Result;12 use topcoat::Result;
13-use topcoat::context::{Cx, app_context};13+use topcoat::context::{Cx, context};
14 use topcoat::router::content::Form;14 use topcoat::router::content::Form;
15 use topcoat::router::error::{forbidden, not_found, see_other};15 use topcoat::router::error::{forbidden, not_found, see_other};
16 use topcoat::router::response::Response;16 use topcoat::router::response::Response;
@@ -88,7 +88,7 @@ fn is_ghost(user: &User) -> bool {
88 }88 }
89 89
90 async fn load(cx: &Cx) -> Result<Detail> {90 async fn load(cx: &Cx) -> Result<Detail> {
91- let store = &app_context::<AppState>(cx).store;91+ let store = &context::<AppState>(cx).store;
92 let id = path_param_segment(cx, "user_id").to_owned();92 let id = path_param_segment(cx, "user_id").to_owned();
93 let Some(target) = store.user_by_id(&id).await? else {93 let Some(target) = store.user_by_id(&id).await? else {
94 return Err(not_found().into());94 return Err(not_found().into());
@@ -161,6 +161,7 @@ fn local_stamp(stamp: &str, tz: &str) -> String {
161 161
162 #[component]162 #[component]
163 async fn detail_body(163 async fn detail_body(
164+ cx: &Cx,
164 lang: Lang,165 lang: Lang,
165 csrf: &str,166 csrf: &str,
166 viewer_id: &str,167 viewer_id: &str,
@@ -445,6 +446,7 @@ async fn detail_body(
445 /// delete, which opens the page that says what goes with it.446 /// delete, which opens the page that says what goes with it.
446 #[component]447 #[component]
447 async fn org_body(448 async fn org_body(
449+ cx: &Cx,
448 lang: Lang,450 lang: Lang,
449 org: User,451 org: User,
450 members: Vec<(User, OrgMemberRole)>,452 members: Vec<(User, OrgMemberRole)>,
@@ -564,7 +566,7 @@ async fn account_fingerprint(store: &Store, user_id: &str) -> Result<String> {
564 async fn detail_events(cx: &Cx) -> Result<Response> {566 async fn detail_events(cx: &Cx) -> Result<Response> {
565 admin_only(cx).await?;567 admin_only(cx).await?;
566 let id = path_param_segment(cx, "user_id").to_owned();568 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();
568 let topic = Topic::AdminUser(id.clone());570 let topic = Topic::AdminUser(id.clone());
569 stream_changes(cx, crate::live::admin(), &[topic], move || {571 stream_changes(cx, crate::live::admin(), &[topic], move || {
570 let store = store.clone();572 let store = store.clone();
@@ -579,7 +581,7 @@ async fn detail_page(cx: &Cx) -> Result<impl View> {
579 let viewer = admin_only(cx).await?;581 let viewer = admin_only(cx).await?;
580 let lang = i18n::lang(cx, Some(&viewer.0));582 let lang = i18n::lang(cx, Some(&viewer.0));
581 let query = query_params::<DoneQuery>(cx)?;583 let query = query_params::<DoneQuery>(cx)?;
582- let store = &app_context::<AppState>(cx).store;584+ let store = &context::<AppState>(cx).store;
583 let id = path_param_segment(cx, "user_id").to_owned();585 let id = path_param_segment(cx, "user_id").to_owned();
584 let org = match store.user_by_id(&id).await? {586 let org = match store.user_by_id(&id).await? {
585 Some(user) if user.is_org() => {587 Some(user) if user.is_org() => {
@@ -625,7 +627,7 @@ async fn perform(cx: &Cx, form: &ActionForm, action: Action) -> Result<(Outcome,
625 return Err(forbidden().into());627 return Err(forbidden().into());
626 }628 }
627 let lang = i18n::lang(cx, Some(&viewer.0));629 let lang = i18n::lang(cx, Some(&viewer.0));
628- let state = app_context::<AppState>(cx);630+ let state = context::<AppState>(cx);
629 let store = &state.store;631 let store = &state.store;
630 let detail = load(cx).await?;632 let detail = load(cx).await?;
631 let target = &detail.target;633 let target = &detail.target;
@@ -661,7 +663,7 @@ async fn perform(cx: &Cx, form: &ActionForm, action: Action) -> Result<(Outcome,
661 Ok(()) => {663 Ok(()) => {
662 // A suspension ends the user's sessions: their open tabs must see it.664 // A suspension ends the user's sessions: their open tabs must see it.
663 crate::pages::settings_live::bump_account(665 crate::pages::settings_live::bump_account(
664- app_context::<AppState>(cx),666+ context::<AppState>(cx),
665 &target.id,667 &target.id,
666 );668 );
667 audit(669 audit(
@@ -748,8 +750,8 @@ async fn perform(cx: &Cx, form: &ActionForm, action: Action) -> Result<(Outcome,
748 750
749 /// Redirects to the detail page after a success, or renders it with a message.751 /// Redirects to the detail page after a success, or renders it with a message.
750 async fn respond(cx: &Cx, form: ActionForm, action: Action) -> Result<impl View> {752 async fn respond(cx: &Cx, form: ActionForm, action: Action) -> Result<impl View> {
751- // `view!` expects the `__cx` binding that `#[page]` provides.753+ // `view!` expects the `cx` binding that `#[page]` provides.
752- let __cx = cx;754+ let cx = cx;
753 let (outcome, detail) = perform(cx, &form, action).await?;755 let (outcome, detail) = perform(cx, &form, action).await?;
754 let viewer = admin_only(cx).await?;756 let viewer = admin_only(cx).await?;
755 let lang = i18n::lang(cx, Some(&viewer.0));757 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};
7 use forge_core::{AuditAction, Session, Store, User};7 use forge_core::{AuditAction, Session, Store, User};
8 use serde::Deserialize;8 use serde::Deserialize;
9 use topcoat::Result;9 use topcoat::Result;
10-use topcoat::context::{Cx, app_context};10+use topcoat::context::{Cx, context};
11 use topcoat::router::content::Form;11 use topcoat::router::content::Form;
12 use topcoat::router::error::{forbidden, not_found, see_other};12 use topcoat::router::error::{forbidden, not_found, see_other};
13 use topcoat::router::response::Response;13 use topcoat::router::response::Response;
@@ -168,6 +168,7 @@ impl UserRow {
168 168
169 #[component]169 #[component]
170 async fn users_view(170 async fn users_view(
171+ cx: &Cx,
171 lang: Lang,172 lang: Lang,
172 csrf: &str,173 csrf: &str,
173 users: Vec<User>,174 users: Vec<User>,
@@ -289,7 +290,7 @@ async fn users_view(
289 290
290 /// The rail of the Users tab: Users and Invites. `current` is `users` or `invites`.291 /// The rail of the Users tab: Users and Invites. `current` is `users` or `invites`.
291 #[component]292 #[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> {
293 let items = vec![294 let items = vec![
294 RailItem {295 RailItem {
295 name: g::t(lang, K::Users).to_owned(),296 name: g::t(lang, K::Users).to_owned(),
@@ -333,7 +334,7 @@ async fn list_fingerprint(store: &Store) -> topcoat::Result<String> {
333 #[route(GET "/admin/users/events")]334 #[route(GET "/admin/users/events")]
334 async fn users_events(cx: &Cx) -> Result<Response> {335 async fn users_events(cx: &Cx) -> Result<Response> {
335 admin_only(cx).await?;336 admin_only(cx).await?;
336- let store = app_context::<AppState>(cx).store.clone();337+ let store = context::<AppState>(cx).store.clone();
337 stream_changes(cx, crate::live::admin(), &[Topic::AdminUsers], move || {338 stream_changes(cx, crate::live::admin(), &[Topic::AdminUsers], move || {
338 let store = store.clone();339 let store = store.clone();
339 async move { list_fingerprint(&store).await }340 async move { list_fingerprint(&store).await }
@@ -346,7 +347,7 @@ async fn users_page(cx: &Cx) -> Result<impl View> {
346 let viewer = admin_only(cx).await?;347 let viewer = admin_only(cx).await?;
347 let lang = i18n::lang(cx, Some(&viewer.0));348 let lang = i18n::lang(cx, Some(&viewer.0));
348 let (finder, kind, page) = listing_args(query_params::<UsersQuery>(cx)?);349 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?;
350 let csrf = viewer.1.csrf_token.clone();351 let csrf = viewer.1.csrf_token.clone();
351 let title = g::t(lang, K::Users);352 let title = g::t(lang, K::Users);
352 Ok(view! {353 Ok(view! {
@@ -361,7 +362,7 @@ async fn users_create(cx: &Cx, Form(form): Form<CreateUserForm>) -> Result<impl
361 return Err(forbidden().into());362 return Err(forbidden().into());
362 }363 }
363 let lang = i18n::lang(cx, Some(&viewer.0));364 let lang = i18n::lang(cx, Some(&viewer.0));
364- let store = &app_context::<AppState>(cx).store;365+ let store = &context::<AppState>(cx).store;
365 366
366 // Ok(Ok(user)) created; Ok(Err(message)) rejected with a user-facing message.367 // Ok(Ok(user)) created; Ok(Err(message)) rejected with a user-facing message.
367 let outcome: Result<std::result::Result<User, String>> = create_user(store, &form, lang).await;368 let outcome: Result<std::result::Result<User, String>> = create_user(store, &form, lang).await;
@@ -487,6 +488,7 @@ async fn review_target(
487 488
488 #[component]489 #[component]
489 async fn delete_body(490 async fn delete_body(
491+ cx: &Cx,
490 lang: Lang,492 lang: Lang,
491 csrf: &str,493 csrf: &str,
492 target: User,494 target: User,
@@ -555,6 +557,7 @@ async fn delete_body(
555 /// An organization is not a person: this points at its own settings instead of offering a delete.557 /// An organization is not a person: this points at its own settings instead of offering a delete.
556 #[component]558 #[component]
557 async fn org_delete_note(559 async fn org_delete_note(
560+ cx: &Cx,
558 lang: Lang,561 lang: Lang,
559 target: User,562 target: User,
560 repos: Vec<String>,563 repos: Vec<String>,
@@ -593,7 +596,7 @@ async fn org_delete_note(
593 async fn user_delete_page(cx: &Cx) -> Result<impl View> {596 async fn user_delete_page(cx: &Cx) -> Result<impl View> {
594 let viewer = admin_only(cx).await?;597 let viewer = admin_only(cx).await?;
595 let lang = i18n::lang(cx, Some(&viewer.0));598 let lang = i18n::lang(cx, Some(&viewer.0));
596- let store = &app_context::<AppState>(cx).store;599+ let store = &context::<AppState>(cx).store;
597 let target_id = path_param_segment(cx, "user_id").to_owned();600 let target_id = path_param_segment(cx, "user_id").to_owned();
598 let Some(target) = store.user_by_id(&target_id).await? else {601 let Some(target) = store.user_by_id(&target_id).await? else {
599 return Err(not_found().into());602 return Err(not_found().into());
@@ -632,7 +635,7 @@ async fn user_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<impl View>
632 return Err(forbidden().into());635 return Err(forbidden().into());
633 }636 }
634 let lang = i18n::lang(cx, Some(&viewer.0));637 let lang = i18n::lang(cx, Some(&viewer.0));
635- let store = &app_context::<AppState>(cx).store;638+ let store = &context::<AppState>(cx).store;
636 let target_id = path_param_segment(cx, "user_id").to_owned();639 let target_id = path_param_segment(cx, "user_id").to_owned();
637 let Some(target) = store.user_by_id(&target_id).await? else {640 let Some(target) = store.user_by_id(&target_id).await? else {
638 return Err(not_found().into());641 return Err(not_found().into());
@@ -654,7 +657,7 @@ async fn user_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<impl View>
654 match store.delete_user(&target.id, &ghost.id).await {657 match store.delete_user(&target.id, &ghost.id).await {
655 Ok(_) => {658 Ok(_) => {
656 // Their sessions and keys are gone: any open tab of theirs must leave.659 // 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);
658 audit::record(661 audit::record(
659 store,662 store,
660 Some(cx),663 Some(cx),
crates/forge-web/src/pages/archive.rsmodified+5 -5
@@ -17,7 +17,7 @@ use tokio::process::Child;
17 use tokio::sync::{OwnedSemaphorePermit, Semaphore};17 use tokio::sync::{OwnedSemaphorePermit, Semaphore};
18 use tokio_util::io::ReaderStream;18 use tokio_util::io::ReaderStream;
19 use topcoat::Result;19 use topcoat::Result;
20-use topcoat::context::{Cx, app_context};20+use topcoat::context::{Cx, context};
21 use topcoat::router::error::not_found;21 use topcoat::router::error::not_found;
22 use topcoat::router::response::Response;22 use topcoat::router::response::Response;
23 use topcoat::router::{Body, path_param, route};23 use topcoat::router::{Body, path_param, route};
@@ -73,15 +73,15 @@ fn archive_prefix(repo: &str, reference: &str, commit: &str) -> String {
73 73
74 #[route(GET "/{owner}/{repo}/archive/{*rest}")]74 #[route(GET "/{owner}/{repo}/archive/{*rest}")]
75 async fn archive(cx: &Cx) -> Result<Response> {75 async fn archive(cx: &Cx) -> Result<Response> {
76- let owner = path_param::<Owner>(cx);76+ let owner = owner(cx);
77- let name = path_param::<Repo>(cx);77+ let name = repo(cx);
78- let rest = path_param::<Rest>(cx).collect::<Vec<_>>().join("/");78+ let rest = rest(cx).collect::<Vec<_>>().join("/");
79 let Some((reference, format)) = split_format(&rest) else {79 let Some((reference, format)) = split_format(&rest) else {
80 return Err(not_found().into());80 return Err(not_found().into());
81 };81 };
82 82
83 let ctx = load_repo(cx, owner, name).await?;83 let ctx = load_repo(cx, owner, name).await?;
84- let state = app_context::<AppState>(cx);84+ let state = context::<AppState>(cx);
85 85
86 let repo_dir = ctx.path.clone();86 let repo_dir = ctx.path.clone();
87 let rev = reference.to_owned();87 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");
134 const OFFLINE_JS: &str = include_str!("../../assets/offline.js");134 const OFFLINE_JS: &str = include_str!("../../assets/offline.js");
135 135
136 #[route(GET "/assets/offline.html")]136 #[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)> {
138 let mut headers = HeaderMap::new();138 let mut headers = HeaderMap::new();
139 headers.insert(139 headers.insert(
140 header::CONTENT_TYPE,140 header::CONTENT_TYPE,
@@ -150,7 +150,7 @@ async fn offline_html() -> Result<(StatusCode, HeaderMap, &'static str)> {
150 }150 }
151 151
152 #[route(GET "/assets/offline.js")]152 #[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)> {
154 let mut headers = HeaderMap::new();154 let mut headers = HeaderMap::new();
155 headers.insert(155 headers.insert(
156 header::CONTENT_TYPE,156 header::CONTENT_TYPE,
@@ -216,42 +216,42 @@ const FONT_CACHE: &str = "public, max-age=31536000, immutable";
216 const LICENSE_CACHE: &str = "public, max-age=86400";216 const LICENSE_CACHE: &str = "public, max-age=86400";
217 217
218 #[route(GET "/assets/fonts/figtree-5.3.0-latin-wght.woff2")]218 #[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> {
220 Ok(bytes_response(FIGTREE_LATIN, "font/woff2", FONT_CACHE))220 Ok(bytes_response(FIGTREE_LATIN, "font/woff2", FONT_CACHE))
221 }221 }
222 222
223 #[route(GET "/assets/fonts/figtree-5.3.0-latin-ext-wght.woff2")]223 #[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> {
225 Ok(bytes_response(FIGTREE_LATIN_EXT, "font/woff2", FONT_CACHE))225 Ok(bytes_response(FIGTREE_LATIN_EXT, "font/woff2", FONT_CACHE))
226 }226 }
227 227
228 #[route(GET "/assets/fonts/archivo-5.3.0-latin-wdth.woff2")]228 #[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> {
230 Ok(bytes_response(ARCHIVO_LATIN, "font/woff2", FONT_CACHE))230 Ok(bytes_response(ARCHIVO_LATIN, "font/woff2", FONT_CACHE))
231 }231 }
232 232
233 #[route(GET "/assets/fonts/archivo-5.3.0-latin-ext-wdth.woff2")]233 #[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> {
235 Ok(bytes_response(ARCHIVO_LATIN_EXT, "font/woff2", FONT_CACHE))235 Ok(bytes_response(ARCHIVO_LATIN_EXT, "font/woff2", FONT_CACHE))
236 }236 }
237 237
238 #[route(GET "/assets/fonts/ibm-plex-mono-2.5.0-400.woff2")]238 #[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> {
240 Ok(bytes_response(PLEX_MONO_400, "font/woff2", FONT_CACHE))240 Ok(bytes_response(PLEX_MONO_400, "font/woff2", FONT_CACHE))
241 }241 }
242 242
243 #[route(GET "/assets/fonts/ibm-plex-mono-2.5.0-500.woff2")]243 #[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> {
245 Ok(bytes_response(PLEX_MONO_500, "font/woff2", FONT_CACHE))245 Ok(bytes_response(PLEX_MONO_500, "font/woff2", FONT_CACHE))
246 }246 }
247 247
248 #[route(GET "/assets/fonts/ibm-plex-mono-2.5.0-600.woff2")]248 #[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> {
250 Ok(bytes_response(PLEX_MONO_600, "font/woff2", FONT_CACHE))250 Ok(bytes_response(PLEX_MONO_600, "font/woff2", FONT_CACHE))
251 }251 }
252 252
253 #[route(GET "/assets/fonts/ibm-plex-mono-2.5.0-400-italic.woff2")]253 #[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> {
255 Ok(bytes_response(255 Ok(bytes_response(
256 PLEX_MONO_400_ITALIC,256 PLEX_MONO_400_ITALIC,
257 "font/woff2",257 "font/woff2",
@@ -260,7 +260,7 @@ async fn plex_mono_400_italic() -> Result<Bytes> {
260 }260 }
261 261
262 #[route(GET "/assets/fonts/Figtree-OFL.txt")]262 #[route(GET "/assets/fonts/Figtree-OFL.txt")]
263-async fn figtree_license() -> Result<Bytes> {263+async fn figtree_license(cx: &Cx) -> Result<Bytes> {
264 Ok(bytes_response(264 Ok(bytes_response(
265 FIGTREE_LICENSE,265 FIGTREE_LICENSE,
266 "text/plain; charset=utf-8",266 "text/plain; charset=utf-8",
@@ -269,7 +269,7 @@ async fn figtree_license() -> Result<Bytes> {
269 }269 }
270 270
271 #[route(GET "/assets/fonts/Archivo-OFL.txt")]271 #[route(GET "/assets/fonts/Archivo-OFL.txt")]
272-async fn archivo_license() -> Result<Bytes> {272+async fn archivo_license(cx: &Cx) -> Result<Bytes> {
273 Ok(bytes_response(273 Ok(bytes_response(
274 ARCHIVO_LICENSE,274 ARCHIVO_LICENSE,
275 "text/plain; charset=utf-8",275 "text/plain; charset=utf-8",
@@ -278,7 +278,7 @@ async fn archivo_license() -> Result<Bytes> {
278 }278 }
279 279
280 #[route(GET "/assets/fonts/IBMPlexMono-OFL.txt")]280 #[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> {
282 Ok(bytes_response(282 Ok(bytes_response(
283 PLEX_MONO_LICENSE,283 PLEX_MONO_LICENSE,
284 "text/plain; charset=utf-8",284 "text/plain; charset=utf-8",
@@ -288,13 +288,16 @@ async fn plex_mono_license() -> Result<Bytes> {
288 288
289 #[cfg(test)]289 #[cfg(test)]
290 mod tests {290 mod tests {
291- use topcoat::cookie::RouterBuilderCookieExt;291+ use topcoat::cookie::CookieLayer;
292 use topcoat::router::request::Request;292 use topcoat::router::request::Request;
293 use topcoat::router::{Body, Router, RouterBuilderDiscoverExt, to_bytes};293 use topcoat::router::{Body, Router, RouterBuilderDiscoverExt, to_bytes};
294 294
295 #[tokio::test]295 #[tokio::test]
296 async fn fonts_and_licenses_are_served() {296 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();
298 // Bundled fonts are immutable woff2 files.301 // Bundled fonts are immutable woff2 files.
299 for uri in [302 for uri in [
300 "/assets/fonts/figtree-5.3.0-latin-wght.woff2",303 "/assets/fonts/figtree-5.3.0-latin-wght.woff2",
@@ -347,7 +350,10 @@ mod tests {
347 350
348 #[tokio::test]351 #[tokio::test]
349 async fn stylesheet_is_served_with_headers_from_the_security_layer() {352 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();
351 let req = Request::builder()357 let req = Request::builder()
352 .method("GET")358 .method("GET")
353 .uri(crate::views::STYLESHEET_HREF)359 .uri(crate::views::STYLESHEET_HREF)
@@ -373,7 +379,10 @@ mod tests {
373 379
374 #[tokio::test]380 #[tokio::test]
375 async fn immutable_assets_are_served_with_long_cache() {381 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();
377 // Each bundle is immutable under its own type. Its body holds the marker, when one is given.386 // Each bundle is immutable under its own type. Its body holds the marker, when one is given.
378 for (uri, kind, marker) in [387 for (uri, kind, marker) in [
379 (crate::views::STYLESHEET_HREF, "text/css; charset=utf-8", ""),388 (crate::views::STYLESHEET_HREF, "text/css; charset=utf-8", ""),
@@ -422,7 +431,10 @@ mod tests {
422 #[tokio::test]431 #[tokio::test]
423 async fn alive_stream_sends_retry_first() {432 async fn alive_stream_sends_retry_first() {
424 use http_body_util::BodyExt;433 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();
426 let req = Request::builder()438 let req = Request::builder()
427 .method("GET")439 .method("GET")
428 .uri("/-/alive")440 .uri("/-/alive")
@@ -447,7 +459,10 @@ mod tests {
447 459
448 #[tokio::test]460 #[tokio::test]
449 async fn offline_page_and_script_are_served_without_caching() {461 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();
451 for (uri, kind) in [466 for (uri, kind) in [
452 ("/assets/offline.html", "text/html"),467 ("/assets/offline.html", "text/html"),
453 ("/assets/offline.js", "text/javascript"),468 ("/assets/offline.js", "text/javascript"),
@@ -471,7 +486,10 @@ mod tests {
471 486
472 #[tokio::test]487 #[tokio::test]
473 async fn custom_css_keys_the_hue_choices_and_is_empty_without_one() {488 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();
475 let req = Request::builder()493 let req = Request::builder()
476 .method("GET")494 .method("GET")
477 .uri("/theme/custom.css?al=hue-215&ad=plum&bl=hue-7&bd=hue-360")495 .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 @@
7 7
8 use forge_core::{AuditAction, AuditEntry, AuditFilter, Store};8 use forge_core::{AuditAction, AuditEntry, AuditFilter, Store};
9 use topcoat::Result;9 use topcoat::Result;
10-use topcoat::context::{Cx, app_context};10+use topcoat::context::{Cx, context};
11 use topcoat::router::response::Response;11 use topcoat::router::response::Response;
12 use topcoat::router::{page, query_params, route};12 use topcoat::router::{page, query_params, route};
13 use topcoat::view::{View, component, view};13 use topcoat::view::{View, component, view};
@@ -84,7 +84,11 @@ impl Span {
84 fn from_query(query: &AuditQuery) -> Span {84 fn from_query(query: &AuditQuery) -> Span {
85 let clean = |v: &Option<String>| v.clone().unwrap_or_default().trim().to_owned();85 let clean = |v: &Option<String>| v.clone().unwrap_or_default().trim().to_owned();
86 let when = clean(&query.when);86 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+ };
88 let (from, to) = if when == "custom" {92 let (from, to) = if when == "custom" {
89 (clean(&query.from), clean(&query.to))93 (clean(&query.from), clean(&query.to))
90 } else {94 } else {
@@ -396,6 +400,7 @@ fn nav_for(
396 /// The search and the action filter, in one GET form to `action`.400 /// The search and the action filter, in one GET form to `action`.
397 #[component]401 #[component]
398 async fn log_tools(402 async fn log_tools(
403+ cx: &Cx,
399 lang: Lang,404 lang: Lang,
400 form_action: &str,405 form_action: &str,
401 finder: Finder,406 finder: Finder,
@@ -451,6 +456,7 @@ async fn log_tools(
451 /// The facts of one entry after its name: time, then whatever `show` asks for.456 /// The facts of one entry after its name: time, then whatever `show` asks for.
452 #[component]457 #[component]
453 async fn entry_facts(458 async fn entry_facts(
459+ cx: &Cx,
454 lang: Lang,460 lang: Lang,
455 row: RowView,461 row: RowView,
456 show_actor: bool,462 show_actor: bool,
@@ -477,7 +483,12 @@ async fn entry_facts(
477 }483 }
478 484
479 #[component]485 #[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> {
481 Ok(view! {492 Ok(view! {
482 if groups.is_empty() {493 if groups.is_empty() {
483 <p class="state">(g::t(lang, K::NoEntries))</p>494 <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
495 506
496 /// One entry on its own line.507 /// One entry on its own line.
497 #[component]508 #[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> {
499 let row = group.rows.remove(0);510 let row = group.rows.remove(0);
500 let name = row.name.clone();511 let name = row.name.clone();
501 let action = row.action.clone();512 let action = row.action.clone();
@@ -510,10 +521,13 @@ async fn single_row(lang: Lang, mut group: Group, show_actor: bool) -> Result<im
510 /// A run of entries: one row with the count and what they share, which opens to list each one521 /// A run of entries: one row with the count and what they share, which opens to list each one
511 /// with what differs.522 /// with what differs.
512 #[component]523 #[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> {
514 let count = group.rows.len().to_string();525 let count = group.rows.len().to_string();
515 let target = group.shared_target().map(str::to_owned);526 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());
517 let details = group531 let details = group
518 .shared_details()532 .shared_details()
519 .map(str::to_owned)533 .map(str::to_owned)
@@ -568,6 +582,7 @@ async fn group_row(lang: Lang, mut group: Group, show_actor: bool) -> Result<imp
568 /// One entry inside an opened run: its time and what the run's row does not already say.582 /// One entry inside an opened run: its time and what the run's row does not already say.
569 #[component]583 #[component]
570 async fn item_line(584 async fn item_line(
585+ cx: &Cx,
571 lang: Lang,586 lang: Lang,
572 row: RowView,587 row: RowView,
573 show_target: bool,588 show_target: bool,
@@ -583,6 +598,7 @@ async fn item_line(
583 598
584 #[component]599 #[component]
585 async fn admin_audit_view(600 async fn admin_audit_view(
601+ cx: &Cx,
586 lang: Lang,602 lang: Lang,
587 live: String,603 live: String,
588 finder: Finder,604 finder: Finder,
@@ -612,6 +628,7 @@ async fn admin_audit_view(
612 628
613 #[component]629 #[component]
614 async fn own_log_view(630 async fn own_log_view(
631+ cx: &Cx,
615 lang: Lang,632 lang: Lang,
616 items: Vec<RailItem>,633 items: Vec<RailItem>,
617 finder: Finder,634 finder: Finder,
@@ -662,7 +679,7 @@ async fn admin_audit_page(cx: &Cx) -> Result<impl View> {
662 let viewer = admin_only(cx).await?;679 let viewer = admin_only(cx).await?;
663 let lang = i18n::lang(cx, Some(&viewer.0));680 let lang = i18n::lang(cx, Some(&viewer.0));
664 let query = query_params::<AuditQuery>(cx)?;681 let query = query_params::<AuditQuery>(cx)?;
665- let store = &app_context::<AppState>(cx).store;682+ let store = &context::<AppState>(cx).store;
666 let (finder, action, actor) = query_parts(query);683 let (finder, action, actor) = query_parts(query);
667 let span = Span::from_query(query);684 let span = Span::from_query(query);
668 685
@@ -734,7 +751,7 @@ async fn admin_audit_events(cx: &Cx) -> Result<Response> {
734 let query = query_params::<AuditQuery>(cx)?;751 let query = query_params::<AuditQuery>(cx)?;
735 let action = query.action.clone().unwrap_or_default().trim().to_owned();752 let action = query.action.clone().unwrap_or_default().trim().to_owned();
736 let actor = query.actor.clone().unwrap_or_default().trim().to_owned();753 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();
738 stream_changes(cx, crate::live::admin(), &[Topic::AdminAudit], move || {755 stream_changes(cx, crate::live::admin(), &[Topic::AdminAudit], move || {
739 let store = store.clone();756 let store = store.clone();
740 let action = action.clone();757 let action = action.clone();
@@ -749,7 +766,7 @@ async fn own_log_page(cx: &Cx) -> Result<impl View> {
749 let viewer = require_user(cx).await?;766 let viewer = require_user(cx).await?;
750 let lang = i18n::lang(cx, Some(&viewer.0));767 let lang = i18n::lang(cx, Some(&viewer.0));
751 let query = query_params::<AuditQuery>(cx)?;768 let query = query_params::<AuditQuery>(cx)?;
752- let store = &app_context::<AppState>(cx).store;769+ let store = &context::<AppState>(cx).store;
753 let (finder, action, _) = query_parts(query);770 let (finder, action, _) = query_parts(query);
754 let span = Span::from_query(query);771 let span = Span::from_query(query);
755 let mut filter = AuditFilter {772 let mut filter = AuditFilter {
@@ -768,7 +785,7 @@ async fn own_log_page(cx: &Cx) -> Result<impl View> {
768 let mut params = keep_params(&finder, &action, "");785 let mut params = keep_params(&finder, &action, "");
769 params.extend(span.params());786 params.extend(span.params());
770 let nav = nav_for(page, pages, "/settings/security/log", &params);787 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?;
772 let title = g::t(lang, K::SecurityLogTitle);789 let title = g::t(lang, K::SecurityLogTitle);
773 Ok(view! {790 Ok(view! {
774 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))791 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;
16 use serde::Deserialize;16 use serde::Deserialize;
17 use serde_json::json;17 use serde_json::json;
18 use topcoat::Result;18 use topcoat::Result;
19-use topcoat::context::{Cx, app_context};19+use topcoat::context::{Cx, context};
20 use topcoat::router::content::Form;20 use topcoat::router::content::Form;
21 use topcoat::router::error::{bad_request, forbidden, not_found};21 use topcoat::router::error::{bad_request, forbidden, not_found};
22 use topcoat::router::request::{headers, uri};22 use topcoat::router::request::{headers, uri};
@@ -121,8 +121,8 @@ fn fail(status: StatusCode, message: &str) -> Response {
121 /// comment can attach), and the repo must not be archived.121 /// comment can attach), and the repo must not be archived.
122 #[route(POST "/{owner}/{repo}/attachments")]122 #[route(POST "/{owner}/{repo}/attachments")]
123 async fn upload(cx: &Cx, body: Body) -> Result<Response> {123 async fn upload(cx: &Cx, body: Body) -> Result<Response> {
124- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;124+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
125- let state = app_context::<AppState>(cx);125+ let state = context::<AppState>(cx);
126 if ctx.repo.archived {126 if ctx.repo.archived {
127 return Err(forbidden().into());127 return Err(forbidden().into());
128 }128 }
@@ -228,11 +228,11 @@ async fn upload(cx: &Cx, body: Body) -> Result<Response> {
228 /// Serves an attachment to anyone who can read its repo; everyone else gets 404.228 /// Serves an attachment to anyone who can read its repo; everyone else gets 404.
229 #[route(GET "/attachments/{id}/{name}")]229 #[route(GET "/attachments/{id}/{name}")]
230 async fn download(cx: &Cx) -> Result<Response> {230 async fn download(cx: &Cx) -> Result<Response> {
231- let state = app_context::<AppState>(cx);231+ let state = context::<AppState>(cx);
232- let Some(att) = state.store.attachment(path_param::<Id>(cx)).await? else {232+ let Some(att) = state.store.attachment(id(cx)).await? else {
233 return Err(not_found().into());233 return Err(not_found().into());
234 };234 };
235- if att.name != path_param::<Name>(cx) {235+ if att.name != name(cx) {
236 return Err(not_found().into());236 return Err(not_found().into());
237 }237 }
238 let Some(repo) = state.store.repo_by_id(&att.repo_id).await? else {238 let Some(repo) = state.store.repo_by_id(&att.repo_id).await? else {
@@ -289,8 +289,8 @@ async fn download(cx: &Cx) -> Result<Response> {
289 /// `kind=issue` lists issues and pull requests by number or title.289 /// `kind=issue` lists issues and pull requests by number or title.
290 #[route(GET "/{owner}/{repo}/suggest")]290 #[route(GET "/{owner}/{repo}/suggest")]
291 async fn suggest(cx: &Cx) -> Result<Response> {291 async fn suggest(cx: &Cx) -> Result<Response> {
292- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;292+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
293- let state = app_context::<AppState>(cx);293+ let state = context::<AppState>(cx);
294 if ctx.viewer.is_none() {294 if ctx.viewer.is_none() {
295 return Err(forbidden().into());295 return Err(forbidden().into());
296 }296 }
@@ -364,10 +364,10 @@ async fn pull_tasks(cx: &Cx, Form(form): Form<TaskForm>) -> Result<Response> {
364 }364 }
365 365
366 async fn toggle(cx: &Cx, kind: ItemKind, form: TaskForm) -> Result<Response> {366 async fn toggle(cx: &Cx, kind: ItemKind, form: TaskForm) -> Result<Response> {
367- let number = parse_number(path_param::<Number>(cx))?;367+ let number = parse_number(number(cx))?;
368- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;368+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
369 let (user, _) = require_csrf(cx, &form.csrf).await?;369 let (user, _) = require_csrf(cx, &form.csrf).await?;
370- let state = app_context::<AppState>(cx);370+ let state = context::<AppState>(cx);
371 let item = item_for(state, &ctx, kind, number).await?;371 let item = item_for(state, &ctx, kind, number).await?;
372 let Ok(index) = form.index.parse::<usize>() else {372 let Ok(index) = form.index.parse::<usize>() else {
373 return Err(bad_request("bad task index").into());373 return Err(bad_request("bad task index").into());
crates/forge-web/src/pages/avatars.rsmodified+6 -3
@@ -8,7 +8,7 @@ use http::header::{
8 };8 };
9 use sha2::{Digest, Sha256};9 use sha2::{Digest, Sha256};
10 use topcoat::Result;10 use topcoat::Result;
11-use topcoat::context::{Cx, app_context};11+use topcoat::context::{Cx, context};
12 use topcoat::router::request::headers;12 use topcoat::router::request::headers;
13 use topcoat::router::{path_param_segment, query_params, route};13 use topcoat::router::{path_param_segment, query_params, route};
14 14
@@ -96,7 +96,7 @@ async fn avatar(cx: &Cx) -> Result<(StatusCode, HeaderMap, Vec<u8>)> {
96 .get(IF_NONE_MATCH)96 .get(IF_NONE_MATCH)
97 .and_then(|v| v.to_str().ok())97 .and_then(|v| v.to_str().ok())
98 .map(str::to_owned);98 .map(str::to_owned);
99- let store = &app_context::<AppState>(cx).store;99+ let store = &context::<AppState>(cx).store;
100 100
101 let Some(user) = store.user_by_username(&name).await? else {101 let Some(user) = store.user_by_username(&name).await? else {
102 return Ok((102 return Ok((
@@ -155,7 +155,10 @@ mod tests {
155 assert_eq!(svg, super::default_svg("<"));155 assert_eq!(svg, super::default_svg("<"));
156 let url = super::default_data_url("<");156 let url = super::default_data_url("<");
157 assert!(url.starts_with("data:image/svg+xml,%3Csvg"), "{url}");157 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+ );
159 assert!(super::PALETTE.iter().any(|c| svg.contains(c)));162 assert!(super::PALETTE.iter().any(|c| svg.contains(c)));
160 }163 }
161 164
crates/forge-web/src/pages/banner.rsmodified+3 -3
@@ -11,7 +11,7 @@ use forge_core::config::BannerConfig;
11 use forge_core::token::hash_token;11 use forge_core::token::hash_token;
12 use serde::Deserialize;12 use serde::Deserialize;
13 use topcoat::Result;13 use topcoat::Result;
14-use topcoat::context::{Cx, app_context, try_app_context};14+use topcoat::context::{Cx, context, try_context};
15 use topcoat::cookie::{Cookie, Cookies, SameSite, cookies, time};15 use topcoat::cookie::{Cookie, Cookies, SameSite, cookies, time};
16 use topcoat::router::content::Form;16 use topcoat::router::content::Form;
17 use topcoat::router::error::{SeeOther, see_other};17 use topcoat::router::error::{SeeOther, see_other};
@@ -66,7 +66,7 @@ pub fn view_for(config: &BannerConfig, now: i64, dismissed: Option<&str>) -> Opt
66 /// The banner for this request, read from the live settings. `prefs` is a signed-in viewer's66 /// The banner for this request, read from the live settings. `prefs` is a signed-in viewer's
67 /// account preferences; without them the dismissal comes from the cookie.67 /// account preferences; without them the dismissal comes from the cookie.
68 pub fn current(cx: &Cx, prefs: Option<&HashMap<String, String>>) -> Option<BannerView> {68 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)?;
70 let live = state.live();70 let live = state.live();
71 if live.banner.message.trim().is_empty() {71 if live.banner.message.trim().is_empty() {
72 return None;72 return None;
@@ -90,7 +90,7 @@ struct DismissForm {
90 async fn dismiss(cx: &Cx, Form(form): Form<DismissForm>) -> Result<SeeOther> {90 async fn dismiss(cx: &Cx, Form(form): Form<DismissForm>) -> Result<SeeOther> {
91 let hash_ok = form.hash.len() == 16 && form.hash.bytes().all(|b| b.is_ascii_hexdigit());91 let hash_ok = form.hash.len() == 16 && form.hash.bytes().all(|b| b.is_ascii_hexdigit());
92 if hash_ok && let Some((user, _)) = current_user(cx).await? {92 if hash_ok && let Some((user, _)) = current_user(cx).await? {
93- app_context::<AppState>(cx)93+ context::<AppState>(cx)
94 .store94 .store
95 .set_user_pref(&user.id, BANNER_PREF, &form.hash)95 .set_user_pref(&user.id, BANNER_PREF, &form.hash)
96 .await?;96 .await?;
crates/forge-web/src/pages/blame.rsmodified+11 -8
@@ -7,7 +7,7 @@ use std::time::Duration;
7 use forge_git::blame::{Blame, blame};7 use forge_git::blame::{Blame, blame};
8 use forge_git::browse::EntryKind;8 use forge_git::browse::EntryKind;
9 use topcoat::Result;9 use topcoat::Result;
10-use topcoat::context::{Cx, app_context};10+use topcoat::context::{Cx, context};
11 use topcoat::router::error::not_found;11 use topcoat::router::error::not_found;
12 use topcoat::router::{page, path_param};12 use topcoat::router::{page, path_param};
13 use topcoat::view::{Unescaped, View, component, view};13 use topcoat::view::{Unescaped, View, component, view};
@@ -16,10 +16,10 @@ use crate::i18n::browse as b;
16 use crate::i18n::code::{self as g, K};16 use crate::i18n::code::{self as g, K};
17 use crate::i18n::{self, Lang};17 use crate::i18n::{self, Lang};
18 use crate::pages::blob::{Line, text_lines};18 use crate::pages::blob::{Line, text_lines};
19+use crate::pages::passkeys::s;
19 use crate::pages::ref_live;20 use crate::pages::ref_live;
20 use crate::pages::repo::repo_head;21 use crate::pages::repo::repo_head;
21 use crate::pages::repo_ctx::load_repo;22 use crate::pages::repo_ctx::load_repo;
22-use crate::pages::passkeys::s;
23 use crate::pages::tree::{MAX_BLOB_BYTES, read_file, resolve};23 use crate::pages::tree::{MAX_BLOB_BYTES, read_file, resolve};
24 use crate::render::emoji::emojify;24 use crate::render::emoji::emojify;
25 use crate::state::AppState;25 use crate::state::AppState;
@@ -103,7 +103,7 @@ fn build_rows(
103 }103 }
104 104
105 #[component]105 #[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> {
107 Ok(view! {107 Ok(view! {
108 <div class="file-view">108 <div class="file-view">
109 <table class="file-table blame-table">109 <table class="file-table blame-table">
@@ -141,12 +141,12 @@ async fn blame_table(rows: Vec<Row>, lang: Lang) -> Result<impl View> {
141 141
142 #[page("/{owner}/{repo}/blame/{*rest}")]142 #[page("/{owner}/{repo}/blame/{*rest}")]
143 async fn blame_page(cx: &Cx) -> Result<impl View> {143 async fn blame_page(cx: &Cx) -> Result<impl View> {
144- let owner = path_param::<Owner>(cx);144+ let owner = owner(cx);
145- let name = path_param::<Repo>(cx);145+ let name = repo(cx);
146- let rest = path_param::<Rest>(cx).collect::<Vec<_>>().join("/");146+ let rest = rest(cx).collect::<Vec<_>>().join("/");
147 147
148 let ctx = load_repo(cx, owner, name).await?;148 let ctx = load_repo(cx, owner, name).await?;
149- let state = app_context::<AppState>(cx);149+ let state = context::<AppState>(cx);
150 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));150 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
151 let repo = &ctx.repo;151 let repo = &ctx.repo;
152 152
@@ -199,7 +199,10 @@ async fn blame_page(cx: &Cx) -> Result<impl View> {
199 );199 );
200 // Blame sits beside the file's source: a markdown file's plain view, any other file's own page.200 // Blame sits beside the file's source: a markdown file's plain view, any other file's own page.
201 let markdown = matches!(201 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(),
203 Some("md" | "markdown")206 Some("md" | "markdown")
204 );207 );
205 let source_href = if markdown {208 let source_href = if markdown {
crates/forge-web/src/pages/blob.rsmodified+11 -7
@@ -4,7 +4,7 @@
4 4
5 use forge_git::browse::EntryKind;5 use forge_git::browse::EntryKind;
6 use topcoat::Result;6 use topcoat::Result;
7-use topcoat::context::{Cx, app_context};7+use topcoat::context::{Cx, context};
8 use topcoat::router::error::not_found;8 use topcoat::router::error::not_found;
9 use topcoat::router::{page, path_param, query_params};9 use topcoat::router::{page, path_param, query_params};
10 use topcoat::view::{Unescaped, View, component, view};10 use topcoat::view::{Unescaped, View, component, view};
@@ -91,7 +91,7 @@ pub fn text_lines(text: &str, file_name: &str) -> Vec<Line> {
91 }91 }
92 92
93 #[component]93 #[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> {
95 Ok(view! {95 Ok(view! {
96 <div class="file-view">96 <div class="file-view">
97 <table class="file-table">97 <table class="file-table">
@@ -116,13 +116,13 @@ async fn file_table(lines: Vec<Line>) -> Result<impl View> {
116 116
117 #[page("/{owner}/{repo}/blob/{*rest}")]117 #[page("/{owner}/{repo}/blob/{*rest}")]
118 async fn blob_page(cx: &Cx) -> Result<impl View> {118 async fn blob_page(cx: &Cx) -> Result<impl View> {
119- let owner = path_param::<Owner>(cx);119+ let owner = owner(cx);
120- let name = path_param::<Repo>(cx);120+ let name = repo(cx);
121- let rest = path_param::<Rest>(cx).collect::<Vec<_>>().join("/");121+ let rest = rest(cx).collect::<Vec<_>>().join("/");
122 let plain = query_params::<BlobQuery>(cx)?.plain.as_deref() == Some("1");122 let plain = query_params::<BlobQuery>(cx)?.plain.as_deref() == Some("1");
123 123
124 let ctx = load_repo(cx, owner, name).await?;124 let ctx = load_repo(cx, owner, name).await?;
125- let state = app_context::<AppState>(cx);125+ let state = context::<AppState>(cx);
126 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));126 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
127 let repo = &ctx.repo;127 let repo = &ctx.repo;
128 128
@@ -262,7 +262,11 @@ async fn blob_page(cx: &Cx) -> Result<impl View> {
262 let mut views: Vec<(&'static str, String, bool)> = Vec::new();262 let mut views: Vec<(&'static str, String, bool)> = Vec::new();
263 if is_markdown {263 if is_markdown {
264 views.push((g::t(lang, K::Rendered), base.clone(), !plain));264 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+ ));
266 } else if is_text {270 } else if is_text {
267 views.push((g::t(lang, K::SourceToggle), base.clone(), true));271 views.push((g::t(lang, K::SourceToggle), base.clone(), true));
268 }272 }
crates/forge-web/src/pages/branches.rsmodified+12 -10
@@ -9,7 +9,7 @@ use forge_git::branches;
9 use forge_git::browse::{self, RefKind};9 use forge_git::browse::{self, RefKind};
10 use serde::Deserialize;10 use serde::Deserialize;
11 use topcoat::Result;11 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};12+use topcoat::context::{Cx, context};
13 use topcoat::cookie::{Cookie, Cookies, SameSite, cookies};13 use topcoat::cookie::{Cookie, Cookies, SameSite, cookies};
14 use topcoat::router::content::Form;14 use topcoat::router::content::Form;
15 use topcoat::router::error::{SeeOther, forbidden, see_other};15 use topcoat::router::error::{SeeOther, forbidden, see_other};
@@ -102,6 +102,7 @@ struct BranchRow {
102 102
103 #[component]103 #[component]
104 async fn new_branch_form(104 async fn new_branch_form(
105+ cx: &Cx,
105 lang: Lang,106 lang: Lang,
106 action: String,107 action: String,
107 csrf: String,108 csrf: String,
@@ -134,6 +135,7 @@ async fn new_branch_form(
134 135
135 #[component]136 #[component]
136 async fn branch_table(137 async fn branch_table(
138+ cx: &Cx,
137 rows: Vec<BranchRow>,139 rows: Vec<BranchRow>,
138 lang: Lang,140 lang: Lang,
139 csrf: String,141 csrf: String,
@@ -175,10 +177,10 @@ async fn branch_table(
175 177
176 #[page("/{owner}/{repo}/branches")]178 #[page("/{owner}/{repo}/branches")]
177 async fn branches_page(cx: &Cx) -> Result<impl View> {179 async fn branches_page(cx: &Cx) -> Result<impl View> {
178- let owner = path_param::<Owner>(cx);180+ let owner = owner(cx);
179- let name = path_param::<Repo>(cx);181+ let name = repo(cx);
180 let ctx = load_repo(cx, owner, name).await?;182 let ctx = load_repo(cx, owner, name).await?;
181- let state = app_context::<AppState>(cx);183+ let state = context::<AppState>(cx);
182 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));184 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
183 let repo = &ctx.repo;185 let repo = &ctx.repo;
184 let now = now_unix();186 let now = now_unix();
@@ -322,14 +324,14 @@ fn back(cx: &Cx, ctx: &RepoCtx, word: &'static str) -> SeeOther {
322 /// A protection rule that only accepts pull requests keeps the name closed to direct creation.324 /// A protection rule that only accepts pull requests keeps the name closed to direct creation.
323 #[route(POST "/{owner}/{repo}/branches")]325 #[route(POST "/{owner}/{repo}/branches")]
324 async fn branch_create(cx: &Cx, Form(form): Form<CreateForm>) -> Result<SeeOther> {326 async fn branch_create(cx: &Cx, Form(form): Form<CreateForm>) -> Result<SeeOther> {
325- let owner = path_param::<Owner>(cx);327+ let owner = owner(cx);
326- let name = path_param::<Repo>(cx);328+ let name = repo(cx);
327 let ctx = load_repo(cx, owner, name).await?;329 let ctx = load_repo(cx, owner, name).await?;
328 let (user, _) = require_csrf(cx, &form.csrf).await?;330 let (user, _) = require_csrf(cx, &form.csrf).await?;
329 if !ctx.can_write() {331 if !ctx.can_write() {
330 return Err(forbidden().into());332 return Err(forbidden().into());
331 }333 }
332- let state = app_context::<AppState>(cx);334+ let state = context::<AppState>(cx);
333 let branch = form.name.trim().to_owned();335 let branch = form.name.trim().to_owned();
334 let from = match form.from.trim() {336 let from = match form.from.trim() {
335 "" => ctx.repo.default_branch.clone(),337 "" => ctx.repo.default_branch.clone(),
@@ -382,14 +384,14 @@ async fn branch_create(cx: &Cx, Form(form): Form<CreateForm>) -> Result<SeeOther
382 /// branches whose protection forbids deletion are refused.384 /// branches whose protection forbids deletion are refused.
383 #[route(POST "/{owner}/{repo}/branches/delete")]385 #[route(POST "/{owner}/{repo}/branches/delete")]
384 async fn branch_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther> {386 async fn branch_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther> {
385- let owner = path_param::<Owner>(cx);387+ let owner = owner(cx);
386- let name = path_param::<Repo>(cx);388+ let name = repo(cx);
387 let ctx = load_repo(cx, owner, name).await?;389 let ctx = load_repo(cx, owner, name).await?;
388 let (user, _) = require_csrf(cx, &form.csrf).await?;390 let (user, _) = require_csrf(cx, &form.csrf).await?;
389 if !ctx.can_write() {391 if !ctx.can_write() {
390 return Err(forbidden().into());392 return Err(forbidden().into());
391 }393 }
392- let state = app_context::<AppState>(cx);394+ let state = context::<AppState>(cx);
393 let branch = form.name.trim().to_owned();395 let branch = form.name.trim().to_owned();
394 if branch == ctx.repo.default_branch {396 if branch == ctx.repo.default_branch {
395 return Ok(back(cx, &ctx, "default"));397 return Ok(back(cx, &ctx, "default"));
crates/forge-web/src/pages/ci_badge.rsmodified+4 -4
@@ -11,7 +11,7 @@
11 use forge_core::ci::{JobState, RunState};11 use forge_core::ci::{JobState, RunState};
12 use http::header::{CACHE_CONTROL, CONTENT_TYPE};12 use http::header::{CACHE_CONTROL, CONTENT_TYPE};
13 use topcoat::Result;13 use topcoat::Result;
14-use topcoat::context::{Cx, app_context};14+use topcoat::context::{Cx, context};
15 use topcoat::router::request::uri;15 use topcoat::router::request::uri;
16 use topcoat::router::response::Response;16 use topcoat::router::response::Response;
17 use topcoat::router::{Body, HeaderValue, StatusCode, path_param, route};17 use topcoat::router::{Body, HeaderValue, StatusCode, path_param, route};
@@ -205,10 +205,10 @@ fn badge_query(cx: &Cx) -> BadgeQuery {
205 /// uses, so a private repo the viewer cannot read is a 404.205 /// uses, so a private repo the viewer cannot read is a 404.
206 #[route(GET "/{owner}/{repo}/badge.svg")]206 #[route(GET "/{owner}/{repo}/badge.svg")]
207 async fn ci_badge(cx: &Cx) -> Result<Response> {207 async fn ci_badge(cx: &Cx) -> Result<Response> {
208- let owner = path_param::<Owner>(cx);208+ let owner = owner(cx);
209- let name = path_param::<Repo>(cx);209+ let name = repo(cx);
210 let ctx = load_repo(cx, owner, name).await?;210 let ctx = load_repo(cx, owner, name).await?;
211- let state = app_context::<AppState>(cx);211+ let state = context::<AppState>(cx);
212 let query = badge_query(cx);212 let query = badge_query(cx);
213 let branch = query213 let branch = query
214 .branch214 .branch
crates/forge-web/src/pages/ci_fail.rsmodified+15 -8
@@ -3,6 +3,7 @@
3 //! not stored, so the failed job is the unit. The log is untrusted: its lines are rendered as text.3 //! not stored, so the failed job is the unit. The log is untrusted: its lines are rendered as text.
4 4
5 use topcoat::Result;5 use topcoat::Result;
6+use topcoat::context::Cx;
6 use topcoat::view::{View, component, view};7 use topcoat::view::{View, component, view};
7 8
8 use crate::ci::log_path;9 use crate::ci::log_path;
@@ -59,14 +60,20 @@ impl FailFirst {
59 /// The `file:line` in a compiler's or test's lines around an error: the first word that ends in60 /// The `file:line` in a compiler's or test's lines around an error: the first word that ends in
60 /// digits after a colon and holds a dot.61 /// digits after a colon and holds a dot.
61 fn place_in(lines: &[String]) -> Option<String> {62 fn place_in(lines: &[String]) -> Option<String> {
62- lines.iter().flat_map(|line| line.split_whitespace()).find_map(|word| {63+ lines
63- let word = word.trim_matches(|c: char| matches!(c, '(' | ')' | ','));64+ .iter()
64- let mut parts = word.split(':');65+ .flat_map(|line| line.split_whitespace())
65- let file = parts.next()?;66+ .find_map(|word| {
66- let line = parts.next()?;67+ let word = word.trim_matches(|c: char| matches!(c, '(' | ')' | ','));
67- (file.contains('.') && !file.contains("::") && !line.is_empty() && line.bytes().all(|b| b.is_ascii_digit()))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()))
68 .then(|| format!("{}:{line}", file.rsplit('/').next().unwrap_or(file)))75 .then(|| format!("{}:{line}", file.rsplit('/').next().unwrap_or(file)))
69- })76+ })
70 }77 }
71 78
72 /// Reads the failed job's log tail (the same bounded read as the job page) and picks the lines to show.79 /// 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(
108 /// The failure row, pinned above the log, which opens at the first error line: why it failed, the115 /// The failure row, pinned above the log, which opens at the first error line: why it failed, the
109 /// place in the code, and a link to that line in the job's log.116 /// place in the code, and a link to that line in the job's log.
110 #[component]117 #[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> {
112 let line_href = fail.line_no.map(|no| format!("{}#L{no}", fail.job_href));119 let line_href = fail.line_no.map(|no| format!("{}#L{no}", fail.job_href));
113 let why = if fail.message.is_empty() {120 let why = if fail.message.is_empty() {
114 fail.error.clone().unwrap_or_else(|| fail.job_name.clone())121 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;
21 use tokio::io::{AsyncReadExt, AsyncSeekExt, SeekFrom};21 use tokio::io::{AsyncReadExt, AsyncSeekExt, SeekFrom};
22 use tokio::sync::watch;22 use tokio::sync::watch;
23 use topcoat::Result;23 use topcoat::Result;
24-use topcoat::context::{Cx, app_context};24+use topcoat::context::{Cx, context};
25 use topcoat::router::content::sse::{Event, last_event_id};25 use topcoat::router::content::sse::{Event, last_event_id};
26 use topcoat::router::error::not_found;26 use topcoat::router::error::not_found;
27 use topcoat::router::request::uri;27 use topcoat::router::request::uri;
@@ -419,6 +419,7 @@ async fn job_fingerprint_now(store: &Store, job_id: &str) -> Result<Option<Strin
419 /// follows its artifacts and log too. The log tail carries the offset its text ends at.419 /// follows its artifacts and log too. The log tail carries the offset its text ends at.
420 #[component]420 #[component]
421 async fn job_body(421 async fn job_body(
422+ cx: &Cx,
422 head: RepoHead,423 head: RepoHead,
423 lang: Lang,424 lang: Lang,
424 job: JobView,425 job: JobView,
@@ -521,12 +522,12 @@ async fn job_body(
521 /// One job: its state, the last 512 KiB of its log and its artifacts.522 /// One job: its state, the last 512 KiB of its log and its artifacts.
522 #[page("/{owner}/{repo}/ci/jobs/{job_id}")]523 #[page("/{owner}/{repo}/ci/jobs/{job_id}")]
523 async fn job_page(cx: &Cx) -> Result<impl View> {524 async fn job_page(cx: &Cx) -> Result<impl View> {
524- let owner = path_param::<Owner>(cx);525+ let owner = owner(cx);
525- let name = path_param::<Repo>(cx);526+ let name = repo(cx);
526- let id = path_param::<JobId>(cx).to_owned();527+ let id = job_id(cx).to_owned();
527 let ctx = load_repo(cx, owner, name).await?;528 let ctx = load_repo(cx, owner, name).await?;
528 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));529 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);
530 let (job, run) = job_of(state, &ctx, &id).await?;531 let (job, run) = job_of(state, &ctx, &id).await?;
531 let Tail {532 let Tail {
532 text: log,533 text: log,
@@ -633,11 +634,11 @@ const LOG_EVENT_BYTES: u64 = 64 * 1024;
633 /// this job (see `CiLive`), so a finished page still hears about deleted artifacts or logs.634 /// this job (see `CiLive`), so a finished page still hears about deleted artifacts or logs.
634 #[route(GET "/{owner}/{repo}/ci/jobs/{job_id}/events")]635 #[route(GET "/{owner}/{repo}/ci/jobs/{job_id}/events")]
635 async fn job_events(cx: &Cx) -> Result<Response> {636 async fn job_events(cx: &Cx) -> Result<Response> {
636- let owner = path_param::<Owner>(cx);637+ let owner = owner(cx);
637- let name = path_param::<Repo>(cx);638+ let name = repo(cx);
638- let id = path_param::<JobId>(cx).to_owned();639+ let id = job_id(cx).to_owned();
639 let ctx = load_repo(cx, owner, name).await?;640 let ctx = load_repo(cx, owner, name).await?;
640- let state = app_context::<AppState>(cx);641+ let state = context::<AppState>(cx);
641 let (job, _) = job_of(state, &ctx, &id).await?;642 let (job, _) = job_of(state, &ctx, &id).await?;
642 let offset = last_event_id(cx)643 let offset = last_event_id(cx)
643 .and_then(|id| id.parse::<u64>().ok())644 .and_then(|id| id.parse::<u64>().ok())
@@ -797,11 +798,11 @@ async fn read_log(
797 /// is terminal.798 /// is terminal.
798 #[route(GET "/{owner}/{repo}/ci/jobs/{job_id}/log.txt")]799 #[route(GET "/{owner}/{repo}/ci/jobs/{job_id}/log.txt")]
799 async fn job_log(cx: &Cx) -> Result<Response> {800 async fn job_log(cx: &Cx) -> Result<Response> {
800- let owner = path_param::<Owner>(cx);801+ let owner = owner(cx);
801- let name = path_param::<Repo>(cx);802+ let name = repo(cx);
802- let id = path_param::<JobId>(cx).to_owned();803+ let id = job_id(cx).to_owned();
803 let ctx = load_repo(cx, owner, name).await?;804 let ctx = load_repo(cx, owner, name).await?;
804- let state = app_context::<AppState>(cx);805+ let state = context::<AppState>(cx);
805 let (job, _) = job_of(state, &ctx, &id).await?;806 let (job, _) = job_of(state, &ctx, &id).await?;
806 let path = log_path(&state.config.data_dir, &job.id);807 let path = log_path(&state.config.data_dir, &job.id);
807 let chunks = follow_log(808 let chunks = follow_log(
@@ -834,12 +835,12 @@ async fn job_log(cx: &Cx) -> Result<Response> {
834 /// Downloads an artifact of a job as an attachment.835 /// Downloads an artifact of a job as an attachment.
835 #[route(GET "/{owner}/{repo}/ci/jobs/{job_id}/artifacts/{artifact_name}")]836 #[route(GET "/{owner}/{repo}/ci/jobs/{job_id}/artifacts/{artifact_name}")]
836 async fn artifact_download(cx: &Cx) -> Result<Response> {837 async fn artifact_download(cx: &Cx) -> Result<Response> {
837- let owner = path_param::<Owner>(cx);838+ let owner = owner(cx);
838- let name = path_param::<Repo>(cx);839+ let name = repo(cx);
839- let id = path_param::<JobId>(cx).to_owned();840+ let id = job_id(cx).to_owned();
840- let file_name = path_param::<ArtifactName>(cx).to_owned();841+ let file_name = artifact_name(cx).to_owned();
841 let ctx = load_repo(cx, owner, name).await?;842 let ctx = load_repo(cx, owner, name).await?;
842- let state = app_context::<AppState>(cx);843+ let state = context::<AppState>(cx);
843 let (job, _) = job_of(state, &ctx, &id).await?;844 let (job, _) = job_of(state, &ctx, &id).await?;
844 let Some(artifact) = state.store.artifact(&job.id, &file_name).await? else {845 let Some(artifact) = state.store.artifact(&job.id, &file_name).await? else {
845 return Err(not_found().into());846 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;
23 use tokio::io::{AsyncReadExt, AsyncSeekExt, SeekFrom};23 use tokio::io::{AsyncReadExt, AsyncSeekExt, SeekFrom};
24 use tokio::sync::watch;24 use tokio::sync::watch;
25 use topcoat::Result;25 use topcoat::Result;
26-use topcoat::context::{Cx, app_context};26+use topcoat::context::{Cx, context};
27 use topcoat::router::content::Form;27 use topcoat::router::content::Form;
28 use topcoat::router::content::sse::{Event, KeepAlive, Sse};28 use topcoat::router::content::sse::{Event, KeepAlive, Sse};
29 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};29 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
@@ -1408,7 +1408,10 @@ fn job_steps(
1408 })1408 })
1409 })1409 })
1410 .collect();1410 .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();
1412 for (step, elapsed) in steps.iter().zip(elapsed_of) {1415 for (step, elapsed) in steps.iter().zip(elapsed_of) {
1413 let state = step.state(job.state);1416 let state = step.state(job.state);
1414 let running = state == StepState::Running;1417 let running = state == StepState::Running;
@@ -1593,6 +1596,7 @@ async fn usernames(
1593 /// A small form that POSTs the CSRF token to `action`, with one button.1596 /// A small form that POSTs the CSRF token to `action`, with one button.
1594 #[component]1597 #[component]
1595 async fn action_button(1598 async fn action_button(
1599+ cx: &Cx,
1596 action: String,1600 action: String,
1597 csrf: String,1601 csrf: String,
1598 label: &'static str,1602 label: &'static str,
@@ -1628,11 +1632,11 @@ async fn runs_split(
1628 job: Option<&str>,1632 job: Option<&str>,
1629 step: Option<i64>,1633 step: Option<i64>,
1630 ) -> Result<SplitPage> {1634 ) -> Result<SplitPage> {
1631- let owner = path_param::<Owner>(cx);1635+ let owner = owner(cx);
1632- let name = path_param::<Repo>(cx);1636+ let name = repo(cx);
1633 let ctx = load_repo(cx, owner, name).await?;1637 let ctx = load_repo(cx, owner, name).await?;
1634 let lang = i18n::lang(cx, viewer_user(&ctx));1638 let lang = i18n::lang(cx, viewer_user(&ctx));
1635- let state = app_context::<AppState>(cx);1639+ let state = context::<AppState>(cx);
1636 let title = title_of(&ctx);1640 let title = title_of(&ctx);
1637 let base = ci_href(&title);1641 let base = ci_href(&title);
1638 let page = page_from_query(cx);1642 let page = page_from_query(cx);
@@ -1743,7 +1747,9 @@ async fn runs_split(
1743 },1747 },
1744 href: row_href(run.number),1748 href: row_href(run.number),
1745 // The list page alone draws no run, so it marks none.1749 // 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+ {
1747 "true"1753 "true"
1748 } else {1754 } else {
1749 "false"1755 "false"
@@ -1937,8 +1943,16 @@ async fn run_detail(
1937 } else {1943 } else {
1938 None1944 None
1939 };1945 };
1940- let gantt = (!jobs.is_empty())1946+ let gantt = (!jobs.is_empty()).then(|| {
1941- .then(|| gantt(&jobs, origin_of(run, now), run_end(run, now), now, lang, picked));1947+ gantt(
1948+ &jobs,
1949+ origin_of(run, now),
1950+ run_end(run, now),
1951+ now,
1952+ lang,
1953+ picked,
1954+ )
1955+ });
1942 let writer = header.writer_csrf.is_some();1956 let writer = header.writer_csrf.is_some();
1943 let rerunnable = writer && header.reachable;1957 let rerunnable = writer && header.reachable;
1944 let mut lines = Vec::with_capacity(jobs.len());1958 let mut lines = Vec::with_capacity(jobs.len());
@@ -2099,7 +2113,11 @@ async fn run_detail(
2099 .map_or(job.name.as_str(), |step| step.name.as_str())2113 .map_or(job.name.as_str(), |step| step.name.as_str())
2100 })2114 })
2101 },2115 },
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+ ),
2103 );2121 );
2104 Ok(RunDetail {2122 Ok(RunDetail {
2105 number: run.number,2123 number: run.number,
@@ -2181,7 +2199,7 @@ fn query_value(cx: &Cx, key: &str) -> Option<String> {
2181 2199
2182 /// The head's one action on the runs list: Run workflow, for a writer. Its form sits in its menu.2200 /// The head's one action on the runs list: Run workflow, for a writer. Its form sits in its menu.
2183 #[component]2201 #[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> {
2185 Ok(view! {2203 Ok(view! {
2186 if let Some(form) = list.manual.as_ref() {2204 if let Some(form) = list.manual.as_ref() {
2187 <details class="menu ci-tool">2205 <details class="menu ci-tool">
@@ -2208,7 +2226,7 @@ async fn ci_menus(lang: Lang, list: &ListView) -> Result<impl View> {
2208 /// The runs list: one sheet with its tools row, one line per run (each opens the run's page) and the2226 /// The runs list: one sheet with its tools row, one line per run (each opens the run's page) and the
2209 /// pager. The live list keeps its classes for the page script.2227 /// pager. The live list keeps its classes for the page script.
2210 #[component]2228 #[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> {
2212 let ListView {2230 let ListView {
2213 badge,2231 badge,
2214 total,2232 total,
@@ -2295,6 +2313,7 @@ async fn runs_sheet(lang: Lang, list: &ListView) -> Result<impl View> {
2295 /// 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.2313 /// 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.
2296 #[component]2314 #[component]
2297 async fn runs_body(2315 async fn runs_body(
2316+ cx: &Cx,
2298 head: RepoHead,2317 head: RepoHead,
2299 lang: Lang,2318 lang: Lang,
2300 notice: Option<(&'static str, bool)>,2319 notice: Option<(&'static str, bool)>,
@@ -2328,7 +2347,7 @@ async fn runs_body(
2328 /// line of each job, and its artifacts. The list route draws it on the right, and the run page draws it2347 /// line of each job, and its artifacts. The list route draws it on the right, and the run page draws it
2329 /// in its Timeline tab.2348 /// in its Timeline tab.
2330 #[component]2349 #[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> {
2332 Ok(view! {2351 Ok(view! {
2333 if let Some(g) = run.gantt.as_ref() {2352 if let Some(g) = run.gantt.as_ref() {
2334 <div class="ci-gantt-scroll">2353 <div class="ci-gantt-scroll">
@@ -2426,12 +2445,15 @@ async fn run_timeline(lang: Lang, run: &RunDetail) -> Result<impl View> {
2426 /// `all_href` adds the All2445 /// `all_href` adds the All
2427 /// runs link, which the run page needs; the list page has the runs beside it.2446 /// runs link, which the run page needs; the list page has the runs beside it.
2428 #[component]2447 #[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> {
2430 let cancel_action = format!("{}/cancel", run.action_base);2454 let cancel_action = format!("{}/cancel", run.action_base);
2431- let rerun_failed_shown = run.writer_csrf.is_some()2455+ let rerun_failed_shown =
2432- && run.can_rerun_failed2456+ run.writer_csrf.is_some() && run.can_rerun_failed && !run.can_approve && !run.can_cancel;
2433- && !run.can_approve
2434- && !run.can_cancel;
2435 Ok(view! {2457 Ok(view! {
2436 <section class="head">2458 <section class="head">
2437 <div class="head-title">2459 <div class="head-title">
@@ -2493,7 +2515,7 @@ async fn run_head(lang: Lang, run: &RunDetail, all_href: Option<String>) -> Resu
2493 /// The jobs of a run with more than one job: one `.job-row` each, its name, its tick and a mini strip2515 /// The jobs of a run with more than one job: one `.job-row` each, its name, its tick and a mini strip
2494 /// of its steps. The selected job's row is marked; its steps are the strip under the head.2516 /// of its steps. The selected job's row is marked; its steps are the strip under the head.
2495 #[component]2517 #[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> {
2497 Ok(view! {2519 Ok(view! {
2498 if run.jobs.len() > 1 {2520 if run.jobs.len() > 1 {
2499 <div class="jobs ci-tl-list">2521 <div class="jobs ci-tl-list">
@@ -2532,7 +2554,7 @@ async fn run_jobs(lang: Lang, run: &RunDetail) -> Result<impl View> {
2532 /// The steps of the selected job, one `.seg` each: a step's name, its time and its state. A step the2554 /// The steps of the selected job, one `.seg` each: a step's name, its time and its state. A step the
2533 /// URL picks is marked, and a step with its log opens that part of the log.2555 /// URL picks is marked, and a step with its log opens that part of the log.
2534 #[component]2556 #[component]
2535-async fn run_strip(run: &RunDetail) -> Result<impl View> {2557+async fn run_strip(cx: &Cx, run: &RunDetail) -> Result<impl View> {
2536 let job = run.jobs.iter().find(|job| job.selected);2558 let job = run.jobs.iter().find(|job| job.selected);
2537 Ok(view! {2559 Ok(view! {
2538 if let Some(job) = job {2560 if let Some(job) = job {
@@ -2567,7 +2589,7 @@ async fn run_strip(run: &RunDetail) -> Result<impl View> {
2567 2589
2568 /// The run's artifacts: the zip of all of them and one download line each.2590 /// The run's artifacts: the zip of all of them and one download line each.
2569 #[component]2591 #[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> {
2571 Ok(view! {2593 Ok(view! {
2572 if !run.artifacts.is_empty() {2594 if !run.artifacts.is_empty() {
2573 <div class="sec">2595 <div class="sec">
@@ -2592,6 +2614,7 @@ async fn run_artifacts(lang: Lang, run: &RunDetail) -> Result<impl View> {
2592 /// log on `--bg` (or the config errors and the fail-first block above it). The timeline is the other tab.2614 /// log on `--bg` (or the config errors and the fail-first block above it). The timeline is the other tab.
2593 #[component]2615 #[component]
2594 async fn run_log(2616 async fn run_log(
2617+ cx: &Cx,
2595 lang: Lang,2618 lang: Lang,
2596 run: &RunDetail,2619 run: &RunDetail,
2597 timeline: bool,2620 timeline: bool,
@@ -2681,6 +2704,7 @@ async fn run_log(
2681 /// history. The live region wraps all of it, so the page re-renders when a run or a job changes.2704 /// history. The live region wraps all of it, so the page re-renders when a run or a job changes.
2682 #[component]2705 #[component]
2683 async fn run_body(2706 async fn run_body(
2707+ cx: &Cx,
2684 head: RepoHead,2708 head: RepoHead,
2685 lang: Lang,2709 lang: Lang,
2686 notice: Option<(&'static str, bool)>,2710 notice: Option<(&'static str, bool)>,
@@ -2745,7 +2769,7 @@ async fn runs_list_page(cx: &Cx) -> Result<impl View> {
2745 /// A run that is not on the list page is still shown.2769 /// A run that is not on the list page is still shown.
2746 #[page("/{owner}/{repo}/ci/runs/{run_number}")]2770 #[page("/{owner}/{repo}/ci/runs/{run_number}")]
2747 async fn run_page(cx: &Cx) -> Result<impl View> {2771 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();
2749 let wanted = job_from_query(cx);2773 let wanted = job_from_query(cx);
2750 let wanted_step = step_from_query(cx);2774 let wanted_step = step_from_query(cx);
2751 let SplitPage {2775 let SplitPage {
@@ -2761,7 +2785,7 @@ async fn run_page(cx: &Cx) -> Result<impl View> {
2761 let Some(run) = detail else {2785 let Some(run) = detail else {
2762 return Err(not_found().into());2786 return Err(not_found().into());
2763 };2787 };
2764- let state = app_context::<AppState>(cx);2788+ let state = context::<AppState>(cx);
2765 let bars = dock_bars(state, &ctx).await;2789 let bars = dock_bars(state, &ctx).await;
2766 let owner = ctx.repo.owner_name.clone();2790 let owner = ctx.repo.owner_name.clone();
2767 let repo = ctx.repo.name.clone();2791 let repo = ctx.repo.name.clone();
@@ -2798,10 +2822,10 @@ pub(crate) async fn dock_bars(state: &AppState, ctx: &RepoCtx) -> Vec<StripBar>
2798 /// created or changed state. Nothing is sent on connect, since the page was just rendered.2822 /// created or changed state. Nothing is sent on connect, since the page was just rendered.
2799 #[route(GET "/{owner}/{repo}/ci/events")]2823 #[route(GET "/{owner}/{repo}/ci/events")]
2800 async fn runs_events(cx: &Cx) -> Result<Response> {2824 async fn runs_events(cx: &Cx) -> Result<Response> {
2801- let owner = path_param::<Owner>(cx);2825+ let owner = owner(cx);
2802- let name = path_param::<Repo>(cx);2826+ let name = repo(cx);
2803 let ctx = load_repo(cx, owner, name).await?;2827 let ctx = load_repo(cx, owner, name).await?;
2804- let state = app_context::<AppState>(cx);2828+ let state = context::<AppState>(cx);
2805 // Subscribed before the response is sent, so a change after this point is sent.2829 // Subscribed before the response is sent, so a change after this point is sent.
2806 let wake = state.ci_live.subscribe_repo(&ctx.repo.id);2830 let wake = state.ci_live.subscribe_repo(&ctx.repo.id);
2807 events_response(cx, repo_changes(wake))2831 events_response(cx, repo_changes(wake))
@@ -2810,12 +2834,12 @@ async fn runs_events(cx: &Cx) -> Result<Response> {
2810 /// Starts a manual run on a branch. Writers only. The branch must be one of the repo's branches.2834 /// Starts a manual run on a branch. Writers only. The branch must be one of the repo's branches.
2811 #[route(POST "/{owner}/{repo}/ci")]2835 #[route(POST "/{owner}/{repo}/ci")]
2812 async fn manual_run_post(cx: &Cx, Form(form): Form<ManualForm>) -> Result<SeeOther> {2836 async fn manual_run_post(cx: &Cx, Form(form): Form<ManualForm>) -> Result<SeeOther> {
2813- let owner = path_param::<Owner>(cx);2837+ let owner = owner(cx);
2814- let name = path_param::<Repo>(cx);2838+ let name = repo(cx);
2815 let ctx = load_repo(cx, owner, name).await?;2839 let ctx = load_repo(cx, owner, name).await?;
2816 let (user, _) = require_csrf(cx, &form.csrf).await?;2840 let (user, _) = require_csrf(cx, &form.csrf).await?;
2817 require_write(&ctx)?;2841 require_write(&ctx)?;
2818- let state = app_context::<AppState>(cx);2842+ let state = context::<AppState>(cx);
2819 let title = title_of(&ctx);2843 let title = title_of(&ctx);
2820 let branch = form.branch.trim();2844 let branch = form.branch.trim();
2821 let refs = load_refs(ctx.path.clone()).await?;2845 let refs = load_refs(ctx.path.clone()).await?;
@@ -2948,7 +2972,7 @@ impl StreamSlot {
2948 /// A slot for this request's client, or `None` when a cap is reached. Without the app state2972 /// A slot for this request's client, or `None` when a cap is reached. Without the app state
2949 /// (unit tests of a bare router) nothing is counted.2973 /// (unit tests of a bare router) nothing is counted.
2950 fn take(cx: &Cx) -> Option<StreamSlot> {2974 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() {
2952 return Some(StreamSlot { ip: None });2976 return Some(StreamSlot { ip: None });
2953 }2977 }
2954 let ip = crate::client_ip::client_ip(cx);2978 let ip = crate::client_ip::client_ip(cx);
@@ -3023,11 +3047,11 @@ pub(crate) fn events_response(
3023 /// or to one of its jobs, so the page can render its rows again.3047 /// or to one of its jobs, so the page can render its rows again.
3024 #[route(GET "/{owner}/{repo}/ci/runs/{run_number}/events")]3048 #[route(GET "/{owner}/{repo}/ci/runs/{run_number}/events")]
3025 async fn run_events(cx: &Cx) -> Result<Response> {3049 async fn run_events(cx: &Cx) -> Result<Response> {
3026- let owner = path_param::<Owner>(cx);3050+ let owner = owner(cx);
3027- let name = path_param::<Repo>(cx);3051+ let name = repo(cx);
3028- let number = path_param::<RunNumber>(cx).to_owned();3052+ let number = run_number(cx).to_owned();
3029 let ctx = load_repo(cx, owner, name).await?;3053 let ctx = load_repo(cx, owner, name).await?;
3030- let state = app_context::<AppState>(cx);3054+ let state = context::<AppState>(cx);
3031 let run = run_of(state, &ctx, &number).await?;3055 let run = run_of(state, &ctx, &number).await?;
3032 // Subscribed before the status is read, so a change in between is sent.3056 // Subscribed before the status is read, so a change in between is sent.
3033 let wake = state.ci_live.subscribe_run(&run.id);3057 let wake = state.ci_live.subscribe_run(&run.id);
@@ -3055,13 +3079,13 @@ async fn run_events(cx: &Cx) -> Result<Response> {
3055 /// get a cancel request that their runner sees on its next heartbeat.3079 /// get a cancel request that their runner sees on its next heartbeat.
3056 #[route(POST "/{owner}/{repo}/ci/runs/{run_number}/cancel")]3080 #[route(POST "/{owner}/{repo}/ci/runs/{run_number}/cancel")]
3057 async fn run_cancel(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {3081 async fn run_cancel(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
3058- let owner = path_param::<Owner>(cx);3082+ let owner = owner(cx);
3059- let name = path_param::<Repo>(cx);3083+ let name = repo(cx);
3060- let number = path_param::<RunNumber>(cx).to_owned();3084+ let number = run_number(cx).to_owned();
3061 let ctx = load_repo(cx, owner, name).await?;3085 let ctx = load_repo(cx, owner, name).await?;
3062 require_csrf(cx, &form.csrf).await?;3086 require_csrf(cx, &form.csrf).await?;
3063 require_write(&ctx)?;3087 require_write(&ctx)?;
3064- let state = app_context::<AppState>(cx);3088+ let state = context::<AppState>(cx);
3065 let run = run_of(state, &ctx, &number).await?;3089 let run = run_of(state, &ctx, &number).await?;
3066 let href = run_href(&title_of(&ctx), run.number);3090 let href = run_href(&title_of(&ctx), run.number);
3067 if run_finished(&run.state) {3091 if run_finished(&run.state) {
@@ -3076,13 +3100,13 @@ async fn run_cancel(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
3076 /// Approves a run that waits for approval: its jobs are queued. Anything else is refused.3100 /// Approves a run that waits for approval: its jobs are queued. Anything else is refused.
3077 #[route(POST "/{owner}/{repo}/ci/runs/{run_number}/approve")]3101 #[route(POST "/{owner}/{repo}/ci/runs/{run_number}/approve")]
3078 async fn run_approve(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {3102 async fn run_approve(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
3079- let owner = path_param::<Owner>(cx);3103+ let owner = owner(cx);
3080- let name = path_param::<Repo>(cx);3104+ let name = repo(cx);
3081- let number = path_param::<RunNumber>(cx).to_owned();3105+ let number = run_number(cx).to_owned();
3082 let ctx = load_repo(cx, owner, name).await?;3106 let ctx = load_repo(cx, owner, name).await?;
3083 require_csrf(cx, &form.csrf).await?;3107 require_csrf(cx, &form.csrf).await?;
3084 require_write(&ctx)?;3108 require_write(&ctx)?;
3085- let state = app_context::<AppState>(cx);3109+ let state = context::<AppState>(cx);
3086 let run = run_of(state, &ctx, &number).await?;3110 let run = run_of(state, &ctx, &number).await?;
3087 let href = run_href(&title_of(&ctx), run.number);3111 let href = run_href(&title_of(&ctx), run.number);
3088 if run.state != RunState::WaitingApproval {3112 if run.state != RunState::WaitingApproval {
@@ -3097,13 +3121,13 @@ async fn run_approve(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
3097 /// Starts a new run with the same commit, ref, trigger and job specs, then opens it.3121 /// Starts a new run with the same commit, ref, trigger and job specs, then opens it.
3098 #[route(POST "/{owner}/{repo}/ci/runs/{run_number}/rerun")]3122 #[route(POST "/{owner}/{repo}/ci/runs/{run_number}/rerun")]
3099 async fn run_rerun(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {3123 async fn run_rerun(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
3100- let owner = path_param::<Owner>(cx);3124+ let owner = owner(cx);
3101- let name = path_param::<Repo>(cx);3125+ let name = repo(cx);
3102- let number = path_param::<RunNumber>(cx).to_owned();3126+ let number = run_number(cx).to_owned();
3103 let ctx = load_repo(cx, owner, name).await?;3127 let ctx = load_repo(cx, owner, name).await?;
3104 let (user, _) = require_csrf(cx, &form.csrf).await?;3128 let (user, _) = require_csrf(cx, &form.csrf).await?;
3105 require_write(&ctx)?;3129 require_write(&ctx)?;
3106- let state = app_context::<AppState>(cx);3130+ let state = context::<AppState>(cx);
3107 let run = run_of(state, &ctx, &number).await?;3131 let run = run_of(state, &ctx, &number).await?;
3108 if !commit_reachable_for(&ctx.path, &run.commit_oid).await? {3132 if !commit_reachable_for(&ctx.path, &run.commit_oid).await? {
3109 return Ok(notice_redirect(3133 return Ok(notice_redirect(
@@ -3123,13 +3147,13 @@ async fn run_rerun(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
3123 /// jobs that depend on them. The specs are the originals.3147 /// jobs that depend on them. The specs are the originals.
3124 #[route(POST "/{owner}/{repo}/ci/runs/{run_number}/rerun-failed")]3148 #[route(POST "/{owner}/{repo}/ci/runs/{run_number}/rerun-failed")]
3125 async fn run_rerun_failed(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {3149 async fn run_rerun_failed(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
3126- let owner = path_param::<Owner>(cx);3150+ let owner = owner(cx);
3127- let name = path_param::<Repo>(cx);3151+ let name = repo(cx);
3128- let number = path_param::<RunNumber>(cx).to_owned();3152+ let number = run_number(cx).to_owned();
3129 let ctx = load_repo(cx, owner, name).await?;3153 let ctx = load_repo(cx, owner, name).await?;
3130 let (user, _) = require_csrf(cx, &form.csrf).await?;3154 let (user, _) = require_csrf(cx, &form.csrf).await?;
3131 require_write(&ctx)?;3155 require_write(&ctx)?;
3132- let state = app_context::<AppState>(cx);3156+ let state = context::<AppState>(cx);
3133 let run = run_of(state, &ctx, &number).await?;3157 let run = run_of(state, &ctx, &number).await?;
3134 let href = run_href(&title_of(&ctx), run.number);3158 let href = run_href(&title_of(&ctx), run.number);
3135 if !commit_reachable_for(&ctx.path, &run.commit_oid).await? {3159 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
3159 /// originals.3183 /// originals.
3160 #[route(POST "/{owner}/{repo}/ci/jobs/{job_id}/rerun")]3184 #[route(POST "/{owner}/{repo}/ci/jobs/{job_id}/rerun")]
3161 async fn job_rerun(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {3185 async fn job_rerun(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
3162- let owner = path_param::<Owner>(cx);3186+ let owner = owner(cx);
3163- let name = path_param::<Repo>(cx);3187+ let name = repo(cx);
3164- let id = path_param::<JobId>(cx).to_owned();3188+ let id = job_id(cx).to_owned();
3165 let ctx = load_repo(cx, owner, name).await?;3189 let ctx = load_repo(cx, owner, name).await?;
3166 let (user, _) = require_csrf(cx, &form.csrf).await?;3190 let (user, _) = require_csrf(cx, &form.csrf).await?;
3167 require_write(&ctx)?;3191 require_write(&ctx)?;
3168- let state = app_context::<AppState>(cx);3192+ let state = context::<AppState>(cx);
3169 let Some(job) = state.store.job_by_id(&id).await? else {3193 let Some(job) = state.store.job_by_id(&id).await? else {
3170 return Err(not_found().into());3194 return Err(not_found().into());
3171 };3195 };
@@ -3225,11 +3249,11 @@ fn zip_path(job: &str, artifact: &str) -> String {
3225 #[route(GET "/{owner}/{repo}/ci/runs/{run_number}/artifacts.zip")]3249 #[route(GET "/{owner}/{repo}/ci/runs/{run_number}/artifacts.zip")]
3226 async fn run_artifacts_zip(cx: &Cx) -> Result<Response> {3250 async fn run_artifacts_zip(cx: &Cx) -> Result<Response> {
3227 use futures_util::TryStreamExt;3251 use futures_util::TryStreamExt;
3228- let owner = path_param::<Owner>(cx);3252+ let owner = owner(cx);
3229- let name = path_param::<Repo>(cx);3253+ let name = repo(cx);
3230- let number = path_param::<RunNumber>(cx).to_owned();3254+ let number = run_number(cx).to_owned();
3231 let ctx = load_repo(cx, owner, name).await?;3255 let ctx = load_repo(cx, owner, name).await?;
3232- let state = app_context::<AppState>(cx);3256+ let state = context::<AppState>(cx);
3233 let run = run_of(state, &ctx, &number).await?;3257 let run = run_of(state, &ctx, &number).await?;
3234 let href = run_href(&title_of(&ctx), run.number);3258 let href = run_href(&title_of(&ctx), run.number);
3235 let mut entries = Vec::new();3259 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() {
261 let run = run_with(&fx, &["build"], false).await;261 let run = run_with(&fx, &["build"], false).await;
262 let run_url = format!("{RUN_BASE}/runs/{}", run.number);262 let run_url = format!("{RUN_BASE}/runs/{}", run.number);
263 let writer = get(&fx.app, &run_url, Some(&cookie_for("bob-token"))).await;263 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+ );
265 assert!(writer.text().contains(">Cancel<"), "writer sees cancel");268 assert!(writer.text().contains(">Cancel<"), "writer sees cancel");
266 let reader = get(&fx.app, &run_url, Some(&cookie_for("dave-token"))).await;269 let reader = get(&fx.app, &run_url, Some(&cookie_for("dave-token"))).await;
267 assert_eq!(reader.status, 200);270 assert_eq!(reader.status, 200);
crates/forge-web/src/pages/code_live.rsmodified+4 -4
@@ -16,7 +16,7 @@ use std::path::PathBuf;
16 use forge_core::{Repo as RepoRecord, User, Visibility};16 use forge_core::{Repo as RepoRecord, User, Visibility};
17 use forge_git::browse::{RefInfo, RefKind};17 use forge_git::browse::{RefInfo, RefKind};
18 use topcoat::Result;18 use topcoat::Result;
19-use topcoat::context::{Cx, app_context};19+use topcoat::context::{Cx, context};
20 use topcoat::router::response::Response;20 use topcoat::router::response::Response;
21 use topcoat::router::{path_param, query_params, route};21 use topcoat::router::{path_param, query_params, route};
22 22
@@ -161,13 +161,13 @@ async fn home_fingerprint(
161 /// repo gets the same 404 as the page.161 /// repo gets the same 404 as the page.
162 #[route(GET "/{owner}/{repo}/events")]162 #[route(GET "/{owner}/{repo}/events")]
163 async fn repo_events(cx: &Cx) -> Result<Response> {163 async fn repo_events(cx: &Cx) -> Result<Response> {
164- let owner = path_param::<Owner>(cx);164+ let owner = owner(cx);
165- let name = path_param::<Repo>(cx);165+ let name = repo(cx);
166 let query = query_params::<LiveQuery>(cx)?;166 let query = query_params::<LiveQuery>(cx)?;
167 let branch = query.ref_name.clone().unwrap_or_default();167 let branch = query.ref_name.clone().unwrap_or_default();
168 let home = query.home.as_deref() == Some("1");168 let home = query.home.as_deref() == Some("1");
169 let ctx = load_repo(cx, owner, name).await?;169 let ctx = load_repo(cx, owner, name).await?;
170- let state = app_context::<AppState>(cx).clone();170+ let state = context::<AppState>(cx).clone();
171 let repo_id = ctx.repo.id.clone();171 let repo_id = ctx.repo.id.clone();
172 let mut topics = vec![172 let mut topics = vec![
173 Topic::Repo(repo_id.clone()),173 Topic::Repo(repo_id.clone()),
crates/forge-web/src/pages/code_search.rsmodified+4 -4
@@ -6,7 +6,7 @@
6 use forge_git::browse;6 use forge_git::browse;
7 use forge_git::search::{GrepHit, GrepOptions, GrepResult, grep};7 use forge_git::search::{GrepHit, GrepOptions, GrepResult, grep};
8 use topcoat::Result;8 use topcoat::Result;
9-use topcoat::context::{Cx, app_context};9+use topcoat::context::{Cx, context};
10 use topcoat::router::error::not_found;10 use topcoat::router::error::not_found;
11 use topcoat::router::{page, path_param, query_params};11 use topcoat::router::{page, path_param, query_params};
12 use topcoat::view::{View, view};12 use topcoat::view::{View, view};
@@ -132,12 +132,12 @@ fn group_hits(
132 132
133 #[page("/{owner}/{repo}/search")]133 #[page("/{owner}/{repo}/search")]
134 async fn search_page(cx: &Cx) -> Result<impl View> {134 async fn search_page(cx: &Cx) -> Result<impl View> {
135- let owner = path_param::<Owner>(cx);135+ let owner = owner(cx);
136- let name = path_param::<Repo>(cx);136+ let name = repo(cx);
137 let query = query_params::<SearchQuery>(cx)?;137 let query = query_params::<SearchQuery>(cx)?;
138 138
139 let ctx = load_repo(cx, owner, name).await?;139 let ctx = load_repo(cx, owner, name).await?;
140- let state = app_context::<AppState>(cx);140+ let state = context::<AppState>(cx);
141 let repo_name = ctx.repo.name.clone();141 let repo_name = ctx.repo.name.clone();
142 let owner_name = ctx.repo.owner_name.clone();142 let owner_name = ctx.repo.owner_name.clone();
143 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));143 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;
5 use forge_git::history;5 use forge_git::history;
6 use forge_git::trailers;6 use forge_git::trailers;
7 use topcoat::Result;7 use topcoat::Result;
8-use topcoat::context::{Cx, app_context};8+use topcoat::context::{Cx, context};
9 use topcoat::router::error::{content_too_large, not_found};9 use topcoat::router::error::{content_too_large, not_found};
10 use topcoat::router::{page, path_param, route};10 use topcoat::router::{page, path_param, route};
11 use topcoat::view::{View, view};11 use topcoat::view::{View, view};
@@ -95,15 +95,15 @@ impl Download {
95 95
96 #[page("/{owner}/{repo}/commit/{oid}")]96 #[page("/{owner}/{repo}/commit/{oid}")]
97 async fn commit_page(cx: &Cx) -> Result<impl View> {97 async fn commit_page(cx: &Cx) -> Result<impl View> {
98- let owner = path_param::<Owner>(cx);98+ let owner = owner(cx);
99- let name = path_param::<Repo>(cx);99+ let name = repo(cx);
100- let (rev, download) = Download::split(path_param::<Oid>(cx));100+ let (rev, download) = Download::split(oid(cx));
101 if !is_hex_prefix(rev) {101 if !is_hex_prefix(rev) {
102 return Err(not_found().into());102 return Err(not_found().into());
103 }103 }
104 104
105 let ctx = load_repo(cx, owner, name).await?;105 let ctx = load_repo(cx, owner, name).await?;
106- let state = app_context::<AppState>(cx);106+ let state = context::<AppState>(cx);
107 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));107 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
108 108
109 let repo_dir = ctx.path.clone();109 let repo_dir = ctx.path.clone();
@@ -360,7 +360,7 @@ async fn commit_page(cx: &Cx) -> Result<impl View> {
360 360
361 /// Other methods on a commit path get a plain 404.361 /// Other methods on a commit path get a plain 404.
362 #[route(* "/{owner}/{repo}/commit/{oid}")]362 #[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> {
364 Err(not_found().into())364 Err(not_found().into())
365 }365 }
366 366
crates/forge-web/src/pages/commits.rsmodified+5 -5
@@ -11,7 +11,7 @@ use forge_git::browse::{self, CommitInfo};
11 use forge_git::history;11 use forge_git::history;
12 use jiff::{Timestamp, civil};12 use jiff::{Timestamp, civil};
13 use topcoat::Result;13 use topcoat::Result;
14-use topcoat::context::{Cx, app_context};14+use topcoat::context::{Cx, context};
15 use topcoat::router::error::{bad_request, not_found};15 use topcoat::router::error::{bad_request, not_found};
16 use topcoat::router::{page, path_param, query_params};16 use topcoat::router::{page, path_param, query_params};
17 use topcoat::view::{View, view};17 use topcoat::view::{View, view};
@@ -241,9 +241,9 @@ impl CommitRow {
241 241
242 #[page("/{owner}/{repo}/commits/{*rest}")]242 #[page("/{owner}/{repo}/commits/{*rest}")]
243 async fn commits_page(cx: &Cx) -> Result<impl View> {243 async fn commits_page(cx: &Cx) -> Result<impl View> {
244- let owner = path_param::<Owner>(cx);244+ let owner = owner(cx);
245- let name = path_param::<Repo>(cx);245+ let name = repo(cx);
246- let rest = path_param::<Rest>(cx).collect::<Vec<_>>().join("/");246+ let rest = rest(cx).collect::<Vec<_>>().join("/");
247 let query = query_params::<CommitsQuery>(cx)?;247 let query = query_params::<CommitsQuery>(cx)?;
248 let page_no = query.page.unwrap_or(1);248 let page_no = query.page.unwrap_or(1);
249 if !(1..=MAX_PAGE).contains(&page_no) {249 if !(1..=MAX_PAGE).contains(&page_no) {
@@ -251,7 +251,7 @@ async fn commits_page(cx: &Cx) -> Result<impl View> {
251 }251 }
252 252
253 let ctx = load_repo(cx, owner, name).await?;253 let ctx = load_repo(cx, owner, name).await?;
254- let state = app_context::<AppState>(cx);254+ let state = context::<AppState>(cx);
255 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));255 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
256 256
257 let repo_dir = ctx.path.clone();257 let repo_dir = ctx.path.clone();
crates/forge-web/src/pages/compare.rsmodified+14 -14
@@ -19,7 +19,7 @@ use forge_git::pulls;
19 use forge_git::repo::repo_path;19 use forge_git::repo::repo_path;
20 use serde::Deserialize;20 use serde::Deserialize;
21 use topcoat::Result;21 use topcoat::Result;
22-use topcoat::context::{Cx, app_context};22+use topcoat::context::{Cx, context};
23 use topcoat::router::content::Form;23 use topcoat::router::content::Form;
24 use topcoat::router::error::{bad_request, forbidden, not_found, see_other};24 use topcoat::router::error::{bad_request, forbidden, not_found, see_other};
25 use topcoat::router::{page, path_param, query_params};25 use topcoat::router::{page, path_param, query_params};
@@ -236,7 +236,7 @@ async fn compare_view(
236 draft: Option<(String, String)>,236 draft: Option<(String, String)>,
237 error: Option<String>,237 error: Option<String>,
238 ) -> Result<impl View> {238 ) -> Result<impl View> {
239- let state = app_context::<AppState>(cx);239+ let state = context::<AppState>(cx);
240 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));240 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
241 let owner = ctx.repo.owner_name.clone();241 let owner = ctx.repo.owner_name.clone();
242 let name = ctx.repo.name.clone();242 let name = ctx.repo.name.clone();
@@ -328,7 +328,7 @@ async fn compare_view(
328 328
329 let mut header = ctx.head(state, "commits").await?;329 let mut header = ctx.head(state, "commits").await?;
330 header.live = ref_live::live_url(&ctx.repo.owner_name, &ctx.repo.name);330 header.live = ref_live::live_url(&ctx.repo.owner_name, &ctx.repo.name);
331- let __cx = cx;331+ let cx = cx;
332 Ok(view! {332 Ok(view! {
333 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),333 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),
334 repo_head(head: header, title: Some(compare_title))334 repo_head(head: header, title: Some(compare_title))
@@ -410,7 +410,7 @@ async fn compare_view(
410 410
411 /// The picker: base and head fields as a plain GET form, with the repo's branches suggested.411 /// The picker: base and head fields as a plain GET form, with the repo's branches suggested.
412 async fn picker_view(cx: &Cx, ctx: RepoCtx, base: String, head: String) -> Result<impl View> {412 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);
414 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));414 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
415 let path = ctx.path.clone();415 let path = ctx.path.clone();
416 let refs = blocking(move || browse::list_refs(&path)).await?;416 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
423 let action = repo_href(&ctx.repo.owner_name, &ctx.repo.name, "compare", "");423 let action = repo_href(&ctx.repo.owner_name, &ctx.repo.name, "compare", "");
424 let mut header = ctx.head(state, "commits").await?;424 let mut header = ctx.head(state, "commits").await?;
425 header.live = ref_live::live_url(&ctx.repo.owner_name, &ctx.repo.name);425 header.live = ref_live::live_url(&ctx.repo.owner_name, &ctx.repo.name);
426- let __cx = cx;426+ let cx = cx;
427 Ok(view! {427 Ok(view! {
428 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),428 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),
429 repo_head(head: header, title: Some(g::t(lang, K::CompareBranches).to_owned()))429 repo_head(head: header, title: Some(g::t(lang, K::CompareBranches).to_owned()))
@@ -460,8 +460,8 @@ struct PickerQuery {
460 /// Picker at `/{owner}/{repo}/compare`. Both fields filled in redirect to the comparison.460 /// Picker at `/{owner}/{repo}/compare`. Both fields filled in redirect to the comparison.
461 #[page("/{owner}/{repo}/compare")]461 #[page("/{owner}/{repo}/compare")]
462 async fn compare_picker(cx: &Cx) -> Result<impl View> {462 async fn compare_picker(cx: &Cx) -> Result<impl View> {
463- let owner = path_param::<Owner>(cx);463+ let owner = owner(cx);
464- let name = path_param::<Repo>(cx);464+ let name = repo(cx);
465 let query = query_params::<PickerQuery>(cx)?;465 let query = query_params::<PickerQuery>(cx)?;
466 let ctx = load_repo(cx, owner, name).await?;466 let ctx = load_repo(cx, owner, name).await?;
467 let base = query.base.clone().unwrap_or_default();467 let base = query.base.clone().unwrap_or_default();
@@ -485,12 +485,12 @@ async fn compare_picker(cx: &Cx) -> Result<impl View> {
485 /// Comparison at `/{owner}/{repo}/compare/{base}...{head}`.485 /// Comparison at `/{owner}/{repo}/compare/{base}...{head}`.
486 #[page("/{owner}/{repo}/compare/{*spec}")]486 #[page("/{owner}/{repo}/compare/{*spec}")]
487 async fn compare_page(cx: &Cx) -> Result<impl View> {487 async fn compare_page(cx: &Cx) -> Result<impl View> {
488- let owner = path_param::<Owner>(cx);488+ let owner = owner(cx);
489- let name = path_param::<Repo>(cx);489+ let name = repo(cx);
490- let full_spec = path_param::<Spec>(cx).collect::<Vec<_>>().join("/");490+ let full_spec = spec(cx).collect::<Vec<_>>().join("/");
491 let (spec, download) = Download::split(&full_spec);491 let (spec, download) = Download::split(&full_spec);
492 let ctx = load_repo(cx, owner, name).await?;492 let ctx = load_repo(cx, owner, name).await?;
493- let state = app_context::<AppState>(cx);493+ let state = context::<AppState>(cx);
494 let Some((base, head)) = spec.split_once("...") else {494 let Some((base, head)) = spec.split_once("...") else {
495 return Err(not_found().into());495 return Err(not_found().into());
496 };496 };
@@ -551,13 +551,13 @@ struct PullForm {
551 /// Opens a pull request from a comparison: `POST /{owner}/{repo}/pulls`.551 /// Opens a pull request from a comparison: `POST /{owner}/{repo}/pulls`.
552 #[page(POST "/{owner}/{repo}/pulls")]552 #[page(POST "/{owner}/{repo}/pulls")]
553 async fn pull_create(cx: &Cx, Form(form): Form<PullForm>) -> Result<impl View> {553 async fn pull_create(cx: &Cx, Form(form): Form<PullForm>) -> Result<impl View> {
554- let owner = path_param::<Owner>(cx);554+ let owner = owner(cx);
555- let name = path_param::<Repo>(cx);555+ let name = repo(cx);
556 let ctx = load_repo(cx, owner, name).await?;556 let ctx = load_repo(cx, owner, name).await?;
557 let (user, session) = require_user(cx).await?;557 let (user, session) = require_user(cx).await?;
558 check_write(&ctx, &session, &form.csrf)?;558 check_write(&ctx, &session, &form.csrf)?;
559 let lang = i18n::lang(cx, Some(&user));559 let lang = i18n::lang(cx, Some(&user));
560- let state = app_context::<AppState>(cx);560+ let state = context::<AppState>(cx);
561 561
562 let Some(cmp) = resolve_comparison(state, &ctx, &form.base, &form.head).await? else {562 let Some(cmp) = resolve_comparison(state, &ctx, &form.base, &form.head).await? else {
563 return Err(bad_request(g::t(lang, K::UnknownBranches)).into());563 return Err(bad_request(g::t(lang, K::UnknownBranches)).into());
crates/forge-web/src/pages/discussion_actions.rsmodified+31 -31
@@ -9,7 +9,7 @@
9 use forge_core::{AuditAction, Reaction, ReactionTarget};9 use forge_core::{AuditAction, Reaction, ReactionTarget};
10 use serde::Deserialize;10 use serde::Deserialize;
11 use topcoat::Result;11 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};12+use topcoat::context::{Cx, context};
13 use topcoat::router::content::Form;13 use topcoat::router::content::Form;
14 use topcoat::router::error::{SeeOther, bad_request, forbidden, not_found, see_other};14 use topcoat::router::error::{SeeOther, bad_request, forbidden, not_found, see_other};
15 use topcoat::router::{page, path_param, route};15 use topcoat::router::{page, path_param, route};
@@ -86,12 +86,12 @@ async fn own_comment(
86 86
87 #[page(POST "/{owner}/{repo}/discussions/{number}/comments")]87 #[page(POST "/{owner}/{repo}/discussions/{number}/comments")]
88 async fn discussion_comment(cx: &Cx, Form(form): Form<ActionForm>) -> Result<impl View> {88 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?;89+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
90- let state = app_context::<AppState>(cx);90+ let state = context::<AppState>(cx);
91 let (user, _) = require_csrf(cx, &form.csrf).await?;91 let (user, _) = require_csrf(cx, &form.csrf).await?;
92 let lang = i18n::lang(cx, Some(&user));92 let lang = i18n::lang(cx, Some(&user));
93 ensure_enabled(state, &ctx).await?;93 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?;
95 if !may_converse(&ctx, discussion.locked) {95 if !may_converse(&ctx, discussion.locked) {
96 return Err(forbidden().into());96 return Err(forbidden().into());
97 }97 }
@@ -111,7 +111,7 @@ async fn discussion_comment(cx: &Cx, Form(form): Form<ActionForm>) -> Result<imp
111 Ok(comment) => comment,111 Ok(comment) => comment,
112 Err(e) => {112 Err(e) => {
113 let message = refusal_message(e)?;113 let message = refusal_message(e)?;
114- return Ok(view! { cx =>114+ return Ok(view! {
115 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),115 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),
116 action_error_at(lang: lang, message: message, back: base))116 action_error_at(lang: lang, message: message, back: base))
117 });117 });
@@ -132,12 +132,12 @@ async fn discussion_comment(cx: &Cx, Form(form): Form<ActionForm>) -> Result<imp
132 132
133 #[page(POST "/{owner}/{repo}/discussions/{number}/edit")]133 #[page(POST "/{owner}/{repo}/discussions/{number}/edit")]
134 async fn discussion_edit(cx: &Cx, Form(form): Form<ActionForm>) -> Result<impl View> {134 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?;135+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
136- let state = app_context::<AppState>(cx);136+ let state = context::<AppState>(cx);
137 let (user, _) = require_csrf(cx, &form.csrf).await?;137 let (user, _) = require_csrf(cx, &form.csrf).await?;
138 let lang = i18n::lang(cx, Some(&user));138 let lang = i18n::lang(cx, Some(&user));
139 ensure_enabled(state, &ctx).await?;139 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?;
141 if ctx.repo.archived || !is_author(&ctx, &discussion.author_id) {141 if ctx.repo.archived || !is_author(&ctx, &discussion.author_id) {
142 return Err(forbidden().into());142 return Err(forbidden().into());
143 }143 }
@@ -148,7 +148,7 @@ async fn discussion_edit(cx: &Cx, Form(form): Form<ActionForm>) -> Result<impl V
148 .await148 .await
149 {149 {
150 let message = refusal_message(e)?;150 let message = refusal_message(e)?;
151- return Ok(view! { cx =>151+ return Ok(view! {
152 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),152 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),
153 action_error_at(lang: lang, message: message, back: base))153 action_error_at(lang: lang, message: message, back: base))
154 });154 });
@@ -177,11 +177,11 @@ async fn discussion_edit(cx: &Cx, Form(form): Form<ActionForm>) -> Result<impl V
177 /// Deletes the discussion with its comments. Its author only.177 /// Deletes the discussion with its comments. Its author only.
178 #[route(POST "/{owner}/{repo}/discussions/{number}/delete")]178 #[route(POST "/{owner}/{repo}/discussions/{number}/delete")]
179 async fn discussion_delete(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther> {179 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?;180+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
181- let state = app_context::<AppState>(cx);181+ let state = context::<AppState>(cx);
182 let (user, _) = require_csrf(cx, &form.csrf).await?;182 let (user, _) = require_csrf(cx, &form.csrf).await?;
183 ensure_enabled(state, &ctx).await?;183 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?;
185 if ctx.repo.archived || !is_author(&ctx, &discussion.author_id) {185 if ctx.repo.archived || !is_author(&ctx, &discussion.author_id) {
186 return Err(forbidden().into());186 return Err(forbidden().into());
187 }187 }
@@ -205,11 +205,11 @@ async fn discussion_delete(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeO
205 /// Locks (`locked=1`) or unlocks (`locked=0`) a discussion. Triage holders only.205 /// Locks (`locked=1`) or unlocks (`locked=0`) a discussion. Triage holders only.
206 #[route(POST "/{owner}/{repo}/discussions/{number}/lock")]206 #[route(POST "/{owner}/{repo}/discussions/{number}/lock")]
207 async fn discussion_lock(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther> {207 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?;208+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
209- let state = app_context::<AppState>(cx);209+ let state = context::<AppState>(cx);
210 let (user, _) = require_csrf(cx, &form.csrf).await?;210 let (user, _) = require_csrf(cx, &form.csrf).await?;
211 ensure_enabled(state, &ctx).await?;211 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?;
213 if !can_triage(&ctx) {213 if !can_triage(&ctx) {
214 return Err(forbidden().into());214 return Err(forbidden().into());
215 }215 }
@@ -233,12 +233,12 @@ async fn discussion_lock(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOth
233 /// Triage holder may do it.233 /// Triage holder may do it.
234 #[page(POST "/{owner}/{repo}/discussions/{number}/answer")]234 #[page(POST "/{owner}/{repo}/discussions/{number}/answer")]
235 async fn discussion_answer(cx: &Cx, Form(form): Form<ActionForm>) -> Result<impl View> {235 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?;236+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
237- let state = app_context::<AppState>(cx);237+ let state = context::<AppState>(cx);
238 let (user, _) = require_csrf(cx, &form.csrf).await?;238 let (user, _) = require_csrf(cx, &form.csrf).await?;
239 let lang = i18n::lang(cx, Some(&user));239 let lang = i18n::lang(cx, Some(&user));
240 ensure_enabled(state, &ctx).await?;240 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?;
242 if ctx.repo.archived || !(can_triage(&ctx) || is_author(&ctx, &discussion.author_id)) {242 if ctx.repo.archived || !(can_triage(&ctx) || is_author(&ctx, &discussion.author_id)) {
243 return Err(forbidden().into());243 return Err(forbidden().into());
244 }244 }
@@ -256,7 +256,7 @@ async fn discussion_answer(cx: &Cx, Form(form): Form<ActionForm>) -> Result<impl
256 .await256 .await
257 {257 {
258 let message = refusal_message(e)?;258 let message = refusal_message(e)?;
259- return Ok(view! { cx =>259+ return Ok(view! {
260 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),260 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),
261 action_error_at(lang: lang, message: message, back: base))261 action_error_at(lang: lang, message: message, back: base))
262 });262 });
@@ -278,13 +278,13 @@ async fn discussion_answer(cx: &Cx, Form(form): Form<ActionForm>) -> Result<impl
278 278
279 #[page(POST "/{owner}/{repo}/discussions/{number}/comments/{comment_id}/edit")]279 #[page(POST "/{owner}/{repo}/discussions/{number}/comments/{comment_id}/edit")]
280 async fn discussion_comment_edit(cx: &Cx, Form(form): Form<ActionForm>) -> Result<impl View> {280 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?;281+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
282- let state = app_context::<AppState>(cx);282+ let state = context::<AppState>(cx);
283 let (user, _) = require_csrf(cx, &form.csrf).await?;283 let (user, _) = require_csrf(cx, &form.csrf).await?;
284 ensure_enabled(state, &ctx).await?;284 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?;
286 let lang = i18n::lang(cx, Some(&user));286 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?;
288 let base = base_of(&ctx, discussion.number);288 let base = base_of(&ctx, discussion.number);
289 if let Err(e) = state289 if let Err(e) = state
290 .store290 .store
@@ -292,7 +292,7 @@ async fn discussion_comment_edit(cx: &Cx, Form(form): Form<ActionForm>) -> Resul
292 .await292 .await
293 {293 {
294 let message = refusal_message(e)?;294 let message = refusal_message(e)?;
295- return Ok(view! { cx =>295+ return Ok(view! {
296 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),296 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),
297 action_error_at(lang: lang, message: message, back: base))297 action_error_at(lang: lang, message: message, back: base))
298 });298 });
@@ -320,12 +320,12 @@ async fn discussion_comment_edit(cx: &Cx, Form(form): Form<ActionForm>) -> Resul
320 320
321 #[route(POST "/{owner}/{repo}/discussions/{number}/comments/{comment_id}/delete")]321 #[route(POST "/{owner}/{repo}/discussions/{number}/comments/{comment_id}/delete")]
322 async fn discussion_comment_delete(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther> {322 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?;323+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
324- let state = app_context::<AppState>(cx);324+ let state = context::<AppState>(cx);
325 let (user, _) = require_csrf(cx, &form.csrf).await?;325 let (user, _) = require_csrf(cx, &form.csrf).await?;
326 ensure_enabled(state, &ctx).await?;326 ensure_enabled(state, &ctx).await?;
327- let discussion = discussion_by_number(state, &ctx, path_param::<Number>(cx)).await?;327+ let discussion = discussion_by_number(state, &ctx, number(cx)).await?;
328- let comment = own_comment(state, &ctx, &discussion.id, path_param::<CommentId>(cx)).await?;328+ let comment = own_comment(state, &ctx, &discussion.id, comment_id(cx)).await?;
329 state.store.delete_discussion_comment(&comment.id).await?;329 state.store.delete_discussion_comment(&comment.id).await?;
330 audit_discussion(330 audit_discussion(
331 cx,331 cx,
@@ -343,11 +343,11 @@ async fn discussion_comment_delete(cx: &Cx, Form(form): Form<ActionForm>) -> Res
343 /// comments (`target_kind=discussion_comment`).343 /// comments (`target_kind=discussion_comment`).
344 #[route(POST "/{owner}/{repo}/discussions/{number}/reactions")]344 #[route(POST "/{owner}/{repo}/discussions/{number}/reactions")]
345 async fn discussion_reaction(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther> {345 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?;346+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
347- let state = app_context::<AppState>(cx);347+ let state = context::<AppState>(cx);
348 let (user, _) = require_csrf(cx, &form.csrf).await?;348 let (user, _) = require_csrf(cx, &form.csrf).await?;
349 ensure_enabled(state, &ctx).await?;349 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?;
351 if !may_converse(&ctx, discussion.locked) {351 if !may_converse(&ctx, discussion.locked) {
352 return Err(forbidden().into());352 return Err(forbidden().into());
353 }353 }
crates/forge-web/src/pages/discussion_live.rsmodified+7 -7
@@ -13,7 +13,7 @@
13 //! that is not there.13 //! that is not there.
14 14
15 use topcoat::Result;15 use topcoat::Result;
16-use topcoat::context::{Cx, app_context};16+use topcoat::context::{Cx, context};
17 use topcoat::router::request::{method, uri};17 use topcoat::router::request::{method, uri};
18 use topcoat::router::response::Response;18 use topcoat::router::response::Response;
19 use topcoat::router::{Body, Layer, LayerFuture, Method, Next, Path, path_param, route};19 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 {
40 /// The change stream of the discussion list.40 /// The change stream of the discussion list.
41 #[route(GET "/{owner}/{repo}/discussions/live")]41 #[route(GET "/{owner}/{repo}/discussions/live")]
42 async fn discussions_live(cx: &Cx) -> Result<Response> {42 async fn discussions_live(cx: &Cx) -> Result<Response> {
43- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;43+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
44- let state = app_context::<AppState>(cx);44+ let state = context::<AppState>(cx);
45 ensure_enabled(state, &ctx).await?;45 ensure_enabled(state, &ctx).await?;
46 stream_wakes(cx, &state.live, &[Topic::Discussions(ctx.repo.id.clone())])46 stream_wakes(cx, &state.live, &[Topic::Discussions(ctx.repo.id.clone())])
47 }47 }
@@ -49,10 +49,10 @@ async fn discussions_live(cx: &Cx) -> Result<Response> {
49 /// The change stream of one discussion page.49 /// The change stream of one discussion page.
50 #[route(GET "/{owner}/{repo}/discussions/{number}/live")]50 #[route(GET "/{owner}/{repo}/discussions/{number}/live")]
51 async fn discussion_live(cx: &Cx) -> Result<Response> {51 async fn discussion_live(cx: &Cx) -> Result<Response> {
52- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;52+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
53- let state = app_context::<AppState>(cx);53+ let state = context::<AppState>(cx);
54 ensure_enabled(state, &ctx).await?;54 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?;
56 stream_wakes(cx, &state.live, &[Topic::Discussion(discussion.id.clone())])56 stream_wakes(cx, &state.live, &[Topic::Discussion(discussion.id.clone())])
57 }57 }
58 58
@@ -128,7 +128,7 @@ async fn topics_of(state: &AppState, target: Written) -> Vec<Topic> {
128 /// through unchanged, so a refused write (an error or a redirect) bumps too: the page re-reads and128 /// through unchanged, so a refused write (an error or a redirect) bumps too: the page re-reads and
129 /// agrees.129 /// agrees.
130 async fn bump_after_write(cx: &Cx, body: Body, next: Next<'_>) -> topcoat::Result<Response> {130 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);
132 let topics = match written(cx) {132 let topics = match written(cx) {
133 Some(target) => topics_of(state, target).await,133 Some(target) => topics_of(state, target).await,
134 None => Vec::new(),134 None => Vec::new(),
crates/forge-web/src/pages/discussion_settings.rsmodified+10 -4
@@ -5,7 +5,7 @@
5 use forge_core::AuditAction;5 use forge_core::AuditAction;
6 use serde::Deserialize;6 use serde::Deserialize;
7 use topcoat::Result;7 use topcoat::Result;
8-use topcoat::context::{Cx, app_context};8+use topcoat::context::{Cx, context};
9 use topcoat::router::content::Form;9 use topcoat::router::content::Form;
10 use topcoat::router::error::{SeeOther, forbidden, see_other};10 use topcoat::router::error::{SeeOther, forbidden, see_other};
11 use topcoat::router::{path_param, route};11 use topcoat::router::{path_param, route};
@@ -26,6 +26,7 @@ path_param!(repo);
26 /// the form on change (`data-autosubmit`); an unchecked box sends no `enabled`, which the handler reads as off.26 /// the form on change (`data-autosubmit`); an unchecked box sends no `enabled`, which the handler reads as off.
27 #[component]27 #[component]
28 pub(crate) async fn discussions_switch(28 pub(crate) async fn discussions_switch(
29+ cx: &Cx,
29 lang: Lang,30 lang: Lang,
30 action: String,31 action: String,
31 csrf: String,32 csrf: String,
@@ -53,13 +54,13 @@ struct ToggleForm {
53 54
54 #[route(POST "/{owner}/{repo}/settings/discussions")]55 #[route(POST "/{owner}/{repo}/settings/discussions")]
55 async fn settings_discussions_save(cx: &Cx, Form(form): Form<ToggleForm>) -> Result<SeeOther> {56 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?;
57 let (user, _) = require_csrf(cx, &form.csrf).await?;58 let (user, _) = require_csrf(cx, &form.csrf).await?;
58 if !ctx.can_admin() {59 if !ctx.can_admin() {
59 return Err(forbidden().into());60 return Err(forbidden().into());
60 }61 }
61 let enabled = form.enabled == "1";62 let enabled = form.enabled == "1";
62- let state = app_context::<AppState>(cx);63+ let state = context::<AppState>(cx);
63 state64 state
64 .store65 .store
65 .set_discussions_enabled(&ctx.repo.id, enabled)66 .set_discussions_enabled(&ctx.repo.id, enabled)
@@ -85,5 +86,10 @@ async fn settings_discussions_save(cx: &Cx, Form(form): Form<ToggleForm>) -> Res
85 serde_json::Value::Null,86 serde_json::Value::Null,
86 )87 )
87 .await;88 .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+ )))
89 }95 }
crates/forge-web/src/pages/discussion_view.rsmodified+11 -7
@@ -8,7 +8,7 @@ use std::collections::HashMap;
8 use forge_core::discussions::{Discussion, DiscussionCategory, DiscussionComment};8 use forge_core::discussions::{Discussion, DiscussionCategory, DiscussionComment};
9 use forge_core::{ReactionMap, ReactionTarget};9 use forge_core::{ReactionMap, ReactionTarget};
10 use topcoat::Result;10 use topcoat::Result;
11-use topcoat::context::{Cx, app_context};11+use topcoat::context::{Cx, context};
12 use topcoat::router::{page, path_param};12 use topcoat::router::{page, path_param};
13 use topcoat::view::{Unescaped, View, component, view};13 use topcoat::view::{Unescaped, View, component, view};
14 14
@@ -151,7 +151,7 @@ fn comment_view(
151 151
152 /// One comment, with its reactions and the forms the viewer may use.152 /// One comment, with its reactions and the forms the viewer may use.
153 #[component]153 #[component]
154-async fn comment_article(item: CommentView) -> Result<impl View> {154+async fn comment_article(cx: &Cx, item: CommentView) -> Result<impl View> {
155 let CommentView {155 let CommentView {
156 lang,156 lang,
157 anchor,157 anchor,
@@ -246,7 +246,11 @@ async fn comment_article(item: CommentView) -> Result<impl View> {
246 246
247 /// A top-level comment with its replies indented under it.247 /// A top-level comment with its replies indented under it.
248 #[component]248 #[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> {
250 Ok(view! {254 Ok(view! {
251 <div class="discussion-thread">255 <div class="discussion-thread">
252 comment_article(item: root)256 comment_article(item: root)
@@ -263,9 +267,9 @@ async fn comment_thread(root: CommentView, replies: Vec<CommentView>) -> Result<
263 267
264 #[page("/{owner}/{repo}/discussions/{number}")]268 #[page("/{owner}/{repo}/discussions/{number}")]
265 async fn discussion_show(cx: &Cx) -> Result<impl View> {269 async fn discussion_show(cx: &Cx) -> Result<impl View> {
266- let number = path_param::<Number>(cx);270+ let number = number(cx);
267- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;271+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
268- let state = app_context::<AppState>(cx);272+ let state = context::<AppState>(cx);
269 ensure_enabled(state, &ctx).await?;273 ensure_enabled(state, &ctx).await?;
270 let discussion = discussion_by_number(state, &ctx, number).await?;274 let discussion = discussion_by_number(state, &ctx, number).await?;
271 discussion_page(cx, state, ctx, discussion).await275 discussion_page(cx, state, ctx, discussion).await
@@ -415,7 +419,7 @@ async fn discussion_page(
415 sub.push(SubPart::link(author.clone(), author_profile.clone()));419 sub.push(SubPart::link(author.clone(), author_profile.clone()));
416 sub.push(SubPart::text(opened.relative.clone()));420 sub.push(SubPart::text(opened.relative.clone()));
417 sub.push(SubPart::text(comments_label));421 sub.push(SubPart::text(comments_label));
418- Ok(view! { cx =>422+ Ok(view! {
419 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(),423 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(),
420 repo_head(head: header, title: Some(discussion.title.clone()), sub: sub,424 repo_head(head: header, title: Some(discussion.title.clone()), sub: sub,
421 <span class="num">(number_label.as_str())</span>425 <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::{
9 };9 };
10 use forge_core::{Action, AuditAction, Role, User, authorize};10 use forge_core::{Action, AuditAction, Role, User, authorize};
11 use topcoat::Result;11 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};12+use topcoat::context::{Cx, context};
13 use topcoat::router::content::RawForm;13 use topcoat::router::content::RawForm;
14 use topcoat::router::error::{bad_request, forbidden, not_found, see_other};14 use topcoat::router::error::{bad_request, forbidden, not_found, see_other};
15 use topcoat::router::{StatusCode, page, path_param, query_params};15 use topcoat::router::{StatusCode, page, path_param, query_params};
@@ -225,11 +225,11 @@ fn row_view(
225 225
226 #[page("/{owner}/{repo}/discussions")]226 #[page("/{owner}/{repo}/discussions")]
227 async fn discussions_list_page(cx: &Cx) -> Result<impl View> {227 async fn discussions_list_page(cx: &Cx) -> Result<impl View> {
228- let owner = path_param::<Owner>(cx);228+ let owner = owner(cx);
229- let name = path_param::<Repo>(cx);229+ let name = repo(cx);
230 let query = query_params::<ListQuery>(cx)?;230 let query = query_params::<ListQuery>(cx)?;
231 let ctx = load_repo(cx, owner, name).await?;231 let ctx = load_repo(cx, owner, name).await?;
232- let state = app_context::<AppState>(cx);232+ let state = context::<AppState>(cx);
233 ensure_enabled(state, &ctx).await?;233 ensure_enabled(state, &ctx).await?;
234 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));234 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
235 235
@@ -373,6 +373,7 @@ struct DraftDiscussion {
373 373
374 #[component]374 #[component]
375 async fn new_discussion_body(375 async fn new_discussion_body(
376+ cx: &Cx,
376 lang: Lang,377 lang: Lang,
377 head: RepoHead,378 head: RepoHead,
378 csrf: String,379 csrf: String,
@@ -416,10 +417,10 @@ async fn new_discussion_body(
416 417
417 #[page("/{owner}/{repo}/discussions/new")]418 #[page("/{owner}/{repo}/discussions/new")]
418 async fn discussion_new_page(cx: &Cx) -> Result<impl View> {419 async fn discussion_new_page(cx: &Cx) -> Result<impl View> {
419- let owner = path_param::<Owner>(cx);420+ let owner = owner(cx);
420- let name = path_param::<Repo>(cx);421+ let name = repo(cx);
421 let ctx = load_repo(cx, owner, name).await?;422 let ctx = load_repo(cx, owner, name).await?;
422- let state = app_context::<AppState>(cx);423+ let state = context::<AppState>(cx);
423 ensure_enabled(state, &ctx).await?;424 ensure_enabled(state, &ctx).await?;
424 let viewer = require_user(cx).await?;425 let viewer = require_user(cx).await?;
425 let lang = i18n::lang(cx, Some(&viewer.0));426 let lang = i18n::lang(cx, Some(&viewer.0));
@@ -443,10 +444,10 @@ async fn discussion_new_page(cx: &Cx) -> Result<impl View> {
443 444
444 #[page(POST "/{owner}/{repo}/discussions/new")]445 #[page(POST "/{owner}/{repo}/discussions/new")]
445 async fn discussion_create(cx: &Cx, RawForm(raw): RawForm) -> Result<impl View> {446 async fn discussion_create(cx: &Cx, RawForm(raw): RawForm) -> Result<impl View> {
446- let owner = path_param::<Owner>(cx);447+ let owner = owner(cx);
447- let name = path_param::<Repo>(cx);448+ let name = repo(cx);
448 let ctx = load_repo(cx, owner, name).await?;449 let ctx = load_repo(cx, owner, name).await?;
449- let state = app_context::<AppState>(cx);450+ let state = context::<AppState>(cx);
450 ensure_enabled(state, &ctx).await?;451 ensure_enabled(state, &ctx).await?;
451 let fields = form_pairs(&raw[..]);452 let fields = form_pairs(&raw[..]);
452 let viewer = require_csrf(cx, &form_field(&fields, "csrf")).await?;453 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;
10 use forge_core::{EditVersion, Issue, Thread};10 use forge_core::{EditVersion, Issue, Thread};
11 use similar::{ChangeTag, TextDiff};11 use similar::{ChangeTag, TextDiff};
12 use topcoat::Result;12 use topcoat::Result;
13-use topcoat::context::{Cx, app_context};13+use topcoat::context::{Cx, context};
14 use topcoat::router::error::not_found;14 use topcoat::router::error::not_found;
15 use topcoat::router::{page, path_param};15 use topcoat::router::{page, path_param};
16 use topcoat::view::{View, component, view};16 use topcoat::view::{View, component, view};
@@ -174,7 +174,7 @@ async fn history_page(
174 ) -> Result<impl View> {174 ) -> Result<impl View> {
175 let target = target.as_str();175 let target = target.as_str();
176 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));176 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);
178 let owner = ctx.repo.owner_name.clone();178 let owner = ctx.repo.owner_name.clone();
179 let name = ctx.repo.name.clone();179 let name = ctx.repo.name.clone();
180 let number = item.number;180 let number = item.number;
@@ -229,17 +229,14 @@ async fn history_page(
229 let heading = g::history_heading(lang, what);229 let heading = g::history_heading(lang, what);
230 let back_label = g::back_to_item(lang, number);230 let back_label = g::back_to_item(lang, number);
231 let count_label = g::earlier_versions(lang, entries.len());231 let count_label = g::earlier_versions(lang, entries.len());
232- let sub = vec![232+ let sub = vec![SubPart::link(back_label, back), SubPart::text(count_label)];
233- SubPart::link(back_label, back),
234- SubPart::text(count_label),
235- ];
236 // A history follows its item: a new edit adds a version to the list.233 // A history follows its item: a new edit adds a version to the list.
237 let live = match kind_item {234 let live = match kind_item {
238 ItemKind::Issue => item_live_url(&owner, &name, number),235 ItemKind::Issue => item_live_url(&owner, &name, number),
239 ItemKind::Pull => pull_live_url(&owner, &name, number),236 ItemKind::Pull => pull_live_url(&owner, &name, number),
240 };237 };
241 238
242- Ok(view! { cx =>239+ Ok(view! {
243 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(),240 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(),
244 repo_head(head: header, title: Some(heading), sub: sub)241 repo_head(head: header, title: Some(heading), sub: sub)
245 <div class="work" data-live=(live.as_str()) data-live-now="">242 <div class="work" data-live=(live.as_str()) data-live-now="">
@@ -260,7 +257,7 @@ async fn history_page(
260 257
261 /// One version: the editor and time, the title change if any, the diff and the raw text.258 /// One version: the editor and time, the title change if any, the diff and the raw text.
262 #[component]259 #[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> {
264 let HistoryEntry {261 let HistoryEntry {
265 editor,262 editor,
266 when,263 when,
@@ -315,11 +312,11 @@ fn parse_kind(raw: &str) -> Result<&'static str> {
315 }312 }
316 313
317 async fn history_route(cx: &Cx, item_kind: ItemKind) -> Result<impl View> {314 async fn history_route(cx: &Cx, item_kind: ItemKind) -> Result<impl View> {
318- let number = parse_number(path_param::<Number>(cx))?;315+ let number = parse_number(number(cx))?;
319- let target_kind = parse_kind(path_param::<Kind>(cx))?;316+ let target_kind = parse_kind(kind(cx))?;
320- let target = path_param::<TargetId>(cx).to_owned();317+ let target = target_id(cx).to_owned();
321- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;318+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
322- let state = app_context::<AppState>(cx);319+ let state = context::<AppState>(cx);
323 let item = item_for(state, &ctx, item_kind, number).await?;320 let item = item_for(state, &ctx, item_kind, number).await?;
324 history_page(cx, ctx, item_kind, item, target_kind, target).await321 history_page(cx, ctx, item_kind, item, target_kind, target).await
325 }322 }
crates/forge-web/src/pages/explore.rsmodified+25 -10
@@ -4,10 +4,10 @@
4 //! page fits the window. `explore` is a reserved username, so this4 //! page fits the window. `explore` is a reserved username, so this
5 //! route cannot collide with a profile.5 //! route cannot collide with a profile.
6 6
7-use forge_core::{Repo, User};
8 use forge_core::store::RepoSort;7 use forge_core::store::RepoSort;
8+use forge_core::{Repo, User};
9 use topcoat::Result;9 use topcoat::Result;
10-use topcoat::context::{Cx, app_context};10+use topcoat::context::{Cx, context};
11 use topcoat::router::response::Response;11 use topcoat::router::response::Response;
12 use topcoat::router::{page, query_params, route};12 use topcoat::router::{page, query_params, route};
13 use topcoat::view::{View, component, view};13 use topcoat::view::{View, component, view};
@@ -16,13 +16,13 @@ use crate::auth::current_user;
16 use crate::i18n::orgs::{self as g, K};16 use crate::i18n::orgs::{self as g, K};
17 use crate::i18n::{self, Lang};17 use crate::i18n::{self, Lang};
18 use crate::live::{Topic, stream_changes};18 use crate::live::{Topic, stream_changes};
19+use crate::pages::issues_list::list_href;
19 use crate::state::AppState;20 use crate::state::AppState;
21+use crate::views::find::{Finder, finder_field};
20 use crate::views::parts::head;22 use crate::views::parts::head;
21 use crate::views::repo_list::{23 use crate::views::repo_list::{
22 PageLink, RepoRow, SortLink, pager, pager_links, repo_rows, sort_chips,24 PageLink, RepoRow, SortLink, pager, pager_links, repo_rows, sort_chips,
23 };25 };
24-use crate::pages::issues_list::list_href;
25-use crate::views::find::{Finder, finder_field};
26 use crate::views::{now_unix, shell};26 use crate::views::{now_unix, shell};
27 27
28 const PER_PAGE: u64 = 12;28 const PER_PAGE: u64 = 12;
@@ -162,7 +162,7 @@ async fn explore_page(cx: &Cx) -> Result<impl View> {
162 let live = explore_href(&finder, sort, page).replacen("/explore?", "/explore/events?", 1);162 let live = explore_href(&finder, sort, page).replacen("/explore?", "/explore/events?", 1);
163 let viewer = current_user(cx).await?;163 let viewer = current_user(cx).await?;
164 let lang = i18n::lang(cx, viewer.as_ref().map(|(u, _)| u));164 let lang = i18n::lang(cx, viewer.as_ref().map(|(u, _)| u));
165- let state = app_context::<AppState>(cx);165+ let state = context::<AppState>(cx);
166 let on_orgs = orgs_tab(query);166 let on_orgs = orgs_tab(query);
167 let (listed, repo_total) = listing(state, &finder, sort, page).await?;167 let (listed, repo_total) = listing(state, &finder, sort, page).await?;
168 let (org_page, org_total) = org_listing(state, &finder, page).await?;168 let (org_page, org_total) = org_listing(state, &finder, page).await?;
@@ -206,12 +206,22 @@ async fn explore_page(cx: &Cx) -> Result<impl View> {
206 pager_links(page, pages, |n| explore_href(&finder, sort, n))206 pager_links(page, pages, |n| explore_href(&finder, sort, n))
207 };207 };
208 let tabs = vec![208 let tabs = vec![
209- (g::t(lang, K::Repositories), explore_href(&Finder::default(), sort, 1), repos_all, !on_orgs),209+ (
210- (g::t(lang, K::Organizations), orgs_href(&Finder::default(), 1), orgs_all, on_orgs),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+ ),
211 ];221 ];
212 let title = g::t(lang, K::Explore);222 let title = g::t(lang, K::Explore);
213 223
214- Ok(view! { cx =>224+ Ok(view! {
215 shell(title: title, viewer: viewer.as_ref(),225 shell(title: title, viewer: viewer.as_ref(),
216 explore_body(finder: finder, sort: sort, sort_links: sort_links, rows: rows,226 explore_body(finder: finder, sort: sort, sort_links: sort_links, rows: rows,
217 total: total, page: page, pages: pages, nav: nav, orgs: orgs, lang: lang, live: live,227 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> {
227 let query = query_params::<ExploreQuery>(cx)?;237 let query = query_params::<ExploreQuery>(cx)?;
228 let (finder, sort, page) = listing_args(query);238 let (finder, sort, page) = listing_args(query);
229 let on_orgs = orgs_tab(query);239 let on_orgs = orgs_tab(query);
230- let state = app_context::<AppState>(cx).clone();240+ let state = context::<AppState>(cx).clone();
231 stream_changes(cx, &state.live.clone(), &[Topic::Explore], move || {241 stream_changes(cx, &state.live.clone(), &[Topic::Explore], move || {
232 let state = state.clone();242 let state = state.clone();
233 let finder = finder.clone();243 let finder = finder.clone();
@@ -263,6 +273,7 @@ async fn explore_fingerprint(
263 273
264 #[component]274 #[component]
265 async fn explore_body(275 async fn explore_body(
276+ cx: &Cx,
266 finder: Finder,277 finder: Finder,
267 sort: &'static str,278 sort: &'static str,
268 sort_links: Vec<SortLink>,279 sort_links: Vec<SortLink>,
@@ -277,7 +288,11 @@ async fn explore_body(
277 on_orgs: bool,288 on_orgs: bool,
278 tabs: Vec<(&'static str, String, u64, bool)>,289 tabs: Vec<(&'static str, String, u64, bool)>,
279 ) -> Result<impl View> {290 ) -> 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+ };
281 let has_search = !finder.is_empty();296 let has_search = !finder.is_empty();
282 let (links, prev, next) = nav;297 let (links, prev, next) = nav;
283 let clear_href = if on_orgs {298 let clear_href = if on_orgs {
crates/forge-web/src/pages/finder.rsmodified+6 -5
@@ -5,7 +5,7 @@
5 use forge_git::history;5 use forge_git::history;
6 use http::header::{CACHE_CONTROL, CONTENT_TYPE};6 use http::header::{CACHE_CONTROL, CONTENT_TYPE};
7 use topcoat::Result;7 use topcoat::Result;
8-use topcoat::context::{Cx, app_context};8+use topcoat::context::{Cx, context};
9 use topcoat::router::error::not_found;9 use topcoat::router::error::not_found;
10 use topcoat::router::response::Response;10 use topcoat::router::response::Response;
11 use topcoat::router::{Body, HeaderValue, path_param, route};11 use topcoat::router::{Body, HeaderValue, path_param, route};
@@ -28,6 +28,7 @@ pub const MAX_PATHS: usize = 20_000;
28 /// The "Go to file" button and its dialog for the tree at `ref_name`.28 /// The "Go to file" button and its dialog for the tree at `ref_name`.
29 #[component]29 #[component]
30 pub async fn file_finder(30 pub async fn file_finder(
31+ cx: &Cx,
31 lang: Lang,32 lang: Lang,
32 owner: String,33 owner: String,
33 repo: String,34 repo: String,
@@ -58,11 +59,11 @@ pub async fn file_finder(
58 /// `{"ref": ..., "commit": ..., "paths": [...], "truncated": bool}` for the tree at the ref.59 /// `{"ref": ..., "commit": ..., "paths": [...], "truncated": bool}` for the tree at the ref.
59 #[route(GET "/{owner}/{repo}/paths/{*rest}")]60 #[route(GET "/{owner}/{repo}/paths/{*rest}")]
60 async fn tree_paths(cx: &Cx) -> Result<Response> {61 async fn tree_paths(cx: &Cx) -> Result<Response> {
61- let owner = path_param::<Owner>(cx);62+ let owner = owner(cx);
62- let name = path_param::<Repo>(cx);63+ let name = repo(cx);
63- let rest = path_param::<Rest>(cx).collect::<Vec<_>>().join("/");64+ let rest = rest(cx).collect::<Vec<_>>().join("/");
64 let ctx = load_repo(cx, owner, name).await?;65 let ctx = load_repo(cx, owner, name).await?;
65- let state = app_context::<AppState>(cx);66+ let state = context::<AppState>(cx);
66 67
67 let Some((ref_name, commit, path)) = resolve(ctx.path.clone(), rest).await? else {68 let Some((ref_name, commit, path)) = resolve(ctx.path.clone(), rest).await? else {
68 return Err(not_found().into());69 return Err(not_found().into());
crates/forge-web/src/pages/forgot.rsmodified+7 -6
@@ -8,7 +8,7 @@ use std::time::Instant;
8 use forge_core::AuditAction;8 use forge_core::AuditAction;
9 use serde::Deserialize;9 use serde::Deserialize;
10 use topcoat::Result;10 use topcoat::Result;
11-use topcoat::context::{Cx, app_context};11+use topcoat::context::{Cx, context};
12 use topcoat::router::content::Form;12 use topcoat::router::content::Form;
13 use topcoat::router::error::forbidden;13 use topcoat::router::error::forbidden;
14 use topcoat::router::{page, path_param_segment};14 use topcoat::router::{page, path_param_segment};
@@ -57,7 +57,7 @@ enum ResetMode {
57 }57 }
58 58
59 #[component]59 #[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> {
61 Ok(view! {61 Ok(view! {
62 head(title: t(lang, Key::ForgotTitle))62 head(title: t(lang, Key::ForgotTitle))
63 <div class="sheet fit">63 <div class="sheet fit">
@@ -74,7 +74,7 @@ async fn forgot_form(lang: Lang, precsrf: &str) -> Result<impl View> {
74 }74 }
75 75
76 #[component]76 #[component]
77-async fn forgot_sent(lang: Lang) -> Result<impl View> {77+async fn forgot_sent(cx: &Cx, lang: Lang) -> Result<impl View> {
78 Ok(view! {78 Ok(view! {
79 head(title: t(lang, Key::ForgotTitle))79 head(title: t(lang, Key::ForgotTitle))
80 <div class="sheet fit">80 <div class="sheet fit">
@@ -110,7 +110,7 @@ async fn forgot_submit(cx: &Cx, Form(form): Form<ForgotForm>) -> Result<impl Vie
110 if !check_pre_csrf(cx, &form.precsrf) {110 if !check_pre_csrf(cx, &form.precsrf) {
111 return Err(forbidden().into());111 return Err(forbidden().into());
112 }112 }
113- let state = app_context::<AppState>(cx);113+ let state = context::<AppState>(cx);
114 let lang = i18n::lang(cx, None);114 let lang = i18n::lang(cx, None);
115 let address = form.email.trim().to_owned();115 let address = form.email.trim().to_owned();
116 let now = Instant::now();116 let now = Instant::now();
@@ -143,6 +143,7 @@ async fn forgot_submit(cx: &Cx, Form(form): Form<ForgotForm>) -> Result<impl Vie
143 143
144 #[component]144 #[component]
145 async fn reset_body(145 async fn reset_body(
146+ cx: &Cx,
146 lang: Lang,147 lang: Lang,
147 token: &str,148 token: &str,
148 precsrf: &str,149 precsrf: &str,
@@ -188,7 +189,7 @@ async fn reset_body(
188 189
189 #[page("/reset/{token}")]190 #[page("/reset/{token}")]
190 async fn reset_page(cx: &Cx) -> Result<impl View> {191 async fn reset_page(cx: &Cx) -> Result<impl View> {
191- let state = app_context::<AppState>(cx);192+ let state = context::<AppState>(cx);
192 let lang = i18n::lang(cx, None);193 let lang = i18n::lang(cx, None);
193 let token = path_param_segment(cx, "token").to_owned();194 let token = path_param_segment(cx, "token").to_owned();
194 let mode = if state.store.reset_token_is_live(&token).await? {195 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>
207 if !check_pre_csrf(cx, &form.precsrf) {208 if !check_pre_csrf(cx, &form.precsrf) {
208 return Err(forbidden().into());209 return Err(forbidden().into());
209 }210 }
210- let state = app_context::<AppState>(cx);211+ let state = context::<AppState>(cx);
211 let lang = i18n::lang(cx, None);212 let lang = i18n::lang(cx, None);
212 let token = path_param_segment(cx, "token").to_owned();213 let token = path_param_segment(cx, "token").to_owned();
213 let mut mode = ResetMode::Form;214 let mut mode = ResetMode::Form;
crates/forge-web/src/pages/fork.rsmodified+4 -4
@@ -8,7 +8,7 @@ use forge_core::AuditAction;
8 use forge_git::repo::{fork_bare, repo_path};8 use forge_git::repo::{fork_bare, repo_path};
9 use serde::Deserialize;9 use serde::Deserialize;
10 use topcoat::Result;10 use topcoat::Result;
11-use topcoat::context::{Cx, app_context};11+use topcoat::context::{Cx, context};
12 use topcoat::router::content::Form;12 use topcoat::router::content::Form;
13 use topcoat::router::error::{SeeOther, see_other};13 use topcoat::router::error::{SeeOther, see_other};
14 use topcoat::router::{path_param, route};14 use topcoat::router::{path_param, route};
@@ -30,11 +30,11 @@ struct ForkForm {
30 30
31 #[route(POST "/{owner}/{repo}/fork")]31 #[route(POST "/{owner}/{repo}/fork")]
32 async fn fork_post(cx: &Cx, Form(form): Form<ForkForm>) -> Result<SeeOther> {32 async fn fork_post(cx: &Cx, Form(form): Form<ForkForm>) -> Result<SeeOther> {
33- let owner = path_param::<Owner>(cx);33+ let owner = owner(cx);
34- let name = path_param::<Repo>(cx);34+ let name = repo(cx);
35 let source = load_repo(cx, owner, name).await?;35 let source = load_repo(cx, owner, name).await?;
36 let (viewer, _) = require_csrf(cx, &form.csrf).await?;36 let (viewer, _) = require_csrf(cx, &form.csrf).await?;
37- let state = app_context::<AppState>(cx);37+ let state = context::<AppState>(cx);
38 let source_repo = &source.repo;38 let source_repo = &source.repo;
39 39
40 // Forking your own repo is a no-op: send the viewer back to it.40 // 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};
7 use forge_core::store::RepoSort;7 use forge_core::store::RepoSort;
8 use forge_core::store::repo_listing::RepoScope;8 use forge_core::store::repo_listing::RepoScope;
9 use topcoat::Result;9 use topcoat::Result;
10-use topcoat::context::{Cx, app_context};10+use topcoat::context::{Cx, context};
11 use topcoat::router::page;11 use topcoat::router::page;
12 use topcoat::view::{View, component, view};12 use topcoat::view::{View, component, view};
13 13
@@ -24,7 +24,7 @@ use crate::pages::repo_settings::{notice_banner_for, take_notice};
24 use crate::state::AppState;24 use crate::state::AppState;
25 use crate::views::parts::head;25 use crate::views::parts::head;
26 use crate::views::repo_list::private_fact;26 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};
28 28
29 /// Rows a topic lists on the home page, before its link to the full list.29 /// Rows a topic lists on the home page, before its link to the full list.
30 const TOPIC_ROWS: usize = 5;30 const TOPIC_ROWS: usize = 5;
@@ -54,7 +54,7 @@ struct SignedHome {
54 54
55 #[page("/")]55 #[page("/")]
56 async fn home(cx: &Cx) -> Result<impl View> {56 async fn home(cx: &Cx) -> Result<impl View> {
57- let state = app_context::<AppState>(cx);57+ let state = context::<AppState>(cx);
58 let viewer = current_user(cx).await?;58 let viewer = current_user(cx).await?;
59 let lang = i18n::lang(cx, viewer.as_ref().map(|(user, _)| user));59 let lang = i18n::lang(cx, viewer.as_ref().map(|(user, _)| user));
60 let notice = take_notice(cx);60 let notice = take_notice(cx);
@@ -197,7 +197,7 @@ async fn load_home(state: &AppState, user: &User, lang: Lang) -> Result<SignedHo
197 197
198 /// The signed-in home: the head's actions, then the two topics on one sheet.198 /// The signed-in home: the head's actions, then the two topics on one sheet.
199 #[component]199 #[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> {
201 let SignedHome {201 let SignedHome {
202 needs,202 needs,
203 repos,203 repos,
@@ -257,7 +257,7 @@ async fn signed_home(lang: Lang, data: SignedHome, may_org: bool) -> Result<impl
257 257
258 /// The visitor's landing: the wordmark's tagline and the way in.258 /// The visitor's landing: the wordmark's tagline and the way in.
259 #[component]259 #[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> {
261 Ok(view! {261 Ok(view! {
262 head(title: "forge",262 head(title: "forge",
263 <a class="button primary" href="/login">(g::t(lang, K::LogIn))</a>263 <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};
10 use futures_util::stream;10 use futures_util::stream;
11 use serde::Deserialize;11 use serde::Deserialize;
12 use topcoat::Result;12 use topcoat::Result;
13-use topcoat::context::{Cx, app_context};13+use topcoat::context::{Cx, context};
14 use topcoat::router::content::Form;14 use topcoat::router::content::Form;
15 use topcoat::router::error::{SeeOther, not_found, see_other};15 use topcoat::router::error::{SeeOther, not_found, see_other};
16 use topcoat::router::response::Response;16 use topcoat::router::response::Response;
@@ -165,7 +165,7 @@ fn token_of(raw: &str) -> Option<String> {
165 // ---- shared pieces ----165 // ---- shared pieces ----
166 166
167 #[component]167 #[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> {
169 let create = active == "create";169 let create = active == "create";
170 let import = active == "import";170 let import = active == "import";
171 let history = active == "history";171 let history = active == "history";
@@ -179,7 +179,7 @@ pub(crate) async fn newrepo_tabs(lang: Lang, active: &str) -> Result<impl View>
179 }179 }
180 180
181 #[component]181 #[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> {
183 let git = format!("{base}?source=git");183 let git = format!("{base}?source=git");
184 let github = format!("{base}?source=github");184 let github = format!("{base}?source=github");
185 let gitlab = format!("{base}?source=gitlab");185 let gitlab = format!("{base}?source=gitlab");
@@ -199,7 +199,7 @@ async fn source_tabs(lang: Lang, base: &str, active: Source) -> Result<impl View
199 199
200 /// Public or private, as two switches with what each means under it. Shared with the create page.200 /// Public or private, as two switches with what each means under it. Shared with the create page.
201 #[component]201 #[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> {
203 Ok(view! {203 Ok(view! {
204 <div class="field">204 <div class="field">
205 <span class="field-label">(crate::i18n::misc::t(lang, crate::i18n::misc::K::VisibilityLegend))</span>205 <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
212 }212 }
213 213
214 #[component]214 #[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> {
216 Ok(view! {216 Ok(view! {
217 <div class="field" role="group" aria-labelledby="import-what">217 <div class="field" role="group" aria-labelledby="import-what">
218 <span class="field-label" id="import-what">(g::t(lang, K::WhatToImport))</span>218 <span class="field-label" id="import-what">(g::t(lang, K::WhatToImport))</span>
@@ -283,6 +283,7 @@ impl Draft {
283 283
284 #[component]284 #[component]
285 async fn import_form(285 async fn import_form(
286+ cx: &Cx,
286 lang: Lang,287 lang: Lang,
287 username: String,288 username: String,
288 csrf: &str,289 csrf: &str,
@@ -391,6 +392,7 @@ async fn import_form(
391 /// The GET import page: the form. Past imports are on the Import history tab.392 /// The GET import page: the form. Past imports are on the Import history tab.
392 #[component]393 #[component]
393 async fn import_home(394 async fn import_home(
395+ cx: &Cx,
394 lang: Lang,396 lang: Lang,
395 username: String,397 username: String,
396 csrf: String,398 csrf: String,
@@ -405,6 +407,7 @@ async fn import_home(
405 /// The import form again after a rejected submit.407 /// The import form again after a rejected submit.
406 #[component]408 #[component]
407 async fn import_error_body(409 async fn import_error_body(
410+ cx: &Cx,
408 lang: Lang,411 lang: Lang,
409 username: String,412 username: String,
410 csrf: String,413 csrf: String,
@@ -423,10 +426,10 @@ async fn import_page(cx: &Cx) -> Result<impl View> {
423 let lang = i18n::lang(cx, Some(&viewer.0));426 let lang = i18n::lang(cx, Some(&viewer.0));
424 let query = query_params::<SourceQuery>(cx)?;427 let query = query_params::<SourceQuery>(cx)?;
425 let source = source_of(query.source.as_deref());428 let source = source_of(query.source.as_deref());
426- let state = app_context::<AppState>(cx);429+ let state = context::<AppState>(cx);
427 let owners = owner_choices(state, &viewer.0).await?;430 let owners = owner_choices(state, &viewer.0).await?;
428 let csrf = viewer.1.csrf_token.clone();431 let csrf = viewer.1.csrf_token.clone();
429- Ok(view! { cx =>432+ Ok(view! {
430 shell(title: g::t(lang, K::ImportTitle), viewer: Some(&viewer),433 shell(title: g::t(lang, K::ImportTitle), viewer: Some(&viewer),
431 import_home(lang: lang, username: viewer.0.username.clone(), csrf: csrf, draft: Draft::fresh(source), owners: owners))434 import_home(lang: lang, username: viewer.0.username.clone(), csrf: csrf, draft: Draft::fresh(source), owners: owners))
432 })435 })
@@ -440,10 +443,10 @@ async fn import_submit(cx: &Cx, Form(form): Form<ImportForm>) -> Result<impl Vie
440 match start_single(cx, &viewer.0, lang, source, &form).await? {443 match start_single(cx, &viewer.0, lang, source, &form).await? {
441 Ok(job_id) => Err(see_other(format!("/import/{job_id}")).into()),444 Ok(job_id) => Err(see_other(format!("/import/{job_id}")).into()),
442 Err(message) => {445 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?;
444 let csrf = viewer.1.csrf_token.clone();447 let csrf = viewer.1.csrf_token.clone();
445 let draft = Draft::from_form(&form, source);448 let draft = Draft::from_form(&form, source);
446- Ok(view! { cx =>449+ Ok(view! {
447 shell(title: g::t(lang, K::ImportTitle), viewer: Some(&viewer),450 shell(title: g::t(lang, K::ImportTitle), viewer: Some(&viewer),
448 import_error_body(lang: lang, username: viewer.0.username.clone(), csrf: csrf, draft: draft, error: message, owners: owners))451 import_error_body(lang: lang, username: viewer.0.username.clone(), csrf: csrf, draft: draft, error: message, owners: owners))
449 })452 })
@@ -460,7 +463,7 @@ async fn start_single(
460 source: Source,463 source: Source,
461 form: &ImportForm,464 form: &ImportForm,
462 ) -> Result<std::result::Result<String, String>> {465 ) -> Result<std::result::Result<String, String>> {
463- let state = app_context::<AppState>(cx);466+ let state = context::<AppState>(cx);
464 let Some((remote, instance)) = parse_remote(source, &form.remote, &form.instance) else {467 let Some((remote, instance)) = parse_remote(source, &form.remote, &form.instance) else {
465 let message = if has_instance(source) && form.remote.trim().starts_with("http") {468 let message = if has_instance(source) && form.remote.trim().starts_with("http") {
466 g::t(lang, K::ErrBadInstance)469 g::t(lang, K::ErrBadInstance)
@@ -526,7 +529,7 @@ async fn begin(
526 visibility: Visibility,529 visibility: Visibility,
527 spec: JobSpec,530 spec: JobSpec,
528 ) -> Result<std::result::Result<String, String>> {531 ) -> Result<std::result::Result<String, String>> {
529- let state = app_context::<AppState>(cx);532+ let state = context::<AppState>(cx);
530 let lang = i18n::lang(cx, Some(actor));533 let lang = i18n::lang(cx, Some(actor));
531 let name = match forge_core::names::validate_name(name) {534 let name = match forge_core::names::validate_name(name) {
532 Ok(name) => name,535 Ok(name) => name,
@@ -589,6 +592,7 @@ async fn begin(
589 592
590 #[component]593 #[component]
591 async fn bulk_form(594 async fn bulk_form(
595+ cx: &Cx,
592 lang: Lang,596 lang: Lang,
593 username: String,597 username: String,
594 csrf: &str,598 csrf: &str,
@@ -652,6 +656,7 @@ struct Listed {
652 656
653 #[component]657 #[component]
654 async fn bulk_select(658 async fn bulk_select(
659+ cx: &Cx,
655 lang: Lang,660 lang: Lang,
656 username: String,661 username: String,
657 csrf: &str,662 csrf: &str,
@@ -748,9 +753,9 @@ async fn bulk_page(cx: &Cx) -> Result<impl View> {
748 Source::Git => Source::GitHub,753 Source::Git => Source::GitHub,
749 other => other,754 other => other,
750 };755 };
751- let owners = owner_choices(app_context::<AppState>(cx), &viewer.0).await?;756+ let owners = owner_choices(context::<AppState>(cx), &viewer.0).await?;
752 let csrf = viewer.1.csrf_token.clone();757 let csrf = viewer.1.csrf_token.clone();
753- Ok(view! { cx =>758+ Ok(view! {
754 shell(title: g::t(lang, K::BulkTitle), viewer: Some(&viewer),759 shell(title: g::t(lang, K::BulkTitle), viewer: Some(&viewer),
755 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)))760 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)))
756 })761 })
@@ -790,7 +795,7 @@ async fn list_remote(
790 async fn bulk_submit(cx: &Cx, Form(form): Form<BulkForm>) -> Result<impl View> {795 async fn bulk_submit(cx: &Cx, Form(form): Form<BulkForm>) -> Result<impl View> {
791 let viewer = require_csrf(cx, &form.csrf).await?;796 let viewer = require_csrf(cx, &form.csrf).await?;
792 let lang = i18n::lang(cx, Some(&viewer.0));797 let lang = i18n::lang(cx, Some(&viewer.0));
793- let state = app_context::<AppState>(cx);798+ let state = context::<AppState>(cx);
794 let source = match source_of(Some(&form.source)) {799 let source = match source_of(Some(&form.source)) {
795 Source::Git => Source::GitHub,800 Source::Git => Source::GitHub,
796 other => other,801 other => other,
@@ -849,7 +854,7 @@ async fn bulk_submit(cx: &Cx, Form(form): Form<BulkForm>) -> Result<impl View> {
849 (None, Some((echo, repos)))854 (None, Some((echo, repos)))
850 }855 }
851 };856 };
852- Ok(view! { cx =>857+ Ok(view! {
853 shell(title: g::t(lang, K::BulkTitle), viewer: Some(&viewer),858 shell(title: g::t(lang, K::BulkTitle), viewer: Some(&viewer),
854 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))859 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))
855 })860 })
@@ -858,6 +863,7 @@ async fn bulk_submit(cx: &Cx, Form(form): Form<BulkForm>) -> Result<impl View> {
858 /// The bulk page body: the picker once a listing exists, the lookup form otherwise.863 /// The bulk page body: the picker once a listing exists, the lookup form otherwise.
859 #[component]864 #[component]
860 async fn bulk_stage(865 async fn bulk_stage(
866+ cx: &Cx,
861 lang: Lang,867 lang: Lang,
862 username: String,868 username: String,
863 csrf: &str,869 csrf: &str,
@@ -885,7 +891,7 @@ async fn run_bulk(
885 instance: &str,891 instance: &str,
886 form: &BulkForm,892 form: &BulkForm,
887 ) -> Result<std::convert::Infallible> {893 ) -> Result<std::convert::Infallible> {
888- let state = app_context::<AppState>(cx);894+ let state = context::<AppState>(cx);
889 let mut picked: Vec<(usize, &String)> = form895 let mut picked: Vec<(usize, &String)> = form
890 .extra896 .extra
891 .iter()897 .iter()
@@ -1025,7 +1031,7 @@ async fn load_job_rows(
1025 1031
1026 /// The import job rows, shared by the Import history page and the recent list on the Import tab.1032 /// The import job rows, shared by the Import history page and the recent list on the Import tab.
1027 #[component]1033 #[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> {
1029 Ok(view! {1035 Ok(view! {
1030 <div>1036 <div>
1031 for (job, repo) in jobs.iter() {1037 for (job, repo) in jobs.iter() {
@@ -1046,6 +1052,7 @@ async fn job_rows(lang: Lang, jobs: Vec<(ImportJob, Option<Repo>)>) -> Result<im
1046 1052
1047 #[component]1053 #[component]
1048 async fn jobs_list(1054 async fn jobs_list(
1055+ cx: &Cx,
1049 lang: Lang,1056 lang: Lang,
1050 username: String,1057 username: String,
1051 jobs: Vec<(ImportJob, Option<Repo>)>,1058 jobs: Vec<(ImportJob, Option<Repo>)>,
@@ -1108,7 +1115,7 @@ async fn jobs_fingerprint(state: &AppState, user_id: &str) -> Result<String> {
1108 #[route(GET "/import/events")]1115 #[route(GET "/import/events")]
1109 async fn jobs_events(cx: &Cx) -> Result<Response> {1116 async fn jobs_events(cx: &Cx) -> Result<Response> {
1110 let viewer = require_user(cx).await?;1117 let viewer = require_user(cx).await?;
1111- let state = app_context::<AppState>(cx).clone();1118+ let state = context::<AppState>(cx).clone();
1112 let user_id = viewer.0.id.clone();1119 let user_id = viewer.0.id.clone();
1113 stream_changes(1120 stream_changes(
1114 cx,1121 cx,
@@ -1130,7 +1137,7 @@ const HISTORY_ROWS: u64 = 10;
1130 async fn jobs_page(cx: &Cx) -> Result<impl View> {1137 async fn jobs_page(cx: &Cx) -> Result<impl View> {
1131 let viewer = require_user(cx).await?;1138 let viewer = require_user(cx).await?;
1132 let lang = i18n::lang(cx, Some(&viewer.0));1139 let lang = i18n::lang(cx, Some(&viewer.0));
1133- let state = app_context::<AppState>(cx);1140+ let state = context::<AppState>(cx);
1134 let query = query_params::<JobsQuery>(cx)?;1141 let query = query_params::<JobsQuery>(cx)?;
1135 let all = state.store.list_import_jobs(&viewer.0.id, 1000).await?;1142 let all = state.store.list_import_jobs(&viewer.0.id, 1000).await?;
1136 let pages = (all.len() as u64).div_ceil(HISTORY_ROWS).max(1);1143 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> {
1157 .clone()1164 .clone()
1158 .filter(|s| !s.is_empty() && s.len() < 2000)1165 .filter(|s| !s.is_empty() && s.len() < 2000)
1159 .map(|s| g::bulk_skipped(lang, &s));1166 .map(|s| g::bulk_skipped(lang, &s));
1160- Ok(view! { cx =>1167+ Ok(view! {
1161 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))1168 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))
1162 })1169 })
1163 }1170 }
1164 1171
1165 #[component]1172 #[component]
1166 async fn job_view(1173 async fn job_view(
1174+ cx: &Cx,
1167 lang: Lang,1175 lang: Lang,
1168 username: String,1176 username: String,
1169 csrf: &str,1177 csrf: &str,
@@ -1256,8 +1264,8 @@ async fn job_view(
1256 1264
1257 /// The job when the viewer owns it. Anyone else gets 404.1265 /// The job when the viewer owns it. Anyone else gets 404.
1258 async fn owned_job(cx: &Cx, viewer: &User) -> Result<ImportJob> {1266 async fn owned_job(cx: &Cx, viewer: &User) -> Result<ImportJob> {
1259- let id = path_param::<JobId>(cx).to_owned();1267+ let id = job_id(cx).to_owned();
1260- let state = app_context::<AppState>(cx);1268+ let state = context::<AppState>(cx);
1261 match state.store.import_job(&id).await? {1269 match state.store.import_job(&id).await? {
1262 Some(job) if job.user_id == viewer.id => Ok(job),1270 Some(job) if job.user_id == viewer.id => Ok(job),
1263 _ => Err(not_found().into()),1271 _ => Err(not_found().into()),
@@ -1268,13 +1276,13 @@ async fn owned_job(cx: &Cx, viewer: &User) -> Result<ImportJob> {
1268 async fn job_page(cx: &Cx) -> Result<impl View> {1276 async fn job_page(cx: &Cx) -> Result<impl View> {
1269 let viewer = require_user(cx).await?;1277 let viewer = require_user(cx).await?;
1270 let lang = i18n::lang(cx, Some(&viewer.0));1278 let lang = i18n::lang(cx, Some(&viewer.0));
1271- let state = app_context::<AppState>(cx);1279+ let state = context::<AppState>(cx);
1272 let job = owned_job(cx, &viewer.0).await?;1280 let job = owned_job(cx, &viewer.0).await?;
1273 let repo = job_repo(state, Some(&viewer.0), &job).await?;1281 let repo = job_repo(state, Some(&viewer.0), &job).await?;
1274 let log = state.store.list_import_events(&job.id, 200).await?;1282 let log = state.store.list_import_events(&job.id, 200).await?;
1275 let csrf = viewer.1.csrf_token.clone();1283 let csrf = viewer.1.csrf_token.clone();
1276 let title = job.source_ref.clone();1284 let title = job.source_ref.clone();
1277- Ok(view! { cx =>1285+ Ok(view! {
1278 shell(title: title.as_str(), viewer: Some(&viewer),1286 shell(title: title.as_str(), viewer: Some(&viewer),
1279 job_view(lang: lang, username: viewer.0.username.clone(), csrf: csrf.as_str(), job: job, repo: repo, log: log))1287 job_view(lang: lang, username: viewer.0.username.clone(), csrf: csrf.as_str(), job: job, repo: repo, log: log))
1280 })1288 })
@@ -1287,7 +1295,7 @@ async fn job_events(cx: &Cx) -> Result<Response> {
1287 let viewer = require_user(cx).await?;1295 let viewer = require_user(cx).await?;
1288 let job = owned_job(cx, &viewer.0).await?;1296 let job = owned_job(cx, &viewer.0).await?;
1289 let query = query_params::<SeenQuery>(cx)?;1297 let query = query_params::<SeenQuery>(cx)?;
1290- let state = app_context::<AppState>(cx);1298+ let state = context::<AppState>(cx);
1291 let seen = query.v.clone().unwrap_or_default();1299 let seen = query.v.clone().unwrap_or_default();
1292 // Subscribed before the job is read again below, so a change in between is not lost.1300 // Subscribed before the job is read again below, so a change in between is not lost.
1293 let wake = (!job.state.is_finished()).then(|| importer::subscribe(&job.id));1301 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
1375 #[route(POST "/import/{job_id}/retry")]1383 #[route(POST "/import/{job_id}/retry")]
1376 async fn job_retry(cx: &Cx, Form(form): Form<RetryForm>) -> Result<SeeOther> {1384 async fn job_retry(cx: &Cx, Form(form): Form<RetryForm>) -> Result<SeeOther> {
1377 let viewer = require_csrf(cx, &form.csrf).await?;1385 let viewer = require_csrf(cx, &form.csrf).await?;
1378- let state = app_context::<AppState>(cx);1386+ let state = context::<AppState>(cx);
1379 let job = owned_job(cx, &viewer.0).await?;1387 let job = owned_job(cx, &viewer.0).await?;
1380 let href = format!("/import/{}", job.id);1388 let href = format!("/import/{}", job.id);
1381 retry_job(state, job, &form.token).await?;1389 retry_job(state, job, &form.token).await?;
@@ -1414,7 +1422,13 @@ fn source_label(raw: &str) -> &'static str {
1414 }1422 }
1415 1423
1416 #[component]1424 #[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> {
1418 let count = rows.len();1432 let count = rows.len();
1419 let empty = rows.is_empty();1433 let empty = rows.is_empty();
1420 Ok(view! {1434 Ok(view! {
@@ -1462,10 +1476,10 @@ async fn retry_list(lang: Lang, username: String, csrf: &str, rows: Vec<(ImportJ
1462 async fn retry_page(cx: &Cx) -> Result<impl View> {1476 async fn retry_page(cx: &Cx) -> Result<impl View> {
1463 let viewer = require_user(cx).await?;1477 let viewer = require_user(cx).await?;
1464 let lang = i18n::lang(cx, Some(&viewer.0));1478 let lang = i18n::lang(cx, Some(&viewer.0));
1465- let state = app_context::<AppState>(cx);1479+ let state = context::<AppState>(cx);
1466 let rows = retry_candidates(state, &viewer.0).await?;1480 let rows = retry_candidates(state, &viewer.0).await?;
1467 let csrf = viewer.1.csrf_token.clone();1481 let csrf = viewer.1.csrf_token.clone();
1468- Ok(view! { cx =>1482+ Ok(view! {
1469 shell(title: g::t(lang, K::RetryFailedTitle), viewer: Some(&viewer),1483 shell(title: g::t(lang, K::RetryFailedTitle), viewer: Some(&viewer),
1470 retry_list(lang: lang, username: viewer.0.username.clone(), csrf: csrf.as_str(), rows: rows))1484 retry_list(lang: lang, username: viewer.0.username.clone(), csrf: csrf.as_str(), rows: rows))
1471 })1485 })
@@ -1485,7 +1499,7 @@ struct RetrySelectedForm {
1485 #[route(POST "/import/retry")]1499 #[route(POST "/import/retry")]
1486 async fn retry_submit(cx: &Cx, Form(form): Form<RetrySelectedForm>) -> Result<SeeOther> {1500 async fn retry_submit(cx: &Cx, Form(form): Form<RetrySelectedForm>) -> Result<SeeOther> {
1487 let viewer = require_csrf(cx, &form.csrf).await?;1501 let viewer = require_csrf(cx, &form.csrf).await?;
1488- let state = app_context::<AppState>(cx);1502+ let state = context::<AppState>(cx);
1489 let mut picked: Vec<(usize, &String)> = form1503 let mut picked: Vec<(usize, &String)> = form
1490 .extra1504 .extra
1491 .iter()1505 .iter()
crates/forge-web/src/pages/invites.rsmodified+3 -2
@@ -6,7 +6,7 @@ use forge_core::store::validate_email;
6 use forge_core::{AuditAction, Registration};6 use forge_core::{AuditAction, Registration};
7 use serde::Deserialize;7 use serde::Deserialize;
8 use topcoat::Result;8 use topcoat::Result;
9-use topcoat::context::{Cx, app_context};9+use topcoat::context::{Cx, context};
10 use topcoat::router::content::Form;10 use topcoat::router::content::Form;
11 use topcoat::router::error::forbidden;11 use topcoat::router::error::forbidden;
12 use topcoat::router::page;12 use topcoat::router::page;
@@ -31,6 +31,7 @@ struct InviteForm {
31 31
32 #[component]32 #[component]
33 async fn invite_body(33 async fn invite_body(
34+ cx: &Cx,
34 lang: Lang,35 lang: Lang,
35 csrf: &str,36 csrf: &str,
36 notice: Option<&'static str>,37 notice: Option<&'static str>,
@@ -78,7 +79,7 @@ async fn invites_submit(cx: &Cx, Form(form): Form<InviteForm>) -> Result<impl Vi
78 if !check_csrf(&viewer.1, &form.csrf) {79 if !check_csrf(&viewer.1, &form.csrf) {
79 return Err(forbidden().into());80 return Err(forbidden().into());
80 }81 }
81- let state = app_context::<AppState>(cx);82+ let state = context::<AppState>(cx);
82 let lang = i18n::lang(cx, Some(&viewer.0));83 let lang = i18n::lang(cx, Some(&viewer.0));
83 let address = form.email.trim().to_owned();84 let address = form.email.trim().to_owned();
84 let mut notice = None;85 let mut notice = None;
crates/forge-web/src/pages/issue_meta.rsmodified+25 -19
@@ -9,7 +9,7 @@ use forge_core::User;
9 use forge_core::authz::{Action, authorize};9 use forge_core::authz::{Action, authorize};
10 use forge_core::issues::{Issue, Label};10 use forge_core::issues::{Issue, Label};
11 use topcoat::Result;11 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};12+use topcoat::context::{Cx, context};
13 use topcoat::router::content::RawForm;13 use topcoat::router::content::RawForm;
14 use topcoat::router::error::{forbidden, not_found, see_other};14 use topcoat::router::error::{forbidden, not_found, see_other};
15 use topcoat::router::{page, path_param};15 use topcoat::router::{page, path_param};
@@ -85,7 +85,12 @@ pub(crate) fn refusal_message(e: forge_core::Error) -> Result<String> {
85 /// Links between the issue-adjacent pages of a repo: Issues, Labels and Milestones. The one named85 /// Links between the issue-adjacent pages of a repo: Issues, Labels and Milestones. The one named
86 /// by `active` is the current page.86 /// by `active` is the current page.
87 #[component]87 #[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> {
89 let issues = format!("/{title}/issues");94 let issues = format!("/{title}/issues");
90 let labels = format!("/{title}/labels");95 let labels = format!("/{title}/labels");
91 let milestones = format!("/{title}/milestones");96 let milestones = format!("/{title}/milestones");
@@ -170,7 +175,7 @@ pub(crate) async fn item_from_path(
170 let Some(n) = number.parse::<i64>().ok() else {175 let Some(n) = number.parse::<i64>().ok() else {
171 return Err(not_found().into());176 return Err(not_found().into());
172 };177 };
173- let store = &app_context::<AppState>(cx).store;178+ let store = &context::<AppState>(cx).store;
174 let found = match kind {179 let found = match kind {
175 ItemKind::Issue => store.issue_by_number(&ctx.repo.id, n).await?,180 ItemKind::Issue => store.issue_by_number(&ctx.repo.id, n).await?,
176 ItemKind::Pull => store181 ItemKind::Pull => store
@@ -197,6 +202,7 @@ pub(crate) fn item_href(ctx: &RepoCtx, kind: ItemKind, number: i64) -> String {
197 /// The error box with a link back to where the action came from, in the viewer's language.202 /// The error box with a link back to where the action came from, in the viewer's language.
198 #[component]203 #[component]
199 pub(crate) async fn action_error_at(204 pub(crate) async fn action_error_at(
205+ cx: &Cx,
200 lang: Lang,206 lang: Lang,
201 message: String,207 message: String,
202 back: String,208 back: String,
@@ -224,19 +230,19 @@ async fn pull_labels_save(cx: &Cx, RawForm(raw): RawForm) -> Result<impl View> {
224 }230 }
225 231
226 async fn labels_save(cx: &Cx, kind: ItemKind, fields: Vec<(String, String)>) -> Result<impl View> {232 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?;233+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
228- let item = item_from_path(cx, &ctx, kind, path_param::<Number>(cx)).await?;234+ let item = item_from_path(cx, &ctx, kind, number(cx)).await?;
229 let user = triage_guard(cx, &ctx, &form_field(&fields, "csrf")).await?;235 let user = triage_guard(cx, &ctx, &form_field(&fields, "csrf")).await?;
230 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));236 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
231 let ids = form_all(&fields, "label");237 let ids = form_all(&fields, "label");
232 let back = item_href(&ctx, kind, item.number);238 let back = item_href(&ctx, kind, item.number);
233- let state = app_context::<AppState>(cx);239+ let state = context::<AppState>(cx);
234 let pull = matches!(kind, ItemKind::Pull);240 let pull = matches!(kind, ItemKind::Pull);
235 let before = item_labels(state, &item.id).await;241 let before = item_labels(state, &item.id).await;
236 let result = state.store.set_issue_labels(&item.id, &user.id, &ids).await;242 let result = state.store.set_issue_labels(&item.id, &user.id, &ids).await;
237 if let Err(e) = result {243 if let Err(e) = result {
238 let message = refusal_message(e)?;244 let message = refusal_message(e)?;
239- return Ok(view! { cx =>245+ return Ok(view! {
240 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),246 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),
241 action_error_at(lang: lang, message: message, back: back))247 action_error_at(lang: lang, message: message, back: back))
242 });248 });
@@ -264,8 +270,8 @@ async fn assignees_save(
264 kind: ItemKind,270 kind: ItemKind,
265 fields: Vec<(String, String)>,271 fields: Vec<(String, String)>,
266 ) -> Result<impl View> {272 ) -> Result<impl View> {
267- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;273+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
268- let item = item_from_path(cx, &ctx, kind, path_param::<Number>(cx)).await?;274+ let item = item_from_path(cx, &ctx, kind, number(cx)).await?;
269 let user = triage_guard(cx, &ctx, &form_field(&fields, "csrf")).await?;275 let user = triage_guard(cx, &ctx, &form_field(&fields, "csrf")).await?;
270 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));276 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
271 let usernames: Vec<String> = form_field(&fields, "assignees")277 let usernames: Vec<String> = form_field(&fields, "assignees")
@@ -275,7 +281,7 @@ async fn assignees_save(
275 .map(str::to_owned)281 .map(str::to_owned)
276 .collect();282 .collect();
277 let back = item_href(&ctx, kind, item.number);283 let back = item_href(&ctx, kind, item.number);
278- let state = app_context::<AppState>(cx);284+ let state = context::<AppState>(cx);
279 let pull = matches!(kind, ItemKind::Pull);285 let pull = matches!(kind, ItemKind::Pull);
280 let before = assignee_names(state, &item.id).await;286 let before = assignee_names(state, &item.id).await;
281 let result = state287 let result = state
@@ -284,7 +290,7 @@ async fn assignees_save(
284 .await;290 .await;
285 if let Err(e) = result {291 if let Err(e) = result {
286 let message = refusal_message(e)?;292 let message = refusal_message(e)?;
287- return Ok(view! { cx =>293+ return Ok(view! {
288 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),294 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),
289 action_error_at(lang: lang, message: message, back: back))295 action_error_at(lang: lang, message: message, back: back))
290 });296 });
@@ -335,14 +341,14 @@ async fn pull_lock_save(cx: &Cx, RawForm(raw): RawForm) -> Result<impl View> {
335 }341 }
336 342
337 async fn lock_save(cx: &Cx, kind: ItemKind, fields: Vec<(String, String)>) -> Result<impl View> {343 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?;344+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
339- let item = item_from_path(cx, &ctx, kind, path_param::<Number>(cx)).await?;345+ let item = item_from_path(cx, &ctx, kind, number(cx)).await?;
340 let user = triage_guard(cx, &ctx, &form_field(&fields, "csrf")).await?;346 let user = triage_guard(cx, &ctx, &form_field(&fields, "csrf")).await?;
341 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));347 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
342 let locked = form_field(&fields, "locked") == "1";348 let locked = form_field(&fields, "locked") == "1";
343 let reason = form_field(&fields, "reason");349 let reason = form_field(&fields, "reason");
344 let back = item_href(&ctx, kind, item.number);350 let back = item_href(&ctx, kind, item.number);
345- let state = app_context::<AppState>(cx);351+ let state = context::<AppState>(cx);
346 let result = state352 let result = state
347 .store353 .store
348 .set_issue_locked(&item.id, Some(&user.id), locked, Some(reason.as_str()))354 .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
351 Ok(changed) => changed,357 Ok(changed) => changed,
352 Err(e) => {358 Err(e) => {
353 let message = refusal_message(e)?;359 let message = refusal_message(e)?;
354- return Ok(view! { cx =>360+ return Ok(view! {
355 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),361 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),
356 action_error_at(lang: lang, message: message, back: back))362 action_error_at(lang: lang, message: message, back: back))
357 });363 });
@@ -383,14 +389,14 @@ async fn milestone_save(
383 kind: ItemKind,389 kind: ItemKind,
384 fields: Vec<(String, String)>,390 fields: Vec<(String, String)>,
385 ) -> Result<impl View> {391 ) -> Result<impl View> {
386- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;392+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
387- let item = item_from_path(cx, &ctx, kind, path_param::<Number>(cx)).await?;393+ let item = item_from_path(cx, &ctx, kind, number(cx)).await?;
388 let user = triage_guard(cx, &ctx, &form_field(&fields, "csrf")).await?;394 let user = triage_guard(cx, &ctx, &form_field(&fields, "csrf")).await?;
389 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));395 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
390 let milestone_id = form_field(&fields, "milestone_id");396 let milestone_id = form_field(&fields, "milestone_id");
391 let milestone = (!milestone_id.is_empty()).then_some(milestone_id.as_str());397 let milestone = (!milestone_id.is_empty()).then_some(milestone_id.as_str());
392 let back = item_href(&ctx, kind, item.number);398 let back = item_href(&ctx, kind, item.number);
393- let state = app_context::<AppState>(cx);399+ let state = context::<AppState>(cx);
394 let before = match item.milestone_id.as_deref() {400 let before = match item.milestone_id.as_deref() {
395 Some(id) => milestone_title(state, &ctx.repo.id, id).await,401 Some(id) => milestone_title(state, &ctx.repo.id, id).await,
396 None => None,402 None => None,
@@ -401,7 +407,7 @@ async fn milestone_save(
401 .await;407 .await;
402 if let Err(e) = result {408 if let Err(e) = result {
403 let message = refusal_message(e)?;409 let message = refusal_message(e)?;
404- return Ok(view! { cx =>410+ return Ok(view! {
405 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),411 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),
406 action_error_at(lang: lang, message: message, back: back))412 action_error_at(lang: lang, message: message, back: back))
407 });413 });
crates/forge-web/src/pages/issue_parts.rsmodified+42 -14
@@ -4,6 +4,7 @@
4 //! On a pull request the timeline also holds its submitted reviews, each with its threads.4 //! On a pull request the timeline also holds its submitted reviews, each with its threads.
5 5
6 use std::collections::HashSet;6 use std::collections::HashSet;
7+use topcoat::context::Cx;
7 8
8 use forge_core::{Action, Comment, Issue, IssueEvent, IssueState, Session, StateReason, User};9 use forge_core::{Action, Comment, Issue, IssueEvent, IssueState, Session, StateReason, User};
9 use forge_core::{Reaction, ReactionSummary, ReactionTarget};10 use forge_core::{Reaction, ReactionSummary, ReactionTarget};
@@ -25,13 +26,13 @@ use crate::pages::repo_ctx::RepoCtx;
25 use crate::pages::tree::link_context;26 use crate::pages::tree::link_context;
26 use crate::render::markdown::{LinkContext, render_markdown};27 use crate::render::markdown::{LinkContext, render_markdown};
27 use crate::state::AppState;28 use crate::state::AppState;
29+use crate::views::parts::{confirm_act, post_act, reveal};
28 use crate::views::review_thread::{ThreadCtx, review_thread_in};30 use crate::views::review_thread::{ThreadCtx, review_thread_in};
29 use crate::views::user_facing_message;31 use crate::views::user_facing_message;
30 use crate::views::{32 use crate::views::{
31- alert, avatar_url, avatar_url_unknown, display_name, iso_time, now_unix, relative_time, repo_href, short_oid,33+ alert, avatar_url, avatar_url_unknown, display_name, iso_time, now_unix, relative_time,
32- user_href, user_link,34+ repo_href, short_oid, user_href, user_link,
33 };35 };
34-use crate::views::parts::{confirm_act, post_act, reveal};
35 use crate::webhooks::emit::{Sender, emit_comment, emit_item_action};36 use crate::webhooks::emit::{Sender, emit_comment, emit_item_action};
36 37
37 /// Which kind of item a page shows. It decides the URL segment of the item's own links and which38 /// 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(
433 }434 }
434 435
435 #[component]436 #[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> {
437 let CommentView {438 let CommentView {
438 anchor,439 anchor,
439 author,440 author,
@@ -499,7 +500,7 @@ pub(crate) async fn comment_item(lang: Lang, item: CommentView) -> Result<impl V
499 500
500 /// The reaction row under an item or comment: the buttons, then the picker when the viewer may react.501 /// The reaction row under an item or comment: the buttons, then the picker when the viewer may react.
501 #[component]502 #[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> {
503 let ReactionBar {504 let ReactionBar {
504 chips,505 chips,
505 picker,506 picker,
@@ -519,7 +520,11 @@ pub(crate) async fn reaction_row(lang: Lang, bar: ReactionBar) -> Result<impl Vi
519 520
520 /// The React tool: a word that opens the reaction options in place.521 /// The React tool: a word that opens the reaction options in place.
521 #[component]522 #[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> {
523 Ok(view! {528 Ok(view! {
524 <details class="reaction-picker">529 <details class="reaction-picker">
525 <summary class="act">(g::t(lang, K::AddReaction))</summary>530 <summary class="act">(g::t(lang, K::AddReaction))</summary>
@@ -535,7 +540,7 @@ pub(crate) async fn reaction_picker(lang: Lang, picker: Vec<ReactionButton>) ->
535 /// One reaction button. Enabled buttons are POST forms that toggle the viewer's reaction; the540 /// One reaction button. Enabled buttons are POST forms that toggle the viewer's reaction; the
536 /// others only show the emoji and count.541 /// others only show the emoji and count.
537 #[component]542 #[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> {
539 let ReactionButton {544 let ReactionButton {
540 action,545 action,
541 csrf,546 csrf,
@@ -581,7 +586,7 @@ pub(crate) async fn reaction_button(button: ReactionButton) -> Result<impl View>
581 }586 }
582 587
583 #[component]588 #[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> {
585 let EventLine {590 let EventLine {
586 actor,591 actor,
587 when,592 when,
@@ -617,8 +622,11 @@ pub(crate) async fn event_item(line: EventLine) -> Result<impl View> {
617 /// Consecutive events by one actor, one line: the actor, each event's words joined with " · ", then622 /// Consecutive events by one actor, one line: the actor, each event's words joined with " · ", then
618 /// the time of the last one.623 /// the time of the last one.
619 #[component]624 #[component]
620-pub(crate) async fn event_run(lines: Vec<EventLine>) -> Result<impl View> {625+pub(crate) async fn event_run(cx: &Cx, lines: Vec<EventLine>) -> Result<impl View> {
621- let actor = lines.first().map(|line| line.actor.clone()).unwrap_or_default();626+ let actor = lines
627+ .first()
628+ .map(|line| line.actor.clone())
629+ .unwrap_or_default();
622 let when = lines.last().map(|line| line.when.clone());630 let when = lines.last().map(|line| line.when.clone());
623 Ok(view! {631 Ok(view! {
624 <div class="thread-event">632 <div class="thread-event">
@@ -663,7 +671,7 @@ fn dismissed_verb(lang: Lang, from: Option<ReviewState>) -> &'static str {
663 671
664 /// One submitted review: the reviewer, the verb, the dismissal reason, the body, then its threads.672 /// One submitted review: the reviewer, the verb, the dismissal reason, the body, then its threads.
665 #[component]673 #[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> {
667 let ReviewView {675 let ReviewView {
668 anchor,676 anchor,
669 author,677 author,
@@ -705,7 +713,7 @@ pub(crate) async fn review_item(lang: Lang, review: ReviewView) -> Result<impl V
705 }713 }
706 714
707 #[component]715 #[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> {
709 Ok(view! {717 Ok(view! {
710 match entry {718 match entry {
711 Entry::Comment(item) => comment_item(lang: lang, item: item),719 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
718 726
719 /// The body followed by every timeline entry.727 /// The body followed by every timeline entry.
720 #[component]728 #[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> {
722 let Discussion { body, entries, .. } = discussion;734 let Discussion { body, entries, .. } = discussion;
723 Ok(view! {735 Ok(view! {
724 <div class="issue-timeline">736 <div class="issue-timeline">
@@ -1023,7 +1035,15 @@ pub(crate) fn reaction_bar_for(
1023 .collect();1035 .collect();
1024 let picker = Reaction::ALL1036 let picker = Reaction::ALL
1025 .into_iter()1037 .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+ })
1027 .collect();1047 .collect();
1028 Some(ReactionBar {1048 Some(ReactionBar {
1029 chips,1049 chips,
@@ -1219,6 +1239,7 @@ pub(crate) async fn load_sidebar(state: &AppState, repo_id: &str, item: &Issue)
1219 1239
1220 #[component]1240 #[component]
1221 pub(crate) async fn labels_box(1241 pub(crate) async fn labels_box(
1242+ cx: &Cx,
1222 lang: Lang,1243 lang: Lang,
1223 write: bool,1244 write: bool,
1224 action: String,1245 action: String,
@@ -1266,6 +1287,7 @@ pub(crate) async fn labels_box(
1266 1287
1267 #[component]1288 #[component]
1268 pub(crate) async fn assignees_box(1289 pub(crate) async fn assignees_box(
1290+ cx: &Cx,
1269 lang: Lang,1291 lang: Lang,
1270 write: bool,1292 write: bool,
1271 action: String,1293 action: String,
@@ -1312,6 +1334,7 @@ pub(crate) async fn assignees_box(
1312 1334
1313 #[component]1335 #[component]
1314 pub(crate) async fn milestone_box(1336 pub(crate) async fn milestone_box(
1337+ cx: &Cx,
1315 lang: Lang,1338 lang: Lang,
1316 write: bool,1339 write: bool,
1317 action: String,1340 action: String,
@@ -1358,6 +1381,7 @@ pub(crate) async fn milestone_box(
1358 /// triage holders. Locking is one of the tools at the foot of the sidebar (`item_tools`).1381 /// triage holders. Locking is one of the tools at the foot of the sidebar (`item_tools`).
1359 #[component]1382 #[component]
1360 pub(crate) async fn lock_box(1383 pub(crate) async fn lock_box(
1384+ cx: &Cx,
1361 lang: Lang,1385 lang: Lang,
1362 write: bool,1386 write: bool,
1363 action: String,1387 action: String,
@@ -1395,6 +1419,7 @@ pub(crate) async fn lock_box(
1395 /// reason. `pin` is the pin action when the issue is not pinned and the viewer may pin it.1419 /// reason. `pin` is the pin action when the issue is not pinned and the viewer may pin it.
1396 #[component]1420 #[component]
1397 pub(crate) async fn item_tools(1421 pub(crate) async fn item_tools(
1422+ cx: &Cx,
1398 lang: Lang,1423 lang: Lang,
1399 pin: Option<String>,1424 pin: Option<String>,
1400 lock: Option<String>,1425 lock: Option<String>,
@@ -1439,6 +1464,7 @@ pub(crate) async fn item_tools(
1439 /// `(pinned, action)` for an issue; the pinned row sits in the page (`pin_box`).1464 /// `(pinned, action)` for an issue; the pinned row sits in the page (`pin_box`).
1440 #[component]1465 #[component]
1441 pub(crate) async fn item_sidebar(1466 pub(crate) async fn item_sidebar(
1467+ cx: &Cx,
1442 lang: Lang,1468 lang: Lang,
1443 write: bool,1469 write: bool,
1444 base: String,1470 base: String,
@@ -1492,6 +1518,7 @@ pub(crate) const COMMENT_FORM: &str = "item-comment";
1492 /// and is given only when the viewer may close the item.1518 /// and is given only when the viewer may close the item.
1493 #[component]1519 #[component]
1494 pub(crate) async fn item_head_tools(1520 pub(crate) async fn item_head_tools(
1521+ cx: &Cx,
1495 lang: Lang,1522 lang: Lang,
1496 close: Option<(bool, String)>,1523 close: Option<(bool, String)>,
1497 notify: Option<NotifyBox>,1524 notify: Option<NotifyBox>,
@@ -1523,6 +1550,7 @@ pub(crate) async fn item_head_tools(
1523 /// readers only.1550 /// readers only.
1524 #[component]1551 #[component]
1525 pub(crate) async fn comment_form(1552 pub(crate) async fn comment_form(
1553+ cx: &Cx,
1526 lang: Lang,1554 lang: Lang,
1527 action: String,1555 action: String,
1528 csrf: String,1556 csrf: String,
crates/forge-web/src/pages/issue_pin.rsmodified+6 -5
@@ -6,7 +6,7 @@
6 use serde::Deserialize;6 use serde::Deserialize;
7 use serde_json::Value as Json;7 use serde_json::Value as Json;
8 use topcoat::Result;8 use topcoat::Result;
9-use topcoat::context::{Cx, app_context};9+use topcoat::context::{Cx, context};
10 use topcoat::router::content::Form;10 use topcoat::router::content::Form;
11 use topcoat::router::error::{bad_request, see_other};11 use topcoat::router::error::{bad_request, see_other};
12 use topcoat::router::{page, path_param};12 use topcoat::router::{page, path_param};
@@ -37,8 +37,8 @@ struct PinForm {
37 37
38 #[page(POST "/{owner}/{repo}/issues/{number}/pin")]38 #[page(POST "/{owner}/{repo}/issues/{number}/pin")]
39 async fn issue_pin_save(cx: &Cx, Form(form): Form<PinForm>) -> Result<impl View> {39 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?;40+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
41- let issue = item_from_path(cx, &ctx, ItemKind::Issue, path_param::<Number>(cx)).await?;41+ let issue = item_from_path(cx, &ctx, ItemKind::Issue, number(cx)).await?;
42 let user = triage_guard(cx, &ctx, &form.csrf).await?;42 let user = triage_guard(cx, &ctx, &form.csrf).await?;
43 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));43 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
44 let pin = match form.pinned.as_str() {44 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>
47 _ => return Err(bad_request("pinned must be 1 or 0").into()),47 _ => return Err(bad_request("pinned must be 1 or 0").into()),
48 };48 };
49 let back = item_href(&ctx, ItemKind::Issue, issue.number);49 let back = item_href(&ctx, ItemKind::Issue, issue.number);
50- let state = app_context::<AppState>(cx);50+ let state = context::<AppState>(cx);
51 let result = if pin {51 let result = if pin {
52 state.store.pin_issue(&ctx.repo.id, &issue.id).await52 state.store.pin_issue(&ctx.repo.id, &issue.id).await
53 } else {53 } else {
@@ -66,7 +66,7 @@ async fn issue_pin_save(cx: &Cx, Form(form): Form<PinForm>) -> Result<impl View>
66 }66 }
67 Err(e) => {67 Err(e) => {
68 let message = refusal_message(e)?;68 let message = refusal_message(e)?;
69- return Ok(view! { cx =>69+ return Ok(view! {
70 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),70 shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(),
71 action_error_at(lang: lang, message: message, back: back))71 action_error_at(lang: lang, message: message, back: back))
72 });72 });
@@ -79,6 +79,7 @@ async fn issue_pin_save(cx: &Cx, Form(form): Form<PinForm>) -> Result<impl View>
79 /// Pinning is a tool at the foot of the sidebar (`item_tools`).79 /// Pinning is a tool at the foot of the sidebar (`item_tools`).
80 #[component]80 #[component]
81 pub(crate) async fn pin_box(81 pub(crate) async fn pin_box(
82+ cx: &Cx,
82 lang: Lang,83 lang: Lang,
83 write: bool,84 write: bool,
84 pinned: bool,85 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() {
328 .contains(&format!("/tahinli/forge/issues/{number}\"")),328 .contains(&format!("/tahinli/forge/issues/{number}\"")),
329 "pinned card links the pinned issue"329 "pinned card links the pinned issue"
330 );330 );
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");
332 let list_at = reply.body.find("class=\"line issue-row\"").expect("list");335 let list_at = reply.body.find("class=\"line issue-row\"").expect("list");
333 assert!(card_at < list_at, "pinned cards sit above the list");336 assert!(card_at < list_at, "pinned cards sit above the list");
334 337
crates/forge-web/src/pages/issue_view.rsmodified+31 -31
@@ -9,7 +9,7 @@ use forge_core::{Comment, Issue, IssueState, StateReason};
9 use forge_core::{validate_body, validate_title};9 use forge_core::{validate_body, validate_title};
10 use serde::Deserialize;10 use serde::Deserialize;
11 use topcoat::Result;11 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};12+use topcoat::context::{Cx, context};
13 use topcoat::router::content::Form;13 use topcoat::router::content::Form;
14 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};14 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
15 use topcoat::router::{page, path_param, route};15 use topcoat::router::{page, path_param, route};
@@ -49,7 +49,7 @@ async fn issue_page(
49 error: Option<String>,49 error: Option<String>,
50 ) -> Result<impl View> {50 ) -> Result<impl View> {
51 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));51 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);
53 let owner = ctx.repo.owner_name.clone();53 let owner = ctx.repo.owner_name.clone();
54 let name = ctx.repo.name.clone();54 let name = ctx.repo.name.clone();
55 let number = issue.number;55 let number = issue.number;
@@ -104,7 +104,7 @@ async fn issue_page(
104 let live_href = item_live_url(&owner, &name, number);104 let live_href = item_live_url(&owner, &name, number);
105 105
106 let header = ctx.head(state, "issues").await?;106 let header = ctx.head(state, "issues").await?;
107- Ok(view! { cx =>107+ Ok(view! {
108 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(), extra_stylesheet: Some(labels_href.as_str()),108 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(), extra_stylesheet: Some(labels_href.as_str()),
109 repo_head(head: header, title: Some(issue.title.clone()), sub: sub,109 repo_head(head: header, title: Some(issue.title.clone()), sub: sub,
110 <span class="num">(number_label.as_str())</span>110 <span class="num">(number_label.as_str())</span>
@@ -134,9 +134,9 @@ async fn issue_page(
134 134
135 #[page("/{owner}/{repo}/issues/{number}")]135 #[page("/{owner}/{repo}/issues/{number}")]
136 async fn issue_show(cx: &Cx) -> Result<impl View> {136 async fn issue_show(cx: &Cx) -> Result<impl View> {
137- let number = parse_number(path_param::<Number>(cx))?;137+ let number = parse_number(number(cx))?;
138- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;138+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
139- let state = app_context::<AppState>(cx);139+ let state = context::<AppState>(cx);
140 let Some(issue) = state.store.issue_by_number(&ctx.repo.id, number).await? else {140 let Some(issue) = state.store.issue_by_number(&ctx.repo.id, number).await? else {
141 if state141 if state
142 .store142 .store
@@ -161,11 +161,11 @@ async fn issue_show(cx: &Cx) -> Result<impl View> {
161 /// reopen; without that the request is 403 and nothing is written.161 /// reopen; without that the request is 403 and nothing is written.
162 #[page(POST "/{owner}/{repo}/issues/{number}/comment")]162 #[page(POST "/{owner}/{repo}/issues/{number}/comment")]
163 async fn issue_comment(cx: &Cx, Form(form): Form<CommentForm>) -> Result<impl View> {163 async fn issue_comment(cx: &Cx, Form(form): Form<CommentForm>) -> Result<impl View> {
164- let number = parse_number(path_param::<Number>(cx))?;164+ let number = parse_number(number(cx))?;
165- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;165+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
166 let (user, session) = require_user(cx).await?;166 let (user, session) = require_user(cx).await?;
167 check_write(&ctx, &session, &form.csrf)?;167 check_write(&ctx, &session, &form.csrf)?;
168- let state = app_context::<AppState>(cx);168+ let state = context::<AppState>(cx);
169 let issue = issue_for(state, &ctx, number).await?;169 let issue = issue_for(state, &ctx, number).await?;
170 let lang = i18n::lang(cx, Some(&user));170 let lang = i18n::lang(cx, Some(&user));
171 match post_comment(lang, state, &ctx, &user, &issue, false, &form).await? {171 match post_comment(lang, state, &ctx, &user, &issue, false, &form).await? {
@@ -205,7 +205,7 @@ async fn edit_item_page(
205 error: Option<String>,205 error: Option<String>,
206 ) -> Result<impl View> {206 ) -> Result<impl View> {
207 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));207 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);
209 let owner = ctx.repo.owner_name.clone();209 let owner = ctx.repo.owner_name.clone();
210 let name = ctx.repo.name.clone();210 let name = ctx.repo.name.clone();
211 let csrf = csrf_of(&ctx);211 let csrf = csrf_of(&ctx);
@@ -215,7 +215,7 @@ async fn edit_item_page(
215 let page_title = g::edit_title(lang, number, &format!("{owner}/{name}"));215 let page_title = g::edit_title(lang, number, &format!("{owner}/{name}"));
216 let heading = g::edit_heading(lang, kind == ItemKind::Pull, number);216 let heading = g::edit_heading(lang, kind == ItemKind::Pull, number);
217 let header = ctx.head(state, kind_tab(kind)).await?;217 let header = ctx.head(state, kind_tab(kind)).await?;
218- Ok(view! { cx =>218+ Ok(view! {
219 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(),219 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(),
220 repo_head(head: header, title: Some(heading))220 repo_head(head: header, title: Some(heading))
221 <div class="sheet fit">221 <div class="sheet fit">
@@ -252,10 +252,10 @@ fn kind_tab(kind: ItemKind) -> &'static str {
252 252
253 /// Shows the edit form. Only the author or Triage; anyone else is 403.253 /// Shows the edit form. Only the author or Triage; anyone else is 403.
254 async fn item_edit_form(cx: &Cx, kind: ItemKind) -> Result<impl View> {254 async fn item_edit_form(cx: &Cx, kind: ItemKind) -> Result<impl View> {
255- let number = parse_number(path_param::<Number>(cx))?;255+ let number = parse_number(number(cx))?;
256- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;256+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
257 require_user(cx).await?;257 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?;
259 if !may_change(&ctx, &item.author_id) {259 if !may_change(&ctx, &item.author_id) {
260 return Err(forbidden().into());260 return Err(forbidden().into());
261 }261 }
@@ -264,11 +264,11 @@ async fn item_edit_form(cx: &Cx, kind: ItemKind) -> Result<impl View> {
264 264
265 /// Saves the title and body. Only the author or Triage; the store records the edit history.265 /// Saves the title and body. Only the author or Triage; the store records the edit history.
266 async fn item_edit_save(cx: &Cx, kind: ItemKind, form: IssueForm) -> Result<impl View> {266 async fn item_edit_save(cx: &Cx, kind: ItemKind, form: IssueForm) -> Result<impl View> {
267- let number = parse_number(path_param::<Number>(cx))?;267+ let number = parse_number(number(cx))?;
268- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;268+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
269 let (user, session) = require_user(cx).await?;269 let (user, session) = require_user(cx).await?;
270 check_write(&ctx, &session, &form.csrf)?;270 check_write(&ctx, &session, &form.csrf)?;
271- let state = app_context::<AppState>(cx);271+ let state = context::<AppState>(cx);
272 let item = item_for(state, &ctx, kind, number).await?;272 let item = item_for(state, &ctx, kind, number).await?;
273 if !may_change(&ctx, &item.author_id) {273 if !may_change(&ctx, &item.author_id) {
274 return Err(forbidden().into());274 return Err(forbidden().into());
@@ -313,7 +313,7 @@ async fn edit_comment_page(
313 error: Option<String>,313 error: Option<String>,
314 ) -> Result<impl View> {314 ) -> Result<impl View> {
315 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));315 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);
317 let owner = ctx.repo.owner_name.clone();317 let owner = ctx.repo.owner_name.clone();
318 let name = ctx.repo.name.clone();318 let name = ctx.repo.name.clone();
319 let csrf = csrf_of(&ctx);319 let csrf = csrf_of(&ctx);
@@ -330,7 +330,7 @@ async fn edit_comment_page(
330 );330 );
331 let page_title = g::edit_comment_title(lang, number, &format!("{owner}/{name}"));331 let page_title = g::edit_comment_title(lang, number, &format!("{owner}/{name}"));
332 let header = ctx.head(state, kind_tab(kind)).await?;332 let header = ctx.head(state, kind_tab(kind)).await?;
333- Ok(view! { cx =>333+ Ok(view! {
334 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(),334 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(),
335 repo_head(head: header, title: Some(g::t(lang, K::EditComment).to_owned()))335 repo_head(head: header, title: Some(g::t(lang, K::EditComment).to_owned()))
336 <div class="sheet fit">336 <div class="sheet fit">
@@ -355,12 +355,12 @@ async fn edit_comment_page(
355 355
356 /// Shows the edit form for a comment. Its author or Triage; anyone else is 403.356 /// Shows the edit form for a comment. Its author or Triage; anyone else is 403.
357 async fn item_comment_edit_form(cx: &Cx, kind: ItemKind) -> Result<impl View> {357 async fn item_comment_edit_form(cx: &Cx, kind: ItemKind) -> Result<impl View> {
358- let number = parse_number(path_param::<Number>(cx))?;358+ let number = parse_number(number(cx))?;
359- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;359+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
360 require_user(cx).await?;360 require_user(cx).await?;
361- let state = app_context::<AppState>(cx);361+ let state = context::<AppState>(cx);
362 let item = item_for(state, &ctx, kind, number).await?;362 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?;
364 if !may_change(&ctx, &comment.author_id) {364 if !may_change(&ctx, &comment.author_id) {
365 return Err(forbidden().into());365 return Err(forbidden().into());
366 }366 }
@@ -378,13 +378,13 @@ async fn item_comment_edit_form(cx: &Cx, kind: ItemKind) -> Result<impl View> {
378 378
379 /// Saves an edited comment. Its author or Triage; the store records the previous body.379 /// Saves an edited comment. Its author or Triage; the store records the previous body.
380 async fn item_comment_edit_save(cx: &Cx, kind: ItemKind, form: CommentForm) -> Result<impl View> {380 async fn item_comment_edit_save(cx: &Cx, kind: ItemKind, form: CommentForm) -> Result<impl View> {
381- let number = parse_number(path_param::<Number>(cx))?;381+ let number = parse_number(number(cx))?;
382- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;382+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
383 let (user, session) = require_user(cx).await?;383 let (user, session) = require_user(cx).await?;
384 check_write(&ctx, &session, &form.csrf)?;384 check_write(&ctx, &session, &form.csrf)?;
385- let state = app_context::<AppState>(cx);385+ let state = context::<AppState>(cx);
386 let item = item_for(state, &ctx, kind, number).await?;386 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?;
388 if !may_change(&ctx, &comment.author_id) {388 if !may_change(&ctx, &comment.author_id) {
389 return Err(forbidden().into());389 return Err(forbidden().into());
390 }390 }
@@ -446,13 +446,13 @@ struct CsrfForm {
446 446
447 /// Deletes one comment: its author or Triage. The item's comment count goes down.447 /// Deletes one comment: its author or Triage. The item's comment count goes down.
448 async fn item_comment_delete(cx: &Cx, kind: ItemKind, form: CsrfForm) -> Result<SeeOther> {448 async fn item_comment_delete(cx: &Cx, kind: ItemKind, form: CsrfForm) -> Result<SeeOther> {
449- let number = parse_number(path_param::<Number>(cx))?;449+ let number = parse_number(number(cx))?;
450- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;450+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
451 let (user, session) = require_user(cx).await?;451 let (user, session) = require_user(cx).await?;
452 check_write(&ctx, &session, &form.csrf)?;452 check_write(&ctx, &session, &form.csrf)?;
453- let state = app_context::<AppState>(cx);453+ let state = context::<AppState>(cx);
454 let item = item_for(state, &ctx, kind, number).await?;454 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?;
456 if !may_change(&ctx, &comment.author_id) {456 if !may_change(&ctx, &comment.author_id) {
457 return Err(forbidden().into());457 return Err(forbidden().into());
458 }458 }
crates/forge-web/src/pages/issues_list.rsmodified+17 -11
@@ -9,7 +9,7 @@ use forge_core::{
9 IssueFilter, IssueListItem, IssueSort, IssueState, validate_body, validate_title,9 IssueFilter, IssueListItem, IssueSort, IssueState, validate_body, validate_title,
10 };10 };
11 use topcoat::Result;11 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};12+use topcoat::context::{Cx, context};
13 use topcoat::router::content::RawForm;13 use topcoat::router::content::RawForm;
14 use topcoat::router::error::{forbidden, see_other};14 use topcoat::router::error::{forbidden, see_other};
15 use topcoat::router::{StatusCode, page, path_param, query_params};15 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
439 439
440 #[page("/{owner}/{repo}/issues")]440 #[page("/{owner}/{repo}/issues")]
441 async fn issues_list_page(cx: &Cx) -> Result<impl View> {441 async fn issues_list_page(cx: &Cx) -> Result<impl View> {
442- let owner = path_param::<Owner>(cx);442+ let owner = owner(cx);
443- let name = path_param::<Repo>(cx);443+ let name = repo(cx);
444 let query = query_params::<ListQuery>(cx)?;444 let query = query_params::<ListQuery>(cx)?;
445 let ctx = load_repo(cx, owner, name).await?;445 let ctx = load_repo(cx, owner, name).await?;
446- let state = app_context::<AppState>(cx);446+ let state = context::<AppState>(cx);
447 let sel = Selection::parse(query);447 let sel = Selection::parse(query);
448 let search_value = sel.search_text();448 let search_value = sel.search_text();
449 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));449 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> {
499 ),499 ),
500 None => (0, 0),500 None => (0, 0),
501 };501 };
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+ );
503 let clear_href = list_href(&base, &[("state", sel.state)]);508 let clear_href = list_href(&base, &[("state", sel.state)]);
504 let has_filters = sel.has_filters();509 let has_filters = sel.has_filters();
505 510
@@ -745,6 +750,7 @@ fn check_draft(title: &str, body: &str) -> forge_core::Result<std::result::Resul
745 /// chooser (`chooser` is `Some`) or the form.750 /// chooser (`chooser` is `Some`) or the form.
746 #[component]751 #[component]
747 async fn new_issue_body(752 async fn new_issue_body(
753+ cx: &Cx,
748 lang: Lang,754 lang: Lang,
749 head: RepoHead,755 head: RepoHead,
750 csrf: String,756 csrf: String,
@@ -814,8 +820,8 @@ async fn new_issue_body(
814 820
815 #[page("/{owner}/{repo}/issues/new")]821 #[page("/{owner}/{repo}/issues/new")]
816 async fn new_issue_page(cx: &Cx) -> Result<impl View> {822 async fn new_issue_page(cx: &Cx) -> Result<impl View> {
817- let owner = path_param::<Owner>(cx);823+ let owner = owner(cx);
818- let name = path_param::<Repo>(cx);824+ let name = repo(cx);
819 let query = query_params::<NewIssueQuery>(cx)?;825 let query = query_params::<NewIssueQuery>(cx)?;
820 let ctx = load_repo(cx, owner, name).await?;826 let ctx = load_repo(cx, owner, name).await?;
821 let viewer = require_user(cx).await?;827 let viewer = require_user(cx).await?;
@@ -823,7 +829,7 @@ async fn new_issue_page(cx: &Cx) -> Result<impl View> {
823 if ctx.repo.archived {829 if ctx.repo.archived {
824 return Err(forbidden().into());830 return Err(forbidden().into());
825 }831 }
826- let state = app_context::<AppState>(cx);832+ let state = context::<AppState>(cx);
827 let header = ctx.head(state, "issues").await?;833 let header = ctx.head(state, "issues").await?;
828 let title = g::new_issue_title(lang, &format!("{}/{}", ctx.repo.owner_name, ctx.repo.name));834 let title = g::new_issue_title(lang, &format!("{}/{}", ctx.repo.owner_name, ctx.repo.name));
829 let csrf = viewer.1.csrf_token.clone();835 let csrf = viewer.1.csrf_token.clone();
@@ -871,8 +877,8 @@ async fn new_issue_page(cx: &Cx) -> Result<impl View> {
871 877
872 #[page(POST "/{owner}/{repo}/issues/new")]878 #[page(POST "/{owner}/{repo}/issues/new")]
873 async fn new_issue_submit(cx: &Cx, RawForm(raw): RawForm) -> Result<impl View> {879 async fn new_issue_submit(cx: &Cx, RawForm(raw): RawForm) -> Result<impl View> {
874- let owner = path_param::<Owner>(cx);880+ let owner = owner(cx);
875- let name = path_param::<Repo>(cx);881+ let name = repo(cx);
876 let ctx = load_repo(cx, owner, name).await?;882 let ctx = load_repo(cx, owner, name).await?;
877 let fields = form_pairs(&raw[..]);883 let fields = form_pairs(&raw[..]);
878 let viewer = require_csrf(cx, &form_field(&fields, "csrf")).await?;884 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> {
880 if ctx.repo.archived {886 if ctx.repo.archived {
881 return Err(forbidden().into());887 return Err(forbidden().into());
882 }888 }
883- let state = app_context::<AppState>(cx);889+ let state = context::<AppState>(cx);
884 let typed_title = form_field(&fields, "title");890 let typed_title = form_field(&fields, "title");
885 let typed_body = form_field(&fields, "body");891 let typed_body = form_field(&fields, "body");
886 let picked = form_all(&fields, "label");892 let picked = form_all(&fields, "label");
crates/forge-web/src/pages/issues_live.rsmodified+6 -6
@@ -6,7 +6,7 @@
6 //! repo, or an issue that is not there, gets the same 404 as the page.6 //! repo, or an issue that is not there, gets the same 404 as the page.
7 7
8 use topcoat::Result;8 use topcoat::Result;
9-use topcoat::context::{Cx, app_context};9+use topcoat::context::{Cx, context};
10 use topcoat::router::error::not_found;10 use topcoat::router::error::not_found;
11 use topcoat::router::response::Response;11 use topcoat::router::response::Response;
12 use topcoat::router::{path_param, route};12 use topcoat::router::{path_param, route};
@@ -33,17 +33,17 @@ pub fn item_live_url(owner: &str, repo: &str, number: i64) -> String {
33 /// The change stream of the issue list, labels and milestones pages.33 /// The change stream of the issue list, labels and milestones pages.
34 #[route(GET "/{owner}/{repo}/issues/live")]34 #[route(GET "/{owner}/{repo}/issues/live")]
35 async fn issues_live(cx: &Cx) -> Result<Response> {35 async fn issues_live(cx: &Cx) -> Result<Response> {
36- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;36+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
37- let state = app_context::<AppState>(cx);37+ let state = context::<AppState>(cx);
38 stream_wakes(cx, &state.live, &[Topic::RepoIssues(ctx.repo.id.clone())])38 stream_wakes(cx, &state.live, &[Topic::RepoIssues(ctx.repo.id.clone())])
39 }39 }
40 40
41 /// The change stream of one issue page.41 /// The change stream of one issue page.
42 #[route(GET "/{owner}/{repo}/issues/{number}/live")]42 #[route(GET "/{owner}/{repo}/issues/{number}/live")]
43 async fn issue_live(cx: &Cx) -> Result<Response> {43 async fn issue_live(cx: &Cx) -> Result<Response> {
44- let number = parse_number(path_param::<Number>(cx))?;44+ let number = parse_number(number(cx))?;
45- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;45+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
46- let state = app_context::<AppState>(cx);46+ let state = context::<AppState>(cx);
47 let Some(issue) = state.store.issue_by_number(&ctx.repo.id, number).await? else {47 let Some(issue) = state.store.issue_by_number(&ctx.repo.id, number).await? else {
48 return Err(not_found().into());48 return Err(not_found().into());
49 };49 };
crates/forge-web/src/pages/labels_css.rsmodified+4 -4
@@ -13,7 +13,7 @@ use http::header::{
13 };13 };
14 use sha2::{Digest, Sha256};14 use sha2::{Digest, Sha256};
15 use topcoat::Result;15 use topcoat::Result;
16-use topcoat::context::{Cx, app_context};16+use topcoat::context::{Cx, context};
17 use topcoat::router::request::headers;17 use topcoat::router::request::headers;
18 use topcoat::router::{path_param, route};18 use topcoat::router::{path_param, route};
19 19
@@ -78,14 +78,14 @@ fn etag_matches(if_none_match: &str, etag: &str) -> bool {
78 78
79 #[route(GET "/{owner}/{repo}/labels.css")]79 #[route(GET "/{owner}/{repo}/labels.css")]
80 async fn labels_css(cx: &Cx) -> Result<(StatusCode, HeaderMap, String)> {80 async fn labels_css(cx: &Cx) -> Result<(StatusCode, HeaderMap, String)> {
81- let owner = path_param::<Owner>(cx);81+ let owner = owner(cx);
82- let name = path_param::<Repo>(cx);82+ let name = repo(cx);
83 let ctx = load_repo(cx, owner, name).await?;83 let ctx = load_repo(cx, owner, name).await?;
84 let if_none_match = headers(cx)84 let if_none_match = headers(cx)
85 .get(IF_NONE_MATCH)85 .get(IF_NONE_MATCH)
86 .and_then(|v| v.to_str().ok())86 .and_then(|v| v.to_str().ok())
87 .map(str::to_owned);87 .map(str::to_owned);
88- let state = app_context::<AppState>(cx);88+ let state = context::<AppState>(cx);
89 89
90 let labels = state.store.list_labels(&ctx.repo.id).await?;90 let labels = state.store.list_labels(&ctx.repo.id).await?;
91 let css = label_css(&labels);91 let css = label_css(&labels);
crates/forge-web/src/pages/labels_page.rsmodified+24 -31
@@ -6,7 +6,7 @@ use std::collections::HashMap;
6 6
7 use serde::Deserialize;7 use serde::Deserialize;
8 use topcoat::Result;8 use topcoat::Result;
9-use topcoat::context::{Cx, app_context};9+use topcoat::context::{Cx, context};
10 use topcoat::router::content::Form;10 use topcoat::router::content::Form;
11 use topcoat::router::error::see_other;11 use topcoat::router::error::see_other;
12 use topcoat::router::{page, path_param, query_params};12 use topcoat::router::{page, path_param, query_params};
@@ -80,6 +80,7 @@ fn labels_href(title: &str) -> String {
80 /// The header, the label list and, for triage holders, the forms.80 /// The header, the label list and, for triage holders, the forms.
81 #[component]81 #[component]
82 async fn labels_body(82 async fn labels_body(
83+ cx: &Cx,
83 lang: Lang,84 lang: Lang,
84 frame: RepoFrame,85 frame: RepoFrame,
85 rows: Vec<LabelRow>,86 rows: Vec<LabelRow>,
@@ -184,19 +185,19 @@ async fn labels_body(
184 /// Gets the labels page. Hidden repos are 404 (checked in `load_repo`).185 /// Gets the labels page. Hidden repos are 404 (checked in `load_repo`).
185 #[page("/{owner}/{repo}/labels")]186 #[page("/{owner}/{repo}/labels")]
186 async fn labels_page(cx: &Cx) -> Result<impl View> {187 async fn labels_page(cx: &Cx) -> Result<impl View> {
187- let owner = path_param::<Owner>(cx);188+ let owner = owner(cx);
188- let name = path_param::<Repo>(cx);189+ let name = repo(cx);
189 let query = query_params::<LabelsQuery>(cx)?;190 let query = query_params::<LabelsQuery>(cx)?;
190 let ctx = load_repo(cx, owner, name).await?;191 let ctx = load_repo(cx, owner, name).await?;
191 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));192 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;
193 let labels = store.list_labels(&ctx.repo.id).await?;194 let labels = store.list_labels(&ctx.repo.id).await?;
194 let counts: HashMap<String, i64> = store195 let counts: HashMap<String, i64> = store
195 .label_open_counts(&ctx.repo.id)196 .label_open_counts(&ctx.repo.id)
196 .await?197 .await?
197 .into_iter()198 .into_iter()
198 .collect();199 .collect();
199- let frame = RepoFrame::new(&ctx, app_context::<AppState>(cx), "issues").await?;200+ let frame = RepoFrame::new(&ctx, context::<AppState>(cx), "issues").await?;
200 let title = frame.title.clone();201 let title = frame.title.clone();
201 let all: Vec<LabelRow> = labels202 let all: Vec<LabelRow> = labels
202 .into_iter()203 .into_iter()
@@ -243,21 +244,19 @@ async fn labels_page(cx: &Cx) -> Result<impl View> {
243 /// Creates a label. A duplicate name is shown on the error page.244 /// Creates a label. A duplicate name is shown on the error page.
244 #[page(POST "/{owner}/{repo}/labels")]245 #[page(POST "/{owner}/{repo}/labels")]
245 async fn label_create(cx: &Cx, Form(form): Form<LabelForm>) -> Result<impl View> {246 async fn label_create(cx: &Cx, Form(form): Form<LabelForm>) -> Result<impl View> {
246- let owner = path_param::<Owner>(cx);247+ let owner = owner(cx);
247- let name = path_param::<Repo>(cx);248+ let name = repo(cx);
248 let ctx = load_repo(cx, owner, name).await?;249 let ctx = load_repo(cx, owner, name).await?;
249 triage_guard(cx, &ctx, &form.csrf).await?;250 triage_guard(cx, &ctx, &form.csrf).await?;
250 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));251 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
251 let back = labels_href(&format!("{}/{}", ctx.repo.owner_name, ctx.repo.name));252 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)
253 .store254 .store
254 .create_label(&ctx.repo.id, &form.name, &form.color, &form.description)255 .create_label(&ctx.repo.id, &form.name, &form.color, &form.description)
255 .await;256 .await;
256 match result {257 match result {
257 Ok(_) => {258 Ok(_) => {
258- app_context::<AppState>(cx)259+ context::<AppState>(cx).live.bump_repo_issues(&ctx.repo.id);
259- .live
260- .bump_repo_issues(&ctx.repo.id);
261 Err(see_other(back).into())260 Err(see_other(back).into())
262 }261 }
263 Err(e) => {262 Err(e) => {
@@ -273,22 +272,20 @@ async fn label_create(cx: &Cx, Form(form): Form<LabelForm>) -> Result<impl View>
273 /// Updates a label's name, color and description.272 /// Updates a label's name, color and description.
274 #[page(POST "/{owner}/{repo}/labels/{label_id}")]273 #[page(POST "/{owner}/{repo}/labels/{label_id}")]
275 async fn label_update(cx: &Cx, Form(form): Form<LabelForm>) -> Result<impl View> {274 async fn label_update(cx: &Cx, Form(form): Form<LabelForm>) -> Result<impl View> {
276- let owner = path_param::<Owner>(cx);275+ let owner = owner(cx);
277- let name = path_param::<Repo>(cx);276+ let name = repo(cx);
278- let id = path_param::<LabelId>(cx);277+ let id = label_id(cx);
279 let ctx = load_repo(cx, owner, name).await?;278 let ctx = load_repo(cx, owner, name).await?;
280 triage_guard(cx, &ctx, &form.csrf).await?;279 triage_guard(cx, &ctx, &form.csrf).await?;
281 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));280 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
282 let back = labels_href(&format!("{}/{}", ctx.repo.owner_name, ctx.repo.name));281 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)
284 .store283 .store
285 .update_label(&ctx.repo.id, id, &form.name, &form.color, &form.description)284 .update_label(&ctx.repo.id, id, &form.name, &form.color, &form.description)
286 .await;285 .await;
287 match result {286 match result {
288 Ok(()) => {287 Ok(()) => {
289- app_context::<AppState>(cx)288+ context::<AppState>(cx).live.bump_repo_issues(&ctx.repo.id);
290- .live
291- .bump_repo_issues(&ctx.repo.id);
292 Err(see_other(back).into())289 Err(see_other(back).into())
293 }290 }
294 Err(e) => {291 Err(e) => {
@@ -305,21 +302,19 @@ async fn label_update(cx: &Cx, Form(form): Form<LabelForm>) -> Result<impl View>
305 /// exist are skipped, so a repeated submit adds nothing.302 /// exist are skipped, so a repeated submit adds nothing.
306 #[page(POST "/{owner}/{repo}/labels/defaults")]303 #[page(POST "/{owner}/{repo}/labels/defaults")]
307 async fn label_defaults(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<impl View> {304 async fn label_defaults(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<impl View> {
308- let owner = path_param::<Owner>(cx);305+ let owner = owner(cx);
309- let name = path_param::<Repo>(cx);306+ let name = repo(cx);
310 let ctx = load_repo(cx, owner, name).await?;307 let ctx = load_repo(cx, owner, name).await?;
311 triage_guard(cx, &ctx, &form.csrf).await?;308 triage_guard(cx, &ctx, &form.csrf).await?;
312 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));309 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
313 let back = labels_href(&format!("{}/{}", ctx.repo.owner_name, ctx.repo.name));310 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)
315 .store312 .store
316 .create_default_labels(&ctx.repo.id)313 .create_default_labels(&ctx.repo.id)
317 .await;314 .await;
318 match result {315 match result {
319 Ok(_) => {316 Ok(_) => {
320- app_context::<AppState>(cx)317+ context::<AppState>(cx).live.bump_repo_issues(&ctx.repo.id);
321- .live
322- .bump_repo_issues(&ctx.repo.id);
323 Err(see_other(back).into())318 Err(see_other(back).into())
324 }319 }
325 Err(e) => {320 Err(e) => {
@@ -335,22 +330,20 @@ async fn label_defaults(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<impl View
335 /// Deletes a label and its links to issues.330 /// Deletes a label and its links to issues.
336 #[page(POST "/{owner}/{repo}/labels/{label_id}/delete")]331 #[page(POST "/{owner}/{repo}/labels/{label_id}/delete")]
337 async fn label_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<impl View> {332 async fn label_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<impl View> {
338- let owner = path_param::<Owner>(cx);333+ let owner = owner(cx);
339- let name = path_param::<Repo>(cx);334+ let name = repo(cx);
340- let id = path_param::<LabelId>(cx);335+ let id = label_id(cx);
341 let ctx = load_repo(cx, owner, name).await?;336 let ctx = load_repo(cx, owner, name).await?;
342 triage_guard(cx, &ctx, &form.csrf).await?;337 triage_guard(cx, &ctx, &form.csrf).await?;
343 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));338 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
344 let back = labels_href(&format!("{}/{}", ctx.repo.owner_name, ctx.repo.name));339 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)
346 .store341 .store
347 .delete_label(&ctx.repo.id, id)342 .delete_label(&ctx.repo.id, id)
348 .await;343 .await;
349 match result {344 match result {
350 Ok(()) => {345 Ok(()) => {
351- app_context::<AppState>(cx)346+ context::<AppState>(cx).live.bump_repo_issues(&ctx.repo.id);
352- .live
353- .bump_repo_issues(&ctx.repo.id);
354 Err(see_other(back).into())347 Err(see_other(back).into())
355 }348 }
356 Err(e) => {349 Err(e) => {
crates/forge-web/src/pages/login.rsmodified+15 -8
@@ -8,7 +8,7 @@ use http::header::{HeaderValue, RETRY_AFTER};
8 use serde::Deserialize;8 use serde::Deserialize;
9 use serde_json::json;9 use serde_json::json;
10 use topcoat::Result;10 use topcoat::Result;
11-use topcoat::context::{Cx, app_context};11+use topcoat::context::{Cx, context};
12 use topcoat::router::content::Form;12 use topcoat::router::content::Form;
13 use topcoat::router::error::{SeeOther, forbidden, see_other};13 use topcoat::router::error::{SeeOther, forbidden, see_other};
14 use topcoat::router::{HeaderMap, StatusCode, page, query_params, route};14 use topcoat::router::{HeaderMap, StatusCode, page, query_params, route};
@@ -71,6 +71,7 @@ struct TwoFactorForm {
71 71
72 #[component]72 #[component]
73 async fn login_form(73 async fn login_form(
74+ cx: &Cx,
74 lang: Lang,75 lang: Lang,
75 next: &str,76 next: &str,
76 username: &str,77 username: &str,
@@ -120,8 +121,9 @@ async fn login_page(cx: &Cx) -> Result<impl View> {
120 let next = safe_next(next.as_deref()).to_owned();121 let next = safe_next(next.as_deref()).to_owned();
121 let precsrf = pre_csrf_token(cx);122 let precsrf = pre_csrf_token(cx);
122 let lang = i18n::lang(cx, None);123 let lang = i18n::lang(cx, None);
123- let passkeys = passkeys_available(app_context::<AppState>(cx));124+ let passkeys = passkeys_available(context::<AppState>(cx));
124- let can_register = app_context::<AppState>(cx).live().registration == forge_core::Registration::Open;125+ let can_register =
126+ context::<AppState>(cx).live().registration == forge_core::Registration::Open;
125 Ok(view! {127 Ok(view! {
126 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))128 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))
127 })129 })
@@ -133,7 +135,7 @@ async fn login_submit(cx: &Cx, Form(form): Form<LoginForm>) -> Result<impl View>
133 if !check_pre_csrf(cx, &form.precsrf) {135 if !check_pre_csrf(cx, &form.precsrf) {
134 return Err(forbidden().into());136 return Err(forbidden().into());
135 }137 }
136- let state = app_context::<AppState>(cx);138+ let state = context::<AppState>(cx);
137 let lang = i18n::lang(cx, None);139 let lang = i18n::lang(cx, None);
138 let limiter = &state.throttle;140 let limiter = &state.throttle;
139 let now = Instant::now();141 let now = Instant::now();
@@ -277,7 +279,12 @@ async fn login_submit(cx: &Cx, Form(form): Form<LoginForm>) -> Result<impl View>
277 }279 }
278 280
279 #[component]281 #[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> {
281 Ok(view! {288 Ok(view! {
282 head(title: t(lang, Key::TwoFactorCheck))289 head(title: t(lang, Key::TwoFactorCheck))
283 <div class="sheet fit">290 <div class="sheet fit">
@@ -299,7 +306,7 @@ async fn two_factor_form(lang: Lang, precsrf: &str, error: Option<String>) -> Re
299 /// The second-factor step. Needs a live pending-login cookie; otherwise back to `/login`.306 /// The second-factor step. Needs a live pending-login cookie; otherwise back to `/login`.
300 #[page("/login/2fa")]307 #[page("/login/2fa")]
301 async fn two_factor_page(cx: &Cx) -> Result<impl View> {308 async fn two_factor_page(cx: &Cx) -> Result<impl View> {
302- let state = app_context::<AppState>(cx);309+ let state = context::<AppState>(cx);
303 if pending_login(cx, &state.key).is_none() {310 if pending_login(cx, &state.key).is_none() {
304 return Err(see_other("/login").into());311 return Err(see_other("/login").into());
305 }312 }
@@ -315,7 +322,7 @@ async fn two_factor_submit(cx: &Cx, Form(form): Form<TwoFactorForm>) -> Result<i
315 if !check_pre_csrf(cx, &form.precsrf) {322 if !check_pre_csrf(cx, &form.precsrf) {
316 return Err(forbidden().into());323 return Err(forbidden().into());
317 }324 }
318- let state = app_context::<AppState>(cx);325+ let state = context::<AppState>(cx);
319 let lang = i18n::lang(cx, None);326 let lang = i18n::lang(cx, None);
320 let Some(pending) = pending_login(cx, &state.key) else {327 let Some(pending) = pending_login(cx, &state.key) else {
321 return Err(see_other("/login").into());328 return Err(see_other("/login").into());
@@ -398,7 +405,7 @@ async fn logout_submit(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther>
398 if !check_csrf(&session, &form.csrf) {405 if !check_csrf(&session, &form.csrf) {
399 return Err(forbidden().into());406 return Err(forbidden().into());
400 }407 }
401- let state = app_context::<AppState>(cx);408+ let state = context::<AppState>(cx);
402 logout(cx, &session).await?;409 logout(cx, &session).await?;
403 audit::record(410 audit::record(
404 &state.store,411 &state.store,
crates/forge-web/src/pages/media.rsmodified+2 -2
@@ -10,7 +10,7 @@ use http_body::Frame;
10 use http_body_util::StreamBody;10 use http_body_util::StreamBody;
11 use serde::Deserialize;11 use serde::Deserialize;
12 use tokio_util::io::ReaderStream;12 use tokio_util::io::ReaderStream;
13-use topcoat::context::{Cx, app_context};13+use topcoat::context::{Cx, context};
14 use topcoat::router::request::method;14 use topcoat::router::request::method;
15 use topcoat::router::response::Response;15 use topcoat::router::response::Response;
16 use topcoat::router::{16 use topcoat::router::{
@@ -58,7 +58,7 @@ pub(crate) fn media_file(cx: &Cx, _body: Body) -> RouteFuture<'_> {
58 58
59 /// Serves one LFS object. Every failure is turned into a response here, so the route never errors.59 /// Serves one LFS object. Every failure is turned into a response here, so the route never errors.
60 async fn serve(cx: &Cx) -> Response {60 async fn serve(cx: &Cx) -> Response {
61- let state = app_context::<AppState>(cx).clone();61+ let state = context::<AppState>(cx).clone();
62 let owner = path_param_segment(cx, "owner").to_owned();62 let owner = path_param_segment(cx, "owner").to_owned();
63 let name = path_param_segment(cx, "repo").to_owned();63 let name = path_param_segment(cx, "repo").to_owned();
64 let rest = path_param_segments(cx, "rest")64 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};
17 use serde::Deserialize;17 use serde::Deserialize;
18 use tokio::sync::watch;18 use tokio::sync::watch;
19 use topcoat::Result;19 use topcoat::Result;
20-use topcoat::context::{Cx, app_context};20+use topcoat::context::{Cx, context};
21 use topcoat::router::content::Form;21 use topcoat::router::content::Form;
22 use topcoat::router::content::sse::Event;22 use topcoat::router::content::sse::Event;
23 use topcoat::router::error::{bad_request, forbidden, not_found, see_other};23 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> {
78 }78 }
79 79
80 async fn load_pull(cx: &Cx, ctx: &RepoCtx, number: i64) -> Result<PullRequest> {80 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);
82 match state.store.pull_by_number(&ctx.repo.id, number).await? {82 match state.store.pull_by_number(&ctx.repo.id, number).await? {
83 Some(pr) => Ok(pr),83 Some(pr) => Ok(pr),
84 None => Err(not_found().into()),84 None => Err(not_found().into()),
@@ -87,8 +87,8 @@ async fn load_pull(cx: &Cx, ctx: &RepoCtx, number: i64) -> Result<PullRequest> {
87 87
88 #[route(POST "/{owner}/{repo}/pulls/{number}/merge-queue")]88 #[route(POST "/{owner}/{repo}/pulls/{number}/merge-queue")]
89 async fn enqueue_post(cx: &Cx, Form(form): Form<QueueForm>) -> Result<Response> {89 async fn enqueue_post(cx: &Cx, Form(form): Form<QueueForm>) -> Result<Response> {
90- let number = parse_number(path_param::<Number>(cx))?;90+ let number = parse_number(number(cx))?;
91- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;91+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
92 let (user, _) = require_csrf(cx, &form.csrf).await?;92 let (user, _) = require_csrf(cx, &form.csrf).await?;
93 if ctx.repo.archived93 if ctx.repo.archived
94 || authorize(94 || authorize(
@@ -102,7 +102,7 @@ async fn enqueue_post(cx: &Cx, Form(form): Form<QueueForm>) -> Result<Response>
102 {102 {
103 return Err(forbidden().into());103 return Err(forbidden().into());
104 }104 }
105- let state = app_context::<AppState>(cx);105+ let state = context::<AppState>(cx);
106 let pr = load_pull(cx, &ctx, number).await?;106 let pr = load_pull(cx, &ctx, number).await?;
107 let href = pull_href(&ctx, number);107 let href = pull_href(&ctx, number);
108 if pr.merged_at.is_some() || pr.issue.state != forge_core::IssueState::Open {108 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>
126 126
127 #[route(POST "/{owner}/{repo}/pulls/{number}/merge-queue/remove")]127 #[route(POST "/{owner}/{repo}/pulls/{number}/merge-queue/remove")]
128 async fn remove_post(cx: &Cx, Form(form): Form<QueueForm>) -> Result<Response> {128 async fn remove_post(cx: &Cx, Form(form): Form<QueueForm>) -> Result<Response> {
129- let number = parse_number(path_param::<Number>(cx))?;129+ let number = parse_number(number(cx))?;
130- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;130+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
131 let (user, _) = require_csrf(cx, &form.csrf).await?;131 let (user, _) = require_csrf(cx, &form.csrf).await?;
132 if ctx.repo.archived132 if ctx.repo.archived
133 || authorize(133 || authorize(
@@ -141,7 +141,7 @@ async fn remove_post(cx: &Cx, Form(form): Form<QueueForm>) -> Result<Response> {
141 {141 {
142 return Err(forbidden().into());142 return Err(forbidden().into());
143 }143 }
144- let state = app_context::<AppState>(cx);144+ let state = context::<AppState>(cx);
145 let pr = load_pull(cx, &ctx, number).await?;145 let pr = load_pull(cx, &ctx, number).await?;
146 let href = pull_href(&ctx, number);146 let href = pull_href(&ctx, number);
147 if let Some(entry) = state.store.queue_entry_for_pull(&pr.issue.id).await? {147 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> {
154 /// The queue page: waiting entries, or the history with `?show=history`.154 /// The queue page: waiting entries, or the history with `?show=history`.
155 #[page("/{owner}/{repo}/merge-queue")]155 #[page("/{owner}/{repo}/merge-queue")]
156 async fn queue_page(cx: &Cx) -> Result<impl View> {156 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?;
158 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));158 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
159 let history = query_params::<QueueQuery>(cx)?.show.as_deref() == Some("history");159 let history = query_params::<QueueQuery>(cx)?.show.as_deref() == Some("history");
160- let state = app_context::<AppState>(cx);160+ let state = context::<AppState>(cx);
161 let frame = crate::pages::issue_meta::RepoFrame::new(&ctx, state, "pulls").await?;161 let frame = crate::pages::issue_meta::RepoFrame::new(&ctx, state, "pulls").await?;
162 let entries = state.store.queue_overview(&ctx.repo.id).await?;162 let entries = state.store.queue_overview(&ctx.repo.id).await?;
163 let rows = queue_rows(state, &ctx, lang, entries, history).await?;163 let rows = queue_rows(state, &ctx, lang, entries, history).await?;
@@ -332,8 +332,8 @@ fn reason_label(lang: Lang, reason: &str) -> String {
332 /// after that point is sent.332 /// after that point is sent.
333 #[route(GET "/{owner}/{repo}/merge-queue/events")]333 #[route(GET "/{owner}/{repo}/merge-queue/events")]
334 async fn queue_events(cx: &Cx) -> Result<Response> {334 async fn queue_events(cx: &Cx) -> Result<Response> {
335- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;335+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
336- let state = app_context::<AppState>(cx);336+ let state = context::<AppState>(cx);
337 let wake = state.ci_live.subscribe_queue(&ctx.repo.id);337 let wake = state.ci_live.subscribe_queue(&ctx.repo.id);
338 events_response(cx, queue_changes(wake))338 events_response(cx, queue_changes(wake))
339 }339 }
@@ -347,6 +347,7 @@ fn queue_changes(wake: watch::Receiver<u64>) -> impl Stream<Item = Result<Event>
347 347
348 #[component]348 #[component]
349 async fn queue_body(349 async fn queue_body(
350+ cx: &Cx,
350 lang: Lang,351 lang: Lang,
351 head: crate::pages::repo_ctx::RepoHead,352 head: crate::pages::repo_ctx::RepoHead,
352 waiting_href: String,353 waiting_href: String,
@@ -359,12 +360,9 @@ async fn queue_body(
359 csrf: String,360 csrf: String,
360 ) -> Result<impl View> {361 ) -> Result<impl View> {
361 let remove_label = g::t(lang, K::RemoveFromQueue);362 let remove_label = g::t(lang, K::RemoveFromQueue);
362- let remove_note = crate::pages::passkeys::s(363+ let remove_note =
363- lang,364+ crate::pages::passkeys::s(lang, "Remove it from the queue?", "Sıradan çıkarılsın mı?")
364- "Remove it from the queue?",365+ .to_owned();
365- "Sıradan çıkarılsın mı?",
366- )
367- .to_owned();
368 Ok(view! {366 Ok(view! {
369 repo_head(head: head, title: Some(g::t(lang, K::MergeQueueTitle).to_owned()))367 repo_head(head: head, title: Some(g::t(lang, K::MergeQueueTitle).to_owned()))
370 <nav class="tabs" aria-label=(g::t(lang, K::MergeQueueNav))>368 <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;
8 use jiff::tz::TimeZone;8 use jiff::tz::TimeZone;
9 use serde::Deserialize;9 use serde::Deserialize;
10 use topcoat::Result;10 use topcoat::Result;
11-use topcoat::context::{Cx, app_context};11+use topcoat::context::{Cx, context};
12 use topcoat::router::content::Form;12 use topcoat::router::content::Form;
13 use topcoat::router::error::{forbidden, not_found, see_other};13 use topcoat::router::error::{forbidden, not_found, see_other};
14 use topcoat::router::{page, path_param, query_params};14 use topcoat::router::{page, path_param, query_params};
@@ -100,7 +100,7 @@ fn due_on_field(raw: &str) -> Option<&str> {
100 100
101 /// The Open and Closed filter as the sheet's tools row: the shown state in bold, the other a link.101 /// The Open and Closed filter as the sheet's tools row: the shown state in bold, the other a link.
102 #[component]102 #[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> {
104 let open_href = format!("{}?state=open", milestones_href(&title));104 let open_href = format!("{}?state=open", milestones_href(&title));
105 let closed_href = format!("{}?state=closed", milestones_href(&title));105 let closed_href = format!("{}?state=closed", milestones_href(&title));
106 Ok(view! {106 Ok(view! {
@@ -120,6 +120,7 @@ async fn state_tabs(lang: Lang, title: String, closed: bool) -> Result<impl View
120 /// and the triage controls.120 /// and the triage controls.
121 #[component]121 #[component]
122 async fn milestone_row(122 async fn milestone_row(
123+ cx: &Cx,
123 lang: Lang,124 lang: Lang,
124 row: MilestoneRow,125 row: MilestoneRow,
125 csrf: String,126 csrf: String,
@@ -166,8 +167,8 @@ async fn milestone_row(
166 /// Gets the milestone list for one state (open by default).167 /// Gets the milestone list for one state (open by default).
167 #[page("/{owner}/{repo}/milestones")]168 #[page("/{owner}/{repo}/milestones")]
168 async fn milestones_page(cx: &Cx) -> Result<impl View> {169 async fn milestones_page(cx: &Cx) -> Result<impl View> {
169- let owner = path_param::<Owner>(cx);170+ let owner = owner(cx);
170- let name = path_param::<Repo>(cx);171+ let name = repo(cx);
171 let ctx = load_repo(cx, owner, name).await?;172 let ctx = load_repo(cx, owner, name).await?;
172 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));173 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
173 let query = query_params::<MilestoneQuery>(cx)?;174 let query = query_params::<MilestoneQuery>(cx)?;
@@ -177,11 +178,11 @@ async fn milestones_page(cx: &Cx) -> Result<impl View> {
177 } else {178 } else {
178 IssueState::Open179 IssueState::Open
179 };180 };
180- let milestones = app_context::<AppState>(cx)181+ let milestones = context::<AppState>(cx)
181 .store182 .store
182 .list_milestones(&ctx.repo.id, Some(state))183 .list_milestones(&ctx.repo.id, Some(state))
183 .await?;184 .await?;
184- let frame = RepoFrame::new(&ctx, app_context::<AppState>(cx), "issues").await?;185+ let frame = RepoFrame::new(&ctx, context::<AppState>(cx), "issues").await?;
185 let today = today_in(ctx.viewer_tz());186 let today = today_in(ctx.viewer_tz());
186 let title = frame.title.clone();187 let title = frame.title.clone();
187 let all: Vec<MilestoneRow> = milestones188 let all: Vec<MilestoneRow> = milestones
@@ -236,6 +237,7 @@ async fn milestones_page(cx: &Cx) -> Result<impl View> {
236 /// The header, state tabs, milestone rows and the create form.237 /// The header, state tabs, milestone rows and the create form.
237 #[component]238 #[component]
238 async fn milestones_body(239 async fn milestones_body(
240+ cx: &Cx,
239 lang: Lang,241 lang: Lang,
240 frame: RepoFrame,242 frame: RepoFrame,
241 rows: Vec<MilestoneRow>,243 rows: Vec<MilestoneRow>,
@@ -310,13 +312,13 @@ async fn milestones_body(
310 /// Creates a milestone with an optional due date.312 /// Creates a milestone with an optional due date.
311 #[page(POST "/{owner}/{repo}/milestones")]313 #[page(POST "/{owner}/{repo}/milestones")]
312 async fn milestone_create(cx: &Cx, Form(form): Form<MilestoneForm>) -> Result<impl View> {314 async fn milestone_create(cx: &Cx, Form(form): Form<MilestoneForm>) -> Result<impl View> {
313- let owner = path_param::<Owner>(cx);315+ let owner = owner(cx);
314- let name = path_param::<Repo>(cx);316+ let name = repo(cx);
315 let ctx = load_repo(cx, owner, name).await?;317 let ctx = load_repo(cx, owner, name).await?;
316 triage_guard(cx, &ctx, &form.csrf).await?;318 triage_guard(cx, &ctx, &form.csrf).await?;
317 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));319 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
318 let back = milestones_href(&format!("{}/{}", ctx.repo.owner_name, ctx.repo.name));320 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)
320 .store322 .store
321 .create_milestone(323 .create_milestone(
322 &ctx.repo.id,324 &ctx.repo.id,
@@ -327,9 +329,7 @@ async fn milestone_create(cx: &Cx, Form(form): Form<MilestoneForm>) -> Result<im
327 .await;329 .await;
328 match result {330 match result {
329 Ok(_) => {331 Ok(_) => {
330- app_context::<AppState>(cx)332+ context::<AppState>(cx).live.bump_repo_issues(&ctx.repo.id);
331- .live
332- .bump_repo_issues(&ctx.repo.id);
333 Err(see_other(back).into())333 Err(see_other(back).into())
334 }334 }
335 Err(e) => {335 Err(e) => {
@@ -345,23 +345,23 @@ async fn milestone_create(cx: &Cx, Form(form): Form<MilestoneForm>) -> Result<im
345 /// The edit page: title, description, due date and state. Triage holders only.345 /// The edit page: title, description, due date and state. Triage holders only.
346 #[page("/{owner}/{repo}/milestones/{milestone_id}/edit")]346 #[page("/{owner}/{repo}/milestones/{milestone_id}/edit")]
347 async fn milestone_edit_page(cx: &Cx) -> Result<impl View> {347 async fn milestone_edit_page(cx: &Cx) -> Result<impl View> {
348- let owner = path_param::<Owner>(cx);348+ let owner = owner(cx);
349- let name = path_param::<Repo>(cx);349+ let name = repo(cx);
350- let id = path_param::<MilestoneId>(cx);350+ let id = milestone_id(cx);
351 let ctx = load_repo(cx, owner, name).await?;351 let ctx = load_repo(cx, owner, name).await?;
352 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));352 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
353 require_user(cx).await?;353 require_user(cx).await?;
354 if !can_triage(&ctx) {354 if !can_triage(&ctx) {
355 return Err(forbidden().into());355 return Err(forbidden().into());
356 }356 }
357- let Some(milestone) = app_context::<AppState>(cx)357+ let Some(milestone) = context::<AppState>(cx)
358 .store358 .store
359 .milestone_by_id(&ctx.repo.id, id)359 .milestone_by_id(&ctx.repo.id, id)
360 .await?360 .await?
361 else {361 else {
362 return Err(not_found().into());362 return Err(not_found().into());
363 };363 };
364- let frame = RepoFrame::new(&ctx, app_context::<AppState>(cx), "issues").await?;364+ let frame = RepoFrame::new(&ctx, context::<AppState>(cx), "issues").await?;
365 let page_title = g::milestone_edit_title(lang, &frame.title);365 let page_title = g::milestone_edit_title(lang, &frame.title);
366 let action = format!("{}/{}/edit", milestones_href(&frame.title), milestone.id);366 let action = format!("{}/{}/edit", milestones_href(&frame.title), milestone.id);
367 let due = milestone.due_on.clone().unwrap_or_default();367 let due = milestone.due_on.clone().unwrap_or_default();
@@ -376,6 +376,7 @@ async fn milestone_edit_page(cx: &Cx) -> Result<impl View> {
376 /// The edit form body.376 /// The edit form body.
377 #[component]377 #[component]
378 async fn milestone_edit_body(378 async fn milestone_edit_body(
379+ cx: &Cx,
379 lang: Lang,380 lang: Lang,
380 frame: RepoFrame,381 frame: RepoFrame,
381 action: String,382 action: String,
@@ -425,9 +426,9 @@ async fn milestone_edit_body(
425 /// Saves the edit form. A state of `closed` closes the milestone; anything else reopens it.426 /// Saves the edit form. A state of `closed` closes the milestone; anything else reopens it.
426 #[page(POST "/{owner}/{repo}/milestones/{milestone_id}/edit")]427 #[page(POST "/{owner}/{repo}/milestones/{milestone_id}/edit")]
427 async fn milestone_edit_save(cx: &Cx, Form(form): Form<MilestoneForm>) -> Result<impl View> {428 async fn milestone_edit_save(cx: &Cx, Form(form): Form<MilestoneForm>) -> Result<impl View> {
428- let owner = path_param::<Owner>(cx);429+ let owner = owner(cx);
429- let name = path_param::<Repo>(cx);430+ let name = repo(cx);
430- let id = path_param::<MilestoneId>(cx);431+ let id = milestone_id(cx);
431 let ctx = load_repo(cx, owner, name).await?;432 let ctx = load_repo(cx, owner, name).await?;
432 triage_guard(cx, &ctx, &form.csrf).await?;433 triage_guard(cx, &ctx, &form.csrf).await?;
433 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));434 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
437 } else {438 } else {
438 IssueState::Open439 IssueState::Open
439 };440 };
440- let result = app_context::<AppState>(cx)441+ let result = context::<AppState>(cx)
441 .store442 .store
442 .update_milestone(443 .update_milestone(
443 &ctx.repo.id,444 &ctx.repo.id,
@@ -450,9 +451,7 @@ async fn milestone_edit_save(cx: &Cx, Form(form): Form<MilestoneForm>) -> Result
450 .await;451 .await;
451 match result {452 match result {
452 Ok(()) => {453 Ok(()) => {
453- app_context::<AppState>(cx)454+ context::<AppState>(cx).live.bump_repo_issues(&ctx.repo.id);
454- .live
455- .bump_repo_issues(&ctx.repo.id);
456 Err(see_other(back).into())455 Err(see_other(back).into())
457 }456 }
458 Err(e) => {457 Err(e) => {
@@ -468,22 +467,20 @@ async fn milestone_edit_save(cx: &Cx, Form(form): Form<MilestoneForm>) -> Result
468 /// Deletes a milestone. Its issues stay open or closed; they just lose the milestone.467 /// Deletes a milestone. Its issues stay open or closed; they just lose the milestone.
469 #[page(POST "/{owner}/{repo}/milestones/{milestone_id}/delete")]468 #[page(POST "/{owner}/{repo}/milestones/{milestone_id}/delete")]
470 async fn milestone_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<impl View> {469 async fn milestone_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<impl View> {
471- let owner = path_param::<Owner>(cx);470+ let owner = owner(cx);
472- let name = path_param::<Repo>(cx);471+ let name = repo(cx);
473- let id = path_param::<MilestoneId>(cx);472+ let id = milestone_id(cx);
474 let ctx = load_repo(cx, owner, name).await?;473 let ctx = load_repo(cx, owner, name).await?;
475 triage_guard(cx, &ctx, &form.csrf).await?;474 triage_guard(cx, &ctx, &form.csrf).await?;
476 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));475 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u));
477 let back = milestones_href(&format!("{}/{}", ctx.repo.owner_name, ctx.repo.name));476 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)
479 .store478 .store
480 .delete_milestone(&ctx.repo.id, id)479 .delete_milestone(&ctx.repo.id, id)
481 .await;480 .await;
482 match result {481 match result {
483 Ok(()) => {482 Ok(()) => {
484- app_context::<AppState>(cx)483+ context::<AppState>(cx).live.bump_repo_issues(&ctx.repo.id);
485- .live
486- .bump_repo_issues(&ctx.repo.id);
487 Err(see_other(back).into())484 Err(see_other(back).into())
488 }485 }
489 Err(e) => {486 Err(e) => {
crates/forge-web/src/pages/needs_you.rsmodified+4 -4
@@ -9,7 +9,7 @@ use forge_core::User;
9 use forge_core::authz::{Action, authorize};9 use forge_core::authz::{Action, authorize};
10 use forge_core::store::needs::Verdict;10 use forge_core::store::needs::Verdict;
11 use topcoat::Result;11 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};12+use topcoat::context::{Cx, context};
13 use topcoat::router::response::Response;13 use topcoat::router::response::Response;
14 use topcoat::router::{Body, StatusCode, page, query_params, route};14 use topcoat::router::{Body, StatusCode, page, query_params, route};
15 use topcoat::view::{View, component, view};15 use topcoat::view::{View, component, view};
@@ -344,7 +344,7 @@ async fn load_full(
344 344
345 /// One section of the page: its head, its rows as a compact list, its full-list link and its pager.345 /// One section of the page: its head, its rows as a compact list, its full-list link and its pager.
346 #[component]346 #[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> {
348 let NeedSection {348 let NeedSection {
349 heading,349 heading,
350 more,350 more,
@@ -386,7 +386,7 @@ pub(crate) async fn need_section(lang: Lang, section: NeedSection) -> Result<imp
386 #[page("/needs-you")]386 #[page("/needs-you")]
387 async fn needs_you(cx: &Cx) -> Result<impl View> {387 async fn needs_you(cx: &Cx) -> Result<impl View> {
388 let viewer = require_user(cx).await?;388 let viewer = require_user(cx).await?;
389- let state = app_context::<AppState>(cx);389+ let state = context::<AppState>(cx);
390 let user = &viewer.0;390 let user = &viewer.0;
391 let lang = i18n::lang(cx, Some(user));391 let lang = i18n::lang(cx, Some(user));
392 let query = query_params::<NeedsQuery>(cx)?;392 let query = query_params::<NeedsQuery>(cx)?;
@@ -444,7 +444,7 @@ async fn needs_you_events(cx: &Cx) -> Result<Response> {
444 *res.status_mut() = StatusCode::UNAUTHORIZED;444 *res.status_mut() = StatusCode::UNAUTHORIZED;
445 return Ok(res);445 return Ok(res);
446 };446 };
447- let state = app_context::<AppState>(cx);447+ let state = context::<AppState>(cx);
448 stream_wakes(448 stream_wakes(
449 cx,449 cx,
450 &state.live,450 &state.live,
crates/forge-web/src/pages/new_repo.rsmodified+7 -6
@@ -7,7 +7,7 @@ use forge_core::{AuditAction, User, Visibility};
7 use forge_git::repo::{init_bare, repo_path};7 use forge_git::repo::{init_bare, repo_path};
8 use serde::Deserialize;8 use serde::Deserialize;
9 use topcoat::Result;9 use topcoat::Result;
10-use topcoat::context::{Cx, app_context};10+use topcoat::context::{Cx, context};
11 use topcoat::router::content::Form;11 use topcoat::router::content::Form;
12 use topcoat::router::error::see_other;12 use topcoat::router::error::see_other;
13 // Named by the `#[query_params]` attribute below, which the unused-import lint does not see.13 // Named by the `#[query_params]` attribute below, which the unused-import lint does not see.
@@ -208,6 +208,7 @@ impl Draft {
208 208
209 #[component]209 #[component]
210 async fn new_repo_form(210 async fn new_repo_form(
211+ cx: &Cx,
211 lang: Lang,212 lang: Lang,
212 username: String,213 username: String,
213 csrf: &str,214 csrf: &str,
@@ -329,7 +330,7 @@ async fn new_repo_page(cx: &Cx) -> Result<impl View> {
329 let viewer = require_user(cx).await?;330 let viewer = require_user(cx).await?;
330 let lang = i18n::lang(cx, Some(&viewer.0));331 let lang = i18n::lang(cx, Some(&viewer.0));
331 let wanted = query_params::<NewRepoQuery>(cx)?.owner.clone();332 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?;
333 let mut draft = Draft::fresh();334 let mut draft = Draft::fresh();
334 if let Some(wanted) = wanted.as_deref()335 if let Some(wanted) = wanted.as_deref()
335 && let Some(owner) = owners.iter().find(|name| name.eq_ignore_ascii_case(wanted))336 && 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> {
337 draft.owner = owner.clone();338 draft.owner = owner.clone();
338 }339 }
339 let csrf = viewer.1.csrf_token.clone();340 let csrf = viewer.1.csrf_token.clone();
340- Ok(view! { cx =>341+ Ok(view! {
341 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))342 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))
342 })343 })
343 }344 }
@@ -350,10 +351,10 @@ async fn new_repo_submit(cx: &Cx, Form(form): Form<NewRepoForm>) -> Result<impl
350 match outcome {351 match outcome {
351 Ok(location) => Err(see_other(location).into()),352 Ok(location) => Err(see_other(location).into()),
352 Err(message) => {353 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?;
354 let csrf = viewer.1.csrf_token.clone();355 let csrf = viewer.1.csrf_token.clone();
355 let draft = Draft::from_form(&form);356 let draft = Draft::from_form(&form);
356- Ok(view! { cx =>357+ Ok(view! {
357 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))358 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))
358 })359 })
359 }360 }
@@ -389,7 +390,7 @@ async fn create_repo(
389 owner: &User,390 owner: &User,
390 form: &NewRepoForm,391 form: &NewRepoForm,
391 ) -> Result<std::result::Result<String, String>> {392 ) -> Result<std::result::Result<String, String>> {
392- let state = app_context::<AppState>(cx);393+ let state = context::<AppState>(cx);
393 let lang = i18n::lang(cx, Some(owner));394 let lang = i18n::lang(cx, Some(owner));
394 let name = match validate_name(&form.name) {395 let name = match validate_name(&form.name) {
395 Ok(name) => name,396 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) {
46 }46 }
47 47
48 #[component]48 #[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> {
50 let (title, hint, back) = texts(lang);50 let (title, hint, back) = texts(lang);
51 Ok(view! {51 Ok(view! {
52 head(title: title, sub: vec![SubPart::mono("404")])52 head(title: title, sub: vec![SubPart::mono("404")])
@@ -101,7 +101,7 @@ fn forbidden_texts(lang: Lang) -> (&'static str, &'static str, &'static str) {
101 }101 }
102 102
103 #[component]103 #[component]
104-async fn forbidden_body(lang: Lang) -> Result<impl View> {104+async fn forbidden_body(cx: &Cx, lang: Lang) -> Result<impl View> {
105 let (title, hint, back) = forbidden_texts(lang);105 let (title, hint, back) = forbidden_texts(lang);
106 Ok(view! {106 Ok(view! {
107 head(title: title, sub: vec![SubPart::mono("403")])107 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};
15 use futures_util::{Stream, StreamExt, future, stream};15 use futures_util::{Stream, StreamExt, future, stream};
16 use serde::Deserialize;16 use serde::Deserialize;
17 use topcoat::Result;17 use topcoat::Result;
18-use topcoat::context::{Cx, app_context};18+use topcoat::context::{Cx, context};
19 use topcoat::router::content::Form;19 use topcoat::router::content::Form;
20 use topcoat::router::content::sse::Event;20 use topcoat::router::content::sse::Event;
21 use topcoat::router::error::{SeeOther, bad_request, not_found, see_other};21 use topcoat::router::error::{SeeOther, bad_request, not_found, see_other};
@@ -320,7 +320,7 @@ async fn entry_visible(
320 #[page("/notifications")]320 #[page("/notifications")]
321 async fn inbox(cx: &Cx) -> Result<impl View> {321 async fn inbox(cx: &Cx) -> Result<impl View> {
322 let viewer = require_user(cx).await?;322 let viewer = require_user(cx).await?;
323- let state = app_context::<AppState>(cx);323+ let state = context::<AppState>(cx);
324 let query = query_params::<InboxQuery>(cx)?;324 let query = query_params::<InboxQuery>(cx)?;
325 let all = query.all.as_deref() == Some("1");325 let all = query.all.as_deref() == Some("1");
326 let before = query.before.clone().filter(|s| !s.is_empty());326 let before = query.before.clone().filter(|s| !s.is_empty());
@@ -545,7 +545,7 @@ async fn inbox_events(cx: &Cx) -> Result<Response> {
545 return Ok(res);545 return Ok(res);
546 };546 };
547 let all = query_params::<InboxQuery>(cx)?.all.as_deref() == Some("1");547 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();
549 let topic = Topic::Inbox(user.id.clone());549 let topic = Topic::Inbox(user.id.clone());
550 stream_changes(cx, &state.live.clone(), &[topic], move || {550 stream_changes(cx, &state.live.clone(), &[topic], move || {
551 let state = state.clone();551 let state = state.clone();
@@ -560,8 +560,8 @@ async fn inbox_events(cx: &Cx) -> Result<Response> {
560 #[route(GET "/notifications/{note}/open")]560 #[route(GET "/notifications/{note}/open")]
561 async fn open_notification(cx: &Cx) -> Result<SeeOther> {561 async fn open_notification(cx: &Cx) -> Result<SeeOther> {
562 let (user, _) = require_user(cx).await?;562 let (user, _) = require_user(cx).await?;
563- let state = app_context::<AppState>(cx);563+ let state = context::<AppState>(cx);
564- let id = path_param::<Note>(cx);564+ let id = note(cx);
565 let Some(target) = state.store.notification_target(&user.id, id).await? else {565 let Some(target) = state.store.notification_target(&user.id, id).await? else {
566 return Err(not_found().into());566 return Err(not_found().into());
567 };567 };
@@ -585,8 +585,8 @@ async fn open_notification(cx: &Cx) -> Result<SeeOther> {
585 #[route(GET "/notifications/discussions/{discussion_id}/open")]585 #[route(GET "/notifications/discussions/{discussion_id}/open")]
586 async fn open_discussion_notification(cx: &Cx) -> Result<SeeOther> {586 async fn open_discussion_notification(cx: &Cx) -> Result<SeeOther> {
587 let (user, _) = require_user(cx).await?;587 let (user, _) = require_user(cx).await?;
588- let state = app_context::<AppState>(cx);588+ let state = context::<AppState>(cx);
589- let id = path_param::<DiscussionId>(cx);589+ let id = discussion_id(cx);
590 let Some(note) = state.store.discussion_notification(&user.id, id).await? else {590 let Some(note) = state.store.discussion_notification(&user.id, id).await? else {
591 return Err(not_found().into());591 return Err(not_found().into());
592 };592 };
@@ -611,8 +611,8 @@ async fn open_discussion_notification(cx: &Cx) -> Result<SeeOther> {
611 #[route(POST "/notifications/discussions/{discussion_id}/read")]611 #[route(POST "/notifications/discussions/{discussion_id}/read")]
612 async fn read_discussion_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {612 async fn read_discussion_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
613 let (user, _) = require_csrf(cx, &form.csrf).await?;613 let (user, _) = require_csrf(cx, &form.csrf).await?;
614- let state = app_context::<AppState>(cx);614+ let state = context::<AppState>(cx);
615- let id = path_param::<DiscussionId>(cx);615+ let id = discussion_id(cx);
616 state616 state
617 .store617 .store
618 .mark_discussion_notification_read(&user.id, id)618 .mark_discussion_notification_read(&user.id, id)
@@ -626,8 +626,8 @@ async fn read_discussion_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Re
626 #[route(GET "/notifications/advisories/{advisory_repo_id}/open")]626 #[route(GET "/notifications/advisories/{advisory_repo_id}/open")]
627 async fn open_advisory_notification(cx: &Cx) -> Result<SeeOther> {627 async fn open_advisory_notification(cx: &Cx) -> Result<SeeOther> {
628 let (user, _) = require_user(cx).await?;628 let (user, _) = require_user(cx).await?;
629- let state = app_context::<AppState>(cx);629+ let state = context::<AppState>(cx);
630- let repo_id = path_param::<AdvisoryRepoId>(cx);630+ let repo_id = advisory_repo_id(cx);
631 let Some(notice) = state.store.advisory_notification(&user.id, repo_id).await? else {631 let Some(notice) = state.store.advisory_notification(&user.id, repo_id).await? else {
632 return Err(not_found().into());632 return Err(not_found().into());
633 };633 };
@@ -651,8 +651,8 @@ async fn open_advisory_notification(cx: &Cx) -> Result<SeeOther> {
651 #[route(POST "/notifications/advisories/{advisory_repo_id}/read")]651 #[route(POST "/notifications/advisories/{advisory_repo_id}/read")]
652 async fn read_advisory_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {652 async fn read_advisory_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
653 let (user, _) = require_csrf(cx, &form.csrf).await?;653 let (user, _) = require_csrf(cx, &form.csrf).await?;
654- let state = app_context::<AppState>(cx);654+ let state = context::<AppState>(cx);
655- let repo_id = path_param::<AdvisoryRepoId>(cx);655+ let repo_id = advisory_repo_id(cx);
656 state656 state
657 .store657 .store
658 .mark_advisory_notification_read(&user.id, repo_id)658 .mark_advisory_notification_read(&user.id, repo_id)
@@ -666,8 +666,8 @@ async fn read_advisory_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Resu
666 #[route(GET "/notifications/admin/{admin_note}/open")]666 #[route(GET "/notifications/admin/{admin_note}/open")]
667 async fn open_admin_notification(cx: &Cx) -> Result<SeeOther> {667 async fn open_admin_notification(cx: &Cx) -> Result<SeeOther> {
668 let (user, _) = require_user(cx).await?;668 let (user, _) = require_user(cx).await?;
669- let state = app_context::<AppState>(cx);669+ let state = context::<AppState>(cx);
670- let id = path_param::<AdminNote>(cx);670+ let id = admin_note(cx);
671 let owned = state671 let owned = state
672 .store672 .store
673 .list_admin_notices(&user.id, false, None, 200)673 .list_admin_notices(&user.id, false, None, 200)
@@ -686,8 +686,8 @@ async fn open_admin_notification(cx: &Cx) -> Result<SeeOther> {
686 #[route(POST "/notifications/admin/{admin_note}/read")]686 #[route(POST "/notifications/admin/{admin_note}/read")]
687 async fn read_admin_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {687 async fn read_admin_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
688 let (user, _) = require_csrf(cx, &form.csrf).await?;688 let (user, _) = require_csrf(cx, &form.csrf).await?;
689- let state = app_context::<AppState>(cx);689+ let state = context::<AppState>(cx);
690- let id = path_param::<AdminNote>(cx);690+ let id = admin_note(cx);
691 state.store.mark_admin_notice_read(&user.id, id).await?;691 state.store.mark_admin_notice_read(&user.id, id).await?;
692 publish_unread(state, &user.id).await;692 publish_unread(state, &user.id).await;
693 Ok(see_other(back(cx)))693 Ok(see_other(back(cx)))
@@ -697,8 +697,8 @@ async fn read_admin_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<
697 #[route(POST "/notifications/{note}/read")]697 #[route(POST "/notifications/{note}/read")]
698 async fn read_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {698 async fn read_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
699 let (user, _) = require_csrf(cx, &form.csrf).await?;699 let (user, _) = require_csrf(cx, &form.csrf).await?;
700- let state = app_context::<AppState>(cx);700+ let state = context::<AppState>(cx);
701- let id = path_param::<Note>(cx);701+ let id = note(cx);
702 state.store.mark_read(&user.id, id).await?;702 state.store.mark_read(&user.id, id).await?;
703 publish_unread(state, &user.id).await;703 publish_unread(state, &user.id).await;
704 Ok(see_other(back(cx)))704 Ok(see_other(back(cx)))
@@ -708,7 +708,7 @@ async fn read_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOth
708 #[route(POST "/notifications/mark_all_read")]708 #[route(POST "/notifications/mark_all_read")]
709 async fn mark_all_read(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {709 async fn mark_all_read(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
710 let (user, _) = require_csrf(cx, &form.csrf).await?;710 let (user, _) = require_csrf(cx, &form.csrf).await?;
711- let state = app_context::<AppState>(cx);711+ let state = context::<AppState>(cx);
712 let query = query_params::<RepoQuery>(cx)?;712 let query = query_params::<RepoQuery>(cx)?;
713 let repo_id = query.repo.as_deref().filter(|s| !s.is_empty());713 let repo_id = query.repo.as_deref().filter(|s| !s.is_empty());
714 if repo_id == Some(ADMIN_GROUP) {714 if repo_id == Some(ADMIN_GROUP) {
@@ -765,7 +765,7 @@ async fn notification_stream(cx: &Cx) -> Result<Response> {
765 *res.status_mut() = StatusCode::UNAUTHORIZED;765 *res.status_mut() = StatusCode::UNAUTHORIZED;
766 return Ok(res);766 return Ok(res);
767 };767 };
768- let state = app_context::<AppState>(cx);768+ let state = context::<AppState>(cx);
769 let events = unread_changes(state, &user.id).await?;769 let events = unread_changes(state, &user.id).await?;
770 events_response(cx, events)770 events_response(cx, events)
771 }771 }
@@ -783,10 +783,10 @@ async fn pull_subscription(cx: &Cx, Form(form): Form<SubscriptionForm>) -> Resul
783 }783 }
784 784
785 async fn set_subscription(cx: &Cx, pull: bool, form: &SubscriptionForm) -> Result<SeeOther> {785 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?;
787 let (user, _) = require_csrf(cx, &form.csrf).await?;787 let (user, _) = require_csrf(cx, &form.csrf).await?;
788- let state = app_context::<AppState>(cx);788+ let state = context::<AppState>(cx);
789- let number = parse_number(path_param::<Number>(cx))?;789+ let number = parse_number(number(cx))?;
790 let issue = if pull {790 let issue = if pull {
791 state791 state
792 .store792 .store
@@ -841,7 +841,7 @@ async fn set_subscription(cx: &Cx, pull: bool, form: &SubscriptionForm) -> Resul
841 /// Sets the viewer's watch level on a repo. The viewer must be able to read the repo.841 /// Sets the viewer's watch level on a repo. The viewer must be able to read the repo.
842 #[route(POST "/{owner}/{repo}/watch")]842 #[route(POST "/{owner}/{repo}/watch")]
843 async fn set_watch(cx: &Cx, Form(form): Form<WatchForm>) -> Result<SeeOther> {843 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?;
845 let (user, _) = require_csrf(cx, &form.csrf).await?;845 let (user, _) = require_csrf(cx, &form.csrf).await?;
846 let level = match form.level.as_str() {846 let level = match form.level.as_str() {
847 "participating" => WatchLevel::Participating,847 "participating" => WatchLevel::Participating,
@@ -849,7 +849,7 @@ async fn set_watch(cx: &Cx, Form(form): Form<WatchForm>) -> Result<SeeOther> {
849 "ignoring" => WatchLevel::Ignoring,849 "ignoring" => WatchLevel::Ignoring,
850 _ => return Err(bad_request("unknown watch level").into()),850 _ => return Err(bad_request("unknown watch level").into()),
851 };851 };
852- let state = app_context::<AppState>(cx);852+ let state = context::<AppState>(cx);
853 state.store.set_watch(&user.id, &ctx.repo.id, level).await?;853 state.store.set_watch(&user.id, &ctx.repo.id, level).await?;
854 state.live.bump_repo(&ctx.repo.owner_id, &ctx.repo.id);854 state.live.bump_repo(&ctx.repo.owner_id, &ctx.repo.id);
855 Ok(see_other(repo_href(855 Ok(see_other(repo_href(
@@ -973,8 +973,18 @@ pub(crate) fn inbox_items(lang: Lang, current: &str, unread_count: u64) -> Vec<R
973 current: key == current,973 current: key == current,
974 };974 };
975 vec![975 vec![
976- item("unread", g::t(lang, K::Unread), unread_count.to_string(), "/notifications"),976+ item(
977- item("all", g::t(lang, K::AllTab), String::new(), "/notifications?all=1"),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+ ),
978 item(988 item(
979 "needs",989 "needs",
980 crate::i18n::needs::t(lang, crate::i18n::needs::K::NeedsYou),990 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
992 1002
993 /// The inbox rail as Needs you and Review requests show it, beside their sheet.1003 /// The inbox rail as Needs you and Review requests show it, beside their sheet.
994 #[component]1004 #[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> {
996 let items = inbox_items(lang, current, unread_count);1011 let items = inbox_items(lang, current, unread_count);
997 Ok(view! {1012 Ok(view! {
998 rail(label: g::t(lang, K::NotificationFilter), items: items)1013 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) ->
1003 /// sheet holding the transfers, the repo groups and the older-rows link.1018 /// sheet holding the transfers, the repo groups and the older-rows link.
1004 #[component]1019 #[component]
1005 async fn inbox_list(1020 async fn inbox_list(
1021+ cx: &Cx,
1006 lang: Lang,1022 lang: Lang,
1007 all: bool,1023 all: bool,
1008 unread_count: u64,1024 unread_count: u64,
@@ -1076,6 +1092,7 @@ async fn inbox_list(
1076 /// The Subscribe or Unsubscribe pill of an issue or pull request, in its head.1092 /// The Subscribe or Unsubscribe pill of an issue or pull request, in its head.
1077 #[component]1093 #[component]
1078 pub(crate) async fn notify_pill(1094 pub(crate) async fn notify_pill(
1095+ cx: &Cx,
1079 lang: Lang,1096 lang: Lang,
1080 action: String,1097 action: String,
1081 csrf: String,1098 csrf: String,
@@ -1100,6 +1117,7 @@ pub(crate) async fn notify_pill(
1100 /// without JavaScript; nav.js submits them in place and closes the menu.1117 /// without JavaScript; nav.js submits them in place and closes the menu.
1101 #[component]1118 #[component]
1102 pub(crate) async fn watch_form(1119 pub(crate) async fn watch_form(
1120+ cx: &Cx,
1103 lang: Lang,1121 lang: Lang,
1104 action: String,1122 action: String,
1105 csrf: String,1123 csrf: String,
crates/forge-web/src/pages/org_ctx.rsmodified+4 -3
@@ -9,7 +9,7 @@ use forge_core::store::orgs::OrgMemberRole;
9 use forge_core::store::repo_listing::RepoScope;9 use forge_core::store::repo_listing::RepoScope;
10 use forge_core::{Role, Session, User};10 use forge_core::{Role, Session, User};
11 use topcoat::Result;11 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};12+use topcoat::context::{Cx, context};
13 use topcoat::router::error::{forbidden, not_found};13 use topcoat::router::error::{forbidden, not_found};
14 use topcoat::router::request::uri;14 use topcoat::router::request::uri;
15 use topcoat::view::{View, component, view};15 use topcoat::view::{View, component, view};
@@ -102,7 +102,7 @@ impl OrgCtx {
102 /// names and people (anything that is not an org) are 404.102 /// names and people (anything that is not an org) are 404.
103 pub async fn load_org(cx: &Cx, name: &str) -> Result<OrgCtx> {103 pub async fn load_org(cx: &Cx, name: &str) -> Result<OrgCtx> {
104 let viewer = require_user(cx).await?;104 let viewer = require_user(cx).await?;
105- let state = app_context::<AppState>(cx);105+ let state = context::<AppState>(cx);
106 let Some(org) = state.store.user_by_username(name).await? else {106 let Some(org) = state.store.user_by_username(name).await? else {
107 return Err(not_found().into());107 return Err(not_found().into());
108 };108 };
@@ -201,6 +201,7 @@ pub async fn org_tab_counts(state: &AppState, org: &User, viewer: &User) -> Resu
201 /// Teams are always listed; an owner also gets Settings. `current` marks the page's own tab.201 /// Teams are always listed; an owner also gets Settings. `current` marks the page's own tab.
202 #[component]202 #[component]
203 pub async fn org_tabs(203 pub async fn org_tabs(
204+ cx: &Cx,
204 lang: Lang,205 lang: Lang,
205 name: String,206 name: String,
206 current: String,207 current: String,
@@ -251,7 +252,7 @@ pub async fn org_tabs(
251 252
252 /// The notice after a write: an error alert, or a status line.253 /// The notice after a write: an error alert, or a status line.
253 #[component]254 #[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> {
255 Ok(view! {256 Ok(view! {
256 if let Some((text, is_error)) = notice {257 if let Some((text, is_error)) = notice {
257 if is_error {258 if is_error {
crates/forge-web/src/pages/org_live.rsmodified+11 -11
@@ -15,7 +15,7 @@ use forge_core::User;
15 use forge_core::store::Store;15 use forge_core::store::Store;
16 use forge_core::store::orgs::OrgMemberRole;16 use forge_core::store::orgs::OrgMemberRole;
17 use topcoat::Result;17 use topcoat::Result;
18-use topcoat::context::{Cx, app_context};18+use topcoat::context::{Cx, context};
19 use topcoat::router::request::{method, uri};19 use topcoat::router::request::{method, uri};
20 use topcoat::router::response::Response;20 use topcoat::router::response::Response;
21 use topcoat::router::{Body, Layer, LayerFuture, Method, Next, Path, path_param, route};21 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> {
130 /// The members page's change stream. Members only, as the page.130 /// The members page's change stream. Members only, as the page.
131 #[route(GET "/org/{org}/members/events")]131 #[route(GET "/org/{org}/members/events")]
132 async fn org_members_events(cx: &Cx) -> Result<Response> {132 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?;
134 require_member(&ctx)?;134 require_member(&ctx)?;
135- let state = app_context::<AppState>(cx);135+ let state = context::<AppState>(cx);
136 let org_id = ctx.org.id.clone();136 let org_id = ctx.org.id.clone();
137 let store = state.store.clone();137 let store = state.store.clone();
138 stream_changes(cx, &state.live, &[Topic::Org(org_id.clone())], move || {138 stream_changes(cx, &state.live, &[Topic::Org(org_id.clone())], move || {
@@ -146,9 +146,9 @@ async fn org_members_events(cx: &Cx) -> Result<Response> {
146 /// The teams list's change stream. Members only, as the page.146 /// The teams list's change stream. Members only, as the page.
147 #[route(GET "/org/{org}/teams/events")]147 #[route(GET "/org/{org}/teams/events")]
148 async fn org_teams_events(cx: &Cx) -> Result<Response> {148 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?;
150 require_member(&ctx)?;150 require_member(&ctx)?;
151- let state = app_context::<AppState>(cx);151+ let state = context::<AppState>(cx);
152 let org_id = ctx.org.id.clone();152 let org_id = ctx.org.id.clone();
153 let store = state.store.clone();153 let store = state.store.clone();
154 stream_changes(cx, &state.live, &[Topic::Org(org_id.clone())], move || {154 stream_changes(cx, &state.live, &[Topic::Org(org_id.clone())], move || {
@@ -163,10 +163,10 @@ async fn org_teams_events(cx: &Cx) -> Result<Response> {
163 /// It also follows each repo the team links, for a rename or a visibility change.163 /// It also follows each repo the team links, for a rename or a visibility change.
164 #[route(GET "/org/{org}/teams/{team}/events")]164 #[route(GET "/org/{org}/teams/{team}/events")]
165 async fn org_team_events(cx: &Cx) -> Result<Response> {165 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?;
167 require_member(&ctx)?;167 require_member(&ctx)?;
168- let state = app_context::<AppState>(cx);168+ let state = context::<AppState>(cx);
169- let team = team_of(state, &ctx, path_param::<Team>(cx)).await?;169+ let team = team_of(state, &ctx, team(cx)).await?;
170 let linked = state.store.team_repos(&team.id).await?;170 let linked = state.store.team_repos(&team.id).await?;
171 let mut topics = vec![Topic::Org(ctx.org.id.clone())];171 let mut topics = vec![Topic::Org(ctx.org.id.clone())];
172 topics.extend(linked.iter().map(|repo| Topic::Repo(repo.id.clone())));172 topics.extend(linked.iter().map(|repo| Topic::Repo(repo.id.clone())));
@@ -187,9 +187,9 @@ async fn org_team_events(cx: &Cx) -> Result<Response> {
187 /// The settings page's change stream. Owners only, as the page.187 /// The settings page's change stream. Owners only, as the page.
188 #[route(GET "/org/{org}/settings/events")]188 #[route(GET "/org/{org}/settings/events")]
189 async fn org_settings_events(cx: &Cx) -> Result<Response> {189 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?;
191 require_owner(&ctx)?;191 require_owner(&ctx)?;
192- let state = app_context::<AppState>(cx);192+ let state = context::<AppState>(cx);
193 let org_id = ctx.org.id.clone();193 let org_id = ctx.org.id.clone();
194 let store = state.store.clone();194 let store = state.store.clone();
195 stream_changes(cx, &state.live, &[Topic::Org(org_id.clone())], move || {195 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
222 let Some(name) = written_org(cx) else {222 let Some(name) = written_org(cx) else {
223 return next.run(cx, body).await;223 return next.run(cx, body).await;
224 };224 };
225- let state = app_context::<AppState>(cx);225+ let state = context::<AppState>(cx);
226 let org_id = match state.store.user_by_username(&name).await {226 let org_id = match state.store.user_by_username(&name).await {
227 Ok(Some(org)) if org.is_org() => Some(org.id),227 Ok(Some(org)) if org.is_org() => Some(org.id),
228 Ok(_) => None,228 Ok(_) => None,
crates/forge-web/src/pages/org_members.rsmodified+20 -11
@@ -9,7 +9,7 @@ use forge_core::AuditAction;
9 use forge_core::store::orgs::OrgMemberRole;9 use forge_core::store::orgs::OrgMemberRole;
10 use serde::Deserialize;10 use serde::Deserialize;
11 use topcoat::Result;11 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};12+use topcoat::context::{Cx, context};
13 use topcoat::router::content::Form;13 use topcoat::router::content::Form;
14 use topcoat::router::error::{SeeOther, see_other};14 use topcoat::router::error::{SeeOther, see_other};
15 use topcoat::router::{page, path_param, route};15 use topcoat::router::{page, path_param, route};
@@ -61,6 +61,7 @@ struct RemoveForm {
61 /// else sees the plain list.61 /// else sees the plain list.
62 #[component]62 #[component]
63 async fn members_body(63 async fn members_body(
64+ cx: &Cx,
64 name: String,65 name: String,
65 description: String,66 description: String,
66 base: String,67 base: String,
@@ -115,10 +116,10 @@ async fn members_body(
115 /// Gets the members page. Non-members get 404.116 /// Gets the members page. Non-members get 404.
116 #[page("/org/{org}/members")]117 #[page("/org/{org}/members")]
117 async fn org_members_page(cx: &Cx) -> Result<impl View> {118 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?;
119 require_member(&ctx)?;120 require_member(&ctx)?;
120 let lang = i18n::lang(cx, Some(&ctx.viewer.0));121 let lang = i18n::lang(cx, Some(&ctx.viewer.0));
121- let state = app_context::<AppState>(cx);122+ let state = context::<AppState>(cx);
122 let members = state.store.org_members(&ctx.org.id).await?;123 let members = state.store.org_members(&ctx.org.id).await?;
123 let rows: Vec<PersonRow> = members124 let rows: Vec<PersonRow> = members
124 .into_iter()125 .into_iter()
@@ -132,7 +133,15 @@ async fn org_members_page(cx: &Cx) -> Result<impl View> {
132 label: display_name(lang, &user.username),133 label: display_name(lang, &user.username),
133 username: user.username,134 username: user.username,
134 role: if is_owner { "owner" } else { "member" }.to_owned(),135 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(),
136 remove_label: g::t(lang, if is_self { K::Leave } else { K::Remove }).to_owned(),145 remove_label: g::t(lang, if is_self { K::Leave } else { K::Remove }).to_owned(),
137 }146 }
138 })147 })
@@ -146,7 +155,7 @@ async fn org_members_page(cx: &Cx) -> Result<impl View> {
146 let csrf = ctx.viewer.1.csrf_token.clone();155 let csrf = ctx.viewer.1.csrf_token.clone();
147 let live = ctx.href("/members/events");156 let live = ctx.href("/members/events");
148 let (repo_count, package_count) = org_tab_counts(state, &ctx.org, &ctx.viewer.0).await?;157 let (repo_count, package_count) = org_tab_counts(state, &ctx.org, &ctx.viewer.0).await?;
149- Ok(view! { cx =>158+ Ok(view! {
150 shell(title: title.as_str(), viewer: Some(&ctx.viewer),159 shell(title: title.as_str(), viewer: Some(&ctx.viewer),
151 members_body(name: name, description: description, base: base, owner: owner,160 members_body(name: name, description: description, base: base, owner: owner,
152 rows: rows, csrf: csrf, notice: notice, lang: lang, live: live,161 rows: rows, csrf: csrf, notice: notice, lang: lang, live: live,
@@ -157,10 +166,10 @@ async fn org_members_page(cx: &Cx) -> Result<impl View> {
157 /// Adds a person as a member or owner. Owners only.166 /// Adds a person as a member or owner. Owners only.
158 #[route(POST "/org/{org}/members/add")]167 #[route(POST "/org/{org}/members/add")]
159 async fn org_members_add(cx: &Cx, Form(form): Form<AddForm>) -> Result<SeeOther> {168 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?;
161 require_form_csrf(&ctx, &form.csrf)?;170 require_form_csrf(&ctx, &form.csrf)?;
162 require_owner(&ctx)?;171 require_owner(&ctx)?;
163- let state = app_context::<AppState>(cx);172+ let state = context::<AppState>(cx);
164 let back = ctx.href("/members");173 let back = ctx.href("/members");
165 174
166 let Some(role) = parse_member_role(form.role.trim()) else {175 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>
208 /// Changes a member's org role. Owners only. Demoting the last owner is refused.217 /// Changes a member's org role. Owners only. Demoting the last owner is refused.
209 #[route(POST "/org/{org}/members/role")]218 #[route(POST "/org/{org}/members/role")]
210 async fn org_members_role(cx: &Cx, Form(form): Form<RoleForm>) -> Result<SeeOther> {219 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?;
212 require_form_csrf(&ctx, &form.csrf)?;221 require_form_csrf(&ctx, &form.csrf)?;
213 require_owner(&ctx)?;222 require_owner(&ctx)?;
214- let state = app_context::<AppState>(cx);223+ let state = context::<AppState>(cx);
215 let back = ctx.href("/members");224 let back = ctx.href("/members");
216 225
217 let Some(role) = parse_member_role(form.role.trim()) else {226 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
257 /// leaving member is sent to the public org page, since the members page is no longer theirs.266 /// leaving member is sent to the public org page, since the members page is no longer theirs.
258 #[route(POST "/org/{org}/members/remove")]267 #[route(POST "/org/{org}/members/remove")]
259 async fn org_members_remove(cx: &Cx, Form(form): Form<RemoveForm>) -> Result<SeeOther> {268 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?;
261 require_form_csrf(&ctx, &form.csrf)?;270 require_form_csrf(&ctx, &form.csrf)?;
262 require_member(&ctx)?;271 require_member(&ctx)?;
263- let state = app_context::<AppState>(cx);272+ let state = context::<AppState>(cx);
264 let user_id = form.user_id.trim().to_owned();273 let user_id = form.user_id.trim().to_owned();
265 let self_removal = user_id == ctx.viewer.0.id;274 let self_removal = user_id == ctx.viewer.0.id;
266 if !self_removal {275 if !self_removal {
crates/forge-web/src/pages/org_new.rsmodified+6 -5
@@ -6,7 +6,7 @@ use forge_core::config::OrgCreation;
6 use forge_core::{AuditAction, User};6 use forge_core::{AuditAction, User};
7 use serde::Deserialize;7 use serde::Deserialize;
8 use topcoat::Result;8 use topcoat::Result;
9-use topcoat::context::{Cx, app_context};9+use topcoat::context::{Cx, context};
10 use topcoat::router::content::Form;10 use topcoat::router::content::Form;
11 use topcoat::router::error::{forbidden, see_other};11 use topcoat::router::error::{forbidden, see_other};
12 use topcoat::router::page;12 use topcoat::router::page;
@@ -43,6 +43,7 @@ pub(crate) fn may_create_org(state: &AppState, user: &User) -> bool {
43 43
44 #[component]44 #[component]
45 async fn new_org_form(45 async fn new_org_form(
46+ cx: &Cx,
46 csrf: String,47 csrf: String,
47 name: String,48 name: String,
48 description: String,49 description: String,
@@ -76,13 +77,13 @@ async fn new_org_form(
76 #[page("/org/new")]77 #[page("/org/new")]
77 async fn new_org_page(cx: &Cx) -> Result<impl View> {78 async fn new_org_page(cx: &Cx) -> Result<impl View> {
78 let viewer = require_user(cx).await?;79 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) {
80 return Err(forbidden().into());81 return Err(forbidden().into());
81 }82 }
82 let lang = i18n::lang(cx, Some(&viewer.0));83 let lang = i18n::lang(cx, Some(&viewer.0));
83 let title = g::t(lang, K::NewOrganization);84 let title = g::t(lang, K::NewOrganization);
84 let csrf = viewer.1.csrf_token.clone();85 let csrf = viewer.1.csrf_token.clone();
85- Ok(view! { cx =>86+ Ok(view! {
86 shell(title: title, viewer: Some(&viewer),87 shell(title: title, viewer: Some(&viewer),
87 new_org_form(csrf: csrf, name: String::new(), description: String::new(), error: None, lang: lang, username: viewer.0.username.clone()))88 new_org_form(csrf: csrf, name: String::new(), description: String::new(), error: None, lang: lang, username: viewer.0.username.clone()))
88 })89 })
@@ -91,7 +92,7 @@ async fn new_org_page(cx: &Cx) -> Result<impl View> {
91 #[page(POST "/org/new")]92 #[page(POST "/org/new")]
92 async fn new_org_submit(cx: &Cx, Form(form): Form<NewOrgForm>) -> Result<impl View> {93 async fn new_org_submit(cx: &Cx, Form(form): Form<NewOrgForm>) -> Result<impl View> {
93 let viewer = require_csrf(cx, &form.csrf).await?;94 let viewer = require_csrf(cx, &form.csrf).await?;
94- let state = app_context::<AppState>(cx);95+ let state = context::<AppState>(cx);
95 if !may_create_org(state, &viewer.0) {96 if !may_create_org(state, &viewer.0) {
96 return Err(forbidden().into());97 return Err(forbidden().into());
97 }98 }
@@ -103,7 +104,7 @@ async fn new_org_submit(cx: &Cx, Form(form): Form<NewOrgForm>) -> Result<impl Vi
103 let csrf = viewer.1.csrf_token.clone();104 let csrf = viewer.1.csrf_token.clone();
104 let name = form.name.clone();105 let name = form.name.clone();
105 let description = form.description.clone();106 let description = form.description.clone();
106- Ok(view! { cx =>107+ Ok(view! {
107 shell(title: title, viewer: Some(&viewer),108 shell(title: title, viewer: Some(&viewer),
108 new_org_form(csrf: csrf, name: name, description: description, error: Some(message), lang: lang, username: viewer.0.username.clone()))109 new_org_form(csrf: csrf, name: name, description: description, error: Some(message), lang: lang, username: viewer.0.username.clone()))
109 })110 })
crates/forge-web/src/pages/org_settings.rsmodified+14 -13
@@ -10,7 +10,7 @@ use forge_core::AuditAction;
10 use forge_core::store::orgs::{DefaultRepoRole, OrgSettings};10 use forge_core::store::orgs::{DefaultRepoRole, OrgSettings};
11 use serde::Deserialize;11 use serde::Deserialize;
12 use topcoat::Result;12 use topcoat::Result;
13-use topcoat::context::{Cx, app_context};13+use topcoat::context::{Cx, context};
14 use topcoat::router::content::Form;14 use topcoat::router::content::Form;
15 use topcoat::router::content::multipart::Multipart;15 use topcoat::router::content::multipart::Multipart;
16 use topcoat::router::error::{SeeOther, see_other};16 use topcoat::router::error::{SeeOther, see_other};
@@ -67,6 +67,7 @@ struct DeleteForm {
67 67
68 #[component]68 #[component]
69 async fn settings_body(69 async fn settings_body(
70+ cx: &Cx,
70 name: String,71 name: String,
71 display_name: String,72 display_name: String,
72 description: String,73 description: String,
@@ -169,10 +170,10 @@ async fn settings_body(
169 /// Gets the settings page. Owners only.170 /// Gets the settings page. Owners only.
170 #[page("/org/{org}/settings")]171 #[page("/org/{org}/settings")]
171 async fn org_settings_page(cx: &Cx) -> Result<impl View> {172 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?;
173 require_owner(&ctx)?;174 require_owner(&ctx)?;
174 let lang = i18n::lang(cx, Some(&ctx.viewer.0));175 let lang = i18n::lang(cx, Some(&ctx.viewer.0));
175- let state = app_context::<AppState>(cx);176+ let state = context::<AppState>(cx);
176 let settings = state.store.org_settings(&ctx.org.id).await?;177 let settings = state.store.org_settings(&ctx.org.id).await?;
177 let default_role = settings.default_repo_role.as_str().to_owned();178 let default_role = settings.default_repo_role.as_str().to_owned();
178 let members_can_create = settings.members_can_create_repos;179 let members_can_create = settings.members_can_create_repos;
@@ -188,7 +189,7 @@ async fn org_settings_page(cx: &Cx) -> Result<impl View> {
188 let csrf = ctx.viewer.1.csrf_token.clone();189 let csrf = ctx.viewer.1.csrf_token.clone();
189 let live = ctx.href("/settings/events");190 let live = ctx.href("/settings/events");
190 let (repo_count, package_count) = org_tab_counts(state, &ctx.org, &ctx.viewer.0).await?;191 let (repo_count, package_count) = org_tab_counts(state, &ctx.org, &ctx.viewer.0).await?;
191- Ok(view! { cx =>192+ Ok(view! {
192 shell(title: title.as_str(), viewer: Some(&ctx.viewer),193 shell(title: title.as_str(), viewer: Some(&ctx.viewer),
193 settings_body(name: name, display_name: display_name, description: description,194 settings_body(name: name, display_name: display_name, description: description,
194 has_avatar: has_avatar, avatar_src: avatar_src, base: base, csrf: csrf,195 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> {
201 /// store refuses redirects with a notice before anything is written.202 /// store refuses redirects with a notice before anything is written.
202 #[route(POST "/org/{org}/settings")]203 #[route(POST "/org/{org}/settings")]
203 async fn org_settings_save(cx: &Cx, Form(form): Form<SettingsForm>) -> Result<SeeOther> {204 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?;
205 require_form_csrf(&ctx, &form.csrf)?;206 require_form_csrf(&ctx, &form.csrf)?;
206 require_owner(&ctx)?;207 require_owner(&ctx)?;
207- let state = app_context::<AppState>(cx);208+ let state = context::<AppState>(cx);
208 let back = ctx.href("/settings");209 let back = ctx.href("/settings");
209 210
210 let description = form.description.trim();211 let description = form.description.trim();
@@ -262,7 +263,7 @@ async fn org_settings_save(cx: &Cx, Form(form): Form<SettingsForm>) -> Result<Se
262 263
263 /// Uploads the org's avatar. Owners only. The multipart fields are read as the person's upload264 /// Uploads the org's avatar. Owners only. The multipart fields are read as the person's upload
264 /// reads them, then the CSRF token and the role are checked before the image is decoded.265 /// 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)))]
266 async fn org_avatar_upload(cx: &Cx, mut multipart: Multipart) -> Result<SeeOther> {267 async fn org_avatar_upload(cx: &Cx, mut multipart: Multipart) -> Result<SeeOther> {
267 let mut csrf = String::new();268 let mut csrf = String::new();
268 let mut image = None;269 let mut image = None;
@@ -274,10 +275,10 @@ async fn org_avatar_upload(cx: &Cx, mut multipart: Multipart) -> Result<SeeOther
274 _ => {}275 _ => {}
275 }276 }
276 }277 }
277- let ctx = load_org(cx, path_param::<Org>(cx)).await?;278+ let ctx = load_org(cx, org(cx)).await?;
278 require_form_csrf(&ctx, &csrf)?;279 require_form_csrf(&ctx, &csrf)?;
279 require_owner(&ctx)?;280 require_owner(&ctx)?;
280- let state = app_context::<AppState>(cx);281+ let state = context::<AppState>(cx);
281 let lang = i18n::lang(cx, Some(&ctx.viewer.0));282 let lang = i18n::lang(cx, Some(&ctx.viewer.0));
282 let back = ctx.href("/settings");283 let back = ctx.href("/settings");
283 284
@@ -308,10 +309,10 @@ async fn org_avatar_upload(cx: &Cx, mut multipart: Multipart) -> Result<SeeOther
308 /// Removes the org's avatar. Owners only.309 /// Removes the org's avatar. Owners only.
309 #[route(POST "/org/{org}/settings/avatar/delete")]310 #[route(POST "/org/{org}/settings/avatar/delete")]
310 async fn org_avatar_remove(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {311 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?;
312 require_form_csrf(&ctx, &form.csrf)?;313 require_form_csrf(&ctx, &form.csrf)?;
313 require_owner(&ctx)?;314 require_owner(&ctx)?;
314- let state = app_context::<AppState>(cx);315+ let state = context::<AppState>(cx);
315 let back = ctx.href("/settings");316 let back = ctx.href("/settings");
316 317
317 state.store.delete_avatar(&ctx.org.id).await?;318 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
335 /// repositories; then the settings page says so.336 /// repositories; then the settings page says so.
336 #[route(POST "/org/{org}/settings/delete")]337 #[route(POST "/org/{org}/settings/delete")]
337 async fn org_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther> {338 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?;
339 require_form_csrf(&ctx, &form.csrf)?;340 require_form_csrf(&ctx, &form.csrf)?;
340 require_owner(&ctx)?;341 require_owner(&ctx)?;
341- let state = app_context::<AppState>(cx);342+ let state = context::<AppState>(cx);
342 let back = ctx.href("/settings");343 let back = ctx.href("/settings");
343 344
344 if form.confirm.trim() != ctx.org.username {345 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};
9 use forge_core::{AuditAction, Role};9 use forge_core::{AuditAction, Role};
10 use serde::Deserialize;10 use serde::Deserialize;
11 use topcoat::Result;11 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};12+use topcoat::context::{Cx, context};
13 use topcoat::router::content::Form;13 use topcoat::router::content::Form;
14 use topcoat::router::error::{SeeOther, not_found, see_other};14 use topcoat::router::error::{SeeOther, not_found, see_other};
15 use topcoat::router::{page, path_param, route};15 use topcoat::router::{page, path_param, route};
@@ -183,6 +183,7 @@ pub(crate) async fn visible_team_repos(
183 183
184 #[component]184 #[component]
185 async fn teams_body(185 async fn teams_body(
186+ cx: &Cx,
186 name: String,187 name: String,
187 description: String,188 description: String,
188 base: String,189 base: String,
@@ -258,10 +259,10 @@ async fn teams_body(
258 /// Gets the teams list. Members only.259 /// Gets the teams list. Members only.
259 #[page("/org/{org}/teams")]260 #[page("/org/{org}/teams")]
260 async fn org_teams_page(cx: &Cx) -> Result<impl View> {261 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?;
262 require_member(&ctx)?;263 require_member(&ctx)?;
263 let lang = i18n::lang(cx, Some(&ctx.viewer.0));264 let lang = i18n::lang(cx, Some(&ctx.viewer.0));
264- let state = app_context::<AppState>(cx);265+ let state = context::<AppState>(cx);
265 let teams = state.store.teams_for_org(&ctx.org.id).await?;266 let teams = state.store.teams_for_org(&ctx.org.id).await?;
266 let rows: Vec<TeamRow> = teams267 let rows: Vec<TeamRow> = teams
267 .into_iter()268 .into_iter()
@@ -282,7 +283,7 @@ async fn org_teams_page(cx: &Cx) -> Result<impl View> {
282 let csrf = ctx.viewer.1.csrf_token.clone();283 let csrf = ctx.viewer.1.csrf_token.clone();
283 let live = ctx.href("/teams/events");284 let live = ctx.href("/teams/events");
284 let (repo_count, package_count) = org_tab_counts(state, &ctx.org, &ctx.viewer.0).await?;285 let (repo_count, package_count) = org_tab_counts(state, &ctx.org, &ctx.viewer.0).await?;
285- Ok(view! { cx =>286+ Ok(view! {
286 shell(title: title.as_str(), viewer: Some(&ctx.viewer),287 shell(title: title.as_str(), viewer: Some(&ctx.viewer),
287 teams_body(name: name, description: description, base: base, owner: owner,288 teams_body(name: name, description: description, base: base, owner: owner,
288 csrf: csrf, rows: rows, notice: notice, lang: lang, live: live,289 csrf: csrf, rows: rows, notice: notice, lang: lang, live: live,
@@ -292,6 +293,7 @@ async fn org_teams_page(cx: &Cx) -> Result<impl View> {
292 293
293 #[component]294 #[component]
294 async fn team_body(295 async fn team_body(
296+ cx: &Cx,
295 data: TeamPage,297 data: TeamPage,
296 notice: Option<(&'static str, bool)>,298 notice: Option<(&'static str, bool)>,
297 lang: Lang,299 lang: Lang,
@@ -443,11 +445,11 @@ async fn team_body(
443 /// Gets one team's page. Members only; a team of another org is 404.445 /// Gets one team's page. Members only; a team of another org is 404.
444 #[page("/org/{org}/teams/{team}")]446 #[page("/org/{org}/teams/{team}")]
445 async fn org_team_page(cx: &Cx) -> Result<impl View> {447 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?;
447 require_member(&ctx)?;449 require_member(&ctx)?;
448 let lang = i18n::lang(cx, Some(&ctx.viewer.0));450 let lang = i18n::lang(cx, Some(&ctx.viewer.0));
449- let state = app_context::<AppState>(cx);451+ let state = context::<AppState>(cx);
450- let team = team_of(state, &ctx, path_param::<Team>(cx)).await?;452+ let team = team_of(state, &ctx, team(cx)).await?;
451 let members: Vec<TeamMemberRow> = state453 let members: Vec<TeamMemberRow> = state
452 .store454 .store
453 .team_members(&team.id)455 .team_members(&team.id)
@@ -492,7 +494,7 @@ async fn org_team_page(cx: &Cx) -> Result<impl View> {
492 choices,494 choices,
493 };495 };
494 let notice = take_notice(cx, lang);496 let notice = take_notice(cx, lang);
495- Ok(view! { cx =>497+ Ok(view! {
496 shell(title: title.as_str(), viewer: Some(&ctx.viewer),498 shell(title: title.as_str(), viewer: Some(&ctx.viewer),
497 team_body(data: data, notice: notice, lang: lang))499 team_body(data: data, notice: notice, lang: lang))
498 })500 })
@@ -501,10 +503,10 @@ async fn org_team_page(cx: &Cx) -> Result<impl View> {
501 /// Creates a team. Owners only.503 /// Creates a team. Owners only.
502 #[route(POST "/org/{org}/teams/new")]504 #[route(POST "/org/{org}/teams/new")]
503 async fn org_team_create(cx: &Cx, Form(form): Form<TeamForm>) -> Result<SeeOther> {505 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?;
505 require_form_csrf(&ctx, &form.csrf)?;507 require_form_csrf(&ctx, &form.csrf)?;
506 require_owner(&ctx)?;508 require_owner(&ctx)?;
507- let state = app_context::<AppState>(cx);509+ let state = context::<AppState>(cx);
508 let back = ctx.href("/teams");510 let back = ctx.href("/teams");
509 511
510 let Some(role) = parse_team_role(&form.role) else {512 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
552 /// Renames a team and changes its description, role and coverage. Owners only.554 /// Renames a team and changes its description, role and coverage. Owners only.
553 #[route(POST "/org/{org}/teams/{team}/update")]555 #[route(POST "/org/{org}/teams/{team}/update")]
554 async fn org_team_update(cx: &Cx, Form(form): Form<TeamForm>) -> Result<SeeOther> {556 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?;
556 require_form_csrf(&ctx, &form.csrf)?;558 require_form_csrf(&ctx, &form.csrf)?;
557 require_owner(&ctx)?;559 require_owner(&ctx)?;
558- let state = app_context::<AppState>(cx);560+ let state = context::<AppState>(cx);
559- let team = team_of(state, &ctx, path_param::<Team>(cx)).await?;561+ let team = team_of(state, &ctx, team(cx)).await?;
560 let back = ctx.href(&format!("/teams/{}", team.id));562 let back = ctx.href(&format!("/teams/{}", team.id));
561 563
562 let Some(role) = parse_team_role(&form.role) else {564 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
603 /// Deletes a team. Owners only.605 /// Deletes a team. Owners only.
604 #[route(POST "/org/{org}/teams/{team}/delete")]606 #[route(POST "/org/{org}/teams/{team}/delete")]
605 async fn org_team_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {607 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?;
607 require_form_csrf(&ctx, &form.csrf)?;609 require_form_csrf(&ctx, &form.csrf)?;
608 require_owner(&ctx)?;610 require_owner(&ctx)?;
609- let state = app_context::<AppState>(cx);611+ let state = context::<AppState>(cx);
610- let team = team_of(state, &ctx, path_param::<Team>(cx)).await?;612+ let team = team_of(state, &ctx, team(cx)).await?;
611 let name = team.name.clone();613 let name = team.name.clone();
612 state.store.delete_team(&team.id).await?;614 state.store.delete_team(&team.id).await?;
613 audit::record(615 audit::record(
@@ -629,11 +631,11 @@ async fn org_team_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther
629 /// Adds an organization member to a team. Owners only.631 /// Adds an organization member to a team. Owners only.
630 #[route(POST "/org/{org}/teams/{team}/members/add")]632 #[route(POST "/org/{org}/teams/{team}/members/add")]
631 async fn org_team_member_add(cx: &Cx, Form(form): Form<TeamMemberForm>) -> Result<SeeOther> {633 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?;
633 require_form_csrf(&ctx, &form.csrf)?;635 require_form_csrf(&ctx, &form.csrf)?;
634 require_owner(&ctx)?;636 require_owner(&ctx)?;
635- let state = app_context::<AppState>(cx);637+ let state = context::<AppState>(cx);
636- let team = team_of(state, &ctx, path_param::<Team>(cx)).await?;638+ let team = team_of(state, &ctx, team(cx)).await?;
637 let back = ctx.href(&format!("/teams/{}", team.id));639 let back = ctx.href(&format!("/teams/{}", team.id));
638 640
639 let username = form.username.trim();641 let username = form.username.trim();
@@ -675,11 +677,11 @@ async fn org_team_member_add(cx: &Cx, Form(form): Form<TeamMemberForm>) -> Resul
675 /// Removes a person from a team. Owners only.677 /// Removes a person from a team. Owners only.
676 #[route(POST "/org/{org}/teams/{team}/members/remove")]678 #[route(POST "/org/{org}/teams/{team}/members/remove")]
677 async fn org_team_member_remove(cx: &Cx, Form(form): Form<TeamUserForm>) -> Result<SeeOther> {679 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?;
679 require_form_csrf(&ctx, &form.csrf)?;681 require_form_csrf(&ctx, &form.csrf)?;
680 require_owner(&ctx)?;682 require_owner(&ctx)?;
681- let state = app_context::<AppState>(cx);683+ let state = context::<AppState>(cx);
682- let team = team_of(state, &ctx, path_param::<Team>(cx)).await?;684+ let team = team_of(state, &ctx, team(cx)).await?;
683 let back = ctx.href(&format!("/teams/{}", team.id));685 let back = ctx.href(&format!("/teams/{}", team.id));
684 686
685 let user_id = form.user_id.trim();687 let user_id = form.user_id.trim();
@@ -705,11 +707,11 @@ async fn org_team_member_remove(cx: &Cx, Form(form): Form<TeamUserForm>) -> Resu
705 /// Links one of the org's repos to a team. Owners only.707 /// Links one of the org's repos to a team. Owners only.
706 #[route(POST "/org/{org}/teams/{team}/repos/add")]708 #[route(POST "/org/{org}/teams/{team}/repos/add")]
707 async fn org_team_repo_add(cx: &Cx, Form(form): Form<TeamRepoForm>) -> Result<SeeOther> {709 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?;
709 require_form_csrf(&ctx, &form.csrf)?;711 require_form_csrf(&ctx, &form.csrf)?;
710 require_owner(&ctx)?;712 require_owner(&ctx)?;
711- let state = app_context::<AppState>(cx);713+ let state = context::<AppState>(cx);
712- let team = team_of(state, &ctx, path_param::<Team>(cx)).await?;714+ let team = team_of(state, &ctx, team(cx)).await?;
713 let back = ctx.href(&format!("/teams/{}", team.id));715 let back = ctx.href(&format!("/teams/{}", team.id));
714 716
715 let repo_id = form.repo_id.trim();717 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
742 /// Unlinks a repo from a team. Owners only.744 /// Unlinks a repo from a team. Owners only.
743 #[route(POST "/org/{org}/teams/{team}/repos/remove")]745 #[route(POST "/org/{org}/teams/{team}/repos/remove")]
744 async fn org_team_repo_remove(cx: &Cx, Form(form): Form<TeamRepoForm>) -> Result<SeeOther> {746 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?;
746 require_form_csrf(&ctx, &form.csrf)?;748 require_form_csrf(&ctx, &form.csrf)?;
747 require_owner(&ctx)?;749 require_owner(&ctx)?;
748- let state = app_context::<AppState>(cx);750+ let state = context::<AppState>(cx);
749- let team = team_of(state, &ctx, path_param::<Team>(cx)).await?;751+ let team = team_of(state, &ctx, team(cx)).await?;
750 let back = ctx.href(&format!("/teams/{}", team.id));752 let back = ctx.href(&format!("/teams/{}", team.id));
751 753
752 let repo_id = form.repo_id.trim();754 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};
9 use serde::Deserialize;9 use serde::Deserialize;
10 use tokio::sync::watch;10 use tokio::sync::watch;
11 use topcoat::Result;11 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};12+use topcoat::context::{Cx, context};
13 use topcoat::router::content::Form;13 use topcoat::router::content::Form;
14 use topcoat::router::content::sse::Event;14 use topcoat::router::content::sse::Event;
15 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};15 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
@@ -98,10 +98,10 @@ struct PackageQuery {
98 /// The package page: the head with the install snippet, then one tab of README or versions.98 /// The package page: the head with the install snippet, then one tab of README or versions.
99 #[page("/{owner}/-/packages/{*pkg}")]99 #[page("/{owner}/-/packages/{*pkg}")]
100 async fn package_page(cx: &Cx) -> Result<impl View> {100 async fn package_page(cx: &Cx) -> Result<impl View> {
101- let owner_name = path_param::<Owner>(cx);101+ let owner_name = owner(cx);
102- let pkg_name = path_param::<Pkg>(cx).collect::<Vec<_>>().join("/");102+ let pkg_name = pkg(cx).collect::<Vec<_>>().join("/");
103 let pkg_name = pkg_name.as_str();103 let pkg_name = pkg_name.as_str();
104- let state = app_context::<AppState>(cx);104+ let state = context::<AppState>(cx);
105 let viewer = current_user(cx).await?;105 let viewer = current_user(cx).await?;
106 let query = query_params::<PackageQuery>(cx)?;106 let query = query_params::<PackageQuery>(cx)?;
107 let actor = viewer.as_ref().map(|(u, _)| u);107 let actor = viewer.as_ref().map(|(u, _)| u);
@@ -202,7 +202,7 @@ async fn package_page(cx: &Cx) -> Result<impl View> {
202 version_rows,202 version_rows,
203 lang,203 lang,
204 };204 };
205- Ok(view! { cx =>205+ Ok(view! {
206 shell(title: title.as_str(), viewer: viewer.as_ref(),206 shell(title: title.as_str(), viewer: viewer.as_ref(),
207 if let Some(page) = oci {207 if let Some(page) = oci {
208 oci_package_view(page: page)208 oci_package_view(page: page)
@@ -228,8 +228,8 @@ struct TagDeleteForm {
228 #[route(POST "/{owner}/-/packages/tags/delete")]228 #[route(POST "/{owner}/-/packages/tags/delete")]
229 async fn tag_delete(cx: &Cx, Form(form): Form<TagDeleteForm>) -> Result<SeeOther> {229 async fn tag_delete(cx: &Cx, Form(form): Form<TagDeleteForm>) -> Result<SeeOther> {
230 let (viewer, _) = require_csrf(cx, &form.csrf).await?;230 let (viewer, _) = require_csrf(cx, &form.csrf).await?;
231- let owner_name = path_param::<Owner>(cx);231+ let owner_name = owner(cx);
232- let state = app_context::<AppState>(cx);232+ let state = context::<AppState>(cx);
233 let Some(owner) = state.store.user_by_username(owner_name).await? else {233 let Some(owner) = state.store.user_by_username(owner_name).await? else {
234 return Err(not_found().into());234 return Err(not_found().into());
235 };235 };
@@ -272,7 +272,7 @@ struct PackagePage {
272 272
273 /// The package page body.273 /// The package page body.
274 #[component]274 #[component]
275-async fn package_view(page: PackagePage) -> Result<impl View> {275+async fn package_view(cx: &Cx, page: PackagePage) -> Result<impl View> {
276 let lang = page.lang;276 let lang = page.lang;
277 let PackagePage {277 let PackagePage {
278 owner_name,278 owner_name,
@@ -393,8 +393,8 @@ async fn package_view(page: PackagePage) -> Result<impl View> {
393 /// on connect, since the page was just rendered.393 /// on connect, since the page was just rendered.
394 #[route(GET "/{owner}/-/packages/events")]394 #[route(GET "/{owner}/-/packages/events")]
395 async fn packages_events(cx: &Cx) -> Result<Response> {395 async fn packages_events(cx: &Cx) -> Result<Response> {
396- let owner_name = path_param::<Owner>(cx);396+ let owner_name = owner(cx);
397- let state = app_context::<AppState>(cx);397+ let state = context::<AppState>(cx);
398 let Some(owner) = state.store.user_by_username(owner_name).await? else {398 let Some(owner) = state.store.user_by_username(owner_name).await? else {
399 return Err(not_found().into());399 return Err(not_found().into());
400 };400 };
@@ -452,7 +452,7 @@ pub async fn repo_package_links(
452 452
453 /// The Packages card of a repo's sidebar: the packages linked to this repo.453 /// The Packages card of a repo's sidebar: the packages linked to this repo.
454 #[component]454 #[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> {
456 let heading = pk::t(lang, K::TabPackages);456 let heading = pk::t(lang, K::TabPackages);
457 Ok(view! {457 Ok(view! {
458 <section class="sec repo-packages">458 <section class="sec repo-packages">
crates/forge-web/src/pages/packages_oci.rsmodified+2 -1
@@ -5,6 +5,7 @@
5 use forge_core::User;5 use forge_core::User;
6 use forge_core::packages::{OciTag, Package};6 use forge_core::packages::{OciTag, Package};
7 use topcoat::Result;7 use topcoat::Result;
8+use topcoat::context::Cx;
8 use topcoat::view::{View, component, view};9 use topcoat::view::{View, component, view};
9 10
10 use crate::i18n::Lang;11 use crate::i18n::Lang;
@@ -72,7 +73,7 @@ fn short_digest(digest: &str) -> String {
72 73
73 /// The container package page body.74 /// The container package page body.
74 #[component]75 #[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> {
76 let lang = page.lang;77 let lang = page.lang;
77 let OciPage {78 let OciPage {
78 owner_name,79 owner_name,
crates/forge-web/src/pages/palette.rsmodified+2 -2
@@ -21,7 +21,7 @@ use forge_core::store::orgs::OrgMemberRole;
21 use http::header::{CACHE_CONTROL, CONTENT_TYPE, X_CONTENT_TYPE_OPTIONS};21 use http::header::{CACHE_CONTROL, CONTENT_TYPE, X_CONTENT_TYPE_OPTIONS};
22 use serde_json::{Value, json};22 use serde_json::{Value, json};
23 use topcoat::Result;23 use topcoat::Result;
24-use topcoat::context::{Cx, app_context};24+use topcoat::context::{Cx, context};
25 use topcoat::router::response::Response;25 use topcoat::router::response::Response;
26 use topcoat::router::{Body, HeaderValue, StatusCode, route};26 use topcoat::router::{Body, HeaderValue, StatusCode, route};
27 27
@@ -379,7 +379,7 @@ async fn palette(cx: &Cx) -> Result<Response> {
379 *res.status_mut() = StatusCode::UNAUTHORIZED;379 *res.status_mut() = StatusCode::UNAUTHORIZED;
380 return Ok(res);380 return Ok(res);
381 };381 };
382- let state = app_context::<AppState>(cx);382+ let state = context::<AppState>(cx);
383 let lang = i18n::lang(cx, Some(&user));383 let lang = i18n::lang(cx, Some(&user));
384 let orgs = state.store.orgs_for_user(&user.id).await?;384 let orgs = state.store.orgs_for_user(&user.id).await?;
385 385
crates/forge-web/src/pages/passkeys.rsmodified+14 -9
@@ -19,7 +19,7 @@ use http::header::{HeaderValue, RETRY_AFTER};
19 use serde::Deserialize;19 use serde::Deserialize;
20 use serde_json::json;20 use serde_json::json;
21 use topcoat::Result;21 use topcoat::Result;
22-use topcoat::context::{Cx, app_context};22+use topcoat::context::{Cx, context};
23 use topcoat::router::content::Form;23 use topcoat::router::content::Form;
24 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};24 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
25 use topcoat::router::response::Response;25 use topcoat::router::response::Response;
@@ -250,7 +250,7 @@ struct LoginFinishForm {
250 #[route(POST "/settings/security/passkeys/register/begin")]250 #[route(POST "/settings/security/passkeys/register/begin")]
251 async fn register_begin(cx: &Cx, Form(form): Form<BeginForm>) -> Result<Response> {251 async fn register_begin(cx: &Cx, Form(form): Form<BeginForm>) -> Result<Response> {
252 let viewer = require_csrf(cx, &form.csrf).await?;252 let viewer = require_csrf(cx, &form.csrf).await?;
253- let state = app_context::<AppState>(cx);253+ let state = context::<AppState>(cx);
254 let lang = i18n::lang(cx, Some(&viewer.0));254 let lang = i18n::lang(cx, Some(&viewer.0));
255 let user = &viewer.0;255 let user = &viewer.0;
256 let webauthn = match relying_party(&state.live().base_url) {256 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
317 #[route(POST "/settings/security/passkeys/register/finish")]317 #[route(POST "/settings/security/passkeys/register/finish")]
318 async fn register_finish(cx: &Cx, Form(form): Form<FinishForm>) -> Result<Response> {318 async fn register_finish(cx: &Cx, Form(form): Form<FinishForm>) -> Result<Response> {
319 let viewer = require_csrf(cx, &form.csrf).await?;319 let viewer = require_csrf(cx, &form.csrf).await?;
320- let state = app_context::<AppState>(cx);320+ let state = context::<AppState>(cx);
321 let lang = i18n::lang(cx, Some(&viewer.0));321 let lang = i18n::lang(cx, Some(&viewer.0));
322 let user = &viewer.0;322 let user = &viewer.0;
323 let webauthn = match relying_party(&state.live().base_url) {323 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
392 #[route(POST "/settings/security/passkeys/{passkey_id}/rename")]392 #[route(POST "/settings/security/passkeys/{passkey_id}/rename")]
393 async fn rename(cx: &Cx, Form(form): Form<RenameForm>) -> Result<SeeOther> {393 async fn rename(cx: &Cx, Form(form): Form<RenameForm>) -> Result<SeeOther> {
394 let (user, _session) = require_csrf(cx, &form.csrf).await?;394 let (user, _session) = require_csrf(cx, &form.csrf).await?;
395- let state = app_context::<AppState>(cx);395+ let state = context::<AppState>(cx);
396 let id = path_param_segment(cx, "passkey_id").to_owned();396 let id = path_param_segment(cx, "passkey_id").to_owned();
397 let Ok(name) = clean_name(&form.name) else {397 let Ok(name) = clean_name(&form.name) else {
398 return Ok(see_other("/settings/security?saved=passkey-bad-name"));398 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> {
415 #[route(POST "/settings/security/passkeys/{passkey_id}/delete")]415 #[route(POST "/settings/security/passkeys/{passkey_id}/delete")]
416 async fn delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {416 async fn delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
417 let (user, _session) = require_csrf(cx, &form.csrf).await?;417 let (user, _session) = require_csrf(cx, &form.csrf).await?;
418- let state = app_context::<AppState>(cx);418+ let state = context::<AppState>(cx);
419 let id = path_param_segment(cx, "passkey_id").to_owned();419 let id = path_param_segment(cx, "passkey_id").to_owned();
420 // Only the owner's own list is searched, so another account's id looks like a missing one.420 // Only the owner's own list is searched, so another account's id looks like a missing one.
421 let Some(row) = state421 let Some(row) = state
@@ -462,7 +462,7 @@ async fn login_begin(cx: &Cx, Form(form): Form<LoginBeginForm>) -> Result<Respon
462 if !check_pre_csrf(cx, &form.precsrf) {462 if !check_pre_csrf(cx, &form.precsrf) {
463 return Err(forbidden().into());463 return Err(forbidden().into());
464 }464 }
465- let state = app_context::<AppState>(cx);465+ let state = context::<AppState>(cx);
466 let lang = i18n::lang(cx, None);466 let lang = i18n::lang(cx, None);
467 let ip_key = throttle::ip_key("passkey-ip", client_ip(cx));467 let ip_key = throttle::ip_key("passkey-ip", client_ip(cx));
468 if let Some(retry) = state468 if let Some(retry) = state
@@ -502,7 +502,7 @@ async fn login_finish(cx: &Cx, Form(form): Form<LoginFinishForm>) -> Result<Resp
502 if !check_pre_csrf(cx, &form.precsrf) {502 if !check_pre_csrf(cx, &form.precsrf) {
503 return Err(forbidden().into());503 return Err(forbidden().into());
504 }504 }
505- let state = app_context::<AppState>(cx);505+ let state = context::<AppState>(cx);
506 let lang = i18n::lang(cx, None);506 let lang = i18n::lang(cx, None);
507 let now = Instant::now();507 let now = Instant::now();
508 let ip_key = throttle::ip_key("passkey-ip", client_ip(cx));508 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<
650 /// The Passkeys topic of the security page: the list, rename and delete, and the add form that650 /// The Passkeys topic of the security page: the list, rename and delete, and the add form that
651 /// `nav.js` drives. The add form stays hidden until the browser proves it supports passkeys.651 /// `nav.js` drives. The add form stays hidden until the browser proves it supports passkeys.
652 #[component]652 #[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> {
654 let PasskeyPanel { items, problem } = panel;659 let PasskeyPanel { items, problem } = panel;
655 let empty = items.is_empty();660 let empty = items.is_empty();
656 let count_text = format!("{} {}", items.len(), s(lang, "passkeys", "geçiş anahtarı"));661 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
721 /// The passkey button and its error line for the login page. Hidden until the browser proves it726 /// The passkey button and its error line for the login page. Hidden until the browser proves it
722 /// supports passkeys.727 /// supports passkeys.
723 #[component]728 #[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> {
725 Ok(view! {730 Ok(view! {
726 <div class="passkey-login" data-passkey-login="" hidden=(true)>731 <div class="passkey-login" data-passkey-login="" hidden=(true)>
727 <p class="passkey-or hint">(s(lang, "or", "veya"))</p>732 <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() {
598 let page = send(&fx.router, "GET", &detail, session_cookie(ADMIN_TOKEN), &[]).await;598 let page = send(&fx.router, "GET", &detail, session_cookie(ADMIN_TOKEN), &[]).await;
599 assert_eq!(page.status, 200);599 assert_eq!(page.status, 200);
600 assert!(page.body.contains("Remove every passkey of this user?"));600 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+ );
602 605
603 let uri = format!("{detail}/remove-passkeys");606 let uri = format!("{detail}/remove-passkeys");
604 let denied = send(607 let denied = send(
crates/forge-web/src/pages/profile.rsmodified+22 -9
@@ -14,7 +14,7 @@ use forge_core::store::repo_listing::RepoScope;
14 use forge_core::tz::local_time_now;14 use forge_core::tz::local_time_now;
15 use forge_core::{Repo, User, Visibility};15 use forge_core::{Repo, User, Visibility};
16 use topcoat::Result;16 use topcoat::Result;
17-use topcoat::context::{Cx, app_context};17+use topcoat::context::{Cx, context};
18 use topcoat::router::error::not_found;18 use topcoat::router::error::not_found;
19 use topcoat::router::response::Response;19 use topcoat::router::response::Response;
20 use topcoat::router::{page, path_param, query_params, route};20 use topcoat::router::{page, path_param, query_params, route};
@@ -98,8 +98,8 @@ fn sort_key(raw: Option<&str>) -> &'static str {
98 98
99 #[page("/{username}")]99 #[page("/{username}")]
100 async fn profile_page(cx: &Cx) -> Result<impl View> {100 async fn profile_page(cx: &Cx) -> Result<impl View> {
101- let name = path_param::<Username>(cx);101+ let name = username(cx);
102- let state = app_context::<AppState>(cx);102+ let state = context::<AppState>(cx);
103 let viewer = current_user(cx).await?;103 let viewer = current_user(cx).await?;
104 let query = query_params::<ProfileQuery>(cx)?;104 let query = query_params::<ProfileQuery>(cx)?;
105 105
@@ -234,7 +234,13 @@ async fn profile_page(cx: &Cx) -> Result<impl View> {
234 let snippet_pages = snippet_total.div_ceil(PER_PAGE).max(1);234 let snippet_pages = snippet_total.div_ceil(PER_PAGE).max(1);
235 let snippet_page = page.min(snippet_pages);235 let snippet_page = page.min(snippet_pages);
236 let snippet_pager = pager_links(snippet_page, snippet_pages, |n| {236 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+ )
238 });244 });
239 let snippets: Vec<ListRow> = snippets245 let snippets: Vec<ListRow> = snippets
240 .into_iter()246 .into_iter()
@@ -370,7 +376,7 @@ async fn profile_page(cx: &Cx) -> Result<impl View> {
370 // A repo deleted just before this redirect here shows its one-line notice once.376 // A repo deleted just before this redirect here shows its one-line notice once.
371 let notice = take_notice(cx);377 let notice = take_notice(cx);
372 let title = user.username.clone();378 let title = user.username.clone();
373- Ok(view! { cx =>379+ Ok(view! {
374 shell(title: title.as_str(), viewer: viewer.as_ref(),380 shell(title: title.as_str(), viewer: viewer.as_ref(),
375 notice_banner_for(lang: lang, title: notice)381 notice_banner_for(lang: lang, title: notice)
376 profile_card(user: user, avatar: avatar, about_html: about_html, local_time: local_time,382 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> {
390 /// comes from the session, so what it sends is what that viewer may read. An unknown name is 404.396 /// comes from the session, so what it sends is what that viewer may read. An unknown name is 404.
391 #[route(GET "/users/{username}/events")]397 #[route(GET "/users/{username}/events")]
392 async fn profile_events(cx: &Cx) -> Result<Response> {398 async fn profile_events(cx: &Cx) -> Result<Response> {
393- let name = path_param::<Username>(cx);399+ let name = username(cx);
394- let state = app_context::<AppState>(cx).clone();400+ let state = context::<AppState>(cx).clone();
395 let Some(user) = state.store.user_by_username(name).await? else {401 let Some(user) = state.store.user_by_username(name).await? else {
396 return Err(not_found().into());402 return Err(not_found().into());
397 };403 };
@@ -601,6 +607,7 @@ async fn readable(
601 607
602 #[component]608 #[component]
603 async fn profile_card(609 async fn profile_card(
610+ cx: &Cx,
604 user: User,611 user: User,
605 avatar: Option<String>,612 avatar: Option<String>,
606 about_html: String,613 about_html: String,
@@ -875,10 +882,15 @@ async fn profile_card(
875 /// The viewer's own profile tabs on a page that makes something of theirs (a repository, a882 /// The viewer's own profile tabs on a page that makes something of theirs (a repository, a
876 /// snippet, an organization): the same tabs and counts as their profile, with `current` marked.883 /// snippet, an organization): the same tabs and counts as their profile, with `current` marked.
877 #[component]884 #[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> {
879 let items = crate::views::profile_items(lang, &username, false, true, false);891 let items = crate::views::profile_items(lang, &username, false, true, false);
880 let mut counts = Vec::new();892 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)
882 && let Some(user) = state.store.user_by_username(&username).await?894 && let Some(user) = state.store.user_by_username(&username).await?
883 {895 {
884 let actor = Some(&user);896 let actor = Some(&user);
@@ -913,6 +925,7 @@ pub async fn own_profile_tabs(lang: Lang, username: String, current: String) ->
913 /// organization's member pages all render it.925 /// organization's member pages all render it.
914 #[component]926 #[component]
915 pub async fn profile_tabs(927 pub async fn profile_tabs(
928+ cx: &Cx,
916 username: String,929 username: String,
917 items: Vec<NavItem>,930 items: Vec<NavItem>,
918 current: String,931 current: String,
crates/forge-web/src/pages/profile_pins.rsmodified+6 -5
@@ -5,7 +5,7 @@
5 use forge_core::store::profile_pins::MAX_PROFILE_PINS;5 use forge_core::store::profile_pins::MAX_PROFILE_PINS;
6 use forge_core::{Repo, Store, User};6 use forge_core::{Repo, Store, User};
7 use topcoat::Result;7 use topcoat::Result;
8-use topcoat::context::{Cx, app_context};8+use topcoat::context::{Cx, context};
9 use topcoat::router::content::RawForm;9 use topcoat::router::content::RawForm;
10 use topcoat::router::error::{SeeOther, see_other};10 use topcoat::router::error::{SeeOther, see_other};
11 use topcoat::router::{path_param, route};11 use topcoat::router::{path_param, route};
@@ -60,6 +60,7 @@ fn selection(raw: Vec<String>) -> Vec<String> {
60 /// the result after the redirect.60 /// the result after the redirect.
61 #[component]61 #[component]
62 pub(crate) async fn pins_menu(62 pub(crate) async fn pins_menu(
63+ cx: &Cx,
63 lang: Lang,64 lang: Lang,
64 action: String,65 action: String,
65 csrf: String,66 csrf: String,
@@ -117,13 +118,13 @@ async fn pins_save(cx: &Cx, RawForm(raw): RawForm) -> Result<SeeOther> {
117 let chosen = selection(form_all(&pairs, "repo"));118 let chosen = selection(form_all(&pairs, "repo"));
118 let back = format!("/{}", viewer.0.username);119 let back = format!("/{}", viewer.0.username);
119 let owner = viewer.0.clone();120 let owner = viewer.0.clone();
120- save_pins(app_context::<AppState>(cx), owner, chosen, back).await121+ save_pins(context::<AppState>(cx), owner, chosen, back).await
121 }122 }
122 123
123 /// Pins are picked on the profile; an old link lands there. Owners only, as the form was.124 /// Pins are picked on the profile; an old link lands there. Owners only, as the form was.
124 #[route(GET "/org/{org}/settings/pins")]125 #[route(GET "/org/{org}/settings/pins")]
125 async fn org_pins_page(cx: &Cx) -> Result<SeeOther> {126 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?;
127 require_owner(&ctx)?;128 require_owner(&ctx)?;
128 Err(see_other(format!("/{}", ctx.org.username)).into())129 Err(see_other(format!("/{}", ctx.org.username)).into())
129 }130 }
@@ -131,13 +132,13 @@ async fn org_pins_page(cx: &Cx) -> Result<SeeOther> {
131 /// Saves an organization's pins, then back to the org profile. Owners only.132 /// Saves an organization's pins, then back to the org profile. Owners only.
132 #[route(POST "/org/{org}/settings/pins")]133 #[route(POST "/org/{org}/settings/pins")]
133 async fn org_pins_save(cx: &Cx, RawForm(raw): RawForm) -> Result<SeeOther> {134 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?;
135 let pairs = form_pairs(&raw[..]);136 let pairs = form_pairs(&raw[..]);
136 require_form_csrf(&ctx, &form_field(&pairs, "csrf"))?;137 require_form_csrf(&ctx, &form_field(&pairs, "csrf"))?;
137 require_owner(&ctx)?;138 require_owner(&ctx)?;
138 let chosen = selection(form_all(&pairs, "repo"));139 let chosen = selection(form_all(&pairs, "repo"));
139 let back = format!("/{}", ctx.org.username);140 let back = format!("/{}", ctx.org.username);
140- save_pins(app_context::<AppState>(cx), ctx.org, chosen, back).await141+ save_pins(context::<AppState>(cx), ctx.org, chosen, back).await
141 }142 }
142 143
143 #[cfg(test)]144 #[cfg(test)]
crates/forge-web/src/pages/pull_branch.rsmodified+5 -4
@@ -17,7 +17,7 @@ use forge_git::repo::repo_path;
17 use serde::Deserialize;17 use serde::Deserialize;
18 use serde_json::json;18 use serde_json::json;
19 use topcoat::Result;19 use topcoat::Result;
20-use topcoat::context::{Cx, app_context};20+use topcoat::context::{Cx, context};
21 use topcoat::router::content::Form;21 use topcoat::router::content::Form;
22 use topcoat::router::error::{forbidden, not_found, see_other};22 use topcoat::router::error::{forbidden, not_found, see_other};
23 use topcoat::router::request::uri;23 use topcoat::router::request::uri;
@@ -81,10 +81,10 @@ async fn restore_branch_post(cx: &Cx, Form(form): Form<BranchForm>) -> Result<Re
81 }81 }
82 82
83 async fn branch_post(cx: &Cx, csrf: &str, op: Op) -> Result<Response> {83 async fn branch_post(cx: &Cx, csrf: &str, op: Op) -> Result<Response> {
84- let number = parse_number(path_param::<Number>(cx))?;84+ let number = parse_number(number(cx))?;
85- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;85+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
86 let (user, _) = require_csrf(cx, csrf).await?;86 let (user, _) = require_csrf(cx, csrf).await?;
87- let state = app_context::<AppState>(cx);87+ let state = context::<AppState>(cx);
88 let Some(pr) = state.store.pull_by_number(&ctx.repo.id, number).await? else {88 let Some(pr) = state.store.pull_by_number(&ctx.repo.id, number).await? else {
89 return Err(not_found().into());89 return Err(not_found().into());
90 };90 };
@@ -374,6 +374,7 @@ pub(crate) fn branch_error_from(cx: &Cx, lang: Lang) -> Option<String> {
374 /// when the viewer may act, the delete or restore tool.374 /// when the viewer may act, the delete or restore tool.
375 #[component]375 #[component]
376 pub(crate) async fn branch_box(376 pub(crate) async fn branch_box(
377+ cx: &Cx,
377 lang: Lang,378 lang: Lang,
378 action: Option<BranchAction>,379 action: Option<BranchAction>,
379 error: Option<String>,380 error: Option<String>,
crates/forge-web/src/pages/pull_files.rsmodified+16 -14
@@ -13,7 +13,7 @@ use forge_git::history::{CommitDiff, DiffStatus, FileDiff};
13 use forge_git::pulls::{blob_at, range_diff_files_ws};13 use forge_git::pulls::{blob_at, range_diff_files_ws};
14 use serde::Deserialize;14 use serde::Deserialize;
15 use topcoat::Result;15 use topcoat::Result;
16-use topcoat::context::{Cx, app_context};16+use topcoat::context::{Cx, context};
17 use topcoat::router::content::Form;17 use topcoat::router::content::Form;
18 use topcoat::router::error::{SeeOther, not_found, see_other};18 use topcoat::router::error::{SeeOther, not_found, see_other};
19 use topcoat::router::request::uri;19 use topcoat::router::request::uri;
@@ -26,9 +26,7 @@ use crate::i18n::pulls as review_strings;
26 use crate::i18n::pulls::{self as g, K};26 use crate::i18n::pulls::{self as g, K};
27 use crate::i18n::{self, Lang};27 use crate::i18n::{self, Lang};
28 use crate::pages::edit_history::thread_edit_counts;28 use crate::pages::edit_history::thread_edit_counts;
29-use crate::pages::issue_parts::{29+use crate::pages::issue_parts::{check_write, csrf_of, may_converse, parse_number, triage, viewer};
30- check_write, csrf_of, may_converse, parse_number, triage, viewer,
31-};
32 use crate::pages::passkeys;30 use crate::pages::passkeys;
33 use crate::pages::pull_reviews::{error_text_in, pull_diff, suggest_states};31 use crate::pages::pull_reviews::{error_text_in, pull_diff, suggest_states};
34 use crate::pages::pull_view::{commits_of, frame_in, is_merged, pull_header};32 use crate::pages::pull_view::{commits_of, frame_in, is_merged, pull_header};
@@ -206,6 +204,7 @@ struct RailFile {
206 /// toggle, and a changed file says so.204 /// toggle, and a changed file says so.
207 #[component]205 #[component]
208 async fn files_rail(206 async fn files_rail(
207+ cx: &Cx,
209 lang: Lang,208 lang: Lang,
210 rows: Vec<RailFile>,209 rows: Vec<RailFile>,
211 done_text: String,210 done_text: String,
@@ -253,6 +252,7 @@ async fn files_rail(
253 /// The diff pane's top row: Unified or Split, and whitespace. Its links are the toolbar's own.252 /// The diff pane's top row: Unified or Split, and whitespace. Its links are the toolbar's own.
254 #[component]253 #[component]
255 async fn diff_top(254 async fn diff_top(
255+ cx: &Cx,
256 lang: Lang,256 lang: Lang,
257 unified: String,257 unified: String,
258 split: String,258 split: String,
@@ -286,11 +286,11 @@ struct ViewedForm {
286 /// unreadable repo answers with the same not-found.286 /// unreadable repo answers with the same not-found.
287 #[route(POST "/{owner}/{repo}/pulls/{number}/viewed")]287 #[route(POST "/{owner}/{repo}/pulls/{number}/viewed")]
288 async fn viewed_post(cx: &Cx, Form(form): Form<ViewedForm>) -> Result<SeeOther> {288 async fn viewed_post(cx: &Cx, Form(form): Form<ViewedForm>) -> Result<SeeOther> {
289- let number = parse_number(path_param::<Number>(cx))?;289+ let number = parse_number(number(cx))?;
290- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;290+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
291 let (user, session) = require_user(cx).await?;291 let (user, session) = require_user(cx).await?;
292 check_write(&ctx, &session, &form.csrf)?;292 check_write(&ctx, &session, &form.csrf)?;
293- let state = app_context::<AppState>(cx);293+ let state = context::<AppState>(cx);
294 let pr = match state.store.pull_by_number(&ctx.repo.id, number).await? {294 let pr = match state.store.pull_by_number(&ctx.repo.id, number).await? {
295 Some(pr) => pr,295 Some(pr) => pr,
296 None => return Err(not_found().into()),296 None => return Err(not_found().into()),
@@ -334,6 +334,7 @@ async fn viewed_post(cx: &Cx, Form(form): Form<ViewedForm>) -> Result<SeeOther>
334 /// Request changes in the pull's head submit the same form.334 /// Request changes in the pull's head submit the same form.
335 #[component]335 #[component]
336 async fn review_bar(336 async fn review_bar(
337+ cx: &Cx,
337 lang: Lang,338 lang: Lang,
338 pr_href: String,339 pr_href: String,
339 csrf: String,340 csrf: String,
@@ -413,9 +414,9 @@ fn file_param(cx: &Cx) -> Option<usize> {
413 414
414 #[page("/{owner}/{repo}/pulls/{number}/files")]415 #[page("/{owner}/{repo}/pulls/{number}/files")]
415 async fn pull_files(cx: &Cx) -> Result<impl View> {416 async fn pull_files(cx: &Cx) -> Result<impl View> {
416- let number = parse_number(path_param::<Number>(cx))?;417+ let number = parse_number(number(cx))?;
417- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;418+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
418- let state = app_context::<AppState>(cx);419+ let state = context::<AppState>(cx);
419 let pr = match state.store.pull_by_number(&ctx.repo.id, number).await? {420 let pr = match state.store.pull_by_number(&ctx.repo.id, number).await? {
420 Some(pr) => pr,421 Some(pr) => pr,
421 None => return Err(not_found().into()),422 None => return Err(not_found().into()),
@@ -568,7 +569,10 @@ async fn pull_files(cx: &Cx) -> Result<impl View> {
568 .as_ref()569 .as_ref()
569 .map(|c| format!("{}/viewed", c.pr_href))570 .map(|c| format!("{}/viewed", c.pr_href))
570 .unwrap_or_default();571 .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();
572 576
573 let done = rows577 let done = rows
574 .iter()578 .iter()
@@ -653,9 +657,7 @@ async fn pull_files(cx: &Cx) -> Result<impl View> {
653 }657 }
654 .to_owned(),658 .to_owned(),
655 tick,659 tick,
656- href: row660+ href: row.index.map(|i| format!("?file={i}#file-{}", i + 1)),
657- .index
658- .map(|i| format!("?file={i}#file-{}", i + 1)),
659 path: row.path,661 path: row.path,
660 label: row.label,662 label: row.label,
661 state: row.state,663 state: row.state,
crates/forge-web/src/pages/pull_flow.rsmodified+11 -11
@@ -13,7 +13,7 @@
13 use forge_core::{Action, IssueState, MergeStyle, PullRequest, authorize};13 use forge_core::{Action, IssueState, MergeStyle, PullRequest, authorize};
14 use serde::Deserialize;14 use serde::Deserialize;
15 use topcoat::Result;15 use topcoat::Result;
16-use topcoat::context::{Cx, app_context};16+use topcoat::context::{Cx, context};
17 use topcoat::router::content::Form;17 use topcoat::router::content::Form;
18 use topcoat::router::error::{bad_request, forbidden, not_found, see_other};18 use topcoat::router::error::{bad_request, forbidden, not_found, see_other};
19 use topcoat::router::response::Response;19 use topcoat::router::response::Response;
@@ -54,7 +54,7 @@ fn can_write(ctx: &RepoCtx, user: &forge_core::User) -> bool {
54 }54 }
55 55
56 async fn load(cx: &Cx, ctx: &RepoCtx, number: i64) -> Result<PullRequest> {56 async fn load(cx: &Cx, ctx: &RepoCtx, number: i64) -> Result<PullRequest> {
57- let state = app_context::<AppState>(cx);57+ let state = context::<AppState>(cx);
58 match state.store.pull_by_number(&ctx.repo.id, number).await? {58 match state.store.pull_by_number(&ctx.repo.id, number).await? {
59 Some(pr) => Ok(pr),59 Some(pr) => Ok(pr),
60 None => Err(not_found().into()),60 None => Err(not_found().into()),
@@ -72,10 +72,10 @@ async fn draft_post(cx: &Cx, Form(form): Form<FlowForm>) -> Result<Response> {
72 }72 }
73 73
74 async fn set_draft(cx: &Cx, csrf: &str, draft: bool) -> Result<Response> {74 async fn set_draft(cx: &Cx, csrf: &str, draft: bool) -> Result<Response> {
75- let number = parse_number(path_param::<Number>(cx))?;75+ let number = parse_number(number(cx))?;
76- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;76+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
77 let (user, _) = require_csrf(cx, csrf).await?;77 let (user, _) = require_csrf(cx, csrf).await?;
78- let state = app_context::<AppState>(cx);78+ let state = context::<AppState>(cx);
79 let pr = load(cx, &ctx, number).await?;79 let pr = load(cx, &ctx, number).await?;
80 if ctx.repo.archived || !(can_write(&ctx, &user) || user.id == pr.issue.author_id) {80 if ctx.repo.archived || !(can_write(&ctx, &user) || user.id == pr.issue.author_id) {
81 return Err(forbidden().into());81 return Err(forbidden().into());
@@ -118,13 +118,13 @@ async fn set_draft(cx: &Cx, csrf: &str, draft: bool) -> Result<Response> {
118 118
119 #[route(POST "/{owner}/{repo}/pulls/{number}/auto-merge")]119 #[route(POST "/{owner}/{repo}/pulls/{number}/auto-merge")]
120 async fn auto_merge_enable(cx: &Cx, Form(form): Form<FlowForm>) -> Result<Response> {120 async fn auto_merge_enable(cx: &Cx, Form(form): Form<FlowForm>) -> Result<Response> {
121- let number = parse_number(path_param::<Number>(cx))?;121+ let number = parse_number(number(cx))?;
122- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;122+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
123 let (user, _) = require_csrf(cx, &form.csrf).await?;123 let (user, _) = require_csrf(cx, &form.csrf).await?;
124 if ctx.repo.archived || !can_write(&ctx, &user) {124 if ctx.repo.archived || !can_write(&ctx, &user) {
125 return Err(forbidden().into());125 return Err(forbidden().into());
126 }126 }
127- let state = app_context::<AppState>(cx);127+ let state = context::<AppState>(cx);
128 let pr = load(cx, &ctx, number).await?;128 let pr = load(cx, &ctx, number).await?;
129 let style = form129 let style = form
130 .style130 .style
@@ -149,13 +149,13 @@ async fn auto_merge_enable(cx: &Cx, Form(form): Form<FlowForm>) -> Result<Respon
149 149
150 #[route(POST "/{owner}/{repo}/pulls/{number}/auto-merge/disable")]150 #[route(POST "/{owner}/{repo}/pulls/{number}/auto-merge/disable")]
151 async fn auto_merge_disable(cx: &Cx, Form(form): Form<FlowForm>) -> Result<Response> {151 async fn auto_merge_disable(cx: &Cx, Form(form): Form<FlowForm>) -> Result<Response> {
152- let number = parse_number(path_param::<Number>(cx))?;152+ let number = parse_number(number(cx))?;
153- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;153+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
154 let (user, _) = require_csrf(cx, &form.csrf).await?;154 let (user, _) = require_csrf(cx, &form.csrf).await?;
155 if ctx.repo.archived || !can_write(&ctx, &user) {155 if ctx.repo.archived || !can_write(&ctx, &user) {
156 return Err(forbidden().into());156 return Err(forbidden().into());
157 }157 }
158- let state = app_context::<AppState>(cx);158+ let state = context::<AppState>(cx);
159 let pr = load(cx, &ctx, number).await?;159 let pr = load(cx, &ctx, number).await?;
160 state160 state
161 .store161 .store
crates/forge-web/src/pages/pull_live.rsmodified+7 -7
@@ -18,7 +18,7 @@ use forge_core::PullRequest;
18 use forge_core::reactions::ReactionTarget;18 use forge_core::reactions::ReactionTarget;
19 use forge_core::store::Store;19 use forge_core::store::Store;
20 use topcoat::Result;20 use topcoat::Result;
21-use topcoat::context::{Cx, app_context};21+use topcoat::context::{Cx, context};
22 use topcoat::router::request::{method, uri};22 use topcoat::router::request::{method, uri};
23 use topcoat::router::response::Response;23 use topcoat::router::response::Response;
24 use topcoat::router::{Body, Layer, LayerFuture, Method, Next, Path, path_param, route};24 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 {
202 /// The pull list's change stream. Auth is the repo read check of the list page.202 /// The pull list's change stream. Auth is the repo read check of the list page.
203 #[route(GET "/{owner}/{repo}/pulls/events")]203 #[route(GET "/{owner}/{repo}/pulls/events")]
204 async fn pulls_events(cx: &Cx) -> Result<Response> {204 async fn pulls_events(cx: &Cx) -> Result<Response> {
205- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;205+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
206- let state = app_context::<AppState>(cx);206+ let state = context::<AppState>(cx);
207 let topic = Topic::PullList(ctx.repo.id.clone());207 let topic = Topic::PullList(ctx.repo.id.clone());
208 let store = state.store.clone();208 let store = state.store.clone();
209 let repo_id = ctx.repo.id.clone();209 let repo_id = ctx.repo.id.clone();
@@ -220,9 +220,9 @@ async fn pulls_events(cx: &Cx) -> Result<Response> {
220 /// One pull request's change stream. Auth is the page's: the repo read check, then the pull.220 /// One pull request's change stream. Auth is the page's: the repo read check, then the pull.
221 #[route(GET "/{owner}/{repo}/pulls/{number}/events")]221 #[route(GET "/{owner}/{repo}/pulls/{number}/events")]
222 async fn pull_events(cx: &Cx) -> Result<Response> {222 async fn pull_events(cx: &Cx) -> Result<Response> {
223- let number = parse_number(path_param::<Number>(cx))?;223+ let number = parse_number(number(cx))?;
224- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;224+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
225- let state = app_context::<AppState>(cx);225+ let state = context::<AppState>(cx);
226 let Some(pr) = state.store.pull_by_number(&ctx.repo.id, number).await? else {226 let Some(pr) = state.store.pull_by_number(&ctx.repo.id, number).await? else {
227 return Err(topcoat::router::error::not_found().into());227 return Err(topcoat::router::error::not_found().into());
228 };228 };
@@ -284,7 +284,7 @@ async fn bump_after_write(cx: &Cx, body: Body, next: Next<'_>) -> topcoat::Resul
284 let target = written(cx);284 let target = written(cx);
285 let result = next.run(cx, body).await;285 let result = next.run(cx, body).await;
286 if let Some(target) = target {286 if let Some(target) = target {
287- bump_written(app_context::<AppState>(cx), target).await;287+ bump_written(context::<AppState>(cx), target).await;
288 }288 }
289 result289 result
290 }290 }
crates/forge-web/src/pages/pull_reviews.rsmodified+40 -40
@@ -20,7 +20,7 @@ use forge_git::history::{CommitDiff, DiffStatus, FileDiff, LineKind};
20 use forge_git::pulls::{FileEdit, Signature, commit_file_edit, range_diff_files};20 use forge_git::pulls::{FileEdit, Signature, commit_file_edit, range_diff_files};
21 use serde::Deserialize;21 use serde::Deserialize;
22 use topcoat::Result;22 use topcoat::Result;
23-use topcoat::context::{Cx, app_context};23+use topcoat::context::{Cx, context};
24 use topcoat::router::content::Form;24 use topcoat::router::content::Form;
25 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};25 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
26 use topcoat::router::request::uri;26 use topcoat::router::request::uri;
@@ -341,11 +341,11 @@ fn signature_of(state: &AppState, user: &User) -> Signature {
341 /// request must name the head the form was rendered for, and the line must be on that diff.341 /// request must name the head the form was rendered for, and the line must be on that diff.
342 #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments")]342 #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments")]
343 async fn review_comment_post(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {343 async fn review_comment_post(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {
344- let number = parse_number(path_param::<Number>(cx))?;344+ let number = parse_number(number(cx))?;
345- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;345+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
346 let (user, session) = require_user(cx).await?;346 let (user, session) = require_user(cx).await?;
347 check_write(&ctx, &session, &form.csrf)?;347 check_write(&ctx, &session, &form.csrf)?;
348- let state = app_context::<AppState>(cx);348+ let state = context::<AppState>(cx);
349 let pr = pull_for(state, &ctx, number).await?;349 let pr = pull_for(state, &ctx, number).await?;
350 if !may_converse(&ctx, &pr.issue) {350 if !may_converse(&ctx, &pr.issue) {
351 return Err(forbidden().into());351 return Err(forbidden().into());
@@ -411,16 +411,16 @@ async fn review_comment_post(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<Se
411 /// Replies in the thread of a root comment. Replies post at once, even on a closed pull request.411 /// Replies in the thread of a root comment. Replies post at once, even on a closed pull request.
412 #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/reply")]412 #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/reply")]
413 async fn review_comment_reply(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {413 async fn review_comment_reply(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {
414- let number = parse_number(path_param::<Number>(cx))?;414+ let number = parse_number(number(cx))?;
415- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;415+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
416 let (user, session) = require_user(cx).await?;416 let (user, session) = require_user(cx).await?;
417 check_write(&ctx, &session, &form.csrf)?;417 check_write(&ctx, &session, &form.csrf)?;
418- let state = app_context::<AppState>(cx);418+ let state = context::<AppState>(cx);
419 let pr = pull_for(state, &ctx, number).await?;419 let pr = pull_for(state, &ctx, number).await?;
420 if !may_converse(&ctx, &pr.issue) {420 if !may_converse(&ctx, &pr.issue) {
421 return Err(forbidden().into());421 return Err(forbidden().into());
422 }422 }
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?;
424 let root = root_of(&parent);424 let root = root_of(&parent);
425 let tab = tab_url(&ctx, number, &form.ret);425 let tab = tab_url(&ctx, number, &form.ret);
426 let anchor = format!("#rc-{root}");426 let anchor = format!("#rc-{root}");
@@ -441,13 +441,13 @@ async fn review_comment_reply(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<S
441 /// The edit form for a comment. Only its author may open it.441 /// The edit form for a comment. Only its author may open it.
442 #[page("/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/edit")]442 #[page("/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/edit")]
443 async fn review_comment_edit_form(cx: &Cx) -> Result<impl View> {443 async fn review_comment_edit_form(cx: &Cx) -> Result<impl View> {
444- let number = parse_number(path_param::<Number>(cx))?;444+ let number = parse_number(number(cx))?;
445- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;445+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
446 let (user, _) = require_user(cx).await?;446 let (user, _) = require_user(cx).await?;
447 let lang = i18n::lang(cx, Some(&user));447 let lang = i18n::lang(cx, Some(&user));
448- let state = app_context::<AppState>(cx);448+ let state = context::<AppState>(cx);
449 let pr = pull_for(state, &ctx, number).await?;449 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?;
451 if comment.author_id != user.id {451 if comment.author_id != user.id {
452 return Err(forbidden().into());452 return Err(forbidden().into());
453 }453 }
@@ -464,7 +464,7 @@ async fn edit_page(
464 error: Option<&'static str>,464 error: Option<&'static str>,
465 lang: Lang,465 lang: Lang,
466 ) -> Result<impl View> {466 ) -> Result<impl View> {
467- let state = app_context::<AppState>(cx);467+ let state = context::<AppState>(cx);
468 let owner = ctx.repo.owner_name.clone();468 let owner = ctx.repo.owner_name.clone();
469 let name = ctx.repo.name.clone();469 let name = ctx.repo.name.clone();
470 let csrf = csrf_of(&ctx);470 let csrf = csrf_of(&ctx);
@@ -481,7 +481,7 @@ async fn edit_page(
481 let save_label = g::t(lang, K::SaveComment);481 let save_label = g::t(lang, K::SaveComment);
482 let cancel_label = g::t(lang, K::CancelButton);482 let cancel_label = g::t(lang, K::CancelButton);
483 let header = ctx.head(state, "pulls").await?;483 let header = ctx.head(state, "pulls").await?;
484- Ok(view! { cx =>484+ Ok(view! {
485 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(),485 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(),
486 repo_head(head: header, title: Some(heading.to_owned()))486 repo_head(head: header, title: Some(heading.to_owned()))
487 <div class="sheet fit">487 <div class="sheet fit">
@@ -507,13 +507,13 @@ async fn edit_page(
507 /// Saves an edited comment. Only its author; the store records the previous body.507 /// Saves an edited comment. Only its author; the store records the previous body.
508 #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/edit")]508 #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/edit")]
509 async fn review_comment_edit_save(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {509 async fn review_comment_edit_save(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {
510- let number = parse_number(path_param::<Number>(cx))?;510+ let number = parse_number(number(cx))?;
511- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;511+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
512 let (user, session) = require_user(cx).await?;512 let (user, session) = require_user(cx).await?;
513 check_write(&ctx, &session, &form.csrf)?;513 check_write(&ctx, &session, &form.csrf)?;
514- let state = app_context::<AppState>(cx);514+ let state = context::<AppState>(cx);
515 let pr = pull_for(state, &ctx, number).await?;515 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?;
517 if comment.author_id != user.id {517 if comment.author_id != user.id {
518 return Err(forbidden().into());518 return Err(forbidden().into());
519 }519 }
@@ -543,13 +543,13 @@ async fn review_comment_edit_save(cx: &Cx, Form(form): Form<ReviewForm>) -> Resu
543 /// Deletes a comment. Its author or Triage. Deleting a root deletes its replies.543 /// Deletes a comment. Its author or Triage. Deleting a root deletes its replies.
544 #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/delete")]544 #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/delete")]
545 async fn review_comment_delete(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {545 async fn review_comment_delete(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {
546- let number = parse_number(path_param::<Number>(cx))?;546+ let number = parse_number(number(cx))?;
547- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;547+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
548 let (user, session) = require_user(cx).await?;548 let (user, session) = require_user(cx).await?;
549 check_write(&ctx, &session, &form.csrf)?;549 check_write(&ctx, &session, &form.csrf)?;
550- let state = app_context::<AppState>(cx);550+ let state = context::<AppState>(cx);
551 let pr = pull_for(state, &ctx, number).await?;551 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?;
553 if !may_change(&ctx, &comment.author_id) {553 if !may_change(&ctx, &comment.author_id) {
554 return Err(forbidden().into());554 return Err(forbidden().into());
555 }555 }
@@ -565,13 +565,13 @@ async fn review_comment_delete(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<
565 /// Resolves or unresolves a thread (`resolved=1|0`). The PR author or Write.565 /// Resolves or unresolves a thread (`resolved=1|0`). The PR author or Write.
566 #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/resolve")]566 #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/resolve")]
567 async fn review_comment_resolve(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {567 async fn review_comment_resolve(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {
568- let number = parse_number(path_param::<Number>(cx))?;568+ let number = parse_number(number(cx))?;
569- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;569+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
570 let (user, session) = require_user(cx).await?;570 let (user, session) = require_user(cx).await?;
571 check_write(&ctx, &session, &form.csrf)?;571 check_write(&ctx, &session, &form.csrf)?;
572- let state = app_context::<AppState>(cx);572+ let state = context::<AppState>(cx);
573 let pr = pull_for(state, &ctx, number).await?;573 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?;
575 let is_pr_author = pr.issue.author_id == user.id;575 let is_pr_author = pr.issue.author_id == user.id;
576 if !is_pr_author576 if !is_pr_author
577 && authorize(577 && authorize(
@@ -607,13 +607,13 @@ async fn review_comment_resolve(cx: &Cx, Form(form): Form<ReviewForm>) -> Result
607 /// suggestion was written against.607 /// suggestion was written against.
608 #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/apply")]608 #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/apply")]
609 async fn review_comment_apply(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {609 async fn review_comment_apply(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {
610- let number = parse_number(path_param::<Number>(cx))?;610+ let number = parse_number(number(cx))?;
611- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;611+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
612 let (user, session) = require_user(cx).await?;612 let (user, session) = require_user(cx).await?;
613 check_write(&ctx, &session, &form.csrf)?;613 check_write(&ctx, &session, &form.csrf)?;
614- let state = app_context::<AppState>(cx);614+ let state = context::<AppState>(cx);
615 let pr = pull_for(state, &ctx, number).await?;615 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?;
617 let files = tab_url(&ctx, number, &form.ret);617 let files = tab_url(&ctx, number, &form.ret);
618 let anchor = format!("#rc-{}", comment.id);618 let anchor = format!("#rc-{}", comment.id);
619 if comment.reply_to.is_some() || comment.pending || comment.side != Side::New {619 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
697 /// cannot approve or request changes on their own pull request. Closed pull requests refuse it.697 /// cannot approve or request changes on their own pull request. Closed pull requests refuse it.
698 #[route(POST "/{owner}/{repo}/pulls/{number}/reviews")]698 #[route(POST "/{owner}/{repo}/pulls/{number}/reviews")]
699 async fn review_submit(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {699 async fn review_submit(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {
700- let number = parse_number(path_param::<Number>(cx))?;700+ let number = parse_number(number(cx))?;
701- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;701+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
702 let (user, session) = require_user(cx).await?;702 let (user, session) = require_user(cx).await?;
703 check_write(&ctx, &session, &form.csrf)?;703 check_write(&ctx, &session, &form.csrf)?;
704- let state = app_context::<AppState>(cx);704+ let state = context::<AppState>(cx);
705 let pr = pull_for(state, &ctx, number).await?;705 let pr = pull_for(state, &ctx, number).await?;
706 if !may_converse(&ctx, &pr.issue) {706 if !may_converse(&ctx, &pr.issue) {
707 return Err(forbidden().into());707 return Err(forbidden().into());
@@ -772,11 +772,11 @@ async fn review_text(
772 /// Discards the viewer's pending review and its draft comments.772 /// Discards the viewer's pending review and its draft comments.
773 #[route(POST "/{owner}/{repo}/pulls/{number}/reviews/discard")]773 #[route(POST "/{owner}/{repo}/pulls/{number}/reviews/discard")]
774 async fn review_discard(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {774 async fn review_discard(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {
775- let number = parse_number(path_param::<Number>(cx))?;775+ let number = parse_number(number(cx))?;
776- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;776+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
777 let (user, session) = require_user(cx).await?;777 let (user, session) = require_user(cx).await?;
778 check_write(&ctx, &session, &form.csrf)?;778 check_write(&ctx, &session, &form.csrf)?;
779- let state = app_context::<AppState>(cx);779+ let state = context::<AppState>(cx);
780 let pr = pull_for(state, &ctx, number).await?;780 let pr = pull_for(state, &ctx, number).await?;
781 state781 state
782 .store782 .store
@@ -788,8 +788,8 @@ async fn review_discard(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOthe
788 /// Dismisses an approval or a change request with a reason. Write only.788 /// Dismisses an approval or a change request with a reason. Write only.
789 #[route(POST "/{owner}/{repo}/pulls/{number}/reviews/{review_id}/dismiss")]789 #[route(POST "/{owner}/{repo}/pulls/{number}/reviews/{review_id}/dismiss")]
790 async fn review_dismiss(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {790 async fn review_dismiss(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> {
791- let number = parse_number(path_param::<Number>(cx))?;791+ let number = parse_number(number(cx))?;
792- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;792+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
793 let (user, session) = require_user(cx).await?;793 let (user, session) = require_user(cx).await?;
794 check_write(&ctx, &session, &form.csrf)?;794 check_write(&ctx, &session, &form.csrf)?;
795 if authorize(795 if authorize(
@@ -803,9 +803,9 @@ async fn review_dismiss(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOthe
803 {803 {
804 return Err(forbidden().into());804 return Err(forbidden().into());
805 }805 }
806- let state = app_context::<AppState>(cx);806+ let state = context::<AppState>(cx);
807 let pr = pull_for(state, &ctx, number).await?;807 let pr = pull_for(state, &ctx, number).await?;
808- let wanted = path_param::<ReviewId>(cx);808+ let wanted = review_id(cx);
809 let Some(review) = state809 let Some(review) = state
810 .store810 .store
811 .list_reviews(&pr.issue.id)811 .list_reviews(&pr.issue.id)
crates/forge-web/src/pages/pull_view.rsmodified+21 -20
@@ -12,7 +12,7 @@ use forge_git::browse::CommitInfo;
12 use forge_git::history::CommitDiff;12 use forge_git::history::CommitDiff;
13 use forge_git::pulls::{is_ancestor, range_diff_files, range_log};13 use forge_git::pulls::{is_ancestor, range_diff_files, range_log};
14 use topcoat::Result;14 use topcoat::Result;
15-use topcoat::context::{Cx, app_context};15+use topcoat::context::{Cx, context};
16 use topcoat::router::content::Form;16 use topcoat::router::content::Form;
17 use topcoat::router::error::{not_found, see_other};17 use topcoat::router::error::{not_found, see_other};
18 use topcoat::router::request::uri;18 use topcoat::router::request::uri;
@@ -69,9 +69,9 @@ async fn pull_for(state: &AppState, ctx: &RepoCtx, number: i64) -> Result<PullRe
69 69
70 /// The repo and pull request for a request whose path names `{owner}/{repo}/pulls/{number}`.70 /// The repo and pull request for a request whose path names `{owner}/{repo}/pulls/{number}`.
71 async fn load_pull(cx: &Cx) -> Result<(RepoCtx, PullRequest)> {71 async fn load_pull(cx: &Cx) -> Result<(RepoCtx, PullRequest)> {
72- let number = parse_number(path_param::<Number>(cx))?;72+ let number = parse_number(number(cx))?;
73- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;73+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
74- let pr = pull_for(app_context::<AppState>(cx), &ctx, number).await?;74+ let pr = pull_for(context::<AppState>(cx), &ctx, number).await?;
75 Ok((ctx, pr))75 Ok((ctx, pr))
76 }76 }
77 77
@@ -192,6 +192,7 @@ pub(crate) async fn frame_in(
192 /// then the pull request's tabs. `active` names the tab that is open.192 /// then the pull request's tabs. `active` names the tab that is open.
193 #[component]193 #[component]
194 pub(crate) async fn pull_header(194 pub(crate) async fn pull_header(
195+ cx: &Cx,
195 frame: Frame,196 frame: Frame,
196 active: String,197 active: String,
197 #[default] child: Child<'_>,198 #[default] child: Child<'_>,
@@ -317,6 +318,7 @@ struct FlowView {
317 /// `ok`, `bad` or `muted` and picks the box colors.318 /// `ok`, `bad` or `muted` and picks the box colors.
318 #[component]319 #[component]
319 async fn merge_box(320 async fn merge_box(
321+ cx: &Cx,
320 headline: String,322 headline: String,
321 tone: String,323 tone: String,
322 conflicts: Vec<String>,324 conflicts: Vec<String>,
@@ -458,6 +460,7 @@ async fn merge_box(
458 /// The note that replaces the merge box once the pull request is merged.460 /// The note that replaces the merge box once the pull request is merged.
459 #[component]461 #[component]
460 async fn merged_notice(462 async fn merged_notice(
463+ cx: &Cx,
461 who: String,464 who: String,
462 when: When,465 when: When,
463 commit: String,466 commit: String,
@@ -500,6 +503,7 @@ struct DismissRow {
500 /// holders. Either summary line may be absent.503 /// holders. Either summary line may be absent.
501 #[component]504 #[component]
502 async fn review_box(505 async fn review_box(
506+ cx: &Cx,
503 approved: Option<String>,507 approved: Option<String>,
504 approved_before: Option<String>,508 approved_before: Option<String>,
505 changes: Option<String>,509 changes: Option<String>,
@@ -571,7 +575,7 @@ async fn head_checks(
571 }575 }
572 576
573 #[component]577 #[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> {
575 let empty = rows.is_empty();579 let empty = rows.is_empty();
576 let no_commits = g::t(lang, K::NoCommits);580 let no_commits = g::t(lang, K::NoCommits);
577 let committed = g::t(lang, K::Committed);581 let committed = g::t(lang, K::Committed);
@@ -612,7 +616,7 @@ async fn pull_conversation(
612 error: Option<String>,616 error: Option<String>,
613 merge_error: Option<String>,617 merge_error: Option<String>,
614 ) -> Result<impl View> {618 ) -> Result<impl View> {
615- let state = app_context::<AppState>(cx);619+ let state = context::<AppState>(cx);
616 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));620 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
617 let commit_count = commits_of(state, &ctx, &pr).await?.len();621 let commit_count = commits_of(state, &ctx, &pr).await?.len();
618 let file_count = diff_of(state, &ctx, &pr).await?.files.len();622 let file_count = diff_of(state, &ctx, &pr).await?.files.len();
@@ -899,7 +903,7 @@ async fn pull_conversation(
899 let labels_href = repo_href(&owner, &name, "labels.css", "");903 let labels_href = repo_href(&owner, &name, "labels.css", "");
900 // The conversation follows the pull request's event stream: a change re-renders it.904 // The conversation follows the pull request's event stream: a change re-renders it.
901 let live = format!("{href}/events");905 let live = format!("{href}/events");
902- Ok(view! { cx =>906+ Ok(view! {
903 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(), extra_stylesheet: Some(labels_href.as_str()),907 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(), extra_stylesheet: Some(labels_href.as_str()),
904 pull_header(frame: frame.clone(), active: "conversation".to_owned(),908 pull_header(frame: frame.clone(), active: "conversation".to_owned(),
905 item_head_tools(lang: lang, close: close, notify: notify)909 item_head_tools(lang: lang, close: close, notify: notify)
@@ -1005,7 +1009,7 @@ async fn pull_show(cx: &Cx) -> Result<impl View> {
1005 #[page("/{owner}/{repo}/pulls/{number}/commits")]1009 #[page("/{owner}/{repo}/pulls/{number}/commits")]
1006 async fn pull_commits(cx: &Cx) -> Result<impl View> {1010 async fn pull_commits(cx: &Cx) -> Result<impl View> {
1007 let (ctx, pr) = load_pull(cx).await?;1011 let (ctx, pr) = load_pull(cx).await?;
1008- let state = app_context::<AppState>(cx);1012+ let state = context::<AppState>(cx);
1009 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));1013 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
1010 let commits = commits_of(state, &ctx, &pr).await?;1014 let commits = commits_of(state, &ctx, &pr).await?;
1011 let file_count = diff_of(state, &ctx, &pr).await?.files.len();1015 let file_count = diff_of(state, &ctx, &pr).await?.files.len();
@@ -1042,11 +1046,11 @@ async fn pull_commits(cx: &Cx) -> Result<impl View> {
1042 /// routes. A merged pull request's state cannot change, and a refused comment re-renders the1046 /// routes. A merged pull request's state cannot change, and a refused comment re-renders the
1043 /// Conversation with its text.1047 /// Conversation with its text.
1044 async fn pull_post(cx: &Cx, form: CommentForm) -> Result<impl View> {1048 async fn pull_post(cx: &Cx, form: CommentForm) -> Result<impl View> {
1045- let number = parse_number(path_param::<Number>(cx))?;1049+ let number = parse_number(number(cx))?;
1046- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;1050+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
1047 let (user, session) = require_user(cx).await?;1051 let (user, session) = require_user(cx).await?;
1048 check_write(&ctx, &session, &form.csrf)?;1052 check_write(&ctx, &session, &form.csrf)?;
1049- let state = app_context::<AppState>(cx);1053+ let state = context::<AppState>(cx);
1050 let pr = pull_for(state, &ctx, number).await?;1054 let pr = pull_for(state, &ctx, number).await?;
1051 let lang = i18n::lang(cx, Some(&user));1055 let lang = i18n::lang(cx, Some(&user));
1052 1056
@@ -1301,10 +1305,7 @@ mod tests {
1301 assert_eq!(status, 200, "clean");1305 assert_eq!(status, 200, "clean");
1302 assert!(body.contains("Add feature"), "clean: {body}");1306 assert!(body.contains("Add feature"), "clean: {body}");
1303 assert!(body.contains("issue-badge-open\">Open<"), "clean: {body}");1307 assert!(body.contains("issue-badge-open\">Open<"), "clean: {body}");
1304- assert!(1308+ assert!(body.contains("Ready to merge"), "clean: {body}");
1305- body.contains("Ready to merge"),
1306- "clean: {body}"
1307- );
1308 assert!(1309 assert!(
1309 body.contains(&format!("action=\"{uri}/merge\"")),1310 body.contains(&format!("action=\"{uri}/merge\"")),
1310 "clean: {body}"1311 "clean: {body}"
@@ -1320,10 +1321,7 @@ mod tests {
1320 // A reader sees the clean status but no merge form.1321 // A reader sees the clean status but no merge form.
1321 let (status, _, body) = send(&fx.router, "GET", &uri, Some("bob-token"), None).await;1322 let (status, _, body) = send(&fx.router, "GET", &uri, Some("bob-token"), None).await;
1322 assert_eq!(status, 200, "reader");1323 assert_eq!(status, 200, "reader");
1323- assert!(1324+ assert!(body.contains("Ready to merge"), "reader: {body}");
1324- body.contains("Ready to merge"),
1325- "reader: {body}"
1326- );
1327 assert!(!body.contains("name=\"style\""), "reader: {body}");1325 assert!(!body.contains("name=\"style\""), "reader: {body}");
1328 assert!(!body.contains("Merge pull request"), "reader: {body}");1326 assert!(!body.contains("Merge pull request"), "reader: {body}");
1329 1327
@@ -1723,7 +1721,10 @@ mod tests {
1723 assert!(body.contains("Please rename this"), "approval: {body}");1721 assert!(body.contains("Please rename this"), "approval: {body}");
1724 assert!(body.contains("feat.txt:1"), "approval: {body}");1722 assert!(body.contains("feat.txt:1"), "approval: {body}");
1725 assert!(body.contains("@@ -0,0 +1 @@"), "approval: {body}");1723 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+ );
1727 assert!(body.contains("Approved by bob"), "approval: {body}");1728 assert!(body.contains("Approved by bob"), "approval: {body}");
1728 1729
1729 fx.store1730 fx.store
crates/forge-web/src/pages/pulls_list.rsmodified+16 -10
@@ -8,7 +8,7 @@ use std::collections::HashMap;
8 use forge_core::tz::format_in_tz;8 use forge_core::tz::format_in_tz;
9 use forge_core::{IssueListItem, IssueState};9 use forge_core::{IssueListItem, IssueState};
10 use topcoat::Result;10 use topcoat::Result;
11-use topcoat::context::{Cx, app_context};11+use topcoat::context::{Cx, context};
12 use topcoat::router::{page, path_param, query_params};12 use topcoat::router::{page, path_param, query_params};
13 use topcoat::view::{View, view};13 use topcoat::view::{View, view};
14 14
@@ -16,13 +16,12 @@ use crate::i18n::merge_queue as mq;
16 use crate::i18n::pulls::{self as g, K};16 use crate::i18n::pulls::{self as g, K};
17 use crate::i18n::{self, Lang};17 use crate::i18n::{self, Lang};
18 use crate::pages::issues_list::{18 use crate::pages::issues_list::{
19- AssigneeView, LabelView, ListQuery, MilestoneView, Selection, SortOption, list_href,19+ AssigneeView, LabelView, ListQuery, MilestoneView, Selection, SortOption, list_href, stamp_unix,
20- stamp_unix,
21 };20 };
21+use crate::pages::passkeys::s;
22 use crate::pages::repo::repo_head;22 use crate::pages::repo::repo_head;
23 use crate::pages::repo_ctx::load_repo;23 use crate::pages::repo_ctx::load_repo;
24 use crate::state::AppState;24 use crate::state::AppState;
25-use crate::pages::passkeys::s;
26 use crate::views::parts::{RailItem, SubPart, rail};25 use crate::views::parts::{RailItem, SubPart, rail};
27 use crate::views::{26 use crate::views::{
28 avatar_url_unknown, iso_time, now_unix, relative_time, repo_href, shell, user_link,27 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
64 if open {63 if open {
65 (g::t(lang, K::PrStateOpenLabel), g::t(lang, K::StateOpen))64 (g::t(lang, K::PrStateOpenLabel), g::t(lang, K::StateOpen))
66 } else if merged {65 } 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+ )
68 } else {70 } 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+ )
70 }75 }
71 }76 }
72 77
@@ -150,11 +155,11 @@ fn row_view(
150 155
151 #[page("/{owner}/{repo}/pulls")]156 #[page("/{owner}/{repo}/pulls")]
152 async fn pulls_list_page(cx: &Cx) -> Result<impl View> {157 async fn pulls_list_page(cx: &Cx) -> Result<impl View> {
153- let owner = path_param::<Owner>(cx);158+ let owner = owner(cx);
154- let name = path_param::<Repo>(cx);159+ let name = repo(cx);
155 let query = query_params::<ListQuery>(cx)?;160 let query = query_params::<ListQuery>(cx)?;
156 let ctx = load_repo(cx, owner, name).await?;161 let ctx = load_repo(cx, owner, name).await?;
157- let state = app_context::<AppState>(cx);162+ let state = context::<AppState>(cx);
158 let mut sel = Selection::parse(query);163 let mut sel = Selection::parse(query);
159 sel.resolve_me(ctx.viewer.as_ref().map(|(user, _)| user.username.as_str()));164 sel.resolve_me(ctx.viewer.as_ref().map(|(user, _)| user.username.as_str()));
160 let search_value = sel.search_text();165 let search_value = sel.search_text();
@@ -411,7 +416,8 @@ mod tests {
411 }416 }
412 417
413 fn rows(html: &str) -> usize {418 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()
415 }421 }
416 422
417 const HEAD_OID: &str = "1111111111111111111111111111111111111111";423 const HEAD_OID: &str = "1111111111111111111111111111111111111111";
crates/forge-web/src/pages/pulls_merge.rsmodified+4 -4
@@ -25,7 +25,7 @@ use http::HeaderValue;
25 use http::header::CONTENT_TYPE;25 use http::header::CONTENT_TYPE;
26 use serde::Deserialize;26 use serde::Deserialize;
27 use topcoat::Result;27 use topcoat::Result;
28-use topcoat::context::{Cx, app_context};28+use topcoat::context::{Cx, context};
29 use topcoat::router::content::Form;29 use topcoat::router::content::Form;
30 use topcoat::router::error::{bad_request, forbidden, not_found, see_other};30 use topcoat::router::error::{bad_request, forbidden, not_found, see_other};
31 use topcoat::router::response::Response;31 use topcoat::router::response::Response;
@@ -110,8 +110,8 @@ pub enum MergeOutcome {
110 110
111 #[route(POST "/{owner}/{repo}/pulls/{number}/merge")]111 #[route(POST "/{owner}/{repo}/pulls/{number}/merge")]
112 async fn merge_post(cx: &Cx, Form(form): Form<MergeForm>) -> Result<Response> {112 async fn merge_post(cx: &Cx, Form(form): Form<MergeForm>) -> Result<Response> {
113- let number = parse_number(path_param::<Number>(cx))?;113+ let number = parse_number(number(cx))?;
114- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;114+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
115 let (user, _) = require_csrf(cx, &form.csrf).await?;115 let (user, _) = require_csrf(cx, &form.csrf).await?;
116 if ctx.repo.archived116 if ctx.repo.archived
117 || authorize(117 || authorize(
@@ -125,7 +125,7 @@ async fn merge_post(cx: &Cx, Form(form): Form<MergeForm>) -> Result<Response> {
125 {125 {
126 return Err(forbidden().into());126 return Err(forbidden().into());
127 }127 }
128- let state = app_context::<AppState>(cx);128+ let state = context::<AppState>(cx);
129 let Some(pr) = state.store.pull_by_number(&ctx.repo.id, number).await? else {129 let Some(pr) = state.store.pull_by_number(&ctx.repo.id, number).await? else {
130 return Err(not_found().into());130 return Err(not_found().into());
131 };131 };
crates/forge-web/src/pages/push.rsmodified+12 -12
@@ -17,7 +17,7 @@ use serde::Deserialize;
17 use serde_json::json;17 use serde_json::json;
18 use tokio::sync::broadcast::error::RecvError;18 use tokio::sync::broadcast::error::RecvError;
19 use topcoat::Result;19 use topcoat::Result;
20-use topcoat::context::{Cx, app_context};20+use topcoat::context::{Cx, context};
21 use topcoat::router::content::Form;21 use topcoat::router::content::Form;
22 use topcoat::router::content::sse::Event;22 use topcoat::router::content::sse::Event;
23 use topcoat::router::error::{SeeOther, see_other};23 use topcoat::router::error::{SeeOther, see_other};
@@ -117,7 +117,7 @@ fn no_content() -> Response {
117 #[route(GET "/push/vapid-key")]117 #[route(GET "/push/vapid-key")]
118 async fn vapid_key(cx: &Cx) -> Result<Response> {118 async fn vapid_key(cx: &Cx) -> Result<Response> {
119 require_user(cx).await?;119 require_user(cx).await?;
120- let state = app_context::<AppState>(cx);120+ let state = context::<AppState>(cx);
121 let keys = web_push::vapid_keys(state).await?;121 let keys = web_push::vapid_keys(state).await?;
122 Ok(json(StatusCode::OK, &json!({ "public_key": keys.public })))122 Ok(json(StatusCode::OK, &json!({ "public_key": keys.public })))
123 }123 }
@@ -126,7 +126,7 @@ async fn vapid_key(cx: &Cx) -> Result<Response> {
126 #[route(POST "/push/subscribe")]126 #[route(POST "/push/subscribe")]
127 async fn subscribe(cx: &Cx, Form(form): Form<SubscribeForm>) -> Result<Response> {127 async fn subscribe(cx: &Cx, Form(form): Form<SubscribeForm>) -> Result<Response> {
128 let (user, _) = require_csrf(cx, &form.csrf).await?;128 let (user, _) = require_csrf(cx, &form.csrf).await?;
129- let state = app_context::<AppState>(cx);129+ let state = context::<AppState>(cx);
130 let policy = crate::mirrors::policy(state);130 let policy = crate::mirrors::policy(state);
131 if let Err(e) =131 if let Err(e) =
132 check_endpoint(&form.endpoint, &policy).and_then(|()| check_keys(&form.p256dh, &form.auth))132 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>
156 #[route(POST "/push/unsubscribe")]156 #[route(POST "/push/unsubscribe")]
157 async fn unsubscribe(cx: &Cx, Form(form): Form<EndpointForm>) -> Result<Response> {157 async fn unsubscribe(cx: &Cx, Form(form): Form<EndpointForm>) -> Result<Response> {
158 let (user, _) = require_csrf(cx, &form.csrf).await?;158 let (user, _) = require_csrf(cx, &form.csrf).await?;
159- let state = app_context::<AppState>(cx);159+ let state = context::<AppState>(cx);
160 if state160 if state
161 .store161 .store
162 .delete_push_subscription_by_endpoint(&user.id, &form.endpoint)162 .delete_push_subscription_by_endpoint(&user.id, &form.endpoint)
@@ -171,7 +171,7 @@ async fn unsubscribe(cx: &Cx, Form(form): Form<EndpointForm>) -> Result<Response
171 #[route(POST "/settings/notifications/push/remove")]171 #[route(POST "/settings/notifications/push/remove")]
172 async fn remove_device(cx: &Cx, Form(form): Form<DeviceForm>) -> Result<SeeOther> {172 async fn remove_device(cx: &Cx, Form(form): Form<DeviceForm>) -> Result<SeeOther> {
173 let (user, _) = require_csrf(cx, &form.csrf).await?;173 let (user, _) = require_csrf(cx, &form.csrf).await?;
174- let state = app_context::<AppState>(cx);174+ let state = context::<AppState>(cx);
175 if state175 if state
176 .store176 .store
177 .delete_push_subscription(&user.id, &form.id)177 .delete_push_subscription(&user.id, &form.id)
@@ -187,7 +187,7 @@ async fn remove_device(cx: &Cx, Form(form): Form<DeviceForm>) -> Result<SeeOther
187 #[route(POST "/settings/notifications/push/test")]187 #[route(POST "/settings/notifications/push/test")]
188 async fn send_test(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {188 async fn send_test(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
189 let (user, _) = require_csrf(cx, &form.csrf).await?;189 let (user, _) = require_csrf(cx, &form.csrf).await?;
190- let state = app_context::<AppState>(cx);190+ let state = context::<AppState>(cx);
191 let devices = state.store.push_subscriptions(&user.id).await?.len();191 let devices = state.store.push_subscriptions(&user.id).await?.len();
192 if devices > 0 {192 if devices > 0 {
193 web_push::queue(state, &user.id, Alert::Test);193 web_push::queue(state, &user.id, Alert::Test);
@@ -204,7 +204,7 @@ async fn push_events(cx: &Cx) -> Result<Response> {
204 *res.status_mut() = StatusCode::UNAUTHORIZED;204 *res.status_mut() = StatusCode::UNAUTHORIZED;
205 return Ok(res);205 return Ok(res);
206 };206 };
207- let state = app_context::<AppState>(cx);207+ let state = context::<AppState>(cx);
208 let rx = state.push_live.subscribe();208 let rx = state.push_live.subscribe();
209 let changes = stream::unfold((rx, user.id), |(mut rx, user_id)| async move {209 let changes = stream::unfold((rx, user.id), |(mut rx, user_id)| async move {
210 loop {210 loop {
@@ -263,31 +263,31 @@ fn static_headers(content_type: &'static str, cache: &'static str) -> HeaderMap
263 }263 }
264 264
265 #[route(GET "/sw.js")]265 #[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)> {
267 let headers = static_headers("text/javascript; charset=utf-8", "no-cache");267 let headers = static_headers("text/javascript; charset=utf-8", "no-cache");
268 Ok((StatusCode::OK, headers, SW_JS))268 Ok((StatusCode::OK, headers, SW_JS))
269 }269 }
270 270
271 #[route(GET "/manifest.webmanifest")]271 #[route(GET "/manifest.webmanifest")]
272-async fn manifest() -> Result<(StatusCode, HeaderMap, &'static str)> {272+async fn manifest(cx: &Cx) -> Result<(StatusCode, HeaderMap, &'static str)> {
273 let headers = static_headers("application/manifest+json", "public, max-age=3600");273 let headers = static_headers("application/manifest+json", "public, max-age=3600");
274 Ok((StatusCode::OK, headers, MANIFEST))274 Ok((StatusCode::OK, headers, MANIFEST))
275 }275 }
276 276
277 #[route(GET "/assets/icons/icon-192.png")]277 #[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])> {
279 let headers = static_headers("image/png", "public, max-age=604800");279 let headers = static_headers("image/png", "public, max-age=604800");
280 Ok((StatusCode::OK, headers, ICON_192))280 Ok((StatusCode::OK, headers, ICON_192))
281 }281 }
282 282
283 #[route(GET "/assets/icons/icon-512.png")]283 #[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])> {
285 let headers = static_headers("image/png", "public, max-age=604800");285 let headers = static_headers("image/png", "public, max-age=604800");
286 Ok((StatusCode::OK, headers, ICON_512))286 Ok((StatusCode::OK, headers, ICON_512))
287 }287 }
288 288
289 #[route(GET "/assets/icons/apple-touch-icon.png")]289 #[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])> {
291 let headers = static_headers("image/png", "public, max-age=604800");291 let headers = static_headers("image/png", "public, max-age=604800");
292 Ok((StatusCode::OK, headers, APPLE_TOUCH_ICON))292 Ok((StatusCode::OK, headers, APPLE_TOUCH_ICON))
293 }293 }
crates/forge-web/src/pages/reactions.rsmodified+4 -4
@@ -7,7 +7,7 @@
7 use forge_core::{Reaction, ReactionTarget};7 use forge_core::{Reaction, ReactionTarget};
8 use serde::Deserialize;8 use serde::Deserialize;
9 use topcoat::Result;9 use topcoat::Result;
10-use topcoat::context::{Cx, app_context};10+use topcoat::context::{Cx, context};
11 use topcoat::router::content::Form;11 use topcoat::router::content::Form;
12 use topcoat::router::error::{SeeOther, bad_request, forbidden, not_found, see_other};12 use topcoat::router::error::{SeeOther, bad_request, forbidden, not_found, see_other};
13 use topcoat::router::{path_param, route};13 use topcoat::router::{path_param, route};
@@ -47,13 +47,13 @@ async fn pull_reaction(cx: &Cx, Form(form): Form<ReactionForm>) -> Result<SeeOth
47 }47 }
48 48
49 async fn react(cx: &Cx, kind: ItemKind, form: ReactionForm) -> Result<SeeOther> {49 async fn react(cx: &Cx, kind: ItemKind, form: ReactionForm) -> Result<SeeOther> {
50- let number = parse_number(path_param::<Number>(cx))?;50+ let number = parse_number(number(cx))?;
51- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;51+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
52 let (user, _) = require_csrf(cx, &form.csrf).await?;52 let (user, _) = require_csrf(cx, &form.csrf).await?;
53 if ctx.repo.archived {53 if ctx.repo.archived {
54 return Err(forbidden().into());54 return Err(forbidden().into());
55 }55 }
56- let state = app_context::<AppState>(cx);56+ let state = context::<AppState>(cx);
57 let item = item_for(state, &ctx, kind, number).await?;57 let item = item_for(state, &ctx, kind, number).await?;
58 if !may_converse(&ctx, &item) {58 if !may_converse(&ctx, &item) {
59 return Err(forbidden().into());59 return Err(forbidden().into());
crates/forge-web/src/pages/ref_live.rsmodified+4 -4
@@ -9,7 +9,7 @@
9 //! the commits they show, and a soft re-read is cheap.9 //! the commits they show, and a soft re-read is cheap.
10 10
11 use topcoat::Result;11 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};12+use topcoat::context::{Cx, context};
13 use topcoat::router::response::Response;13 use topcoat::router::response::Response;
14 use topcoat::router::{path_param, route};14 use topcoat::router::{path_param, route};
15 15
@@ -38,10 +38,10 @@ pub fn topics(repo: &forge_core::Repo) -> [Topic; 3] {
38 /// who cannot read the repo gets the same 404 as the page.38 /// who cannot read the repo gets the same 404 as the page.
39 #[route(GET "/{owner}/{repo}/refs/events")]39 #[route(GET "/{owner}/{repo}/refs/events")]
40 async fn ref_events(cx: &Cx) -> Result<Response> {40 async fn ref_events(cx: &Cx) -> Result<Response> {
41- let owner = path_param::<Owner>(cx);41+ let owner = owner(cx);
42- let name = path_param::<Repo>(cx);42+ let name = repo(cx);
43 let ctx = load_repo(cx, owner, name).await?;43 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;
45 stream_wakes(cx, hub, &topics(&ctx.repo))45 stream_wakes(cx, hub, &topics(&ctx.repo))
46 }46 }
47 47
crates/forge-web/src/pages/refs.rsmodified+5 -5
@@ -8,7 +8,7 @@ use crate::state::AppState;
8 use forge_core::Repo as RepoRow;8 use forge_core::Repo as RepoRow;
9 use forge_git::browse::{self, CommitInfo, RefInfo, RefKind};9 use forge_git::browse::{self, CommitInfo, RefInfo, RefKind};
10 use topcoat::Result;10 use topcoat::Result;
11-use topcoat::context::{Cx, app_context};11+use topcoat::context::{Cx, context};
12 use topcoat::router::{page, path_param};12 use topcoat::router::{page, path_param};
13 use topcoat::view::{View, component, view};13 use topcoat::view::{View, component, view};
14 14
@@ -105,7 +105,7 @@ pub(crate) async fn ref_rows(
105 }105 }
106 106
107 #[component]107 #[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> {
109 let empty = rows.is_empty();109 let empty = rows.is_empty();
110 Ok(view! {110 Ok(view! {
111 if empty {111 if empty {
@@ -142,8 +142,8 @@ struct RefsPage {
142 }142 }
143 143
144 async fn refs_data(cx: &Cx, kind: RefKind) -> Result<RefsPage> {144 async fn refs_data(cx: &Cx, kind: RefKind) -> Result<RefsPage> {
145- let owner = path_param::<Owner>(cx);145+ let owner = owner(cx);
146- let name = path_param::<Repo>(cx);146+ let name = repo(cx);
147 let ctx = load_repo(cx, owner, name).await?;147 let ctx = load_repo(cx, owner, name).await?;
148 let now = now_unix();148 let now = now_unix();
149 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));149 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> {
174 ctx.repo.name,174 ctx.repo.name,
175 g::t(lang, K::TagsTitle)175 g::t(lang, K::TagsTitle)
176 );176 );
177- let mut header = ctx.head(app_context::<AppState>(cx), "tags").await?;177+ let mut header = ctx.head(context::<AppState>(cx), "tags").await?;
178 header.live = ref_live::live_url(&ctx.repo.owner_name, &ctx.repo.name);178 header.live = ref_live::live_url(&ctx.repo.owner_name, &ctx.repo.name);
179 Ok(view! {179 Ok(view! {
180 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),180 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;
9 use forge_core::{AuditAction, Registration, User};9 use forge_core::{AuditAction, Registration, User};
10 use serde::Deserialize;10 use serde::Deserialize;
11 use topcoat::Result;11 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};12+use topcoat::context::{Cx, context};
13 use topcoat::router::content::Form;13 use topcoat::router::content::Form;
14 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};14 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
15 use topcoat::router::{page, path_param_segment, query_params, route};15 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 {
120 120
121 #[component]121 #[component]
122 async fn register_form(122 async fn register_form(
123+ cx: &Cx,
123 lang: Lang,124 lang: Lang,
124 gate: Gate,125 gate: Gate,
125 invite: &str,126 invite: &str,
@@ -179,7 +180,7 @@ async fn register_form(
179 180
180 #[page("/register")]181 #[page("/register")]
181 async fn register_page(cx: &Cx) -> Result<impl View> {182 async fn register_page(cx: &Cx) -> Result<impl View> {
182- let state = app_context::<AppState>(cx);183+ let state = context::<AppState>(cx);
183 if state.live().registration == Registration::Closed {184 if state.live().registration == Registration::Closed {
184 return Err(not_found().into());185 return Err(not_found().into());
185 }186 }
@@ -260,7 +261,7 @@ async fn create_account(
260 261
261 #[page(POST "/register")]262 #[page(POST "/register")]
262 async fn register_submit(cx: &Cx, Form(form): Form<RegisterForm>) -> Result<impl View> {263 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);
264 if state.live().registration == Registration::Closed {265 if state.live().registration == Registration::Closed {
265 return Err(not_found().into());266 return Err(not_found().into());
266 }267 }
@@ -343,6 +344,7 @@ async fn register_submit(cx: &Cx, Form(form): Form<RegisterForm>) -> Result<impl
343 344
344 #[component]345 #[component]
345 async fn verify_body(346 async fn verify_body(
347+ cx: &Cx,
346 lang: Lang,348 lang: Lang,
347 token: &str,349 token: &str,
348 precsrf: &str,350 precsrf: &str,
@@ -382,7 +384,7 @@ async fn verify_submit(cx: &Cx, Form(form): Form<VerifyForm>) -> Result<impl Vie
382 if !check_pre_csrf(cx, &form.precsrf) {384 if !check_pre_csrf(cx, &form.precsrf) {
383 return Err(forbidden().into());385 return Err(forbidden().into());
384 }386 }
385- let state = app_context::<AppState>(cx);387+ let state = context::<AppState>(cx);
386 let lang = i18n::lang(cx, None);388 let lang = i18n::lang(cx, None);
387 let token = path_param_segment(cx, "token").to_owned();389 let token = path_param_segment(cx, "token").to_owned();
388 let mode = match state.store.redeem_verify_token(&token).await? {390 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
415 #[route(POST "/settings/security/email/resend")]417 #[route(POST "/settings/security/email/resend")]
416 async fn verify_resend(cx: &Cx, Form(form): Form<ResendForm>) -> Result<SeeOther> {418 async fn verify_resend(cx: &Cx, Form(form): Form<ResendForm>) -> Result<SeeOther> {
417 let viewer = require_csrf(cx, &form.csrf).await?;419 let viewer = require_csrf(cx, &form.csrf).await?;
418- let state = app_context::<AppState>(cx);420+ let state = context::<AppState>(cx);
419 if !mail_can_send(state).await {421 if !mail_can_send(state).await {
420 return Ok(see_other("/settings/security?saved=verify_wait"));422 return Ok(see_other("/settings/security?saved=verify_wait"));
421 }423 }
crates/forge-web/src/pages/releases.rsmodified+45 -40
@@ -20,7 +20,7 @@ use http_body::Frame;
20 use http_body_util::StreamBody;20 use http_body_util::StreamBody;
21 use serde::Deserialize;21 use serde::Deserialize;
22 use topcoat::Result;22 use topcoat::Result;
23-use topcoat::context::{Cx, app_context};23+use topcoat::context::{Cx, context};
24 use topcoat::router::content::Form;24 use topcoat::router::content::Form;
25 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};25 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
26 use topcoat::router::request::headers;26 use topcoat::router::request::headers;
@@ -344,6 +344,7 @@ fn check_title_body(lang: Lang, title: &str, body: &str) -> std::result::Result<
344 /// Release-form list of branches and the form itself, shared by the new and edit pages.344 /// Release-form list of branches and the form itself, shared by the new and edit pages.
345 #[component]345 #[component]
346 async fn release_form(346 async fn release_form(
347+ cx: &Cx,
347 action: String,348 action: String,
348 csrf: String,349 csrf: String,
349 lang: Lang,350 lang: Lang,
@@ -413,6 +414,7 @@ async fn release_form(
413 /// The assets table on the edit page. `delete_actions` holds one form action per asset.414 /// The assets table on the edit page. `delete_actions` holds one form action per asset.
414 #[component]415 #[component]
415 async fn asset_rows(416 async fn asset_rows(
417+ cx: &Cx,
416 assets: Vec<AssetLink>,418 assets: Vec<AssetLink>,
417 delete_actions: Vec<String>,419 delete_actions: Vec<String>,
418 upload_action: String,420 upload_action: String,
@@ -464,6 +466,7 @@ async fn asset_rows(
464 /// The list page body.466 /// The list page body.
465 #[component]467 #[component]
466 async fn list_body(468 async fn list_body(
469+ cx: &Cx,
467 head: crate::pages::repo_ctx::RepoHead,470 head: crate::pages::repo_ctx::RepoHead,
468 lang: Lang,471 lang: Lang,
469 notice: Option<(&'static str, bool)>,472 notice: Option<(&'static str, bool)>,
@@ -537,12 +540,12 @@ async fn list_body(
537 /// Lists the repo's releases, newest first. Drafts appear only for writers.540 /// Lists the repo's releases, newest first. Drafts appear only for writers.
538 #[page("/{owner}/{repo}/releases")]541 #[page("/{owner}/{repo}/releases")]
539 async fn releases_list_page(cx: &Cx) -> Result<impl View> {542 async fn releases_list_page(cx: &Cx) -> Result<impl View> {
540- let owner = path_param::<Owner>(cx);543+ let owner = owner(cx);
541- let name = path_param::<Repo>(cx);544+ let name = repo(cx);
542 let query = query_params::<ReleasesQuery>(cx)?;545 let query = query_params::<ReleasesQuery>(cx)?;
543 let ctx = load_repo(cx, owner, name).await?;546 let ctx = load_repo(cx, owner, name).await?;
544 let lang = i18n::lang(cx, viewer_user(&ctx));547 let lang = i18n::lang(cx, viewer_user(&ctx));
545- let state = app_context::<AppState>(cx);548+ let state = context::<AppState>(cx);
546 let writer = can_write(&ctx);549 let writer = can_write(&ctx);
547 let latest_id = state550 let latest_id = state
548 .store551 .store
@@ -605,6 +608,7 @@ async fn new_form_data(state: &AppState, ctx: &RepoCtx) -> Result<(RepoHead, Vec
605 /// The new-release form body, below the repo header.608 /// The new-release form body, below the repo header.
606 #[component]609 #[component]
607 async fn new_form_body(610 async fn new_form_body(
611+ cx: &Cx,
608 head: RepoHead,612 head: RepoHead,
609 lang: Lang,613 lang: Lang,
610 action: String,614 action: String,
@@ -626,12 +630,12 @@ async fn new_form_body(
626 /// The new-release form.630 /// The new-release form.
627 #[page("/{owner}/{repo}/releases/new")]631 #[page("/{owner}/{repo}/releases/new")]
628 async fn release_new_page(cx: &Cx) -> Result<impl View> {632 async fn release_new_page(cx: &Cx) -> Result<impl View> {
629- let owner = path_param::<Owner>(cx);633+ let owner = owner(cx);
630- let name = path_param::<Repo>(cx);634+ let name = repo(cx);
631 let ctx = load_repo(cx, owner, name).await?;635 let ctx = load_repo(cx, owner, name).await?;
632 require_write(&ctx)?;636 require_write(&ctx)?;
633 let lang = i18n::lang(cx, viewer_user(&ctx));637 let lang = i18n::lang(cx, viewer_user(&ctx));
634- let state = app_context::<AppState>(cx);638+ let state = context::<AppState>(cx);
635 let csrf = match crate::auth::current_user(cx).await? {639 let csrf = match crate::auth::current_user(cx).await? {
636 Some((_, session)) => session.csrf_token.clone(),640 Some((_, session)) => session.csrf_token.clone(),
637 None => String::new(),641 None => String::new(),
@@ -653,13 +657,13 @@ async fn release_new_page(cx: &Cx) -> Result<impl View> {
653 /// Creates a release. The tag is created at the target branch's head when it does not exist.657 /// Creates a release. The tag is created at the target branch's head when it does not exist.
654 #[page(POST "/{owner}/{repo}/releases/new")]658 #[page(POST "/{owner}/{repo}/releases/new")]
655 async fn release_create(cx: &Cx, Form(form): Form<CreateForm>) -> Result<impl View> {659 async fn release_create(cx: &Cx, Form(form): Form<CreateForm>) -> Result<impl View> {
656- let owner = path_param::<Owner>(cx);660+ let owner = owner(cx);
657- let name = path_param::<Repo>(cx);661+ let name = repo(cx);
658 let ctx = load_repo(cx, owner, name).await?;662 let ctx = load_repo(cx, owner, name).await?;
659 let (user, session) = require_csrf(cx, &form.csrf).await?;663 let (user, session) = require_csrf(cx, &form.csrf).await?;
660 require_write(&ctx)?;664 require_write(&ctx)?;
661 let lang = i18n::lang(cx, viewer_user(&ctx));665 let lang = i18n::lang(cx, viewer_user(&ctx));
662- let state = app_context::<AppState>(cx);666+ let state = context::<AppState>(cx);
663 let draft = FormDraft {667 let draft = FormDraft {
664 tag: form.tag.trim().to_owned(),668 tag: form.tag.trim().to_owned(),
665 target: form.target.trim().to_owned(),669 target: form.target.trim().to_owned(),
@@ -733,12 +737,12 @@ async fn create_checked(
733 /// The public view of one release: notes, assets and the source archive links.737 /// The public view of one release: notes, assets and the source archive links.
734 #[page("/{owner}/{repo}/releases/tag/{tag}")]738 #[page("/{owner}/{repo}/releases/tag/{tag}")]
735 async fn release_tag_page(cx: &Cx) -> Result<impl View> {739 async fn release_tag_page(cx: &Cx) -> Result<impl View> {
736- let owner = path_param::<Owner>(cx);740+ let owner = owner(cx);
737- let name = path_param::<Repo>(cx);741+ let name = repo(cx);
738- let tag_param = path_param::<Tag>(cx).to_owned();742+ let tag_param = tag(cx).to_owned();
739 let ctx = load_repo(cx, owner, name).await?;743 let ctx = load_repo(cx, owner, name).await?;
740 let lang = i18n::lang(cx, viewer_user(&ctx));744 let lang = i18n::lang(cx, viewer_user(&ctx));
741- let state = app_context::<AppState>(cx);745+ let state = context::<AppState>(cx);
742 let writer = can_write(&ctx);746 let writer = can_write(&ctx);
743 let Some(release) = state.store.release_by_tag(&ctx.repo.id, &tag_param).await? else {747 let Some(release) = state.store.release_by_tag(&ctx.repo.id, &tag_param).await? else {
744 return Err(not_found().into());748 return Err(not_found().into());
@@ -864,6 +868,7 @@ async fn release_tag_page(cx: &Cx) -> Result<impl View> {
864 /// which shows the typed values again.868 /// which shows the typed values again.
865 #[component]869 #[component]
866 async fn edit_body(870 async fn edit_body(
871+ cx: &Cx,
867 head: RepoHead,872 head: RepoHead,
868 lang: Lang,873 lang: Lang,
869 notice: Option<(&'static str, bool)>,874 notice: Option<(&'static str, bool)>,
@@ -976,13 +981,13 @@ async fn edit_parts(
976 /// The edit page: the release fields, its assets, and the upload form.981 /// The edit page: the release fields, its assets, and the upload form.
977 #[page("/{owner}/{repo}/releases/{release_id}/edit")]982 #[page("/{owner}/{repo}/releases/{release_id}/edit")]
978 async fn release_edit_page(cx: &Cx) -> Result<impl View> {983 async fn release_edit_page(cx: &Cx) -> Result<impl View> {
979- let owner = path_param::<Owner>(cx);984+ let owner = owner(cx);
980- let name = path_param::<Repo>(cx);985+ let name = repo(cx);
981- let id = path_param::<ReleaseId>(cx).to_owned();986+ let id = release_id(cx).to_owned();
982 let ctx = load_repo(cx, owner, name).await?;987 let ctx = load_repo(cx, owner, name).await?;
983 require_write(&ctx)?;988 require_write(&ctx)?;
984 let lang = i18n::lang(cx, viewer_user(&ctx));989 let lang = i18n::lang(cx, viewer_user(&ctx));
985- let state = app_context::<AppState>(cx);990+ let state = context::<AppState>(cx);
986 let Some(release) = state.store.release(&id).await? else {991 let Some(release) = state.store.release(&id).await? else {
987 return Err(not_found().into());992 return Err(not_found().into());
988 };993 };
@@ -1016,14 +1021,14 @@ async fn release_edit_page(cx: &Cx) -> Result<impl View> {
1016 /// unchanged tag keeps the tag. A refused save shows its message and keeps the typed values.1021 /// unchanged tag keeps the tag. A refused save shows its message and keeps the typed values.
1017 #[page(POST "/{owner}/{repo}/releases/{release_id}/edit")]1022 #[page(POST "/{owner}/{repo}/releases/{release_id}/edit")]
1018 async fn release_update(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View> {1023 async fn release_update(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View> {
1019- let owner = path_param::<Owner>(cx);1024+ let owner = owner(cx);
1020- let name = path_param::<Repo>(cx);1025+ let name = repo(cx);
1021- let id = path_param::<ReleaseId>(cx).to_owned();1026+ let id = release_id(cx).to_owned();
1022 let ctx = load_repo(cx, owner, name).await?;1027 let ctx = load_repo(cx, owner, name).await?;
1023 let (user, session) = require_csrf(cx, &form.csrf).await?;1028 let (user, session) = require_csrf(cx, &form.csrf).await?;
1024 require_write(&ctx)?;1029 require_write(&ctx)?;
1025 let lang = i18n::lang(cx, viewer_user(&ctx));1030 let lang = i18n::lang(cx, viewer_user(&ctx));
1026- let state = app_context::<AppState>(cx);1031+ let state = context::<AppState>(cx);
1027 let Some(before) = state.store.release(&id).await? else {1032 let Some(before) = state.store.release(&id).await? else {
1028 return Err(not_found().into());1033 return Err(not_found().into());
1029 };1034 };
@@ -1072,9 +1077,9 @@ async fn release_update(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View
1072 /// Deletes a release and its assets, then their blobs. The git tag is kept. Requires the confirm box.1077 /// Deletes a release and its assets, then their blobs. The git tag is kept. Requires the confirm box.
1073 #[route(POST "/{owner}/{repo}/releases/{release_id}/delete")]1078 #[route(POST "/{owner}/{repo}/releases/{release_id}/delete")]
1074 async fn release_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<Response> {1079 async fn release_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<Response> {
1075- let owner = path_param::<Owner>(cx);1080+ let owner = owner(cx);
1076- let name = path_param::<Repo>(cx);1081+ let name = repo(cx);
1077- let id = path_param::<ReleaseId>(cx).to_owned();1082+ let id = release_id(cx).to_owned();
1078 let ctx = load_repo(cx, owner, name).await?;1083 let ctx = load_repo(cx, owner, name).await?;
1079 let (user, _) = require_csrf(cx, &form.csrf).await?;1084 let (user, _) = require_csrf(cx, &form.csrf).await?;
1080 require_write(&ctx)?;1085 require_write(&ctx)?;
@@ -1083,7 +1088,7 @@ async fn release_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<Response>
1083 let href = release_edit_href(&title, &id);1088 let href = release_edit_href(&title, &id);
1084 return Err(notice_redirect(&href, "confirm").into());1089 return Err(notice_redirect(&href, "confirm").into());
1085 }1090 }
1086- let state = app_context::<AppState>(cx);1091+ let state = context::<AppState>(cx);
1087 let Some(release) = state.store.release(&id).await? else {1092 let Some(release) = state.store.release(&id).await? else {
1088 return Err(not_found().into());1093 return Err(not_found().into());
1089 };1094 };
@@ -1097,14 +1102,14 @@ async fn release_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<Response>
1097 /// Deletes one asset row and its blob.1102 /// Deletes one asset row and its blob.
1098 #[route(POST "/{owner}/{repo}/releases/{release_id}/assets/{asset_id}/delete")]1103 #[route(POST "/{owner}/{repo}/releases/{release_id}/assets/{asset_id}/delete")]
1099 async fn asset_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<Response> {1104 async fn asset_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<Response> {
1100- let owner = path_param::<Owner>(cx);1105+ let owner = owner(cx);
1101- let name = path_param::<Repo>(cx);1106+ let name = repo(cx);
1102- let release_id = path_param::<ReleaseId>(cx).to_owned();1107+ let release_id = release_id(cx).to_owned();
1103- let asset = path_param::<AssetId>(cx).to_owned();1108+ let asset = asset_id(cx).to_owned();
1104 let ctx = load_repo(cx, owner, name).await?;1109 let ctx = load_repo(cx, owner, name).await?;
1105 require_csrf(cx, &form.csrf).await?;1110 require_csrf(cx, &form.csrf).await?;
1106 require_write(&ctx)?;1111 require_write(&ctx)?;
1107- let state = app_context::<AppState>(cx);1112+ let state = context::<AppState>(cx);
1108 let Some(release) = state.store.release(&release_id).await? else {1113 let Some(release) = state.store.release(&release_id).await? else {
1109 return Err(not_found().into());1114 return Err(not_found().into());
1110 };1115 };
@@ -1123,11 +1128,11 @@ async fn asset_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<Response> {
1123 /// `assets/<id>` only when it is complete and the row is stored.1128 /// `assets/<id>` only when it is complete and the row is stored.
1124 #[route(POST "/{owner}/{repo}/releases/{release_id}/assets")]1129 #[route(POST "/{owner}/{repo}/releases/{release_id}/assets")]
1125 async fn asset_upload(cx: &Cx, body: Body) -> Result<Response> {1130 async fn asset_upload(cx: &Cx, body: Body) -> Result<Response> {
1126- let owner = path_param::<Owner>(cx);1131+ let owner = owner(cx);
1127- let name = path_param::<Repo>(cx);1132+ let name = repo(cx);
1128- let id = path_param::<ReleaseId>(cx).to_owned();1133+ let id = release_id(cx).to_owned();
1129 let ctx = load_repo(cx, owner, name).await?;1134 let ctx = load_repo(cx, owner, name).await?;
1130- let state = app_context::<AppState>(cx);1135+ let state = context::<AppState>(cx);
1131 let href = release_edit_href(&title_of(&ctx), &id);1136 let href = release_edit_href(&title_of(&ctx), &id);
1132 let max_bytes = state1137 let max_bytes = state
1133 .config1138 .config
@@ -1255,11 +1260,11 @@ async fn store_upload(
1255 /// people who can write; anyone else gets a 404.1260 /// people who can write; anyone else gets a 404.
1256 #[route(GET "/{owner}/{repo}/releases/download/{tag}/{name}")]1261 #[route(GET "/{owner}/{repo}/releases/download/{tag}/{name}")]
1257 async fn asset_download(cx: &Cx) -> Result<Response> {1262 async fn asset_download(cx: &Cx) -> Result<Response> {
1258- let owner = path_param::<Owner>(cx);1263+ let owner = owner(cx);
1259- let repo_name = path_param::<Repo>(cx);1264+ let repo_name = repo(cx);
1260- let tag_param = path_param::<Tag>(cx).to_owned();1265+ let tag_param = tag(cx).to_owned();
1261- let file_name = path_param::<Name>(cx).to_owned();1266+ let file_name = name(cx).to_owned();
1262- let state = app_context::<AppState>(cx);1267+ let state = context::<AppState>(cx);
1263 // A caller that sends credentials (a Gitea or Forgejo server migrating this repo) is judged by1268 // A caller that sends credentials (a Gitea or Forgejo server migrating this repo) is judged by
1264 // its token, with the same rules as the API. Everyone else goes through the session.1269 // its token, with the same rules as the API. Everyone else goes through the session.
1265 if headers(cx).contains_key(http::header::AUTHORIZATION) {1270 if headers(cx).contains_key(http::header::AUTHORIZATION) {
crates/forge-web/src/pages/releases_live.rsmodified+6 -6
@@ -11,7 +11,7 @@
11 11
12 use forge_core::store::Store;12 use forge_core::store::Store;
13 use topcoat::Result;13 use topcoat::Result;
14-use topcoat::context::{Cx, app_context};14+use topcoat::context::{Cx, context};
15 use topcoat::router::error::not_found;15 use topcoat::router::error::not_found;
16 use topcoat::router::response::Response;16 use topcoat::router::response::Response;
17 use topcoat::router::{path_param, route};17 use topcoat::router::{path_param, route};
@@ -85,8 +85,8 @@ pub(crate) async fn release_fingerprint(
85 /// The release list's change stream.85 /// The release list's change stream.
86 #[route(GET "/{owner}/{repo}/releases/events")]86 #[route(GET "/{owner}/{repo}/releases/events")]
87 async fn releases_events(cx: &Cx) -> Result<Response> {87 async fn releases_events(cx: &Cx) -> Result<Response> {
88- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;88+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
89- let state = app_context::<AppState>(cx);89+ let state = context::<AppState>(cx);
90 let writer = can_write(&ctx);90 let writer = can_write(&ctx);
91 let topic = Topic::RepoReleases(ctx.repo.id.clone());91 let topic = Topic::RepoReleases(ctx.repo.id.clone());
92 let store = state.store.clone();92 let store = state.store.clone();
@@ -102,9 +102,9 @@ async fn releases_events(cx: &Cx) -> Result<Response> {
102 /// One release page's change stream. A release the viewer cannot open gets the page's 404.102 /// One release page's change stream. A release the viewer cannot open gets the page's 404.
103 #[route(GET "/{owner}/{repo}/releases/tag/{tag}/events")]103 #[route(GET "/{owner}/{repo}/releases/tag/{tag}/events")]
104 async fn release_events(cx: &Cx) -> Result<Response> {104 async fn release_events(cx: &Cx) -> Result<Response> {
105- let tag = path_param::<Tag>(cx).to_owned();105+ let tag = tag(cx).to_owned();
106- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;106+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
107- let state = app_context::<AppState>(cx);107+ let state = context::<AppState>(cx);
108 let writer = can_write(&ctx);108 let writer = can_write(&ctx);
109 let visible = match state.store.release_by_tag(&ctx.repo.id, &tag).await? {109 let visible = match state.store.release_by_tag(&ctx.repo.id, &tag).await? {
110 Some(release) => writer || !release.draft,110 Some(release) => writer || !release.draft,
crates/forge-web/src/pages/repo.rsmodified+14 -6
@@ -12,7 +12,7 @@ use forge_core::time::stamp_before;
12 use forge_git::browse;12 use forge_git::browse;
13 use forge_git::repo::repo_path;13 use forge_git::repo::repo_path;
14 use topcoat::Result;14 use topcoat::Result;
15-use topcoat::context::{Cx, app_context};15+use topcoat::context::{Cx, context};
16 use topcoat::router::error::not_found;16 use topcoat::router::error::not_found;
17 use topcoat::router::{page, path_param, route};17 use topcoat::router::{page, path_param, route};
18 use topcoat::view::{Child, View, ViewExt, component, view};18 use topcoat::view::{Child, View, ViewExt, component, view};
@@ -84,6 +84,7 @@ pub(crate) fn tab_title(lang: Lang, active: &str, repo: &str) -> String {
84 /// `RepoCtx::head`; every repo page passes one.84 /// `RepoCtx::head`; every repo page passes one.
85 #[component]85 #[component]
86 pub async fn repo_head(86 pub async fn repo_head(
87+ cx: &Cx,
87 head: RepoHead,88 head: RepoHead,
88 #[default] title: Option<String>,89 #[default] title: Option<String>,
89 #[default] sub: Vec<SubPart>,90 #[default] sub: Vec<SubPart>,
@@ -228,6 +229,7 @@ pub async fn repo_head(
228 /// the branch has a commit, links to its archive (`downloads`: the zip and tar.gz hrefs).229 /// the branch has a commit, links to its archive (`downloads`: the zip and tar.gz hrefs).
229 #[component]230 #[component]
230 async fn clone_popover(231 async fn clone_popover(
232+ cx: &Cx,
231 https: String,233 https: String,
232 ssh: String,234 ssh: String,
233 downloads: Option<(String, String)>,235 downloads: Option<(String, String)>,
@@ -258,6 +260,7 @@ async fn clone_popover(
258 /// or push instructions when there are none.260 /// or push instructions when there are none.
259 #[component]261 #[component]
260 async fn branches_card(262 async fn branches_card(
263+ cx: &Cx,
261 branches: Vec<String>,264 branches: Vec<String>,
262 push_https: String,265 push_https: String,
263 push_ssh: String,266 push_ssh: String,
@@ -408,7 +411,12 @@ async fn recent_push_banners(
408 411
409 /// The "had recent pushes" banners above the code tab.412 /// The "had recent pushes" banners above the code tab.
410 #[component]413 #[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> {
412 Ok(view! {420 Ok(view! {
413 <section class="recent-pushes" aria-label=(g::t(lang, K::RecentPushes))>421 <section class="recent-pushes" aria-label=(g::t(lang, K::RecentPushes))>
414 for banner in banners.into_iter() {422 for banner in banners.into_iter() {
@@ -426,10 +434,10 @@ async fn recent_pushes(banners: Vec<PushBanner>, now: i64, lang: Lang) -> Result
426 434
427 #[page("/{owner}/{repo}")]435 #[page("/{owner}/{repo}")]
428 async fn repo_page(cx: &Cx) -> Result<impl View> {436 async fn repo_page(cx: &Cx) -> Result<impl View> {
429- let owner = path_param::<Owner>(cx);437+ let owner = owner(cx);
430- let name = path_param::<Repo>(cx);438+ let name = repo(cx);
431 let ctx = load_repo(cx, owner, name).await?;439 let ctx = load_repo(cx, owner, name).await?;
432- let state = app_context::<AppState>(cx);440+ let state = context::<AppState>(cx);
433 let lang = ctx.lang;441 let lang = ctx.lang;
434 let repo = &ctx.repo;442 let repo = &ctx.repo;
435 let branch = repo.default_branch.clone();443 let branch = repo.default_branch.clone();
@@ -530,7 +538,7 @@ async fn repo_page(cx: &Cx) -> Result<impl View> {
530 538
531 /// Other methods on a repo path get a plain 404, not a 405 that would reveal the route shape.539 /// Other methods on a repo path get a plain 404, not a 405 that would reveal the route shape.
532 #[route(* "/{owner}/{repo}")]540 #[route(* "/{owner}/{repo}")]
533-async fn repo_other_methods() -> Result<&'static str> {541+async fn repo_other_methods(cx: &Cx) -> Result<&'static str> {
534 Err(not_found().into())542 Err(not_found().into())
535 }543 }
536 544
crates/forge-web/src/pages/repo_collaborators.rsmodified+14 -13
@@ -14,7 +14,7 @@ use forge_core::store::orgs::OrgMemberRole;
14 use forge_core::{AuditAction, Role, User};14 use forge_core::{AuditAction, Role, User};
15 use serde::Deserialize;15 use serde::Deserialize;
16 use topcoat::Result;16 use topcoat::Result;
17-use topcoat::context::{Cx, app_context};17+use topcoat::context::{Cx, context};
18 use topcoat::cookie::{Cookie, Cookies, SameSite, cookies};18 use topcoat::cookie::{Cookie, Cookies, SameSite, cookies};
19 use topcoat::router::content::Form;19 use topcoat::router::content::Form;
20 use topcoat::router::error::{SeeOther, forbidden, see_other};20 use topcoat::router::error::{SeeOther, forbidden, see_other};
@@ -159,6 +159,7 @@ impl FrameData {
159 /// The page body: repo header with Settings active, the notice, then the collaborators topic.159 /// The page body: repo header with Settings active, the notice, then the collaborators topic.
160 #[component]160 #[component]
161 async fn collaborators_body(161 async fn collaborators_body(
162+ cx: &Cx,
162 lang: Lang,163 lang: Lang,
163 frame: FrameData,164 frame: FrameData,
164 rows: Vec<PersonRow>,165 rows: Vec<PersonRow>,
@@ -230,15 +231,15 @@ async fn collaborators_body(
230 /// and signed-in viewers who may not manage the repo get 403.231 /// and signed-in viewers who may not manage the repo get 403.
231 #[page("/{owner}/{repo}/settings/collaborators")]232 #[page("/{owner}/{repo}/settings/collaborators")]
232 async fn collaborators_page(cx: &Cx) -> Result<impl View> {233 async fn collaborators_page(cx: &Cx) -> Result<impl View> {
233- let owner = path_param::<Owner>(cx);234+ let owner = owner(cx);
234- let name = path_param::<Repo>(cx);235+ let name = repo(cx);
235 let ctx = load_repo(cx, owner, name).await?;236 let ctx = load_repo(cx, owner, name).await?;
236 let (user, session) = require_user(cx).await?;237 let (user, session) = require_user(cx).await?;
237 if !ctx.can_admin() {238 if !ctx.can_admin() {
238 return Err(forbidden().into());239 return Err(forbidden().into());
239 }240 }
240 let lang = i18n::lang(cx, Some(&user));241 let lang = i18n::lang(cx, Some(&user));
241- let state = app_context::<AppState>(cx);242+ let state = context::<AppState>(cx);
242 let collaborators = state.store.list_collaborators(&ctx.repo.id).await?;243 let collaborators = state.store.list_collaborators(&ctx.repo.id).await?;
243 let viewer_id = user.id.clone();244 let viewer_id = user.id.clone();
244 let rows = collaborators245 let rows = collaborators
@@ -275,15 +276,15 @@ async fn collaborators_page(cx: &Cx) -> Result<impl View> {
275 /// Adds a collaborator or updates an existing one's role. Admin grants need the owner or an instance admin.276 /// Adds a collaborator or updates an existing one's role. Admin grants need the owner or an instance admin.
276 #[route(POST "/{owner}/{repo}/settings/collaborators/add")]277 #[route(POST "/{owner}/{repo}/settings/collaborators/add")]
277 async fn collaborators_add(cx: &Cx, Form(form): Form<AddForm>) -> Result<SeeOther> {278 async fn collaborators_add(cx: &Cx, Form(form): Form<AddForm>) -> Result<SeeOther> {
278- let owner = path_param::<Owner>(cx);279+ let owner = owner(cx);
279- let name = path_param::<Repo>(cx);280+ let name = repo(cx);
280 let ctx = load_repo(cx, owner, name).await?;281 let ctx = load_repo(cx, owner, name).await?;
281 let (actor, _) = require_csrf(cx, &form.csrf).await?;282 let (actor, _) = require_csrf(cx, &form.csrf).await?;
282 if !ctx.can_admin() {283 if !ctx.can_admin() {
283 return Err(forbidden().into());284 return Err(forbidden().into());
284 }285 }
285 let title = title_of(&ctx);286 let title = title_of(&ctx);
286- let state = app_context::<AppState>(cx);287+ let state = context::<AppState>(cx);
287 288
288 let Ok(role) = form.role.trim().parse::<Role>() else {289 let Ok(role) = form.role.trim().parse::<Role>() else {
289 set_notice(cx, "invalid_role");290 set_notice(cx, "invalid_role");
@@ -361,15 +362,15 @@ async fn collaborators_add(cx: &Cx, Form(form): Form<AddForm>) -> Result<SeeOthe
361 /// Changes an existing collaborator's role. Only existing collaborators can be changed here.362 /// Changes an existing collaborator's role. Only existing collaborators can be changed here.
362 #[route(POST "/{owner}/{repo}/settings/collaborators/role")]363 #[route(POST "/{owner}/{repo}/settings/collaborators/role")]
363 async fn collaborators_role(cx: &Cx, Form(form): Form<RoleForm>) -> Result<SeeOther> {364 async fn collaborators_role(cx: &Cx, Form(form): Form<RoleForm>) -> Result<SeeOther> {
364- let owner = path_param::<Owner>(cx);365+ let owner = owner(cx);
365- let name = path_param::<Repo>(cx);366+ let name = repo(cx);
366 let ctx = load_repo(cx, owner, name).await?;367 let ctx = load_repo(cx, owner, name).await?;
367 let (actor, _) = require_csrf(cx, &form.csrf).await?;368 let (actor, _) = require_csrf(cx, &form.csrf).await?;
368 if !ctx.can_admin() {369 if !ctx.can_admin() {
369 return Err(forbidden().into());370 return Err(forbidden().into());
370 }371 }
371 let title = title_of(&ctx);372 let title = title_of(&ctx);
372- let state = app_context::<AppState>(cx);373+ let state = context::<AppState>(cx);
373 374
374 let Ok(role) = form.role.trim().parse::<Role>() else {375 let Ok(role) = form.role.trim().parse::<Role>() else {
375 set_notice(cx, "invalid_role");376 set_notice(cx, "invalid_role");
@@ -422,15 +423,15 @@ async fn collaborators_role(cx: &Cx, Form(form): Form<RoleForm>) -> Result<SeeOt
422 /// yourself is allowed and redirects to the repo home page.423 /// yourself is allowed and redirects to the repo home page.
423 #[route(POST "/{owner}/{repo}/settings/collaborators/remove")]424 #[route(POST "/{owner}/{repo}/settings/collaborators/remove")]
424 async fn collaborators_remove(cx: &Cx, Form(form): Form<RemoveForm>) -> Result<SeeOther> {425 async fn collaborators_remove(cx: &Cx, Form(form): Form<RemoveForm>) -> Result<SeeOther> {
425- let owner = path_param::<Owner>(cx);426+ let owner = owner(cx);
426- let name = path_param::<Repo>(cx);427+ let name = repo(cx);
427 let ctx = load_repo(cx, owner, name).await?;428 let ctx = load_repo(cx, owner, name).await?;
428 let (actor, _) = require_csrf(cx, &form.csrf).await?;429 let (actor, _) = require_csrf(cx, &form.csrf).await?;
429 if !ctx.can_admin() {430 if !ctx.can_admin() {
430 return Err(forbidden().into());431 return Err(forbidden().into());
431 }432 }
432 let title = title_of(&ctx);433 let title = title_of(&ctx);
433- let state = app_context::<AppState>(cx);434+ let state = context::<AppState>(cx);
434 let target_id = form.user_id.trim();435 let target_id = form.user_id.trim();
435 let self_removal = target_id == actor.id;436 let self_removal = target_id == actor.id;
436 437
crates/forge-web/src/pages/repo_ctx.rsmodified+6 -3
@@ -8,9 +8,12 @@ use std::path::PathBuf;
8 use forge_core::authz::{Action, authorize};8 use forge_core::authz::{Action, authorize};
9 use forge_core::{Repo, Role, Session, Store, User, Visibility, WatchLevel};9 use forge_core::{Repo, Role, Session, Store, User, Visibility, WatchLevel};
10 use forge_git::repo::repo_path;10 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+};
12 use topcoat::Result;15 use topcoat::Result;
13-use topcoat::context::{Cx, app_context};16+use topcoat::context::{Cx, context};
14 use topcoat::router::error::not_found;17 use topcoat::router::error::not_found;
15 use topcoat::router::request::uri;18 use topcoat::router::request::uri;
16 use topcoat::router::response::Response;19 use topcoat::router::response::Response;
@@ -306,7 +309,7 @@ pub async fn fork_count(state: &AppState, repo_id: &str) -> Result<u64> {
306 }309 }
307 310
308 pub async fn load_repo(cx: &Cx, owner: &str, name: &str) -> Result<RepoCtx> {311 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);
310 let viewer = current_user(cx).await?;313 let viewer = current_user(cx).await?;
311 314
312 let Some(repo) = state.store.repo_by_owner_and_name(owner, name).await? else {315 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;
16 use time::OffsetDateTime;16 use time::OffsetDateTime;
17 use time::format_description::well_known::Rfc3339;17 use time::format_description::well_known::Rfc3339;
18 use topcoat::Result;18 use topcoat::Result;
19-use topcoat::context::{Cx, app_context};19+use topcoat::context::{Cx, context};
20 use topcoat::router::content::Form;20 use topcoat::router::content::Form;
21 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};21 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
22 use topcoat::router::request::uri;22 use topcoat::router::request::uri;
@@ -391,6 +391,7 @@ async fn rows_of(state: &AppState, ctx: &RepoCtx, frame: &Frame) -> Result<Vec<M
391 /// mirror's redacted URL on its own page.391 /// mirror's redacted URL on its own page.
392 #[component]392 #[component]
393 async fn frame_top(393 async fn frame_top(
394+ cx: &Cx,
394 head: RepoHead,395 head: RepoHead,
395 title: String,396 title: String,
396 heading: String,397 heading: String,
@@ -421,6 +422,7 @@ async fn frame_top(
421 /// `direction` is sent as a hidden field by the add-pull form only (empty for the others).422 /// `direction` is sent as a hidden field by the add-pull form only (empty for the others).
422 #[component]423 #[component]
423 async fn mirror_form(424 async fn mirror_form(
425+ cx: &Cx,
424 action: String,426 action: String,
425 csrf: String,427 csrf: String,
426 prefix: &'static str,428 prefix: &'static str,
@@ -494,6 +496,7 @@ async fn mirror_form(
494 /// Archived repos show no add rows.496 /// Archived repos show no add rows.
495 #[component]497 #[component]
496 async fn mirrors_list_body(498 async fn mirrors_list_body(
499+ cx: &Cx,
497 head: RepoHead,500 head: RepoHead,
498 title: String,501 title: String,
499 notice: Option<(&'static str, bool)>,502 notice: Option<(&'static str, bool)>,
@@ -575,14 +578,14 @@ async fn mirrors_list_body(
575 /// Lists the repo's mirrors. Admins only: anyone else gets 404.578 /// Lists the repo's mirrors. Admins only: anyone else gets 404.
576 #[page("/{owner}/{repo}/settings/mirrors")]579 #[page("/{owner}/{repo}/settings/mirrors")]
577 async fn mirrors_list_page(cx: &Cx) -> Result<impl View> {580 async fn mirrors_list_page(cx: &Cx) -> Result<impl View> {
578- let owner = path_param::<Owner>(cx);581+ let owner = owner(cx);
579- let name = path_param::<Repo>(cx);582+ let name = repo(cx);
580 let ctx = load_repo(cx, owner, name).await?;583 let ctx = load_repo(cx, owner, name).await?;
581 let (_, session) = require_user(cx).await?;584 let (_, session) = require_user(cx).await?;
582 if !ctx.can_admin() {585 if !ctx.can_admin() {
583 return Err(not_found().into());586 return Err(not_found().into());
584 }587 }
585- let state = app_context::<AppState>(cx);588+ let state = context::<AppState>(cx);
586 let lang = lang_of(cx, &ctx);589 let lang = lang_of(cx, &ctx);
587 let frame = Frame::new(&ctx, state, lang).await?;590 let frame = Frame::new(&ctx, state, lang).await?;
588 let rows = rows_of(state, &ctx, &frame).await?;591 let rows = rows_of(state, &ctx, &frame).await?;
@@ -690,8 +693,8 @@ async fn add_pull_mirror(
690 /// before anything is stored.693 /// before anything is stored.
691 #[page(POST "/{owner}/{repo}/settings/mirrors")]694 #[page(POST "/{owner}/{repo}/settings/mirrors")]
692 async fn mirror_create(cx: &Cx, Form(form): Form<PushForm>) -> Result<impl View> {695 async fn mirror_create(cx: &Cx, Form(form): Form<PushForm>) -> Result<impl View> {
693- let owner = path_param::<Owner>(cx);696+ let owner = owner(cx);
694- let name = path_param::<Repo>(cx);697+ let name = repo(cx);
695 let ctx = load_repo(cx, owner, name).await?;698 let ctx = load_repo(cx, owner, name).await?;
696 let (user, session) = require_csrf(cx, &form.csrf).await?;699 let (user, session) = require_csrf(cx, &form.csrf).await?;
697 if !ctx.can_admin() {700 if !ctx.can_admin() {
@@ -700,7 +703,7 @@ async fn mirror_create(cx: &Cx, Form(form): Form<PushForm>) -> Result<impl View>
700 if ctx.repo.archived {703 if ctx.repo.archived {
701 return Err(forbidden().into());704 return Err(forbidden().into());
702 }705 }
703- let state = app_context::<AppState>(cx);706+ let state = context::<AppState>(cx);
704 let lang = lang_of(cx, &ctx);707 let lang = lang_of(cx, &ctx);
705 let pull = form.direction == "pull";708 let pull = form.direction == "pull";
706 let stored = if pull {709 let stored = if pull {
@@ -768,6 +771,7 @@ async fn repo_mirror(state: &AppState, ctx: &RepoCtx, id: &str) -> Result<Mirror
768 /// The edit page body: the form, the sync and delete controls.771 /// The edit page body: the form, the sync and delete controls.
769 #[component]772 #[component]
770 async fn mirror_body(773 async fn mirror_body(
774+ cx: &Cx,
771 head: RepoHead,775 head: RepoHead,
772 title: String,776 title: String,
773 notice: Option<(&'static str, bool)>,777 notice: Option<(&'static str, bool)>,
@@ -844,15 +848,15 @@ impl EditDraft {
844 /// The edit page for one mirror.848 /// The edit page for one mirror.
845 #[page("/{owner}/{repo}/settings/mirrors/{mirror_id}")]849 #[page("/{owner}/{repo}/settings/mirrors/{mirror_id}")]
846 async fn mirror_page(cx: &Cx) -> Result<impl View> {850 async fn mirror_page(cx: &Cx) -> Result<impl View> {
847- let owner = path_param::<Owner>(cx);851+ let owner = owner(cx);
848- let name = path_param::<Repo>(cx);852+ let name = repo(cx);
849- let id = path_param::<MirrorId>(cx);853+ let id = mirror_id(cx);
850 let ctx = load_repo(cx, owner, name).await?;854 let ctx = load_repo(cx, owner, name).await?;
851 let (_, session) = require_user(cx).await?;855 let (_, session) = require_user(cx).await?;
852 if !ctx.can_admin() {856 if !ctx.can_admin() {
853 return Err(not_found().into());857 return Err(not_found().into());
854 }858 }
855- let state = app_context::<AppState>(cx);859+ let state = context::<AppState>(cx);
856 let mirror = repo_mirror(state, &ctx, id).await?;860 let mirror = repo_mirror(state, &ctx, id).await?;
857 let lang = lang_of(cx, &ctx);861 let lang = lang_of(cx, &ctx);
858 let frame = Frame::new(&ctx, state, lang).await?;862 let frame = Frame::new(&ctx, state, lang).await?;
@@ -872,9 +876,9 @@ async fn mirror_page(cx: &Cx) -> Result<impl View> {
872 /// the clear box removes it. A refused form shows the error on the edit page.876 /// the clear box removes it. A refused form shows the error on the edit page.
873 #[page(POST "/{owner}/{repo}/settings/mirrors/{mirror_id}")]877 #[page(POST "/{owner}/{repo}/settings/mirrors/{mirror_id}")]
874 async fn mirror_update(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View> {878 async fn mirror_update(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View> {
875- let owner = path_param::<Owner>(cx);879+ let owner = owner(cx);
876- let name = path_param::<Repo>(cx);880+ let name = repo(cx);
877- let id = path_param::<MirrorId>(cx);881+ let id = mirror_id(cx);
878 let ctx = load_repo(cx, owner, name).await?;882 let ctx = load_repo(cx, owner, name).await?;
879 let (user, session) = require_csrf(cx, &form.csrf).await?;883 let (user, session) = require_csrf(cx, &form.csrf).await?;
880 if !ctx.can_admin() {884 if !ctx.can_admin() {
@@ -883,7 +887,7 @@ async fn mirror_update(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View>
883 if ctx.repo.archived {887 if ctx.repo.archived {
884 return Err(forbidden().into());888 return Err(forbidden().into());
885 }889 }
886- let state = app_context::<AppState>(cx);890+ let state = context::<AppState>(cx);
887 let mirror = repo_mirror(state, &ctx, id).await?;891 let mirror = repo_mirror(state, &ctx, id).await?;
888 let url = if form.url.trim().is_empty() {892 let url = if form.url.trim().is_empty() {
889 mirror.url.clone()893 mirror.url.clone()
@@ -966,9 +970,9 @@ async fn mirror_update(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View>
966 /// Queues a sync now: the mirror is due at the current time and the worker is woken.970 /// Queues a sync now: the mirror is due at the current time and the worker is woken.
967 #[route(POST "/{owner}/{repo}/settings/mirrors/{mirror_id}/sync")]971 #[route(POST "/{owner}/{repo}/settings/mirrors/{mirror_id}/sync")]
968 async fn mirror_sync(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {972 async fn mirror_sync(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
969- let owner = path_param::<Owner>(cx);973+ let owner = owner(cx);
970- let name = path_param::<Repo>(cx);974+ let name = repo(cx);
971- let id = path_param::<MirrorId>(cx);975+ let id = mirror_id(cx);
972 let ctx = load_repo(cx, owner, name).await?;976 let ctx = load_repo(cx, owner, name).await?;
973 require_csrf(cx, &form.csrf).await?;977 require_csrf(cx, &form.csrf).await?;
974 if !ctx.can_admin() {978 if !ctx.can_admin() {
@@ -977,7 +981,7 @@ async fn mirror_sync(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
977 if ctx.repo.archived {981 if ctx.repo.archived {
978 return Err(forbidden().into());982 return Err(forbidden().into());
979 }983 }
980- let state = app_context::<AppState>(cx);984+ let state = context::<AppState>(cx);
981 let mirror = repo_mirror(state, &ctx, id).await?;985 let mirror = repo_mirror(state, &ctx, id).await?;
982 state986 state
983 .store987 .store
@@ -990,9 +994,9 @@ async fn mirror_sync(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
990 /// Deletes a mirror. The box must be ticked. Deleting the pull mirror makes the repo a normal one.994 /// Deletes a mirror. The box must be ticked. Deleting the pull mirror makes the repo a normal one.
991 #[route(POST "/{owner}/{repo}/settings/mirrors/{mirror_id}/delete")]995 #[route(POST "/{owner}/{repo}/settings/mirrors/{mirror_id}/delete")]
992 async fn mirror_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther> {996 async fn mirror_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther> {
993- let owner = path_param::<Owner>(cx);997+ let owner = owner(cx);
994- let name = path_param::<Repo>(cx);998+ let name = repo(cx);
995- let id = path_param::<MirrorId>(cx);999+ let id = mirror_id(cx);
996 let ctx = load_repo(cx, owner, name).await?;1000 let ctx = load_repo(cx, owner, name).await?;
997 let (user, _) = require_csrf(cx, &form.csrf).await?;1001 let (user, _) = require_csrf(cx, &form.csrf).await?;
998 if !ctx.can_admin() {1002 if !ctx.can_admin() {
@@ -1001,7 +1005,7 @@ async fn mirror_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther
1001 if ctx.repo.archived {1005 if ctx.repo.archived {
1002 return Err(forbidden().into());1006 return Err(forbidden().into());
1003 }1007 }
1004- let state = app_context::<AppState>(cx);1008+ let state = context::<AppState>(cx);
1005 let mirror = repo_mirror(state, &ctx, id).await?;1009 let mirror = repo_mirror(state, &ctx, id).await?;
1006 let title = title_of(&ctx);1010 let title = title_of(&ctx);
1007 if form.confirm.is_none() {1011 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;
10 use forge_core::{AuditAction, Error as CoreError};10 use forge_core::{AuditAction, Error as CoreError};
11 use serde::Deserialize;11 use serde::Deserialize;
12 use topcoat::Result;12 use topcoat::Result;
13-use topcoat::context::{Cx, app_context};13+use topcoat::context::{Cx, context};
14 use topcoat::router::content::Form;14 use topcoat::router::content::Form;
15 use topcoat::router::error::{SeeOther, forbidden, see_other};15 use topcoat::router::error::{SeeOther, forbidden, see_other};
16 use topcoat::router::{page, path_param, route};16 use topcoat::router::{page, path_param, route};
@@ -51,6 +51,7 @@ struct TransferForm {
51 /// form opens with it and keeps the typed `name`.51 /// form opens with it and keeps the typed `name`.
52 #[component]52 #[component]
53 pub(crate) async fn rename_section(53 pub(crate) async fn rename_section(
54+ cx: &Cx,
54 lang: Lang,55 lang: Lang,
55 title: String,56 title: String,
56 csrf: String,57 csrf: String,
@@ -84,17 +85,19 @@ pub(crate) async fn rename_section(
84 /// The rename form moved into the danger zone; the old address goes there.85 /// The rename form moved into the danger zone; the old address goes there.
85 #[route(GET "/{owner}/{repo}/settings/rename")]86 #[route(GET "/{owner}/{repo}/settings/rename")]
86 async fn rename_get(cx: &Cx) -> Result<SeeOther> {87 async fn rename_get(cx: &Cx) -> Result<SeeOther> {
87- let owner = path_param::<Owner>(cx);88+ let owner = owner(cx);
88- let name = path_param::<Repo>(cx);89+ let name = repo(cx);
89- Ok(see_other(format!("/{owner}/{name}/settings?section=danger")))90+ Ok(see_other(format!(
91+ "/{owner}/{name}/settings?section=danger"
92+ )))
90 }93 }
91 94
92 /// Renames the repo. The store validates the name with `validate_name`; an invalid name or a name95 /// Renames the repo. The store validates the name with `validate_name`; an invalid name or a name
93 /// taken by another repo of the owner re-renders the danger zone with the message.96 /// taken by another repo of the owner re-renders the danger zone with the message.
94 #[page(POST "/{owner}/{repo}/settings/rename")]97 #[page(POST "/{owner}/{repo}/settings/rename")]
95 async fn rename_post(cx: &Cx, Form(form): Form<RenameForm>) -> Result<impl View> {98 async fn rename_post(cx: &Cx, Form(form): Form<RenameForm>) -> Result<impl View> {
96- let owner = path_param::<Owner>(cx);99+ let owner = owner(cx);
97- let name = path_param::<Repo>(cx);100+ let name = repo(cx);
98 let ctx = load_repo(cx, owner, name).await?;101 let ctx = load_repo(cx, owner, name).await?;
99 let (user, session) = require_csrf(cx, &form.csrf).await?;102 let (user, session) = require_csrf(cx, &form.csrf).await?;
100 if !ctx.can_admin() {103 if !ctx.can_admin() {
@@ -107,7 +110,7 @@ async fn rename_post(cx: &Cx, Form(form): Form<RenameForm>) -> Result<impl View>
107 .chars()110 .chars()
108 .all(|c| c.is_ascii_alphanumeric() || matches!(c, '.' | '_' | '-'))111 .all(|c| c.is_ascii_alphanumeric() || matches!(c, '.' | '_' | '-'))
109 {112 {
110- let state = app_context::<AppState>(cx);113+ let state = context::<AppState>(cx);
111 state114 state
112 .store115 .store
113 .rename_repo(&ctx.repo.id, &new_name)116 .rename_repo(&ctx.repo.id, &new_name)
@@ -127,7 +130,7 @@ async fn rename_post(cx: &Cx, Form(form): Form<RenameForm>) -> Result<impl View>
127 "repository renamed"130 "repository renamed"
128 );131 );
129 audit::record(132 audit::record(
130- &app_context::<AppState>(cx).store,133+ &context::<AppState>(cx).store,
131 Some(cx),134 Some(cx),
132 Actor::User(&user),135 Actor::User(&user),
133 AuditAction::RepoRenamed,136 AuditAction::RepoRenamed,
@@ -170,8 +173,8 @@ async fn rename_post(cx: &Cx, Form(form): Form<RenameForm>) -> Result<impl View>
170 /// `owner/name` confirmation. The store removes the new owner's collaborator row.173 /// `owner/name` confirmation. The store removes the new owner's collaborator row.
171 #[page(POST "/{owner}/{repo}/settings/transfer")]174 #[page(POST "/{owner}/{repo}/settings/transfer")]
172 async fn transfer_post(cx: &Cx, Form(form): Form<TransferForm>) -> Result<impl View> {175 async fn transfer_post(cx: &Cx, Form(form): Form<TransferForm>) -> Result<impl View> {
173- let owner = path_param::<Owner>(cx);176+ let owner = owner(cx);
174- let name = path_param::<Repo>(cx);177+ let name = repo(cx);
175 let ctx = load_repo(cx, owner, name).await?;178 let ctx = load_repo(cx, owner, name).await?;
176 let (user, session) = require_csrf(cx, &form.csrf).await?;179 let (user, session) = require_csrf(cx, &form.csrf).await?;
177 if !ctx.can_delete() {180 if !ctx.can_delete() {
@@ -180,7 +183,7 @@ async fn transfer_post(cx: &Cx, Form(form): Form<TransferForm>) -> Result<impl V
180 let lang = i18n::lang(cx, Some(&user));183 let lang = i18n::lang(cx, Some(&user));
181 let title = format!("{}/{}", ctx.repo.owner_name, ctx.repo.name);184 let title = format!("{}/{}", ctx.repo.owner_name, ctx.repo.name);
182 let target = form.new_owner.trim().to_owned();185 let target = form.new_owner.trim().to_owned();
183- let state = app_context::<AppState>(cx);186+ let state = context::<AppState>(cx);
184 187
185 let error: Option<String> = 'attempt: {188 let error: Option<String> = 'attempt: {
186 if form.confirm.trim() != title {189 if form.confirm.trim() != title {
@@ -226,10 +229,7 @@ async fn transfer_post(cx: &Cx, Form(form): Form<TransferForm>) -> Result<impl V
226 serde_json::json!({ "to": new_owner.username }),229 serde_json::json!({ "to": new_owner.username }),
227 )230 )
228 .await;231 .await;
229- return Err(see_other(format!(232+ return Err(see_other(format!("/{title}/settings?section=danger")).into());
230- "/{title}/settings?section=danger"
231- ))
232- .into());
233 }233 }
234 Err(CoreError::Conflict(message)) => break 'attempt Some(message),234 Err(CoreError::Conflict(message)) => break 'attempt Some(message),
235 Err(other) => return Err(other.into()),235 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};
12 use forge_core::Repo as RepoRow;12 use forge_core::Repo as RepoRow;
13 use forge_git::browse;13 use forge_git::browse;
14 use topcoat::Result;14 use topcoat::Result;
15-use topcoat::context::{Cx, app_context};15+use topcoat::context::{Cx, context};
16 use topcoat::router::error::not_found;16 use topcoat::router::error::not_found;
17 use topcoat::router::{page, path_param};17 use topcoat::router::{page, path_param};
18 use topcoat::view::{View, component, view};18 use topcoat::view::{View, component, view};
@@ -162,7 +162,7 @@ async fn scrub_parts(state: &AppState, ctx: &RepoCtx, oid: &str) -> Result<Optio
162 162
163 /// The listing rows. Names link to their entry at the commit; directories get the folder icon.163 /// The listing rows. Names link to their entry at the commit; directories get the folder icon.
164 #[component]164 #[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> {
166 Ok(view! {166 Ok(view! {
167 for row in rows.into_iter() {167 for row in rows.into_iter() {
168 <div class="tree-entry">168 <div class="tree-entry">
@@ -187,14 +187,14 @@ async fn scrub_table(rows: Vec<ScrubRow>, lang: Lang) -> Result<impl View> {
187 187
188 #[page("/{owner}/{repo}/scrub/{oid}")]188 #[page("/{owner}/{repo}/scrub/{oid}")]
189 async fn scrub_page(cx: &Cx) -> Result<impl View> {189 async fn scrub_page(cx: &Cx) -> Result<impl View> {
190- let owner = path_param::<Owner>(cx);190+ let owner = owner(cx);
191- let name = path_param::<Repo>(cx);191+ let name = repo(cx);
192- let oid = path_param::<Oid>(cx);192+ let oid = oid(cx);
193 let ctx = load_repo(cx, owner, name).await?;193 let ctx = load_repo(cx, owner, name).await?;
194 if !is_full_oid(&oid) {194 if !is_full_oid(&oid) {
195 return Err(not_found().into());195 return Err(not_found().into());
196 }196 }
197- let state = app_context::<AppState>(cx);197+ let state = context::<AppState>(cx);
198 let Some(parts) = scrub_parts(state, &ctx, &oid).await? else {198 let Some(parts) = scrub_parts(state, &ctx, &oid).await? else {
199 return Err(not_found().into());199 return Err(not_found().into());
200 };200 };
crates/forge-web/src/pages/repo_secrets.rsmodified+12 -10
@@ -7,7 +7,7 @@
7 use forge_core::AuditAction;7 use forge_core::AuditAction;
8 use serde::Deserialize;8 use serde::Deserialize;
9 use topcoat::Result;9 use topcoat::Result;
10-use topcoat::context::{Cx, app_context};10+use topcoat::context::{Cx, context};
11 use topcoat::router::content::Form;11 use topcoat::router::content::Form;
12 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};12 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
13 use topcoat::router::request::uri;13 use topcoat::router::request::uri;
@@ -151,6 +151,7 @@ impl SecretsData {
151 /// Header, the rail and the one-line notice.151 /// Header, the rail and the one-line notice.
152 #[component]152 #[component]
153 async fn frame_top(153 async fn frame_top(
154+ cx: &Cx,
154 lang: Lang,155 lang: Lang,
155 head: RepoHead,156 head: RepoHead,
156 title: String,157 title: String,
@@ -182,6 +183,7 @@ async fn frame_top(
182 /// value is never passed back, so the textarea is always empty.183 /// value is never passed back, so the textarea is always empty.
183 #[component]184 #[component]
184 async fn secrets_body(185 async fn secrets_body(
186+ cx: &Cx,
185 lang: Lang,187 lang: Lang,
186 head: RepoHead,188 head: RepoHead,
187 title: String,189 title: String,
@@ -252,15 +254,15 @@ async fn secrets_body(
252 /// Lists the repo's CI secret names. Admins only: anyone else gets 404.254 /// Lists the repo's CI secret names. Admins only: anyone else gets 404.
253 #[page("/{owner}/{repo}/settings/secrets")]255 #[page("/{owner}/{repo}/settings/secrets")]
254 async fn secrets_list_page(cx: &Cx) -> Result<impl View> {256 async fn secrets_list_page(cx: &Cx) -> Result<impl View> {
255- let owner = path_param::<Owner>(cx);257+ let owner = owner(cx);
256- let name = path_param::<Repo>(cx);258+ let name = repo(cx);
257 let ctx = load_repo(cx, owner, name).await?;259 let ctx = load_repo(cx, owner, name).await?;
258 let (user, session) = require_user(cx).await?;260 let (user, session) = require_user(cx).await?;
259 if !ctx.can_admin() {261 if !ctx.can_admin() {
260 return Err(not_found().into());262 return Err(not_found().into());
261 }263 }
262 let lang = i18n::lang(cx, Some(&user));264 let lang = i18n::lang(cx, Some(&user));
263- let state = app_context::<AppState>(cx);265+ let state = context::<AppState>(cx);
264 let data = SecretsData::load(state, &ctx, lang).await?;266 let data = SecretsData::load(state, &ctx, lang).await?;
265 let csrf = session.csrf_token.clone();267 let csrf = session.csrf_token.clone();
266 let notice = notice_from_query(cx);268 let notice = notice_from_query(cx);
@@ -276,8 +278,8 @@ async fn secrets_list_page(cx: &Cx) -> Result<impl View> {
276 /// is dropped, not sent back.278 /// is dropped, not sent back.
277 #[page(POST "/{owner}/{repo}/settings/secrets")]279 #[page(POST "/{owner}/{repo}/settings/secrets")]
278 async fn secret_set(cx: &Cx, Form(form): Form<SetForm>) -> Result<impl View> {280 async fn secret_set(cx: &Cx, Form(form): Form<SetForm>) -> Result<impl View> {
279- let owner = path_param::<Owner>(cx);281+ let owner = owner(cx);
280- let name = path_param::<Repo>(cx);282+ let name = repo(cx);
281 let ctx = load_repo(cx, owner, name).await?;283 let ctx = load_repo(cx, owner, name).await?;
282 let (user, session) = require_csrf(cx, &form.csrf).await?;284 let (user, session) = require_csrf(cx, &form.csrf).await?;
283 if !ctx.can_admin() {285 if !ctx.can_admin() {
@@ -287,7 +289,7 @@ async fn secret_set(cx: &Cx, Form(form): Form<SetForm>) -> Result<impl View> {
287 return Err(forbidden().into());289 return Err(forbidden().into());
288 }290 }
289 let lang = i18n::lang(cx, Some(&user));291 let lang = i18n::lang(cx, Some(&user));
290- let state = app_context::<AppState>(cx);292+ let state = context::<AppState>(cx);
291 let secret_name = form.name.trim().to_owned();293 let secret_name = form.name.trim().to_owned();
292 if let Err(message) = check_secret(lang, &secret_name, &form.value) {294 if let Err(message) = check_secret(lang, &secret_name, &form.value) {
293 let data = SecretsData::load(state, &ctx, lang).await?;295 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> {
323 /// Deletes a secret by name. A name that is not stored is refused with a notice.325 /// Deletes a secret by name. A name that is not stored is refused with a notice.
324 #[route(POST "/{owner}/{repo}/settings/secrets/delete")]326 #[route(POST "/{owner}/{repo}/settings/secrets/delete")]
325 async fn secret_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther> {327 async fn secret_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther> {
326- let owner = path_param::<Owner>(cx);328+ let owner = owner(cx);
327- let name = path_param::<Repo>(cx);329+ let name = repo(cx);
328 let ctx = load_repo(cx, owner, name).await?;330 let ctx = load_repo(cx, owner, name).await?;
329 let (user, _) = require_csrf(cx, &form.csrf).await?;331 let (user, _) = require_csrf(cx, &form.csrf).await?;
330 if !ctx.can_admin() {332 if !ctx.can_admin() {
@@ -333,7 +335,7 @@ async fn secret_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther
333 if ctx.repo.archived {335 if ctx.repo.archived {
334 return Err(forbidden().into());336 return Err(forbidden().into());
335 }337 }
336- let state = app_context::<AppState>(cx);338+ let state = context::<AppState>(cx);
337 let title = title_of(&ctx);339 let title = title_of(&ctx);
338 let secret_name = form.name.trim().to_owned();340 let secret_name = form.name.trim().to_owned();
339 if !valid_name(&secret_name)341 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};
9 use serde::Deserialize;9 use serde::Deserialize;
10 use serde_json::json;10 use serde_json::json;
11 use topcoat::Result;11 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};12+use topcoat::context::{Cx, context};
13 use topcoat::router::content::Form;13 use topcoat::router::content::Form;
14 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};14 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
15 use topcoat::router::{page, path_param, route};15 use topcoat::router::{page, path_param, route};
@@ -112,6 +112,7 @@ fn row_of(alert: &Alert, title: &str, lang: Lang) -> AlertRow {
112 112
113 #[component]113 #[component]
114 async fn security_body(114 async fn security_body(
115+ cx: &Cx,
115 lang: Lang,116 lang: Lang,
116 head: RepoHead,117 head: RepoHead,
117 enabled: bool,118 enabled: bool,
@@ -156,15 +157,15 @@ async fn security_body(
156 /// The security page. Write on the repo or 404.157 /// The security page. Write on the repo or 404.
157 #[page("/{owner}/{repo}/security")]158 #[page("/{owner}/{repo}/security")]
158 async fn security_page(cx: &Cx) -> Result<impl View> {159 async fn security_page(cx: &Cx) -> Result<impl View> {
159- let owner = path_param::<Owner>(cx);160+ let owner = owner(cx);
160- let name = path_param::<Repo>(cx);161+ let name = repo(cx);
161 let ctx = load_repo(cx, owner, name).await?;162 let ctx = load_repo(cx, owner, name).await?;
162 let (user, session) = require_user(cx).await?;163 let (user, session) = require_user(cx).await?;
163 if !can_write(&ctx) {164 if !can_write(&ctx) {
164 return Err(not_found().into());165 return Err(not_found().into());
165 }166 }
166 let lang = i18n::lang(cx, Some(&user));167 let lang = i18n::lang(cx, Some(&user));
167- let state = app_context::<AppState>(cx);168+ let state = context::<AppState>(cx);
168 let title = title_of(&ctx);169 let title = title_of(&ctx);
169 let mut head = ctx.head(state, "security").await?;170 let mut head = ctx.head(state, "security").await?;
170 head.live = security_live_url(&ctx.repo.owner_name, &ctx.repo.name);171 head.live = security_live_url(&ctx.repo.owner_name, &ctx.repo.name);
@@ -195,8 +196,8 @@ async fn change_alert(
195 to: AlertState,196 to: AlertState,
196 action: AuditAction,197 action: AuditAction,
197 ) -> Result<SeeOther> {198 ) -> Result<SeeOther> {
198- let owner = path_param::<Owner>(cx);199+ let owner = owner(cx);
199- let name = path_param::<Repo>(cx);200+ let name = repo(cx);
200 let ctx = load_repo(cx, owner, name).await?;201 let ctx = load_repo(cx, owner, name).await?;
201 let (user, _) = require_csrf(cx, &form.csrf).await?;202 let (user, _) = require_csrf(cx, &form.csrf).await?;
202 if !can_write(&ctx) {203 if !can_write(&ctx) {
@@ -205,7 +206,7 @@ async fn change_alert(
205 if ctx.repo.archived {206 if ctx.repo.archived {
206 return Err(forbidden().into());207 return Err(forbidden().into());
207 }208 }
208- let state = app_context::<AppState>(cx);209+ let state = context::<AppState>(cx);
209 let key = AlertKey {210 let key = AlertKey {
210 advisory_id: form.advisory.clone(),211 advisory_id: form.advisory.clone(),
211 ecosystem: form.ecosystem.clone(),212 ecosystem: form.ecosystem.clone(),
crates/forge-web/src/pages/repo_settings.rsmodified+87 -41
@@ -22,7 +22,7 @@ use forge_git::repo::{
22 };22 };
23 use serde::Deserialize;23 use serde::Deserialize;
24 use topcoat::Result;24 use topcoat::Result;
25-use topcoat::context::{Cx, app_context};25+use topcoat::context::{Cx, context};
26 use topcoat::cookie::{Cookie, Cookies, SameSite, cookies};26 use topcoat::cookie::{Cookie, Cookies, SameSite, cookies};
27 use topcoat::router::content::Form;27 use topcoat::router::content::Form;
28 use topcoat::router::error::{SeeOther, forbidden, see_other};28 use topcoat::router::error::{SeeOther, forbidden, see_other};
@@ -261,7 +261,7 @@ async fn load_branch_names(ctx: &RepoCtx) -> Result<Vec<String>> {
261 261
262 /// The one-line notice on the profile page after a delete.262 /// The one-line notice on the profile page after a delete.
263 #[component]263 #[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> {
265 Ok(view! {265 Ok(view! {
266 if let Some(title) = title {266 if let Some(title) = title {
267 <p class="state" role="status">267 <p class="state" role="status">
@@ -296,6 +296,7 @@ impl DangerForms {
296 /// The Visibility topic: the current value as a line, and the other side behind a confirm.296 /// The Visibility topic: the current value as a line, and the other side behind a confirm.
297 #[component]297 #[component]
298 async fn visibility_section(298 async fn visibility_section(
299+ cx: &Cx,
299 lang: Lang,300 lang: Lang,
300 title: String,301 title: String,
301 csrf: String,302 csrf: String,
@@ -334,6 +335,7 @@ async fn visibility_section(
334 /// The Archive topic: what archiving does, and the one action for the repo's state.335 /// The Archive topic: what archiving does, and the one action for the repo's state.
335 #[component]336 #[component]
336 async fn archive_section(337 async fn archive_section(
338+ cx: &Cx,
337 lang: Lang,339 lang: Lang,
338 title: String,340 title: String,
339 csrf: String,341 csrf: String,
@@ -363,6 +365,7 @@ async fn archive_section(
363 /// action is a small pill that opens its form or confirm in place.365 /// action is a small pill that opens its form or confirm in place.
364 #[component]366 #[component]
365 async fn danger_section(367 async fn danger_section(
368+ cx: &Cx,
366 lang: Lang,369 lang: Lang,
367 title: String,370 title: String,
368 csrf: String,371 csrf: String,
@@ -396,6 +399,7 @@ async fn danger_section(
396 /// The Delete topic: what deleting does, and the confirmation form, which opens in place.399 /// The Delete topic: what deleting does, and the confirmation form, which opens in place.
397 #[component]400 #[component]
398 async fn delete_section(401 async fn delete_section(
402+ cx: &Cx,
399 lang: Lang,403 lang: Lang,
400 csrf: String,404 csrf: String,
401 title: String,405 title: String,
@@ -437,6 +441,7 @@ async fn delete_section(
437 /// page is for a repo admin, so the Danger zone is always listed.441 /// page is for a repo admin, so the Danger zone is always listed.
438 #[component]442 #[component]
439 pub async fn settings_frame(443 pub async fn settings_frame(
444+ cx: &Cx,
440 lang: Lang,445 lang: Lang,
441 title: String,446 title: String,
442 current: &'static str,447 current: &'static str,
@@ -449,13 +454,41 @@ pub async fn settings_frame(
449 current: on,454 current: on,
450 };455 };
451 let items = vec![456 let items = vec![
452- item(g::t(lang, K::General), format!("/{title}/settings"), current == "general"),457+ item(
453- item(g::t(lang, K::Collaborators), format!("/{title}/settings/collaborators"), current == "collaborators"),458+ g::t(lang, K::General),
454- item(g::t(lang, K::BranchProtection), format!("/{title}/settings?section=branches"), current == "branches"),459+ format!("/{title}/settings"),
455- item(g::t(lang, K::Webhooks), format!("/{title}/settings/hooks"), current == "webhooks"),460+ current == "general",
456- item(g::t(lang, K::Mirrors), format!("/{title}/settings/mirrors"), current == "mirrors"),461+ ),
457- item(g::t(lang, K::Secrets), format!("/{title}/settings/secrets"), current == "secrets"),462+ item(
458- item(g::t(lang, K::DangerZone), format!("/{title}/settings?section=danger"), current == "danger"),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+ ),
459 ];492 ];
460 Ok(view! {493 Ok(view! {
461 <div class="work">494 <div class="work">
@@ -467,12 +500,12 @@ pub async fn settings_frame(
467 })500 })
468 }501 }
469 502
470-
471 /// The General section: description and default branch in one form, under no heading (the page's503 /// The General section: description and default branch in one form, under no heading (the page's
472 /// head names it), then the Features topic with one switch per feature. Each form carries its own504 /// head names it), then the Features topic with one switch per feature. Each form carries its own
473 /// CSRF token. An empty repo shows "No branches yet" and no selector.505 /// CSRF token. An empty repo shows "No branches yet" and no selector.
474 #[component]506 #[component]
475 async fn general_section(507 async fn general_section(
508+ cx: &Cx,
476 lang: Lang,509 lang: Lang,
477 title: String,510 title: String,
478 csrf: String,511 csrf: String,
@@ -617,6 +650,7 @@ struct RuleCard {
617 /// opens with the draft when no rule takes it. The rows share one `name`, so opening one closes the rest.650 /// opens with the draft when no rule takes it. The rows share one `name`, so opening one closes the rest.
618 #[component]651 #[component]
619 async fn branch_rule_cards(652 async fn branch_rule_cards(
653+ cx: &Cx,
620 lang: Lang,654 lang: Lang,
621 cards: Vec<RuleCard>,655 cards: Vec<RuleCard>,
622 builtin_row: bool,656 builtin_row: bool,
@@ -673,6 +707,7 @@ async fn branch_rule_cards(
673 /// an existing rule's Remove action is a confirm_act beside them, on the same row.707 /// an existing rule's Remove action is a confirm_act beside them, on the same row.
674 #[component]708 #[component]
675 async fn branch_rule_form(709 async fn branch_rule_form(
710+ cx: &Cx,
676 lang: Lang,711 lang: Lang,
677 csrf: String,712 csrf: String,
678 save_action: String,713 save_action: String,
@@ -700,7 +735,11 @@ async fn branch_rule_form(
700 || require_up_to_date735 || require_up_to_date
701 || require_merge_queue736 || require_merge_queue
702 || !required_checks.trim().is_empty();737 || !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+ };
704 // Field ids are per rule, so two open rule forms never share an id.743 // Field ids are per rule, so two open rule forms never share an id.
705 let prefix = match &rule_id {744 let prefix = match &rule_id {
706 Some(id) => format!("rule-{id}"),745 Some(id) => format!("rule-{id}"),
@@ -896,7 +935,7 @@ pub(crate) async fn render_settings(
896 lang: Lang,935 lang: Lang,
897 shown: Shown,936 shown: Shown,
898 ) -> Result<impl View> {937 ) -> Result<impl View> {
899- let state = app_context::<AppState>(cx);938+ let state = context::<AppState>(cx);
900 let Shown {939 let Shown {
901 section,940 section,
902 notice,941 notice,
@@ -915,14 +954,11 @@ pub(crate) async fn render_settings(
915 danger,954 danger,
916 transfer,955 transfer,
917 wiki_on: state.store.wiki_enabled(&ctx.repo.id).await?,956 wiki_on: state.store.wiki_enabled(&ctx.repo.id).await?,
918- contexts: state957+ contexts: state.store.recent_status_contexts(&ctx.repo.id, 20).await?,
919- .store
920- .recent_status_contexts(&ctx.repo.id, 20)
921- .await?,
922 };958 };
923 let frame = SettingsFrame::new(&ctx, state, lang).await?;959 let frame = SettingsFrame::new(&ctx, state, lang).await?;
924 let branches = load_branch_names(&ctx).await?;960 let branches = load_branch_names(&ctx).await?;
925- Ok(view! { cx =>961+ Ok(view! {
926 shell(title: frame.page_title.as_str(), viewer: ctx.viewer.as_ref(),962 shell(title: frame.page_title.as_str(), viewer: ctx.viewer.as_ref(),
927 settings_body(lang: lang, head: frame.head, default_branch: frame.default_branch, archived: frame.archived,963 settings_body(lang: lang, head: frame.head, default_branch: frame.default_branch, archived: frame.archived,
928 branches: branches, title: frame.title, csrf: csrf,964 branches: branches, title: frame.title, csrf: csrf,
@@ -934,6 +970,7 @@ pub(crate) async fn render_settings(
934 /// general, branches or danger) in the sheet.970 /// general, branches or danger) in the sheet.
935 #[component]971 #[component]
936 async fn settings_body(972 async fn settings_body(
973+ cx: &Cx,
937 lang: Lang,974 lang: Lang,
938 head: RepoHead,975 head: RepoHead,
939 default_branch: String,976 default_branch: String,
@@ -1057,8 +1094,8 @@ impl SettingsFrame {
1057 /// visible repos go to login, and signed-in viewers who may not manage the repo get 403.1094 /// visible repos go to login, and signed-in viewers who may not manage the repo get 403.
1058 #[page("/{owner}/{repo}/settings")]1095 #[page("/{owner}/{repo}/settings")]
1059 async fn settings_page(cx: &Cx) -> Result<impl View> {1096 async fn settings_page(cx: &Cx) -> Result<impl View> {
1060- let owner = path_param::<Owner>(cx);1097+ let owner = owner(cx);
1061- let name = path_param::<Repo>(cx);1098+ let name = repo(cx);
1062 let ctx = load_repo(cx, owner, name).await?;1099 let ctx = load_repo(cx, owner, name).await?;
1063 let (user, session) = require_user(cx).await?;1100 let (user, session) = require_user(cx).await?;
1064 if !ctx.can_admin() {1101 if !ctx.can_admin() {
@@ -1080,15 +1117,15 @@ async fn settings_page(cx: &Cx) -> Result<impl View> {
1080 /// and the database changes only when that succeeds. A failed database write puts HEAD back.1117 /// and the database changes only when that succeeds. A failed database write puts HEAD back.
1081 #[route(POST "/{owner}/{repo}/settings/general")]1118 #[route(POST "/{owner}/{repo}/settings/general")]
1082 async fn settings_general_save(cx: &Cx, Form(form): Form<GeneralForm>) -> Result<SeeOther> {1119 async fn settings_general_save(cx: &Cx, Form(form): Form<GeneralForm>) -> Result<SeeOther> {
1083- let owner = path_param::<Owner>(cx);1120+ let owner = owner(cx);
1084- let name = path_param::<Repo>(cx);1121+ let name = repo(cx);
1085 let ctx = load_repo(cx, owner, name).await?;1122 let ctx = load_repo(cx, owner, name).await?;
1086 let (user, _) = require_csrf(cx, &form.csrf).await?;1123 let (user, _) = require_csrf(cx, &form.csrf).await?;
1087 if !ctx.can_admin() {1124 if !ctx.can_admin() {
1088 return Err(forbidden().into());1125 return Err(forbidden().into());
1089 }1126 }
1090 let title = format!("{}/{}", ctx.repo.owner_name, ctx.repo.name);1127 let title = format!("{}/{}", ctx.repo.owner_name, ctx.repo.name);
1091- let state = app_context::<AppState>(cx);1128+ let state = context::<AppState>(cx);
1092 1129
1093 let description = clean_description(&form.description);1130 let description = clean_description(&form.description);
1094 if description.chars().count() > MAX_DESCRIPTION_CHARS {1131 if description.chars().count() > MAX_DESCRIPTION_CHARS {
@@ -1149,8 +1186,8 @@ async fn settings_general_save(cx: &Cx, Form(form): Form<GeneralForm>) -> Result
1149 /// changes nothing.1186 /// changes nothing.
1150 #[route(POST "/{owner}/{repo}/settings/visibility")]1187 #[route(POST "/{owner}/{repo}/settings/visibility")]
1151 async fn settings_visibility_save(cx: &Cx, Form(form): Form<VisibilityForm>) -> Result<SeeOther> {1188 async fn settings_visibility_save(cx: &Cx, Form(form): Form<VisibilityForm>) -> Result<SeeOther> {
1152- let owner = path_param::<Owner>(cx);1189+ let owner = owner(cx);
1153- let name = path_param::<Repo>(cx);1190+ let name = repo(cx);
1154 let ctx = load_repo(cx, owner, name).await?;1191 let ctx = load_repo(cx, owner, name).await?;
1155 let (user, _) = require_csrf(cx, &form.csrf).await?;1192 let (user, _) = require_csrf(cx, &form.csrf).await?;
1156 if !ctx.can_admin() {1193 if !ctx.can_admin() {
@@ -1166,7 +1203,7 @@ async fn settings_visibility_save(cx: &Cx, Form(form): Form<VisibilityForm>) ->
1166 set_settings_notice(cx, "understand");1203 set_settings_notice(cx, "understand");
1167 return Ok(back_to_section(&title, "danger"));1204 return Ok(back_to_section(&title, "danger"));
1168 }1205 }
1169- let state = app_context::<AppState>(cx);1206+ let state = context::<AppState>(cx);
1170 state1207 state
1171 .store1208 .store
1172 .set_repo_visibility(&ctx.repo.id, target)1209 .set_repo_visibility(&ctx.repo.id, target)
@@ -1201,8 +1238,8 @@ async fn settings_visibility_save(cx: &Cx, Form(form): Form<VisibilityForm>) ->
1201 /// the archived flag does not block Admin.1238 /// the archived flag does not block Admin.
1202 #[route(POST "/{owner}/{repo}/settings/archive")]1239 #[route(POST "/{owner}/{repo}/settings/archive")]
1203 async fn settings_archive_save(cx: &Cx, Form(form): Form<ArchiveForm>) -> Result<SeeOther> {1240 async fn settings_archive_save(cx: &Cx, Form(form): Form<ArchiveForm>) -> Result<SeeOther> {
1204- let owner = path_param::<Owner>(cx);1241+ let owner = owner(cx);
1205- let name = path_param::<Repo>(cx);1242+ let name = repo(cx);
1206 let ctx = load_repo(cx, owner, name).await?;1243 let ctx = load_repo(cx, owner, name).await?;
1207 let (user, _) = require_csrf(cx, &form.csrf).await?;1244 let (user, _) = require_csrf(cx, &form.csrf).await?;
1208 if !ctx.can_admin() {1245 if !ctx.can_admin() {
@@ -1217,7 +1254,7 @@ async fn settings_archive_save(cx: &Cx, Form(form): Form<ArchiveForm>) -> Result
1217 return Ok(back_to_section(&title, "danger"));1254 return Ok(back_to_section(&title, "danger"));
1218 }1255 }
1219 };1256 };
1220- let state = app_context::<AppState>(cx);1257+ let state = context::<AppState>(cx);
1221 state1258 state
1222 .store1259 .store
1223 .set_repo_archived(&ctx.repo.id, archived)1260 .set_repo_archived(&ctx.repo.id, archived)
@@ -1258,8 +1295,8 @@ async fn settings_archive_save(cx: &Cx, Form(form): Form<ArchiveForm>) -> Result
1258 /// A wrong confirmation re-renders the page with an error and changes nothing.1295 /// A wrong confirmation re-renders the page with an error and changes nothing.
1259 #[page(POST "/{owner}/{repo}/settings/delete")]1296 #[page(POST "/{owner}/{repo}/settings/delete")]
1260 async fn settings_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<impl View> {1297 async fn settings_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<impl View> {
1261- let owner = path_param::<Owner>(cx);1298+ let owner = owner(cx);
1262- let name = path_param::<Repo>(cx);1299+ let name = repo(cx);
1263 let ctx = load_repo(cx, owner, name).await?;1300 let ctx = load_repo(cx, owner, name).await?;
1264 let (user, session) = require_csrf(cx, &form.csrf).await?;1301 let (user, session) = require_csrf(cx, &form.csrf).await?;
1265 if !ctx.can_delete() {1302 if !ctx.can_delete() {
@@ -1274,7 +1311,7 @@ async fn settings_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<impl V
1274 };1311 };
1275 1312
1276 if error.is_none() {1313 if error.is_none() {
1277- let state = app_context::<AppState>(cx);1314+ let state = context::<AppState>(cx);
1278 let repo: &RepoRow = &ctx.repo;1315 let repo: &RepoRow = &ctx.repo;
1279 let data_dir = &state.config.data_dir;1316 let data_dir = &state.config.data_dir;
1280 // A missing directory (already removed by hand) has nothing to trash, so only the rows go.1317 // 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
1378 /// `Action::Admin` first. An invalid pattern re-renders the page with the error next to the form.1415 /// `Action::Admin` first. An invalid pattern re-renders the page with the error next to the form.
1379 #[page(POST "/{owner}/{repo}/settings/branches")]1416 #[page(POST "/{owner}/{repo}/settings/branches")]
1380 async fn settings_branch_save(cx: &Cx, Form(form): Form<BranchForm>) -> Result<impl View> {1417 async fn settings_branch_save(cx: &Cx, Form(form): Form<BranchForm>) -> Result<impl View> {
1381- let owner = path_param::<Owner>(cx);1418+ let owner = owner(cx);
1382- let name = path_param::<Repo>(cx);1419+ let name = repo(cx);
1383 let ctx = load_repo(cx, owner, name).await?;1420 let ctx = load_repo(cx, owner, name).await?;
1384 let (user, session) = require_csrf(cx, &form.csrf).await?;1421 let (user, session) = require_csrf(cx, &form.csrf).await?;
1385 if !ctx.can_admin() {1422 if !ctx.can_admin() {
@@ -1391,7 +1428,7 @@ async fn settings_branch_save(cx: &Cx, Form(form): Form<BranchForm>) -> Result<i
1391 1428
1392 let is_new = form.existing.is_none();1429 let is_new = form.existing.is_none();
1393 let taken = is_new1430 let taken = is_new
1394- && app_context::<AppState>(cx)1431+ && context::<AppState>(cx)
1395 .store1432 .store
1396 .list_branch_rules(&ctx.repo.id)1433 .list_branch_rules(&ctx.repo.id)
1397 .await?1434 .await?
@@ -1433,7 +1470,7 @@ async fn settings_branch_save(cx: &Cx, Form(form): Form<BranchForm>) -> Result<i
1433 }1470 }
1434 };1471 };
1435 1472
1436- let state = app_context::<AppState>(cx);1473+ let state = context::<AppState>(cx);
1437 state1474 state
1438 .store1475 .store
1439 .upsert_branch_rule(&ctx.repo.id, &pattern, flags.clone())1476 .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
1458 /// Removes a branch rule by id, scoped to this repo. Same checks as the save form.1495 /// Removes a branch rule by id, scoped to this repo. Same checks as the save form.
1459 #[route(POST "/{owner}/{repo}/settings/branches/delete")]1496 #[route(POST "/{owner}/{repo}/settings/branches/delete")]
1460 async fn settings_branch_delete(cx: &Cx, Form(form): Form<BranchDeleteForm>) -> Result<SeeOther> {1497 async fn settings_branch_delete(cx: &Cx, Form(form): Form<BranchDeleteForm>) -> Result<SeeOther> {
1461- let owner = path_param::<Owner>(cx);1498+ let owner = owner(cx);
1462- let name = path_param::<Repo>(cx);1499+ let name = repo(cx);
1463 let ctx = load_repo(cx, owner, name).await?;1500 let ctx = load_repo(cx, owner, name).await?;
1464 let (user, _) = require_csrf(cx, &form.csrf).await?;1501 let (user, _) = require_csrf(cx, &form.csrf).await?;
1465 if !ctx.can_admin() {1502 if !ctx.can_admin() {
1466 return Err(forbidden().into());1503 return Err(forbidden().into());
1467 }1504 }
1468- let state = app_context::<AppState>(cx);1505+ let state = context::<AppState>(cx);
1469 state1506 state
1470 .store1507 .store
1471 .delete_branch_rule(&ctx.repo.id, &form.rule_id)1508 .delete_branch_rule(&ctx.repo.id, &form.rule_id)
@@ -1568,7 +1605,11 @@ mod tests {
1568 let (status, _) = post_rule(1605 let (status, _) = post_rule(
1569 &app,1606 &app,
1570 &cookie,1607 &cookie,
1571- &[("pattern", "main"), ("existing", "1"), ("required_approvals", "")],1608+ &[
1609+ ("pattern", "main"),
1610+ ("existing", "1"),
1611+ ("required_approvals", ""),
1612+ ],
1572 )1613 )
1573 .await;1614 .await;
1574 assert_eq!(status, 303);1615 assert_eq!(status, 303);
@@ -1583,7 +1624,8 @@ mod tests {
1583 &app,1624 &app,
1584 &cookie,1625 &cookie,
1585 &[1626 &[
1586- ("pattern", "main"), ("existing", "1"),1627+ ("pattern", "main"),
1628+ ("existing", "1"),
1587 ("required_approvals", "21"),1629 ("required_approvals", "21"),
1588 ("restrict_push", "on"),1630 ("restrict_push", "on"),
1589 ],1631 ],
@@ -1602,7 +1644,11 @@ mod tests {
1602 let (status, body) = post_rule(1644 let (status, body) = post_rule(
1603 &app,1645 &app,
1604 &cookie,1646 &cookie,
1605- &[("pattern", "main"), ("existing", "1"), ("required_approvals", "two")],1647+ &[
1648+ ("pattern", "main"),
1649+ ("existing", "1"),
1650+ ("required_approvals", "two"),
1651+ ],
1606 )1652 )
1607 .await;1653 .await;
1608 assert_eq!(status, 200);1654 assert_eq!(status, 200);
crates/forge-web/src/pages/repo_settings_live.rsmodified+7 -7
@@ -15,7 +15,7 @@
15 //! security and transfer streams for the signed-in viewers their pages admit.15 //! security and transfer streams for the signed-in viewers their pages admit.
16 16
17 use topcoat::Result;17 use topcoat::Result;
18-use topcoat::context::{Cx, app_context};18+use topcoat::context::{Cx, context};
19 use topcoat::router::error::forbidden;19 use topcoat::router::error::forbidden;
20 use topcoat::router::request::{method, uri};20 use topcoat::router::request::{method, uri};
21 use topcoat::router::response::Response;21 use topcoat::router::response::Response;
@@ -56,11 +56,11 @@ pub fn bump_settings(hub: &LiveHub, repo_id: &str) {
56 /// as the settings page is.56 /// as the settings page is.
57 #[route(GET "/{owner}/{repo}/settings/live")]57 #[route(GET "/{owner}/{repo}/settings/live")]
58 async fn settings_live(cx: &Cx) -> Result<Response> {58 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?;
60 if !ctx.can_admin() {60 if !ctx.can_admin() {
61 return Err(forbidden().into());61 return Err(forbidden().into());
62 }62 }
63- let state = app_context::<AppState>(cx);63+ let state = context::<AppState>(cx);
64 let topics = [64 let topics = [
65 Topic::RepoSettings(ctx.repo.id.clone()),65 Topic::RepoSettings(ctx.repo.id.clone()),
66 Topic::RepoRefs(ctx.repo.id.clone()),66 Topic::RepoRefs(ctx.repo.id.clone()),
@@ -72,9 +72,9 @@ async fn settings_live(cx: &Cx) -> Result<Response> {
72 /// read the repo.72 /// read the repo.
73 #[route(GET "/{owner}/{repo}/security/live")]73 #[route(GET "/{owner}/{repo}/security/live")]
74 async fn security_live(cx: &Cx) -> Result<Response> {74 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?;
76 require_user(cx).await?;76 require_user(cx).await?;
77- let state = app_context::<AppState>(cx);77+ let state = context::<AppState>(cx);
78 stream_wakes(cx, &state.live, &[Topic::RepoSettings(ctx.repo.id.clone())])78 stream_wakes(cx, &state.live, &[Topic::RepoSettings(ctx.repo.id.clone())])
79 }79 }
80 80
@@ -115,7 +115,7 @@ fn written(cx: &Cx) -> Option<(String, String)> {
115 async fn bump_after_write(cx: &Cx, body: Body, next: Next<'_>) -> Result<Response> {115 async fn bump_after_write(cx: &Cx, body: Body, next: Next<'_>) -> Result<Response> {
116 let repo_id = match written(cx) {116 let repo_id = match written(cx) {
117 Some((owner, name)) => {117 Some((owner, name)) => {
118- let state = app_context::<AppState>(cx);118+ let state = context::<AppState>(cx);
119 match state.store.repo_by_owner_and_name(&owner, &name).await {119 match state.store.repo_by_owner_and_name(&owner, &name).await {
120 Ok(repo) => repo.map(|repo| repo.id),120 Ok(repo) => repo.map(|repo| repo.id),
121 Err(e) => {121 Err(e) => {
@@ -128,7 +128,7 @@ async fn bump_after_write(cx: &Cx, body: Body, next: Next<'_>) -> Result<Respons
128 };128 };
129 let result = next.run(cx, body).await;129 let result = next.run(cx, body).await;
130 if let Some(repo_id) = repo_id {130 if let Some(repo_id) = repo_id {
131- let state = app_context::<AppState>(cx);131+ let state = context::<AppState>(cx);
132 bump_settings(&state.live, &repo_id);132 bump_settings(&state.live, &repo_id);
133 // The repo header shows settings too (the mirror line, the archived notice, the tabs); its133 // The repo header shows settings too (the mirror line, the archived notice, the tabs); its
134 // stream sends nothing when its fingerprint holds.134 // 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(
256 parts.push(SubPart::text(lang_name(lang, share)));256 parts.push(SubPart::text(lang_name(lang, share)));
257 }257 }
258 if let Some((file, id)) = facts.license.as_ref() {258 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+ ));
260 }262 }
261 if facts.size > 0 {263 if facts.size > 0 {
262 parts.push(SubPart::text(human_size(lang, facts.size)));264 parts.push(SubPart::text(human_size(lang, facts.size)));
@@ -329,4 +331,3 @@ fn lang_name(lang: Lang, share: &LangShare) -> String {
329 s(lang, "Other", "Diğer").to_owned()331 s(lang, "Other", "Diğer").to_owned()
330 }332 }
331 }333 }
332-
crates/forge-web/src/pages/repo_transfer.rsmodified+14 -10
@@ -12,7 +12,7 @@ use forge_core::store::transfers::PendingTransfer;
12 use forge_core::{AuditAction, Error as CoreError};12 use forge_core::{AuditAction, Error as CoreError};
13 use serde::Deserialize;13 use serde::Deserialize;
14 use topcoat::Result;14 use topcoat::Result;
15-use topcoat::context::{Cx, app_context};15+use topcoat::context::{Cx, context};
16 use topcoat::router::content::Form;16 use topcoat::router::content::Form;
17 use topcoat::router::error::{SeeOther, forbidden, see_other};17 use topcoat::router::error::{SeeOther, forbidden, see_other};
18 use topcoat::router::{path_param, route};18 use topcoat::router::{path_param, route};
@@ -94,6 +94,7 @@ pub(crate) async fn transfer_status(
94 /// with an error opens with it.94 /// with an error opens with it.
95 #[component]95 #[component]
96 pub(crate) async fn transfer_section(96 pub(crate) async fn transfer_section(
97+ cx: &Cx,
97 lang: Lang,98 lang: Lang,
98 title: String,99 title: String,
99 csrf: String,100 csrf: String,
@@ -146,9 +147,11 @@ pub(crate) async fn transfer_section(
146 /// The transfer page moved into the danger zone; the old address goes there.147 /// The transfer page moved into the danger zone; the old address goes there.
147 #[route(GET "/{owner}/{repo}/transfer")]148 #[route(GET "/{owner}/{repo}/transfer")]
148 async fn transfer_get(cx: &Cx) -> Result<SeeOther> {149 async fn transfer_get(cx: &Cx) -> Result<SeeOther> {
149- let owner = path_param::<Owner>(cx);150+ let owner = owner(cx);
150- let repo = path_param::<Repo>(cx);151+ let repo = repo(cx);
151- Ok(see_other(format!("/{owner}/{repo}/settings?section=danger")))152+ Ok(see_other(format!(
153+ "/{owner}/{repo}/settings?section=danger"
154+ )))
152 }155 }
153 156
154 /// The open transfer `repo_id`, or `NotFound`.157 /// The open transfer `repo_id`, or `NotFound`.
@@ -163,9 +166,9 @@ async fn open_transfer(state: &AppState, repo_id: &str) -> Result<PendingTransfe
163 /// Accepts the transfer as the target and moves the repo. Then goes to the repo at its new owner.166 /// Accepts the transfer as the target and moves the repo. Then goes to the repo at its new owner.
164 #[route(POST "/-/transfers/{transfer}/accept")]167 #[route(POST "/-/transfers/{transfer}/accept")]
165 async fn accept_post(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther> {168 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();
167 let (user, _) = require_csrf(cx, &form.csrf).await?;170 let (user, _) = require_csrf(cx, &form.csrf).await?;
168- let state = app_context::<AppState>(cx);171+ let state = context::<AppState>(cx);
169 let pending = open_transfer(state, &repo_id).await?;172 let pending = open_transfer(state, &repo_id).await?;
170 let from_owner = state173 let from_owner = state
171 .store174 .store
@@ -201,9 +204,9 @@ async fn accept_post(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther>
201 /// Declines the transfer as one of its target's owners. The repo stays where it is.204 /// Declines the transfer as one of its target's owners. The repo stays where it is.
202 #[route(POST "/-/transfers/{transfer}/decline")]205 #[route(POST "/-/transfers/{transfer}/decline")]
203 async fn decline_post(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther> {206 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();
205 let (user, _) = require_csrf(cx, &form.csrf).await?;208 let (user, _) = require_csrf(cx, &form.csrf).await?;
206- let state = app_context::<AppState>(cx);209+ let state = context::<AppState>(cx);
207 let pending = open_transfer(state, &repo_id).await?;210 let pending = open_transfer(state, &repo_id).await?;
208 state.store.decline_transfer(&repo_id, &user.id).await?;211 state.store.decline_transfer(&repo_id, &user.id).await?;
209 bump_settings(&state.live, &repo_id);212 bump_settings(&state.live, &repo_id);
@@ -226,9 +229,9 @@ async fn decline_post(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther>
226 /// Cancels the transfer. The initiator may, and so may anyone who may delete the repo.229 /// Cancels the transfer. The initiator may, and so may anyone who may delete the repo.
227 #[route(POST "/-/transfers/{transfer}/cancel")]230 #[route(POST "/-/transfers/{transfer}/cancel")]
228 async fn cancel_post(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther> {231 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();
230 let (user, _) = require_csrf(cx, &form.csrf).await?;233 let (user, _) = require_csrf(cx, &form.csrf).await?;
231- let state = app_context::<AppState>(cx);234+ let state = context::<AppState>(cx);
232 let pending = open_transfer(state, &repo_id).await?;235 let pending = open_transfer(state, &repo_id).await?;
233 let repo = state236 let repo = state
234 .store237 .store
@@ -276,6 +279,7 @@ struct InboxRow {
276 /// private repo.279 /// private repo.
277 #[component]280 #[component]
278 pub(crate) async fn transfer_list_for(281 pub(crate) async fn transfer_list_for(
282+ cx: &Cx,
279 lang: Lang,283 lang: Lang,
280 transfers: Vec<PendingTransfer>,284 transfers: Vec<PendingTransfer>,
281 csrf: String,285 csrf: String,
crates/forge-web/src/pages/repo_webhooks.rsmodified+37 -31
@@ -13,7 +13,7 @@ use serde_json::Value;
13 use time::OffsetDateTime;13 use time::OffsetDateTime;
14 use time::format_description::well_known::Rfc3339;14 use time::format_description::well_known::Rfc3339;
15 use topcoat::Result;15 use topcoat::Result;
16-use topcoat::context::{Cx, app_context};16+use topcoat::context::{Cx, context};
17 use topcoat::router::content::Form;17 use topcoat::router::content::Form;
18 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};18 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
19 use topcoat::router::request::uri;19 use topcoat::router::request::uri;
@@ -490,6 +490,7 @@ impl Frame {
490 /// list's name, or the hook's URL); `action` is the head's main action as (href, label), if any.490 /// list's name, or the hook's URL); `action` is the head's main action as (href, label), if any.
491 #[component]491 #[component]
492 async fn frame_top(492 async fn frame_top(
493+ cx: &Cx,
493 head: RepoHead,494 head: RepoHead,
494 title: String,495 title: String,
495 heading: String,496 heading: String,
@@ -524,6 +525,7 @@ async fn frame_top(
524 /// The add or edit form. `secret_hint` says what the secret field does for this form.525 /// The add or edit form. `secret_hint` says what the secret field does for this form.
525 #[component]526 #[component]
526 async fn hook_form(527 async fn hook_form(
528+ cx: &Cx,
527 action: String,529 action: String,
528 csrf: String,530 csrf: String,
529 url: String,531 url: String,
@@ -584,6 +586,7 @@ async fn hook_form(
584 586
585 #[component]587 #[component]
586 async fn hooks_list_body(588 async fn hooks_list_body(
589+ cx: &Cx,
587 head: RepoHead,590 head: RepoHead,
588 title: String,591 title: String,
589 notice: Option<(&'static str, bool)>,592 notice: Option<(&'static str, bool)>,
@@ -628,6 +631,7 @@ async fn hooks_list_body(
628 631
629 #[component]632 #[component]
630 async fn delivery_list(633 async fn delivery_list(
634+ cx: &Cx,
631 deliveries: Vec<DeliveryRow>,635 deliveries: Vec<DeliveryRow>,
632 csrf: String,636 csrf: String,
633 archived: bool,637 archived: bool,
@@ -671,6 +675,7 @@ async fn delivery_list(
671 675
672 #[component]676 #[component]
673 async fn hook_body(677 async fn hook_body(
678+ cx: &Cx,
674 head: RepoHead,679 head: RepoHead,
675 title: String,680 title: String,
676 notice: Option<(&'static str, bool)>,681 notice: Option<(&'static str, bool)>,
@@ -731,14 +736,14 @@ async fn hook_body(
731 /// Lists the repo's hooks. Admins only: a hidden repo is 404, any other viewer is 403.736 /// Lists the repo's hooks. Admins only: a hidden repo is 404, any other viewer is 403.
732 #[page("/{owner}/{repo}/settings/hooks")]737 #[page("/{owner}/{repo}/settings/hooks")]
733 async fn hooks_list_page(cx: &Cx) -> Result<impl View> {738 async fn hooks_list_page(cx: &Cx) -> Result<impl View> {
734- let owner = path_param::<Owner>(cx);739+ let owner = owner(cx);
735- let name = path_param::<Repo>(cx);740+ let name = repo(cx);
736 let ctx = load_repo(cx, owner, name).await?;741 let ctx = load_repo(cx, owner, name).await?;
737 require_user(cx).await?;742 require_user(cx).await?;
738 if !ctx.can_admin() {743 if !ctx.can_admin() {
739 return Err(forbidden().into());744 return Err(forbidden().into());
740 }745 }
741- let state = app_context::<AppState>(cx);746+ let state = context::<AppState>(cx);
742 let hooks = state.store.list_webhooks(&ctx.repo.id).await?;747 let hooks = state.store.list_webhooks(&ctx.repo.id).await?;
743 let lang = lang_of(cx, &ctx);748 let lang = lang_of(cx, &ctx);
744 let frame = Frame::new(&ctx, state, lang).await?;749 let frame = Frame::new(&ctx, state, lang).await?;
@@ -771,14 +776,14 @@ async fn hooks_list_page(cx: &Cx) -> Result<impl View> {
771 /// The add form.776 /// The add form.
772 #[page("/{owner}/{repo}/settings/hooks/new")]777 #[page("/{owner}/{repo}/settings/hooks/new")]
773 async fn hook_new_page(cx: &Cx) -> Result<impl View> {778 async fn hook_new_page(cx: &Cx) -> Result<impl View> {
774- let owner = path_param::<Owner>(cx);779+ let owner = owner(cx);
775- let name = path_param::<Repo>(cx);780+ let name = repo(cx);
776 let ctx = load_repo(cx, owner, name).await?;781 let ctx = load_repo(cx, owner, name).await?;
777 let (_, session) = require_user(cx).await?;782 let (_, session) = require_user(cx).await?;
778 if !ctx.can_admin() {783 if !ctx.can_admin() {
779 return Err(forbidden().into());784 return Err(forbidden().into());
780 }785 }
781- let state = app_context::<AppState>(cx);786+ let state = context::<AppState>(cx);
782 let lang = lang_of(cx, &ctx);787 let lang = lang_of(cx, &ctx);
783 let frame = Frame::new(&ctx, state, lang).await?;788 let frame = Frame::new(&ctx, state, lang).await?;
784 let csrf = session.csrf_token.clone();789 let csrf = session.csrf_token.clone();
@@ -793,6 +798,7 @@ async fn hook_new_page(cx: &Cx) -> Result<impl View> {
793 798
794 #[component]799 #[component]
795 async fn hook_new_body(800 async fn hook_new_body(
801+ cx: &Cx,
796 head: RepoHead,802 head: RepoHead,
797 title: String,803 title: String,
798 archived: bool,804 archived: bool,
@@ -820,14 +826,14 @@ async fn hook_new_body(
820 /// Creates a hook. The secret is sealed before it is stored. A ping is queued on success.826 /// Creates a hook. The secret is sealed before it is stored. A ping is queued on success.
821 #[page(POST "/{owner}/{repo}/settings/hooks/new")]827 #[page(POST "/{owner}/{repo}/settings/hooks/new")]
822 async fn hook_create(cx: &Cx, Form(form): Form<HookForm>) -> Result<impl View> {828 async fn hook_create(cx: &Cx, Form(form): Form<HookForm>) -> Result<impl View> {
823- let owner = path_param::<Owner>(cx);829+ let owner = owner(cx);
824- let name = path_param::<Repo>(cx);830+ let name = repo(cx);
825 let ctx = load_repo(cx, owner, name).await?;831 let ctx = load_repo(cx, owner, name).await?;
826 let (user, session) = require_csrf(cx, &form.csrf).await?;832 let (user, session) = require_csrf(cx, &form.csrf).await?;
827 if !ctx.can_admin() || ctx.repo.archived {833 if !ctx.can_admin() || ctx.repo.archived {
828 return Err(forbidden().into());834 return Err(forbidden().into());
829 }835 }
830- let state = app_context::<AppState>(cx);836+ let state = context::<AppState>(cx);
831 let url = form.url.trim().to_owned();837 let url = form.url.trim().to_owned();
832 let events = form.events();838 let events = form.events();
833 let lang = lang_of(cx, &ctx);839 let lang = lang_of(cx, &ctx);
@@ -970,15 +976,15 @@ async fn hook_page_data(
970 /// The hook page: its form, a test button, the last deliveries and the delete form.976 /// The hook page: its form, a test button, the last deliveries and the delete form.
971 #[page("/{owner}/{repo}/settings/hooks/{hook_id}")]977 #[page("/{owner}/{repo}/settings/hooks/{hook_id}")]
972 async fn hook_page(cx: &Cx) -> Result<impl View> {978 async fn hook_page(cx: &Cx) -> Result<impl View> {
973- let owner = path_param::<Owner>(cx);979+ let owner = owner(cx);
974- let name = path_param::<Repo>(cx);980+ let name = repo(cx);
975- let id = path_param::<HookId>(cx);981+ let id = hook_id(cx);
976 let ctx = load_repo(cx, owner, name).await?;982 let ctx = load_repo(cx, owner, name).await?;
977 let (_, session) = require_user(cx).await?;983 let (_, session) = require_user(cx).await?;
978 if !ctx.can_admin() {984 if !ctx.can_admin() {
979 return Err(forbidden().into());985 return Err(forbidden().into());
980 }986 }
981- let state = app_context::<AppState>(cx);987+ let state = context::<AppState>(cx);
982 let hook = repo_hook(state, &ctx, id).await?;988 let hook = repo_hook(state, &ctx, id).await?;
983 let draft = HookDraft::of_hook(&hook);989 let draft = HookDraft::of_hook(&hook);
984 let csrf = session.csrf_token.clone();990 let csrf = session.csrf_token.clone();
@@ -998,15 +1004,15 @@ async fn hook_page(cx: &Cx) -> Result<impl View> {
998 /// page with the submitted values.1004 /// page with the submitted values.
999 #[page(POST "/{owner}/{repo}/settings/hooks/{hook_id}")]1005 #[page(POST "/{owner}/{repo}/settings/hooks/{hook_id}")]
1000 async fn hook_update(cx: &Cx, Form(form): Form<HookForm>) -> Result<impl View> {1006 async fn hook_update(cx: &Cx, Form(form): Form<HookForm>) -> Result<impl View> {
1001- let owner = path_param::<Owner>(cx);1007+ let owner = owner(cx);
1002- let name = path_param::<Repo>(cx);1008+ let name = repo(cx);
1003- let id = path_param::<HookId>(cx);1009+ let id = hook_id(cx);
1004 let ctx = load_repo(cx, owner, name).await?;1010 let ctx = load_repo(cx, owner, name).await?;
1005 let (user, session) = require_csrf(cx, &form.csrf).await?;1011 let (user, session) = require_csrf(cx, &form.csrf).await?;
1006 if !ctx.can_admin() || ctx.repo.archived {1012 if !ctx.can_admin() || ctx.repo.archived {
1007 return Err(forbidden().into());1013 return Err(forbidden().into());
1008 }1014 }
1009- let state = app_context::<AppState>(cx);1015+ let state = context::<AppState>(cx);
1010 let hook = repo_hook(state, &ctx, id).await?;1016 let hook = repo_hook(state, &ctx, id).await?;
1011 let url = form.url.trim().to_owned();1017 let url = form.url.trim().to_owned();
1012 let events = form.events();1018 let events = form.events();
@@ -1064,15 +1070,15 @@ async fn hook_update(cx: &Cx, Form(form): Form<HookForm>) -> Result<impl View> {
1064 /// Sends a ping to the hook now.1070 /// Sends a ping to the hook now.
1065 #[route(POST "/{owner}/{repo}/settings/hooks/{hook_id}/test")]1071 #[route(POST "/{owner}/{repo}/settings/hooks/{hook_id}/test")]
1066 async fn hook_test(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {1072 async fn hook_test(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
1067- let owner = path_param::<Owner>(cx);1073+ let owner = owner(cx);
1068- let name = path_param::<Repo>(cx);1074+ let name = repo(cx);
1069- let id = path_param::<HookId>(cx);1075+ let id = hook_id(cx);
1070 let ctx = load_repo(cx, owner, name).await?;1076 let ctx = load_repo(cx, owner, name).await?;
1071 require_csrf(cx, &form.csrf).await?;1077 require_csrf(cx, &form.csrf).await?;
1072 if !ctx.can_admin() || ctx.repo.archived {1078 if !ctx.can_admin() || ctx.repo.archived {
1073 return Err(forbidden().into());1079 return Err(forbidden().into());
1074 }1080 }
1075- let state = app_context::<AppState>(cx);1081+ let state = context::<AppState>(cx);
1076 let hook = repo_hook(state, &ctx, id).await?;1082 let hook = repo_hook(state, &ctx, id).await?;
1077 emit_ping(state, &hook).await?;1083 emit_ping(state, &hook).await?;
1078 Ok(back_to_hook(&title_of(&ctx), &hook.id, "tested"))1084 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> {
1081 /// Queues a new delivery with the same payload as an earlier one, then wakes the worker.1087 /// Queues a new delivery with the same payload as an earlier one, then wakes the worker.
1082 #[route(POST "/{owner}/{repo}/settings/hooks/{hook_id}/deliveries/{delivery_id}/redeliver")]1088 #[route(POST "/{owner}/{repo}/settings/hooks/{hook_id}/deliveries/{delivery_id}/redeliver")]
1083 async fn hook_redeliver(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {1089 async fn hook_redeliver(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
1084- let owner = path_param::<Owner>(cx);1090+ let owner = owner(cx);
1085- let name = path_param::<Repo>(cx);1091+ let name = repo(cx);
1086- let id = path_param::<HookId>(cx);1092+ let id = hook_id(cx);
1087- let delivery = path_param::<DeliveryId>(cx);1093+ let delivery = delivery_id(cx);
1088 let ctx = load_repo(cx, owner, name).await?;1094 let ctx = load_repo(cx, owner, name).await?;
1089 require_csrf(cx, &form.csrf).await?;1095 require_csrf(cx, &form.csrf).await?;
1090 if !ctx.can_admin() || ctx.repo.archived {1096 if !ctx.can_admin() || ctx.repo.archived {
1091 return Err(forbidden().into());1097 return Err(forbidden().into());
1092 }1098 }
1093- let state = app_context::<AppState>(cx);1099+ let state = context::<AppState>(cx);
1094 let hook = repo_hook(state, &ctx, id).await?;1100 let hook = repo_hook(state, &ctx, id).await?;
1095 match state.store.delivery(delivery).await? {1101 match state.store.delivery(delivery).await? {
1096 Some(original) if original.hook_id == hook.id => {}1102 Some(original) if original.hook_id == hook.id => {}
@@ -1104,15 +1110,15 @@ async fn hook_redeliver(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther>
1104 /// Deletes a hook and its deliveries. The box must be ticked.1110 /// Deletes a hook and its deliveries. The box must be ticked.
1105 #[route(POST "/{owner}/{repo}/settings/hooks/{hook_id}/delete")]1111 #[route(POST "/{owner}/{repo}/settings/hooks/{hook_id}/delete")]
1106 async fn hook_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther> {1112 async fn hook_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther> {
1107- let owner = path_param::<Owner>(cx);1113+ let owner = owner(cx);
1108- let name = path_param::<Repo>(cx);1114+ let name = repo(cx);
1109- let id = path_param::<HookId>(cx);1115+ let id = hook_id(cx);
1110 let ctx = load_repo(cx, owner, name).await?;1116 let ctx = load_repo(cx, owner, name).await?;
1111 let (user, _) = require_csrf(cx, &form.csrf).await?;1117 let (user, _) = require_csrf(cx, &form.csrf).await?;
1112 if !ctx.can_admin() || ctx.repo.archived {1118 if !ctx.can_admin() || ctx.repo.archived {
1113 return Err(forbidden().into());1119 return Err(forbidden().into());
1114 }1120 }
1115- let state = app_context::<AppState>(cx);1121+ let state = context::<AppState>(cx);
1116 let hook = repo_hook(state, &ctx, id).await?;1122 let hook = repo_hook(state, &ctx, id).await?;
1117 let title = title_of(&ctx);1123 let title = title_of(&ctx);
1118 if form.confirm.is_none() {1124 if form.confirm.is_none() {
crates/forge-web/src/pages/review_requests.rsmodified+11 -7
@@ -7,7 +7,7 @@
7 use forge_core::authz::{Action, authorize};7 use forge_core::authz::{Action, authorize};
8 use serde::Deserialize;8 use serde::Deserialize;
9 use topcoat::Result;9 use topcoat::Result;
10-use topcoat::context::{Cx, app_context};10+use topcoat::context::{Cx, context};
11 use topcoat::router::content::Form;11 use topcoat::router::content::Form;
12 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};12 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
13 use topcoat::router::request::uri;13 use topcoat::router::request::uri;
@@ -76,7 +76,7 @@ async fn review_requests_events(cx: &Cx) -> Result<Response> {
76 *res.status_mut() = StatusCode::UNAUTHORIZED;76 *res.status_mut() = StatusCode::UNAUTHORIZED;
77 return Ok(res);77 return Ok(res);
78 };78 };
79- let state = app_context::<AppState>(cx);79+ let state = context::<AppState>(cx);
80 stream_wakes(cx, &state.live, &[Topic::ReviewRequests(user.id)])80 stream_wakes(cx, &state.live, &[Topic::ReviewRequests(user.id)])
81 }81 }
82 82
@@ -87,11 +87,11 @@ fn refusal(code: &str, href: &str) -> SeeOther {
87 87
88 #[route(POST "/{owner}/{repo}/pulls/{number}/reviewers")]88 #[route(POST "/{owner}/{repo}/pulls/{number}/reviewers")]
89 async fn reviewers_save(cx: &Cx, Form(form): Form<ReviewerForm>) -> Result<SeeOther> {89 async fn reviewers_save(cx: &Cx, Form(form): Form<ReviewerForm>) -> Result<SeeOther> {
90- let number = parse_number(path_param::<Number>(cx))?;90+ let number = parse_number(number(cx))?;
91- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;91+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
92 let (user, session) = require_user(cx).await?;92 let (user, session) = require_user(cx).await?;
93 check_write(&ctx, &session, &form.csrf)?;93 check_write(&ctx, &session, &form.csrf)?;
94- let state = app_context::<AppState>(cx);94+ let state = context::<AppState>(cx);
95 let Some(pr) = state.store.pull_by_number(&ctx.repo.id, number).await? else {95 let Some(pr) = state.store.pull_by_number(&ctx.repo.id, number).await? else {
96 return Err(not_found().into());96 return Err(not_found().into());
97 };97 };
@@ -201,7 +201,11 @@ fn error_text(lang: Lang, code: &str) -> &'static str {
201 }201 }
202 202
203 #[component]203 #[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> {
205 let ReviewersView {209 let ReviewersView {
206 action,210 action,
207 csrf,211 csrf,
@@ -251,7 +255,7 @@ pub(crate) async fn reviewers_box(lang: Lang, reviewers: ReviewersView) -> Resul
251 #[page("/review-requests")]255 #[page("/review-requests")]
252 async fn review_requests(cx: &Cx) -> Result<impl View> {256 async fn review_requests(cx: &Cx) -> Result<impl View> {
253 let viewer = require_user(cx).await?;257 let viewer = require_user(cx).await?;
254- let state = app_context::<AppState>(cx);258+ let state = context::<AppState>(cx);
255 let user = &viewer.0;259 let user = &viewer.0;
256 let lang = i18n::lang(cx, Some(user));260 let lang = i18n::lang(cx, Some(user));
257 let items = state.store.review_requests_for_user(&user.id).await?;261 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};
11 use forge_core::{Error as CoreError, Session, Store, User};11 use forge_core::{Error as CoreError, Session, Store, User};
12 use serde::{Deserialize, Deserializer};12 use serde::{Deserialize, Deserializer};
13 use topcoat::Result;13 use topcoat::Result;
14-use topcoat::context::{Cx, app_context};14+use topcoat::context::{Cx, context};
15 use topcoat::router::content::Form;15 use topcoat::router::content::Form;
16 use topcoat::router::error::{SeeOther, see_other};16 use topcoat::router::error::{SeeOther, see_other};
17 use topcoat::router::{page, route};17 use topcoat::router::{page, route};
@@ -289,7 +289,7 @@ fn colour_group(lang: Lang, dark: bool, base: &str, accent_id: &str) -> ColourGr
289 /// vividness slider and a hex box. The Custom radio carries `hue-H-vV`, and nav.js keeps it, the289 /// vividness slider and a hex box. The Custom radio carries `hue-H-vV`, and nav.js keeps it, the
290 /// sliders and the hex box in step while the row is used.290 /// sliders and the hex box in step while the row is used.
291 #[component]291 #[component]
292-async fn colour_row(row: ColourRow) -> Result<impl View> {292+async fn colour_row(cx: &Cx, row: ColourRow) -> Result<impl View> {
293 let ColourRow {293 let ColourRow {
294 dark,294 dark,
295 base,295 base,
@@ -358,7 +358,7 @@ async fn colour_row(row: ColourRow) -> Result<impl View> {
358 358
359 /// One theme's panel: a Background row and an Accent row.359 /// One theme's panel: a Background row and an Accent row.
360 #[component]360 #[component]
361-async fn colour_panel(group: ColourGroup) -> Result<impl View> {361+async fn colour_panel(cx: &Cx, group: ColourGroup) -> Result<impl View> {
362 let ColourGroup {362 let ColourGroup {
363 dark,363 dark,
364 background,364 background,
@@ -408,7 +408,7 @@ async fn colour_panel(group: ColourGroup) -> Result<impl View> {
408 }408 }
409 409
410 #[component]410 #[component]
411-async fn appearance_body(page: AppearancePage) -> Result<impl View> {411+async fn appearance_body(cx: &Cx, page: AppearancePage) -> Result<impl View> {
412 let AppearancePage {412 let AppearancePage {
413 lang,413 lang,
414 csrf,414 csrf,
@@ -591,7 +591,7 @@ fn pref_choice(
591 async fn appearance_page(cx: &Cx) -> Result<impl View> {591 async fn appearance_page(cx: &Cx) -> Result<impl View> {
592 let viewer = require_user(cx).await?;592 let viewer = require_user(cx).await?;
593 let lang = i18n::lang(cx, Some(&viewer.0));593 let lang = i18n::lang(cx, Some(&viewer.0));
594- let prefs = app_context::<AppState>(cx)594+ let prefs = context::<AppState>(cx)
595 .store595 .store
596 .user_prefs(&viewer.0.id)596 .user_prefs(&viewer.0.id)
597 .await?;597 .await?;
@@ -609,7 +609,7 @@ async fn appearance_page(cx: &Cx) -> Result<impl View> {
609 async fn appearance_save(cx: &Cx, Form(form): Form<AppearanceForm>) -> Result<SeeOther> {609 async fn appearance_save(cx: &Cx, Form(form): Form<AppearanceForm>) -> Result<SeeOther> {
610 let viewer = require_csrf(cx, &form.csrf).await?;610 let viewer = require_csrf(cx, &form.csrf).await?;
611 let lang = i18n::lang(cx, Some(&viewer.0));611 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;
613 let user = &viewer.0;613 let user = &viewer.0;
614 614
615 check_choice(lang, &form.theme, &form.language)?;615 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;
16 use serde::Deserialize;16 use serde::Deserialize;
17 use tokio_util::io::ReaderStream;17 use tokio_util::io::ReaderStream;
18 use topcoat::Result;18 use topcoat::Result;
19-use topcoat::context::{Cx, app_context};19+use topcoat::context::{Cx, context};
20 use topcoat::router::content::Form;20 use topcoat::router::content::Form;
21 use topcoat::router::error::{SeeOther, not_found, see_other};21 use topcoat::router::error::{SeeOther, not_found, see_other};
22 use topcoat::router::response::Response;22 use topcoat::router::response::Response;
@@ -79,7 +79,12 @@ fn data_rail_items(lang: Lang, delete: bool) -> Vec<RailItem> {
79 79
80 /// The archives sheet: the request's state, and each archive with its download and delete.80 /// The archives sheet: the request's state, and each archive with its download and delete.
81 #[component]81 #[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> {
83 let building = exports.iter().any(|e| e.state == ExportState::Building);88 let building = exports.iter().any(|e| e.state == ExportState::Building);
84 let live = building.then(|| {89 let live = building.then(|| {
85 format!(90 format!(
@@ -139,6 +144,7 @@ async fn export_sheet(lang: Lang, csrf: &str, exports: Vec<DataExport>) -> Resul
139 /// username, in one reveal. Repositories still owned by the user block it, and are listed.144 /// username, in one reveal. Repositories still owned by the user block it, and are listed.
140 #[component]145 #[component]
141 async fn delete_sheet(146 async fn delete_sheet(
147+ cx: &Cx,
142 lang: Lang,148 lang: Lang,
143 csrf: &str,149 csrf: &str,
144 two_factor_on: bool,150 two_factor_on: bool,
@@ -196,6 +202,7 @@ async fn delete_sheet(
196 /// The Data page body: the head of the topic, then the rail beside its sheet.202 /// The Data page body: the head of the topic, then the rail beside its sheet.
197 #[component]203 #[component]
198 async fn data_body(204 async fn data_body(
205+ cx: &Cx,
199 lang: Lang,206 lang: Lang,
200 csrf: &str,207 csrf: &str,
201 delete: bool,208 delete: bool,
@@ -239,7 +246,7 @@ async fn page_view(
239 delete_error: Option<String>,246 delete_error: Option<String>,
240 throttled: Option<Duration>,247 throttled: Option<Duration>,
241 ) -> Result<impl View> {248 ) -> Result<impl View> {
242- let state = app_context::<AppState>(cx);249+ let state = context::<AppState>(cx);
243 let lang = i18n::lang(cx, Some(&viewer.0));250 let lang = i18n::lang(cx, Some(&viewer.0));
244 let user_id = viewer.0.id.clone();251 let user_id = viewer.0.id.clone();
245 let exports = state.store.list_exports(&user_id).await?;252 let exports = state.store.list_exports(&user_id).await?;
@@ -260,9 +267,9 @@ async fn page_view(
260 None => StatusCode::OK,267 None => StatusCode::OK,
261 };268 };
262 let csrf = viewer.1.csrf_token.clone();269 let csrf = viewer.1.csrf_token.clone();
263- // `view!` expects the `__cx` binding that `#[page]` and `#[component]` provide. This plain270+ // `view!` expects the `cx` binding that `#[page]` and `#[component]` provide. This plain
264 // helper has to bind it itself.271 // helper has to bind it itself.
265- let __cx = cx;272+ let cx = cx;
266 Ok(view! {273 Ok(view! {
267 (status)274 (status)
268 (headers)275 (headers)
@@ -286,16 +293,23 @@ pub(crate) async fn respond_delete(
286 #[page("/settings/export")]293 #[page("/settings/export")]
287 async fn export_page(cx: &Cx) -> Result<impl View> {294 async fn export_page(cx: &Cx) -> Result<impl View> {
288 let viewer = require_user(cx).await?;295 let viewer = require_user(cx).await?;
289- let state = app_context::<AppState>(cx);296+ let state = context::<AppState>(cx);
290 exporter::sweep_expired(state).await;297 exporter::sweep_expired(state).await;
291 let query = query_params::<TopicQuery>(cx)?;298 let query = query_params::<TopicQuery>(cx)?;
292- page_view(cx, viewer, query.part.as_deref() == Some("delete"), None, None).await299+ page_view(
300+ cx,
301+ viewer,
302+ query.part.as_deref() == Some("delete"),
303+ None,
304+ None,
305+ )
306+ .await
293 }307 }
294 308
295 #[route(POST "/settings/export")]309 #[route(POST "/settings/export")]
296 async fn export_request(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {310 async fn export_request(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
297 let viewer = require_csrf(cx, &form.csrf).await?;311 let viewer = require_csrf(cx, &form.csrf).await?;
298- let state = app_context::<AppState>(cx);312+ let state = context::<AppState>(cx);
299 exporter::start(state, &viewer.0).await?;313 exporter::start(state, &viewer.0).await?;
300 Err(see_other("/settings/export").into())314 Err(see_other("/settings/export").into())
301 }315 }
@@ -304,8 +318,8 @@ async fn export_request(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther>
304 #[route(POST "/settings/export/{export_id}/delete")]318 #[route(POST "/settings/export/{export_id}/delete")]
305 async fn export_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {319 async fn export_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
306 let viewer = require_csrf(cx, &form.csrf).await?;320 let viewer = require_csrf(cx, &form.csrf).await?;
307- let id = path_param::<ExportId>(cx).to_owned();321+ let id = export_id(cx).to_owned();
308- let state = app_context::<AppState>(cx);322+ let state = context::<AppState>(cx);
309 let export = match state.store.data_export(&id).await? {323 let export = match state.store.data_export(&id).await? {
310 Some(e) if e.user_id == viewer.0.id && e.state != ExportState::Building => e,324 Some(e) if e.user_id == viewer.0.id && e.state != ExportState::Building => e,
311 _ => return Err(not_found().into()),325 _ => return Err(not_found().into()),
@@ -320,7 +334,7 @@ async fn export_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther>
320 async fn export_events(cx: &Cx) -> Result<Response> {334 async fn export_events(cx: &Cx) -> Result<Response> {
321 let viewer = require_user(cx).await?;335 let viewer = require_user(cx).await?;
322 let query = query_params::<SeenQuery>(cx)?;336 let query = query_params::<SeenQuery>(cx)?;
323- let state = app_context::<AppState>(cx);337+ let state = context::<AppState>(cx);
324 let user_id = viewer.0.id.clone();338 let user_id = viewer.0.id.clone();
325 let wake = exporter::subscribe(&user_id);339 let wake = exporter::subscribe(&user_id);
326 let store = state.store.clone();340 let store = state.store.clone();
@@ -354,8 +368,8 @@ async fn export_events(cx: &Cx) -> Result<Response> {
354 #[route(GET "/settings/export/{export_id}/download")]368 #[route(GET "/settings/export/{export_id}/download")]
355 async fn export_download(cx: &Cx) -> Result<Response> {369 async fn export_download(cx: &Cx) -> Result<Response> {
356 let viewer = require_user(cx).await?;370 let viewer = require_user(cx).await?;
357- let id = path_param::<ExportId>(cx).to_owned();371+ let id = export_id(cx).to_owned();
358- let state = app_context::<AppState>(cx);372+ let state = context::<AppState>(cx);
359 exporter::sweep_expired(state).await;373 exporter::sweep_expired(state).await;
360 let export = match state.store.data_export(&id).await? {374 let export = match state.store.data_export(&id).await? {
361 Some(e) if e.user_id == viewer.0.id && e.state == ExportState::Ready => e,375 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;
5 use forge_core::store::signatures::GpgKey;5 use forge_core::store::signatures::GpgKey;
6 use serde::Deserialize;6 use serde::Deserialize;
7 use topcoat::Result;7 use topcoat::Result;
8-use topcoat::context::{Cx, app_context};8+use topcoat::context::{Cx, context};
9 use topcoat::router::content::Form;9 use topcoat::router::content::Form;
10 use topcoat::router::error::{SeeOther, not_found, see_other};10 use topcoat::router::error::{SeeOther, not_found, see_other};
11 use topcoat::router::{page, query_params, route};11 use topcoat::router::{page, query_params, route};
@@ -39,6 +39,7 @@ struct DeleteKeyForm {
39 39
40 #[component]40 #[component]
41 pub(crate) async fn gpg_section(41 pub(crate) async fn gpg_section(
42+ cx: &Cx,
42 lang: Lang,43 lang: Lang,
43 csrf: &str,44 csrf: &str,
44 keys: Vec<GpgKey>,45 keys: Vec<GpgKey>,
@@ -87,7 +88,7 @@ pub(crate) async fn gpg_section(
87 async fn gpg_page(cx: &Cx) -> Result<impl View> {88 async fn gpg_page(cx: &Cx) -> Result<impl View> {
88 let viewer = require_user(cx).await?;89 let viewer = require_user(cx).await?;
89 let lang = i18n::lang(cx, Some(&viewer.0));90 let lang = i18n::lang(cx, Some(&viewer.0));
90- let state = app_context::<AppState>(cx);91+ let state = context::<AppState>(cx);
91 let draft = KeysDraft {92 let draft = KeysDraft {
92 add: query_params::<AddQuery>(cx)?.add.is_some(),93 add: query_params::<AddQuery>(cx)?.add.is_some(),
93 ..KeysDraft::default()94 ..KeysDraft::default()
@@ -101,7 +102,7 @@ async fn gpg_page(cx: &Cx) -> Result<impl View> {
101 async fn gpg_add(cx: &Cx, Form(form): Form<AddKeyForm>) -> Result<impl View> {102 async fn gpg_add(cx: &Cx, Form(form): Form<AddKeyForm>) -> Result<impl View> {
102 let viewer = require_csrf(cx, &form.csrf).await?;103 let viewer = require_csrf(cx, &form.csrf).await?;
103 let lang = i18n::lang(cx, Some(&viewer.0));104 let lang = i18n::lang(cx, Some(&viewer.0));
104- let state = app_context::<AppState>(cx);105+ let state = context::<AppState>(cx);
105 106
106 let message: String = match signatures::import_gpg_key(state, &form.armored).await {107 let message: String = match signatures::import_gpg_key(state, &form.armored).await {
107 Err(message) => message,108 Err(message) => message,
@@ -149,7 +150,7 @@ async fn gpg_add(cx: &Cx, Form(form): Form<AddKeyForm>) -> Result<impl View> {
149 #[route(POST "/settings/gpg/delete")]150 #[route(POST "/settings/gpg/delete")]
150 async fn gpg_delete(cx: &Cx, Form(form): Form<DeleteKeyForm>) -> Result<SeeOther> {151 async fn gpg_delete(cx: &Cx, Form(form): Form<DeleteKeyForm>) -> Result<SeeOther> {
151 let (user, _) = require_csrf(cx, &form.csrf).await?;152 let (user, _) = require_csrf(cx, &form.csrf).await?;
152- let state = app_context::<AppState>(cx);153+ let state = context::<AppState>(cx);
153 // `delete_gpg_key` only matches the viewer's own keys, so anything else is a 404.154 // `delete_gpg_key` only matches the viewer's own keys, so anything else is a 404.
154 let Some(key) = state.store.delete_gpg_key(&user.id, &form.id).await? else {155 let Some(key) = state.store.delete_gpg_key(&user.id, &form.id).await? else {
155 return Err(not_found().into());156 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};
6 use serde::Deserialize;6 use serde::Deserialize;
7 use sha2::{Digest, Sha256};7 use sha2::{Digest, Sha256};
8 use topcoat::Result;8 use topcoat::Result;
9-use topcoat::context::{Cx, app_context};9+use topcoat::context::{Cx, context};
10 use topcoat::router::content::Form;10 use topcoat::router::content::Form;
11 use topcoat::router::error::{SeeOther, see_other};11 use topcoat::router::error::{SeeOther, see_other};
12 use topcoat::router::{page, query_params, route};12 use topcoat::router::{page, query_params, route};
@@ -195,6 +195,7 @@ pub(crate) struct AddQuery {
195 /// The keys page for the viewer, one kind at a time, with what a form sent back.195 /// The keys page for the viewer, one kind at a time, with what a form sent back.
196 #[component]196 #[component]
197 pub(crate) async fn keys_page_view(197 pub(crate) async fn keys_page_view(
198+ cx: &Cx,
198 lang: Lang,199 lang: Lang,
199 state: &AppState,200 state: &AppState,
200 viewer: &(User, Session),201 viewer: &(User, Session),
@@ -255,6 +256,7 @@ fn pk_title(lang: Lang) -> &'static str {
255 256
256 #[component]257 #[component]
257 async fn ssh_section(258 async fn ssh_section(
259+ cx: &Cx,
258 lang: Lang,260 lang: Lang,
259 csrf: &str,261 csrf: &str,
260 keys: Vec<SshKey>,262 keys: Vec<SshKey>,
@@ -303,7 +305,7 @@ async fn ssh_section(
303 async fn keys_page(cx: &Cx) -> Result<impl View> {305 async fn keys_page(cx: &Cx) -> Result<impl View> {
304 let viewer = require_user(cx).await?;306 let viewer = require_user(cx).await?;
305 let lang = i18n::lang(cx, Some(&viewer.0));307 let lang = i18n::lang(cx, Some(&viewer.0));
306- let state = app_context::<AppState>(cx);308+ let state = context::<AppState>(cx);
307 let draft = KeysDraft {309 let draft = KeysDraft {
308 add: query_params::<AddQuery>(cx)?.add.is_some(),310 add: query_params::<AddQuery>(cx)?.add.is_some(),
309 ..KeysDraft::default()311 ..KeysDraft::default()
@@ -317,7 +319,7 @@ async fn keys_page(cx: &Cx) -> Result<impl View> {
317 async fn keys_add(cx: &Cx, Form(form): Form<AddKeyForm>) -> Result<impl View> {319 async fn keys_add(cx: &Cx, Form(form): Form<AddKeyForm>) -> Result<impl View> {
318 let viewer = require_csrf(cx, &form.csrf).await?;320 let viewer = require_csrf(cx, &form.csrf).await?;
319 let lang = i18n::lang(cx, Some(&viewer.0));321 let lang = i18n::lang(cx, Some(&viewer.0));
320- let state = app_context::<AppState>(cx);322+ let state = context::<AppState>(cx);
321 let store = &state.store;323 let store = &state.store;
322 324
323 let outcome: std::result::Result<(), String> = match parse_public_key(&form.public_key) {325 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> {
375 #[route(POST "/settings/keys/delete")]377 #[route(POST "/settings/keys/delete")]
376 async fn keys_delete(cx: &Cx, Form(form): Form<DeleteKeyForm>) -> Result<SeeOther> {378 async fn keys_delete(cx: &Cx, Form(form): Form<DeleteKeyForm>) -> Result<SeeOther> {
377 let (user, _) = require_csrf(cx, &form.csrf).await?;379 let (user, _) = require_csrf(cx, &form.csrf).await?;
378- let state = app_context::<AppState>(cx);380+ let state = context::<AppState>(cx);
379 if state.store.delete_ssh_key(&user.id, &form.id).await? {381 if state.store.delete_ssh_key(&user.id, &form.id).await? {
380 audit::record(382 audit::record(
381 &state.store,383 &state.store,
crates/forge-web/src/pages/settings_live.rsmodified+4 -4
@@ -27,7 +27,7 @@ use forge_core::server_settings::{self, FIELDS, Kind};
27 use futures_util::stream::{self, BoxStream, StreamExt};27 use futures_util::stream::{self, BoxStream, StreamExt};
28 use tokio::sync::watch;28 use tokio::sync::watch;
29 use topcoat::Result;29 use topcoat::Result;
30-use topcoat::context::{Cx, app_context, try_app_context};30+use topcoat::context::{Cx, context, try_context};
31 use topcoat::router::content::sse::Event;31 use topcoat::router::content::sse::Event;
32 use topcoat::router::request::{method, uri};32 use topcoat::router::request::{method, uri};
33 use topcoat::router::response::Response;33 use topcoat::router::response::Response;
@@ -52,7 +52,7 @@ async fn settings_events(cx: &Cx) -> Result<Response> {
52 *res.status_mut() = StatusCode::UNAUTHORIZED;52 *res.status_mut() = StatusCode::UNAUTHORIZED;
53 return Ok(res);53 return Ok(res);
54 };54 };
55- let hub: &LiveHub = &app_context::<AppState>(cx).live;55+ let hub: &LiveHub = &context::<AppState>(cx).live;
56 stream_wakes(cx, hub, &[Topic::Account(user.id)])56 stream_wakes(cx, hub, &[Topic::Account(user.id)])
57 }57 }
58 58
@@ -166,7 +166,7 @@ async fn wait_account(account: &mut Option<AccountFollow>) -> bool {
166 /// means the server is back.166 /// means the server is back.
167 pub async fn alive_response(cx: &Cx) -> Result<Response> {167 pub async fn alive_response(cx: &Cx) -> Result<Response> {
168 // A router with no app state (the asset tests) has nothing to follow: the stream only stays open.168 // 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 {
170 return events_response(cx, stream::pending::<Result<Event>>());170 return events_response(cx, stream::pending::<Result<Event>>());
171 };171 };
172 let viewer = current_user(cx)172 let viewer = current_user(cx)
@@ -305,7 +305,7 @@ async fn bump_after_settings_write(cx: &Cx, body: Body, next: Next<'_>) -> Resul
305 .map(|(user, _)| user.id);305 .map(|(user, _)| user.id);
306 let result = next.run(cx, body).await;306 let result = next.run(cx, body).await;
307 if let Some(user_id) = viewer {307 if let Some(user_id) = viewer {
308- bump_account(app_context::<AppState>(cx), &user_id);308+ bump_account(context::<AppState>(cx), &user_id);
309 }309 }
310 result310 result
311 }311 }
crates/forge-web/src/pages/settings_notifications.rsmodified+4 -4
@@ -8,7 +8,7 @@ use forge_core::store::web_push::PushSubscription;
8 use forge_core::{Session, Store, User};8 use forge_core::{Session, Store, User};
9 use serde::Deserialize;9 use serde::Deserialize;
10 use topcoat::Result;10 use topcoat::Result;
11-use topcoat::context::{Cx, app_context};11+use topcoat::context::{Cx, context};
12 use topcoat::router::content::Form;12 use topcoat::router::content::Form;
13 use topcoat::router::error::{SeeOther, see_other};13 use topcoat::router::error::{SeeOther, see_other};
14 use topcoat::router::{page, query_params, route};14 use topcoat::router::{page, query_params, route};
@@ -56,7 +56,7 @@ struct NotificationsPage {
56 }56 }
57 57
58 #[component]58 #[component]
59-async fn notifications_body(page: NotificationsPage) -> Result<impl View> {59+async fn notifications_body(cx: &Cx, page: NotificationsPage) -> Result<impl View> {
60 let NotificationsPage {60 let NotificationsPage {
61 lang,61 lang,
62 csrf,62 csrf,
@@ -166,7 +166,7 @@ async fn page_for(
166 #[page("/settings/notifications")]166 #[page("/settings/notifications")]
167 async fn notifications_page(cx: &Cx) -> Result<impl View> {167 async fn notifications_page(cx: &Cx) -> Result<impl View> {
168 let viewer = require_user(cx).await?;168 let viewer = require_user(cx).await?;
169- let store: &Store = &app_context::<AppState>(cx).store;169+ let store: &Store = &context::<AppState>(cx).store;
170 let lang = i18n::lang(cx, Some(&viewer.0));170 let lang = i18n::lang(cx, Some(&viewer.0));
171 let query = query_params::<NotificationsQuery>(cx)?;171 let query = query_params::<NotificationsQuery>(cx)?;
172 let notice = if query.saved.as_deref() == Some("1") {172 let notice = if query.saved.as_deref() == Some("1") {
@@ -191,7 +191,7 @@ async fn notifications_page(cx: &Cx) -> Result<impl View> {
191 #[route(POST "/settings/notifications")]191 #[route(POST "/settings/notifications")]
192 async fn notifications_save(cx: &Cx, Form(form): Form<NotificationsForm>) -> Result<SeeOther> {192 async fn notifications_save(cx: &Cx, Form(form): Form<NotificationsForm>) -> Result<SeeOther> {
193 let viewer = require_csrf(cx, &form.csrf).await?;193 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;
195 store195 store
196 .set_email_notifications(&viewer.0.id, form.email_notifications.is_some())196 .set_email_notifications(&viewer.0.id, form.email_notifications.is_some())
197 .await?;197 .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
12 use serde::Deserialize;12 use serde::Deserialize;
13 use tokio::sync::Semaphore;13 use tokio::sync::Semaphore;
14 use topcoat::Result;14 use topcoat::Result;
15-use topcoat::context::{Cx, app_context};15+use topcoat::context::{Cx, context};
16 use topcoat::router::content::Form;16 use topcoat::router::content::Form;
17 use topcoat::router::content::multipart::Multipart;17 use topcoat::router::content::multipart::Multipart;
18 use topcoat::router::error::{SeeOther, see_other};18 use topcoat::router::error::{SeeOther, see_other};
@@ -33,16 +33,8 @@ pub const MAX_ABOUT_CHARS: usize = 2000;
33 /// Multipart framing overhead allowed on top of the image itself.33 /// Multipart framing overhead allowed on top of the image itself.
34 const MULTIPART_OVERHEAD: usize = 64 * 1024;34 const MULTIPART_OVERHEAD: usize = 64 * 1024;
35 35
36-/// Body limit for the avatar upload route. The default 2 MiB is too small for a 5 MiB image.36+/// Body limit for the avatar upload routes. The default 2 MiB is too small for a 5 MiB image.
37-pub fn avatar_body_limit() -> BodyLimit {37+pub const AVATAR_BODY_LIMIT: usize = MAX_UPLOAD_BYTES + MULTIPART_OVERHEAD;
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-}
46 38
47 #[query_params(error = bad_request)]39 #[query_params(error = bad_request)]
48 struct ProfileQuery {40 struct ProfileQuery {
@@ -127,7 +119,7 @@ struct ProfilePage {
127 }119 }
128 120
129 #[component]121 #[component]
130-async fn profile_body(page: ProfilePage) -> Result<impl View> {122+async fn profile_body(cx: &Cx, page: ProfilePage) -> Result<impl View> {
131 let ProfilePage {123 let ProfilePage {
132 lang,124 lang,
133 csrf,125 csrf,
@@ -352,7 +344,7 @@ async fn profile_page(cx: &Cx) -> Result<impl View> {
352 async fn profile_save(cx: &Cx, Form(form): Form<ProfileForm>) -> Result<impl View> {344 async fn profile_save(cx: &Cx, Form(form): Form<ProfileForm>) -> Result<impl View> {
353 let viewer = require_csrf(cx, &form.csrf).await?;345 let viewer = require_csrf(cx, &form.csrf).await?;
354 let lang = i18n::lang(cx, Some(&viewer.0));346 let lang = i18n::lang(cx, Some(&viewer.0));
355- let store = &app_context::<AppState>(cx).store;347+ let store = &context::<AppState>(cx).store;
356 let about = form.about.replace("\r\n", "\n");348 let about = form.about.replace("\r\n", "\n");
357 349
358 let mut errors = Errors::default();350 let mut errors = Errors::default();
@@ -413,14 +405,14 @@ async fn profile_save(cx: &Cx, Form(form): Form<ProfileForm>) -> Result<impl Vie
413 }405 }
414 // The public profile shows the name, the username and the about text: its viewers follow the406 // The public profile shows the name, the username and the about text: its viewers follow the
415 // user's topic too.407 // user's topic too.
416- app_context::<AppState>(cx)408+ context::<AppState>(cx)
417 .live409 .live
418 .bump(&Topic::User(viewer.0.id.clone()));410 .bump(&Topic::User(viewer.0.id.clone()));
419 Err(see_other("/settings/profile?saved=1").into())411 Err(see_other("/settings/profile?saved=1").into())
420 }412 }
421 413
422 /// Reads the multipart body. The CSRF field is checked before the image is decoded.414 /// 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)))]
424 async fn avatar_upload(cx: &Cx, mut multipart: Multipart) -> Result<impl View> {416 async fn avatar_upload(cx: &Cx, mut multipart: Multipart) -> Result<impl View> {
425 let mut csrf = String::new();417 let mut csrf = String::new();
426 let mut image = None;418 let mut image = None;
@@ -434,11 +426,11 @@ async fn avatar_upload(cx: &Cx, mut multipart: Multipart) -> Result<impl View> {
434 }426 }
435 let viewer = require_csrf(cx, &csrf).await?;427 let viewer = require_csrf(cx, &csrf).await?;
436 let lang = i18n::lang(cx, Some(&viewer.0));428 let lang = i18n::lang(cx, Some(&viewer.0));
437- let store = &app_context::<AppState>(cx).store;429+ let store = &context::<AppState>(cx).store;
438 430
439 let message = match store_avatar(store, &viewer.0.id, image, lang).await {431 let message = match store_avatar(store, &viewer.0.id, image, lang).await {
440 Ok(()) => {432 Ok(()) => {
441- app_context::<AppState>(cx)433+ context::<AppState>(cx)
442 .live434 .live
443 .bump(&Topic::User(viewer.0.id.clone()));435 .bump(&Topic::User(viewer.0.id.clone()));
444 return Err(see_other("/settings/profile?saved=avatar").into());436 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> {
461 #[route(POST "/settings/profile/avatar/delete")]453 #[route(POST "/settings/profile/avatar/delete")]
462 async fn avatar_remove(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {454 async fn avatar_remove(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
463 let viewer = require_csrf(cx, &form.csrf).await?;455 let viewer = require_csrf(cx, &form.csrf).await?;
464- let state = app_context::<AppState>(cx);456+ let state = context::<AppState>(cx);
465 state.store.delete_avatar(&viewer.0.id).await?;457 state.store.delete_avatar(&viewer.0.id).await?;
466 state.live.bump(&Topic::User(viewer.0.id.clone()));458 state.live.bump(&Topic::User(viewer.0.id.clone()));
467 Ok(see_other("/settings/profile?saved=avatar-removed"))459 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};
11 use http::header::{HeaderValue, RETRY_AFTER};11 use http::header::{HeaderValue, RETRY_AFTER};
12 use serde::Deserialize;12 use serde::Deserialize;
13 use topcoat::Result;13 use topcoat::Result;
14-use topcoat::context::{Cx, app_context};14+use topcoat::context::{Cx, context};
15 use topcoat::router::content::Form;15 use topcoat::router::content::Form;
16 use topcoat::router::error::{SeeOther, see_other};16 use topcoat::router::error::{SeeOther, see_other};
17 use topcoat::router::{HeaderMap, StatusCode, page, query_params, route};17 use topcoat::router::{HeaderMap, StatusCode, page, query_params, route};
@@ -274,7 +274,7 @@ pub(crate) async fn security_rail_for(
274 }274 }
275 275
276 #[component]276 #[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> {
278 let SecurityPage {278 let SecurityPage {
279 lang,279 lang,
280 email,280 email,
@@ -656,10 +656,10 @@ async fn build_page(
656 656
657 /// Renders the page. A throttled check answers 429 with `Retry-After`.657 /// Renders the page. A throttled check answers 429 with `Retry-After`.
658 async fn respond(cx: &Cx, viewer: (User, Session), shown: Shown) -> Result<impl View> {658 async fn respond(cx: &Cx, viewer: (User, Session), shown: Shown) -> Result<impl View> {
659- let state = app_context::<AppState>(cx);659+ let state = context::<AppState>(cx);
660- // `view!` expects the `__cx` binding that `#[page]` and `#[component]` provide. This plain660+ // `view!` expects the `cx` binding that `#[page]` and `#[component]` provide. This plain
661 // helper has to bind it itself.661 // helper has to bind it itself.
662- let __cx = cx;662+ let cx = cx;
663 let mut headers = HeaderMap::new();663 let mut headers = HeaderMap::new();
664 let status = match shown.throttled {664 let status = match shown.throttled {
665 Some(retry) => {665 Some(retry) => {
@@ -779,7 +779,7 @@ async fn security_page(cx: &Cx) -> Result<impl View> {
779 async fn password_change(cx: &Cx, Form(form): Form<PasswordForm>) -> Result<impl View> {779 async fn password_change(cx: &Cx, Form(form): Form<PasswordForm>) -> Result<impl View> {
780 let viewer = require_csrf(cx, &form.csrf).await?;780 let viewer = require_csrf(cx, &form.csrf).await?;
781 let lang = i18n::lang(cx, Some(&viewer.0));781 let lang = i18n::lang(cx, Some(&viewer.0));
782- let state = app_context::<AppState>(cx);782+ let state = context::<AppState>(cx);
783 let mut shown = Shown::default();783 let mut shown = Shown::default();
784 if let Err(refused) = require_password(lang, state, &viewer.0, &form.current_password).await? {784 if let Err(refused) = require_password(lang, state, &viewer.0, &form.current_password).await? {
785 shown.password_error = Some(refused.message.into());785 shown.password_error = Some(refused.message.into());
@@ -822,7 +822,7 @@ async fn password_change(cx: &Cx, Form(form): Form<PasswordForm>) -> Result<impl
822 async fn email_change(cx: &Cx, Form(form): Form<EmailForm>) -> Result<impl View> {822 async fn email_change(cx: &Cx, Form(form): Form<EmailForm>) -> Result<impl View> {
823 let viewer = require_csrf(cx, &form.csrf).await?;823 let viewer = require_csrf(cx, &form.csrf).await?;
824 let lang = i18n::lang(cx, Some(&viewer.0));824 let lang = i18n::lang(cx, Some(&viewer.0));
825- let state = app_context::<AppState>(cx);825+ let state = context::<AppState>(cx);
826 let email = form.email.trim().to_owned();826 let email = form.email.trim().to_owned();
827 let mut shown = Shown {827 let mut shown = Shown {
828 email_draft: Some(email.clone()),828 email_draft: Some(email.clone()),
@@ -865,7 +865,7 @@ async fn email_change(cx: &Cx, Form(form): Form<EmailForm>) -> Result<impl View>
865 #[route(POST "/settings/security/2fa/enable")]865 #[route(POST "/settings/security/2fa/enable")]
866 async fn two_factor_enable(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {866 async fn two_factor_enable(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
867 let (user, _session) = require_csrf(cx, &form.csrf).await?;867 let (user, _session) = require_csrf(cx, &form.csrf).await?;
868- let state = app_context::<AppState>(cx);868+ let state = context::<AppState>(cx);
869 if !two_factor_enabled(&state.store, &user.id).await? {869 if !two_factor_enabled(&state.store, &user.id).await? {
870 // A new enrollment replaces any unconfirmed secret.870 // A new enrollment replaces any unconfirmed secret.
871 let sealed = secret::seal(&state.key, &totp::new_secret())?;871 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
878 async fn two_factor_confirm(cx: &Cx, Form(form): Form<EnrollForm>) -> Result<impl View> {878 async fn two_factor_confirm(cx: &Cx, Form(form): Form<EnrollForm>) -> Result<impl View> {
879 let viewer = require_csrf(cx, &form.csrf).await?;879 let viewer = require_csrf(cx, &form.csrf).await?;
880 let lang = i18n::lang(cx, Some(&viewer.0));880 let lang = i18n::lang(cx, Some(&viewer.0));
881- let state = app_context::<AppState>(cx);881+ let state = context::<AppState>(cx);
882 let user_id = viewer.0.id.clone();882 let user_id = viewer.0.id.clone();
883 let Some(totp_state) = state.store.totp_state(&user_id).await? else {883 let Some(totp_state) = state.store.totp_state(&user_id).await? else {
884 return Err(see_other("/settings/security").into());884 return Err(see_other("/settings/security").into());
@@ -938,7 +938,7 @@ async fn two_factor_confirm(cx: &Cx, Form(form): Form<EnrollForm>) -> Result<imp
938 async fn two_factor_disable(cx: &Cx, Form(form): Form<DisableForm>) -> Result<impl View> {938 async fn two_factor_disable(cx: &Cx, Form(form): Form<DisableForm>) -> Result<impl View> {
939 let viewer = require_csrf(cx, &form.csrf).await?;939 let viewer = require_csrf(cx, &form.csrf).await?;
940 let lang = i18n::lang(cx, Some(&viewer.0));940 let lang = i18n::lang(cx, Some(&viewer.0));
941- let state = app_context::<AppState>(cx);941+ let state = context::<AppState>(cx);
942 let user_id = viewer.0.id.clone();942 let user_id = viewer.0.id.clone();
943 if !two_factor_enabled(&state.store, &user_id).await? {943 if !two_factor_enabled(&state.store, &user_id).await? {
944 return Err(see_other("/settings/security").into());944 return Err(see_other("/settings/security").into());
@@ -981,7 +981,7 @@ async fn two_factor_disable(cx: &Cx, Form(form): Form<DisableForm>) -> Result<im
981 async fn account_delete(cx: &Cx, Form(form): Form<DeleteAccountForm>) -> Result<impl View> {981 async fn account_delete(cx: &Cx, Form(form): Form<DeleteAccountForm>) -> Result<impl View> {
982 let viewer = require_csrf(cx, &form.csrf).await?;982 let viewer = require_csrf(cx, &form.csrf).await?;
983 let lang = i18n::lang(cx, Some(&viewer.0));983 let lang = i18n::lang(cx, Some(&viewer.0));
984- let state = app_context::<AppState>(cx);984+ let state = context::<AppState>(cx);
985 let user_id = viewer.0.id.clone();985 let user_id = viewer.0.id.clone();
986 if form.confirm_username != viewer.0.username {986 if form.confirm_username != viewer.0.username {
987 let error = Some(t(lang, Key::ErrConfirmUsername).into());987 let error = Some(t(lang, Key::ErrConfirmUsername).into());
@@ -1036,7 +1036,7 @@ async fn account_delete(cx: &Cx, Form(form): Form<DeleteAccountForm>) -> Result<
1036 async fn two_factor_recovery(cx: &Cx, Form(form): Form<CodeForm>) -> Result<impl View> {1036 async fn two_factor_recovery(cx: &Cx, Form(form): Form<CodeForm>) -> Result<impl View> {
1037 let viewer = require_csrf(cx, &form.csrf).await?;1037 let viewer = require_csrf(cx, &form.csrf).await?;
1038 let lang = i18n::lang(cx, Some(&viewer.0));1038 let lang = i18n::lang(cx, Some(&viewer.0));
1039- let state = app_context::<AppState>(cx);1039+ let state = context::<AppState>(cx);
1040 let user_id = viewer.0.id.clone();1040 let user_id = viewer.0.id.clone();
1041 if !two_factor_enabled(&state.store, &user_id).await? {1041 if !two_factor_enabled(&state.store, &user_id).await? {
1042 return Err(see_other("/settings/security").into());1042 return Err(see_other("/settings/security").into());
@@ -1089,7 +1089,7 @@ mod tests {
1089 use forge_core::token::hash_token;1089 use forge_core::token::hash_token;
1090 use forge_core::{Config, Registration, Store, User, secret, totp};1090 use forge_core::{Config, Registration, Store, User, secret, totp};
1091 use forge_git::GitEnv;1091 use forge_git::GitEnv;
1092- use topcoat::cookie::RouterBuilderCookieExt;1092+ use topcoat::cookie::CookieLayer;
1093 use topcoat::router::request::Request;1093 use topcoat::router::request::Request;
1094 use topcoat::router::{Body, Router, RouterBuilderDiscoverExt, to_bytes};1094 use topcoat::router::{Body, Router, RouterBuilderDiscoverExt, to_bytes};
1095 1095
@@ -1184,8 +1184,8 @@ mod tests {
1184 .unwrap();1184 .unwrap();
1185 let router = Router::builder()1185 let router = Router::builder()
1186 .discover()1186 .discover()
1187- .cookies()1187+ .layer(CookieLayer::new())
1188- .app_context(state.clone())1188+ .with(state.clone())
1189 .build();1189 .build();
1190 Fixture {1190 Fixture {
1191 router,1191 router,
crates/forge-web/src/pages/settings_sessions.rsmodified+4 -4
@@ -5,7 +5,7 @@
5 use forge_core::{AuditAction, Session};5 use forge_core::{AuditAction, Session};
6 use serde::Deserialize;6 use serde::Deserialize;
7 use topcoat::Result;7 use topcoat::Result;
8-use topcoat::context::{Cx, app_context};8+use topcoat::context::{Cx, context};
9 use topcoat::router::content::Form;9 use topcoat::router::content::Form;
10 use topcoat::router::error::{SeeOther, see_other};10 use topcoat::router::error::{SeeOther, see_other};
11 use topcoat::router::route;11 use topcoat::router::route;
@@ -55,7 +55,7 @@ async fn sessions_revoke(cx: &Cx, Form(form): Form<RevokeForm>) -> Result<SeeOth
55 let (user, current) = require_csrf(cx, &form.csrf).await?;55 let (user, current) = require_csrf(cx, &form.csrf).await?;
56 if form.id == current.id {56 if form.id == current.id {
57 audit::record(57 audit::record(
58- &app_context::<AppState>(cx).store,58+ &context::<AppState>(cx).store,
59 Some(cx),59 Some(cx),
60 Actor::User(&user),60 Actor::User(&user),
61 AuditAction::SessionRevoked,61 AuditAction::SessionRevoked,
@@ -70,7 +70,7 @@ async fn sessions_revoke(cx: &Cx, Form(form): Form<RevokeForm>) -> Result<SeeOth
70 logout(cx, &current).await?;70 logout(cx, &current).await?;
71 return Ok(see_other("/"));71 return Ok(see_other("/"));
72 }72 }
73- let store = &app_context::<AppState>(cx).store;73+ let store = &context::<AppState>(cx).store;
74 // Only revoke sessions that belong to the signed-in user.74 // Only revoke sessions that belong to the signed-in user.
75 let owned = store.list_sessions(&user.id).await?;75 let owned = store.list_sessions(&user.id).await?;
76 if owned.iter().any(|s| s.id == form.id) {76 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
95 #[route(POST "/settings/sessions/revoke-others")]95 #[route(POST "/settings/sessions/revoke-others")]
96 async fn sessions_revoke_others(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {96 async fn sessions_revoke_others(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> {
97 let (user, current) = require_csrf(cx, &form.csrf).await?;97 let (user, current) = require_csrf(cx, &form.csrf).await?;
98- let store = &app_context::<AppState>(cx).store;98+ let store = &context::<AppState>(cx).store;
99 let mut revoked = 0_u64;99 let mut revoked = 0_u64;
100 for session in store.list_sessions(&user.id).await? {100 for session in store.list_sessions(&user.id).await? {
101 if session.id != current.id {101 if session.id != current.id {
crates/forge-web/src/pages/settings_tokens.rsmodified+5 -4
@@ -9,7 +9,7 @@ use http::HeaderValue;
9 use http::header::CACHE_CONTROL;9 use http::header::CACHE_CONTROL;
10 use serde::Deserialize;10 use serde::Deserialize;
11 use topcoat::Result;11 use topcoat::Result;
12-use topcoat::context::{Cx, app_context};12+use topcoat::context::{Cx, context};
13 use topcoat::router::content::Form;13 use topcoat::router::content::Form;
14 use topcoat::router::error::{SeeOther, see_other};14 use topcoat::router::error::{SeeOther, see_other};
15 use topcoat::router::response::response_headers;15 use topcoat::router::response::response_headers;
@@ -66,6 +66,7 @@ fn expiry_days(choice: &str) -> Option<u64> {
66 66
67 #[component]67 #[component]
68 pub(crate) async fn tokens_section(68 pub(crate) async fn tokens_section(
69+ cx: &Cx,
69 lang: Lang,70 lang: Lang,
70 csrf: &str,71 csrf: &str,
71 tokens: Vec<AccessToken>,72 tokens: Vec<AccessToken>,
@@ -133,7 +134,7 @@ pub(crate) async fn tokens_section(
133 async fn tokens_page(cx: &Cx) -> Result<impl View> {134 async fn tokens_page(cx: &Cx) -> Result<impl View> {
134 let viewer = require_user(cx).await?;135 let viewer = require_user(cx).await?;
135 let lang = i18n::lang(cx, Some(&viewer.0));136 let lang = i18n::lang(cx, Some(&viewer.0));
136- let state = app_context::<AppState>(cx);137+ let state = context::<AppState>(cx);
137 let draft = KeysDraft {138 let draft = KeysDraft {
138 add: query_params::<AddQuery>(cx)?.add.is_some(),139 add: query_params::<AddQuery>(cx)?.add.is_some(),
139 ..KeysDraft::default()140 ..KeysDraft::default()
@@ -147,7 +148,7 @@ async fn tokens_page(cx: &Cx) -> Result<impl View> {
147 async fn tokens_create(cx: &Cx, Form(form): Form<CreateTokenForm>) -> Result<impl View> {148 async fn tokens_create(cx: &Cx, Form(form): Form<CreateTokenForm>) -> Result<impl View> {
148 let viewer = require_csrf(cx, &form.csrf).await?;149 let viewer = require_csrf(cx, &form.csrf).await?;
149 let lang = i18n::lang(cx, Some(&viewer.0));150 let lang = i18n::lang(cx, Some(&viewer.0));
150- let state = app_context::<AppState>(cx);151+ let state = context::<AppState>(cx);
151 let store = &state.store;152 let store = &state.store;
152 let name = form.name.trim();153 let name = form.name.trim();
153 154
@@ -211,7 +212,7 @@ async fn tokens_create(cx: &Cx, Form(form): Form<CreateTokenForm>) -> Result<imp
211 #[route(POST "/settings/tokens/delete")]212 #[route(POST "/settings/tokens/delete")]
212 async fn tokens_delete(cx: &Cx, Form(form): Form<DeleteTokenForm>) -> Result<SeeOther> {213 async fn tokens_delete(cx: &Cx, Form(form): Form<DeleteTokenForm>) -> Result<SeeOther> {
213 let (user, _) = require_csrf(cx, &form.csrf).await?;214 let (user, _) = require_csrf(cx, &form.csrf).await?;
214- let state = app_context::<AppState>(cx);215+ let state = context::<AppState>(cx);
215 if state.store.delete_token(&user.id, &form.id).await? {216 if state.store.delete_token(&user.id, &form.id).await? {
216 audit::record(217 audit::record(
217 &state.store,218 &state.store,
crates/forge-web/src/pages/setup.rsmodified+4 -3
@@ -4,7 +4,7 @@ use forge_core::AuditAction;
4 use forge_core::names::validate_username;4 use forge_core::names::validate_username;
5 use serde::Deserialize;5 use serde::Deserialize;
6 use topcoat::Result;6 use topcoat::Result;
7-use topcoat::context::{Cx, app_context};7+use topcoat::context::{Cx, context};
8 use topcoat::router::content::Form;8 use topcoat::router::content::Form;
9 use topcoat::router::error::{forbidden, not_found, see_other};9 use topcoat::router::error::{forbidden, not_found, see_other};
10 use topcoat::router::page;10 use topcoat::router::page;
@@ -36,6 +36,7 @@ struct SetupForm {
36 36
37 #[component]37 #[component]
38 async fn setup_form(38 async fn setup_form(
39+ cx: &Cx,
39 lang: Lang,40 lang: Lang,
40 username: &str,41 username: &str,
41 email: &str,42 email: &str,
@@ -75,7 +76,7 @@ async fn setup_form(
75 76
76 #[page("/setup")]77 #[page("/setup")]
77 async fn setup_page(cx: &Cx) -> Result<impl View> {78 async fn setup_page(cx: &Cx) -> Result<impl View> {
78- let state = app_context::<AppState>(cx);79+ let state = context::<AppState>(cx);
79 if state.store.user_count().await? != 0 {80 if state.store.user_count().await? != 0 {
80 return Err(not_found().into());81 return Err(not_found().into());
81 }82 }
@@ -92,7 +93,7 @@ async fn setup_submit(cx: &Cx, Form(form): Form<SetupForm>) -> Result<impl View>
92 if !check_pre_csrf(cx, &form.precsrf) {93 if !check_pre_csrf(cx, &form.precsrf) {
93 return Err(forbidden().into());94 return Err(forbidden().into());
94 }95 }
95- let state = app_context::<AppState>(cx);96+ let state = context::<AppState>(cx);
96 if state.store.user_count().await? != 0 {97 if state.store.user_count().await? != 0 {
97 return Err(not_found().into());98 return Err(not_found().into());
98 }99 }
crates/forge-web/src/pages/shell_events.rsmodified+2 -2
@@ -12,7 +12,7 @@
12 use futures_util::StreamExt;12 use futures_util::StreamExt;
13 use futures_util::stream::{self, BoxStream};13 use futures_util::stream::{self, BoxStream};
14 use topcoat::Result;14 use topcoat::Result;
15-use topcoat::context::{Cx, try_app_context};15+use topcoat::context::{Cx, try_context};
16 use topcoat::router::content::sse::Event;16 use topcoat::router::content::sse::Event;
17 use topcoat::router::response::Response;17 use topcoat::router::response::Response;
18 use topcoat::router::route;18 use topcoat::router::route;
@@ -29,7 +29,7 @@ use crate::state::AppState;
29 #[route(GET "/-/shell/events")]29 #[route(GET "/-/shell/events")]
30 async fn shell_events(cx: &Cx) -> Result<Response> {30 async fn shell_events(cx: &Cx) -> Result<Response> {
31 // A router with no app state (the asset tests) has nothing to follow: the stream only stays open.31 // 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 {
33 return events_response(cx, stream::pending::<Result<Event>>());33 return events_response(cx, stream::pending::<Result<Event>>());
34 };34 };
35 let viewer = current_user(cx).await?;35 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};
7 use forge_core::store::snippets::{Snippet, SnippetVisibility};7 use forge_core::store::snippets::{Snippet, SnippetVisibility};
8 use serde::Deserialize;8 use serde::Deserialize;
9 use sha2::{Digest, Sha256};9 use sha2::{Digest, Sha256};
10-use topcoat::context::{Cx, app_context};10+use topcoat::context::{Cx, context};
11 use topcoat::router::request::{headers, method};11 use topcoat::router::request::{headers, method};
12 use topcoat::router::response::Response;12 use topcoat::router::response::Response;
13 use topcoat::router::{13 use topcoat::router::{
@@ -66,7 +66,7 @@ fn content_type(file_name: &str) -> &'static str {
66 66
67 /// Serves one file. Every failure is turned into a response here, so the route never errors.67 /// Serves one file. Every failure is turned into a response here, so the route never errors.
68 async fn serve(cx: &Cx) -> Response {68 async fn serve(cx: &Cx) -> Response {
69- let state = app_context::<AppState>(cx).clone();69+ let state = context::<AppState>(cx).clone();
70 let id = path_param_segment(cx, "id").to_owned();70 let id = path_param_segment(cx, "id").to_owned();
71 let segments: Vec<&str> = path_param_segments(cx, "rest").collect();71 let segments: Vec<&str> = path_param_segments(cx, "rest").collect();
72 let [name] = segments.as_slice() else {72 let [name] = segments.as_slice() else {
crates/forge-web/src/pages/snippets.rsmodified+24 -18
@@ -12,7 +12,7 @@ use forge_core::store::snippets::{
12 };12 };
13 use forge_core::{AuditAction, Session, User};13 use forge_core::{AuditAction, Session, User};
14 use topcoat::Result;14 use topcoat::Result;
15-use topcoat::context::{Cx, app_context};15+use topcoat::context::{Cx, context};
16 use topcoat::router::content::Form;16 use topcoat::router::content::Form;
17 use topcoat::router::error::{SeeOther, not_found, see_other};17 use topcoat::router::error::{SeeOther, not_found, see_other};
18 use topcoat::router::{page, path_param, route};18 use topcoat::router::{page, path_param, route};
@@ -257,7 +257,7 @@ pub(crate) async fn readable(
257 viewer_id: Option<&str>,257 viewer_id: Option<&str>,
258 snippet_id: &str,258 snippet_id: &str,
259 ) -> Result<Snippet> {259 ) -> Result<Snippet> {
260- let store = &app_context::<AppState>(cx).store;260+ let store = &context::<AppState>(cx).store;
261 match store.get_snippet(snippet_id).await? {261 match store.get_snippet(snippet_id).await? {
262 Some(snippet) if snippet.is_visible_to(viewer_id) => Ok(snippet),262 Some(snippet) if snippet.is_visible_to(viewer_id) => Ok(snippet),
263 _ => Err(not_found().into()),263 _ => Err(not_found().into()),
@@ -266,7 +266,7 @@ pub(crate) async fn readable(
266 266
267 /// The snippet if the user owns it, else 404. Edits and deletes go through this check.267 /// The snippet if the user owns it, else 404. Edits and deletes go through this check.
268 async fn owned(cx: &Cx, user: &User, snippet_id: &str) -> Result<Snippet> {268 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;
270 match store.get_snippet(snippet_id).await? {270 match store.get_snippet(snippet_id).await? {
271 Some(snippet) if snippet.owner_id == user.id => Ok(snippet),271 Some(snippet) if snippet.owner_id == user.id => Ok(snippet),
272 _ => Err(not_found().into()),272 _ => Err(not_found().into()),
@@ -275,7 +275,7 @@ async fn owned(cx: &Cx, user: &User, snippet_id: &str) -> Result<Snippet> {
275 275
276 /// The snippet rows, one linked line each: title, owner, visibility, file count and update time.276 /// The snippet rows, one linked line each: title, owner, visibility, file count and update time.
277 #[component]277 #[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> {
279 Ok(view! {279 Ok(view! {
280 <div class="snippet-list">280 <div class="snippet-list">
281 for row in rows.into_iter() {281 for row in rows.into_iter() {
@@ -290,6 +290,7 @@ pub(crate) async fn snippet_rows(lang: Lang, rows: Vec<ListRow>) -> Result<impl
290 290
291 #[component]291 #[component]
292 async fn snippet_list_body(292 async fn snippet_list_body(
293+ cx: &Cx,
293 lang: Lang,294 lang: Lang,
294 rows: Vec<ListRow>,295 rows: Vec<ListRow>,
295 signed_in: bool,296 signed_in: bool,
@@ -317,6 +318,7 @@ async fn snippet_list_body(
317 /// The panel's remove button is shown only when there is more than one file.318 /// The panel's remove button is shown only when there is more than one file.
318 #[component]319 #[component]
319 async fn snippet_files(320 async fn snippet_files(
321+ cx: &Cx,
320 lang: Lang,322 lang: Lang,
321 slots: Vec<Slot>,323 slots: Vec<Slot>,
322 active: usize,324 active: usize,
@@ -389,6 +391,7 @@ async fn snippet_files(
389 /// and the remove buttons submit the same form with `formnovalidate` and never save.391 /// and the remove buttons submit the same form with `formnovalidate` and never save.
390 #[component]392 #[component]
391 async fn snippet_form(393 async fn snippet_form(
394+ cx: &Cx,
392 lang: Lang,395 lang: Lang,
393 csrf: &str,396 csrf: &str,
394 action: &str,397 action: &str,
@@ -452,6 +455,7 @@ async fn snippet_form(
452 455
453 #[component]456 #[component]
454 async fn snippet_body(457 async fn snippet_body(
458+ cx: &Cx,
455 lang: Lang,459 lang: Lang,
456 snippet_id: &str,460 snippet_id: &str,
457 title: &str,461 title: &str,
@@ -508,6 +512,7 @@ async fn snippet_body(
508 512
509 #[component]513 #[component]
510 async fn revisions_body(514 async fn revisions_body(
515+ cx: &Cx,
511 lang: Lang,516 lang: Lang,
512 snippet_id: &str,517 snippet_id: &str,
513 title: &str,518 title: &str,
@@ -541,6 +546,7 @@ async fn revisions_body(
541 546
542 #[component]547 #[component]
543 async fn snippet_form_page(548 async fn snippet_form_page(
549+ cx: &Cx,
544 lang: Lang,550 lang: Lang,
545 viewer: &(User, Session),551 viewer: &(User, Session),
546 heading: &str,552 heading: &str,
@@ -573,7 +579,7 @@ async fn snippets_list(cx: &Cx) -> Result<impl View> {
573 let viewer = current_user(cx).await?;579 let viewer = current_user(cx).await?;
574 let lang = i18n::lang(cx, viewer.as_ref().map(|(user, _)| user));580 let lang = i18n::lang(cx, viewer.as_ref().map(|(user, _)| user));
575 let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone());581 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)
577 .store583 .store
578 .list_snippets(viewer_id.as_deref())584 .list_snippets(viewer_id.as_deref())
579 .await?;585 .await?;
@@ -605,7 +611,7 @@ async fn snippet_create(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> R
605 let mut error = None;611 let mut error = None;
606 let step = apply_slot_step(&mut draft, &form);612 let step = apply_slot_step(&mut draft, &form);
607 if step.is_none() {613 if step.is_none() {
608- let store = &app_context::<AppState>(cx).store;614+ let store = &context::<AppState>(cx).store;
609 let files = draft.saved_files();615 let files = draft.saved_files();
610 let saved = match SnippetVisibility::parse(&draft.visibility) {616 let saved = match SnippetVisibility::parse(&draft.visibility) {
611 None => Err(g::t(lang, K::ChooseVisibility).to_owned()),617 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
641 serde_json::Value::Null,647 serde_json::Value::Null,
642 )648 )
643 .await;649 .await;
644- bump_snippet(app_context::<AppState>(cx), &snippet.id);650+ bump_snippet(context::<AppState>(cx), &snippet.id);
645 return Err(see_other(format!("/snippets/{}", snippet.id)).into());651 return Err(see_other(format!("/snippets/{}", snippet.id)).into());
646 }652 }
647 Err(message) => error = Some(message),653 Err(message) => error = Some(message),
@@ -657,12 +663,12 @@ async fn snippet_create(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> R
657 663
658 #[page("/snippets/{id}")]664 #[page("/snippets/{id}")]
659 async fn snippet_view(cx: &Cx) -> Result<impl View> {665 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();
661 let viewer = current_user(cx).await?;667 let viewer = current_user(cx).await?;
662 let lang = i18n::lang(cx, viewer.as_ref().map(|(user, _)| user));668 let lang = i18n::lang(cx, viewer.as_ref().map(|(user, _)| user));
663 let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone());669 let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone());
664 let snippet = readable(cx, viewer_id.as_deref(), &snippet_id).await?;670 let snippet = readable(cx, viewer_id.as_deref(), &snippet_id).await?;
665- let state = app_context::<AppState>(cx);671+ let state = context::<AppState>(cx);
666 let files: Vec<FileView> = snippet672 let files: Vec<FileView> = snippet
667 .files673 .files
668 .iter()674 .iter()
@@ -685,7 +691,7 @@ async fn snippet_view(cx: &Cx) -> Result<impl View> {
685 691
686 #[page("/snippets/{id}/edit")]692 #[page("/snippets/{id}/edit")]
687 async fn snippet_edit(cx: &Cx) -> Result<impl View> {693 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();
689 let viewer = require_user(cx).await?;695 let viewer = require_user(cx).await?;
690 let lang = i18n::lang(cx, Some(&viewer.0));696 let lang = i18n::lang(cx, Some(&viewer.0));
691 let snippet = owned(cx, &viewer.0, &snippet_id).await?;697 let snippet = owned(cx, &viewer.0, &snippet_id).await?;
@@ -699,7 +705,7 @@ async fn snippet_edit(cx: &Cx) -> Result<impl View> {
699 705
700 #[page(POST "/snippets/{id}/edit")]706 #[page(POST "/snippets/{id}/edit")]
701 async fn snippet_update(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> Result<impl View> {707 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();
703 let (user, _) = require_csrf(cx, form.get("csrf").map_or("", String::as_str)).await?;709 let (user, _) = require_csrf(cx, form.get("csrf").map_or("", String::as_str)).await?;
704 let lang = i18n::lang(cx, Some(&user));710 let lang = i18n::lang(cx, Some(&user));
705 owned(cx, &user, &snippet_id).await?;711 owned(cx, &user, &snippet_id).await?;
@@ -707,7 +713,7 @@ async fn snippet_update(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> R
707 let mut error = None;713 let mut error = None;
708 let step = apply_slot_step(&mut draft, &form);714 let step = apply_slot_step(&mut draft, &form);
709 if step.is_none() {715 if step.is_none() {
710- let store = &app_context::<AppState>(cx).store;716+ let store = &context::<AppState>(cx).store;
711 let files = draft.saved_files();717 let files = draft.saved_files();
712 let saved = match SnippetVisibility::parse(&draft.visibility) {718 let saved = match SnippetVisibility::parse(&draft.visibility) {
713 None => Err(g::t(lang, K::ChooseVisibility).to_owned()),719 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
744 serde_json::Value::Null,750 serde_json::Value::Null,
745 )751 )
746 .await;752 .await;
747- bump_snippet(app_context::<AppState>(cx), &snippet.id);753+ bump_snippet(context::<AppState>(cx), &snippet.id);
748 return Err(see_other(format!("/snippets/{}", snippet.id)).into());754 return Err(see_other(format!("/snippets/{}", snippet.id)).into());
749 }755 }
750 Err(message) => error = Some(message),756 Err(message) => error = Some(message),
@@ -761,12 +767,12 @@ async fn snippet_update(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> R
761 767
762 #[page("/snippets/{id}/revisions")]768 #[page("/snippets/{id}/revisions")]
763 async fn snippet_revisions(cx: &Cx) -> Result<impl View> {769 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();
765 let viewer = current_user(cx).await?;771 let viewer = current_user(cx).await?;
766 let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone());772 let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone());
767 let snippet = readable(cx, viewer_id.as_deref(), &snippet_id).await?;773 let snippet = readable(cx, viewer_id.as_deref(), &snippet_id).await?;
768 let lang = i18n::lang(cx, viewer.as_ref().map(|(user, _)| user));774 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;
770 let revisions: Vec<SnippetRevision> = store.list_snippet_revisions(&snippet.id).await?;776 let revisions: Vec<SnippetRevision> = store.list_snippet_revisions(&snippet.id).await?;
771 // Stored oldest first; the page shows the newest first with its number.777 // Stored oldest first; the page shows the newest first with its number.
772 let rows: Vec<RevisionView> = revisions778 let rows: Vec<RevisionView> = revisions
@@ -796,10 +802,10 @@ async fn snippet_revisions(cx: &Cx) -> Result<impl View> {
796 802
797 #[route(POST "/snippets/{id}/delete")]803 #[route(POST "/snippets/{id}/delete")]
798 async fn snippet_delete(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> Result<SeeOther> {804 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();
800 let (user, _) = require_csrf(cx, form.get("csrf").map_or("", String::as_str)).await?;806 let (user, _) = require_csrf(cx, form.get("csrf").map_or("", String::as_str)).await?;
801 let snippet = owned(cx, &user, &snippet_id).await?;807 let snippet = owned(cx, &user, &snippet_id).await?;
802- let store = &app_context::<AppState>(cx).store;808+ let store = &context::<AppState>(cx).store;
803 if store.delete_snippet(&user.id, &snippet.id).await? {809 if store.delete_snippet(&user.id, &snippet.id).await? {
804 audit::record(810 audit::record(
805 store,811 store,
@@ -814,7 +820,7 @@ async fn snippet_delete(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> R
814 serde_json::Value::Null,820 serde_json::Value::Null,
815 )821 )
816 .await;822 .await;
817- bump_snippet(app_context::<AppState>(cx), &snippet.id);823+ bump_snippet(context::<AppState>(cx), &snippet.id);
818 }824 }
819 Ok(see_other("/snippets"))825 Ok(see_other("/snippets"))
820 }826 }
crates/forge-web/src/pages/snippets_live.rsmodified+4 -4
@@ -12,7 +12,7 @@
12 use forge_core::store::Store;12 use forge_core::store::Store;
13 use forge_core::store::snippets::{Snippet, SnippetSummary};13 use forge_core::store::snippets::{Snippet, SnippetSummary};
14 use topcoat::Result;14 use topcoat::Result;
15-use topcoat::context::{Cx, app_context};15+use topcoat::context::{Cx, context};
16 use topcoat::router::response::Response;16 use topcoat::router::response::Response;
17 use topcoat::router::{path_param, route};17 use topcoat::router::{path_param, route};
18 18
@@ -87,7 +87,7 @@ fn snippet_fingerprint(viewer_id: Option<&str>, snippet: Option<Snippet>) -> Str
87 async fn snippets_events(cx: &Cx) -> Result<Response> {87 async fn snippets_events(cx: &Cx) -> Result<Response> {
88 let viewer = current_user(cx).await?;88 let viewer = current_user(cx).await?;
89 let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone());89 let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone());
90- let state = app_context::<AppState>(cx);90+ let state = context::<AppState>(cx);
91 let store = state.store.clone();91 let store = state.store.clone();
92 stream_changes(cx, &state.live, &[Topic::Snippets], move || {92 stream_changes(cx, &state.live, &[Topic::Snippets], move || {
93 let store = store.clone();93 let store = store.clone();
@@ -101,11 +101,11 @@ async fn snippets_events(cx: &Cx) -> Result<Response> {
101 /// must be readable by the viewer.101 /// must be readable by the viewer.
102 #[route(GET "/snippets/{id}/events")]102 #[route(GET "/snippets/{id}/events")]
103 async fn snippet_events(cx: &Cx) -> Result<Response> {103 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();
105 let viewer = current_user(cx).await?;105 let viewer = current_user(cx).await?;
106 let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone());106 let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone());
107 readable(cx, viewer_id.as_deref(), &snippet_id).await?;107 readable(cx, viewer_id.as_deref(), &snippet_id).await?;
108- let state = app_context::<AppState>(cx);108+ let state = context::<AppState>(cx);
109 let store = state.store.clone();109 let store = state.store.clone();
110 stream_changes(110 stream_changes(
111 cx,111 cx,
crates/forge-web/src/pages/star.rsmodified+4 -4
@@ -6,7 +6,7 @@
6 use http::header::{HOST, REFERER};6 use http::header::{HOST, REFERER};
7 use serde::Deserialize;7 use serde::Deserialize;
8 use topcoat::Result;8 use topcoat::Result;
9-use topcoat::context::{Cx, app_context};9+use topcoat::context::{Cx, context};
10 use topcoat::router::content::Form;10 use topcoat::router::content::Form;
11 use topcoat::router::error::{SeeOther, see_other};11 use topcoat::router::error::{SeeOther, see_other};
12 use topcoat::router::request::headers;12 use topcoat::router::request::headers;
@@ -37,11 +37,11 @@ async fn unstar_post(cx: &Cx, Form(form): Form<StarForm>) -> Result<SeeOther> {
37 }37 }
38 38
39 async fn set_starred(cx: &Cx, csrf: &str, starred: bool) -> Result<SeeOther> {39 async fn set_starred(cx: &Cx, csrf: &str, starred: bool) -> Result<SeeOther> {
40- let owner = path_param::<Owner>(cx);40+ let owner = owner(cx);
41- let name = path_param::<Repo>(cx);41+ let name = repo(cx);
42 let ctx = load_repo(cx, owner, name).await?;42 let ctx = load_repo(cx, owner, name).await?;
43 let (user, _) = require_csrf(cx, csrf).await?;43 let (user, _) = require_csrf(cx, csrf).await?;
44- let state = app_context::<AppState>(cx);44+ let state = context::<AppState>(cx);
45 if starred {45 if starred {
46 state.store.star(&user.id, &ctx.repo.id).await?;46 state.store.star(&user.id, &ctx.repo.id).await?;
47 } else {47 } else {
crates/forge-web/src/pages/theme_cookie.rsmodified+2 -2
@@ -5,7 +5,7 @@
5 5
6 use serde::Deserialize;6 use serde::Deserialize;
7 use topcoat::Result;7 use topcoat::Result;
8-use topcoat::context::{Cx, app_context};8+use topcoat::context::{Cx, context};
9 use topcoat::router::content::Form;9 use topcoat::router::content::Form;
10 use topcoat::router::error::{SeeOther, see_other};10 use topcoat::router::error::{SeeOther, see_other};
11 use topcoat::router::route;11 use topcoat::router::route;
@@ -54,7 +54,7 @@ async fn set_theme(cx: &Cx, Form(form): Form<ThemeForm>) -> Result<SeeOther> {
54 if !THEMES.contains(&form.theme.as_str()) {54 if !THEMES.contains(&form.theme.as_str()) {
55 return Err(forge_core::Error::Invalid("theme".into()).into());55 return Err(forge_core::Error::Invalid("theme".into()).into());
56 }56 }
57- let store: &Store = &app_context::<AppState>(cx).store;57+ let store: &Store = &context::<AppState>(cx).store;
58 store58 store
59 .set_ui_prefs(&viewer.0.id, &form.theme, &viewer.0.language)59 .set_ui_prefs(&viewer.0.id, &form.theme, &viewer.0.language)
60 .await?;60 .await?;
crates/forge-web/src/pages/tree.rsmodified+16 -10
@@ -10,7 +10,7 @@ use forge_core::tz::format_in_tz;
10 use forge_git::browse::{self, BlobData, CommitInfo, EntryKind, RefInfo, TreeEntry};10 use forge_git::browse::{self, BlobData, CommitInfo, EntryKind, RefInfo, TreeEntry};
11 use forge_git::history;11 use forge_git::history;
12 use topcoat::Result;12 use topcoat::Result;
13-use topcoat::context::{Cx, app_context};13+use topcoat::context::{Cx, context};
14 use topcoat::router::error::not_found;14 use topcoat::router::error::not_found;
15 use topcoat::router::{page, path_param};15 use topcoat::router::{page, path_param};
16 use topcoat::view::{Unescaped, View, component, view};16 use topcoat::view::{Unescaped, View, component, view};
@@ -24,9 +24,7 @@ use crate::pages::passkeys::s;
24 use crate::pages::refs::{load_refs, ref_links};24 use crate::pages::refs::{load_refs, ref_links};
25 use crate::pages::repo::repo_head;25 use crate::pages::repo::repo_head;
26 use crate::pages::repo_ctx::load_repo;26 use crate::pages::repo_ctx::load_repo;
27-use crate::pages::repo_side::{27+use crate::pages::repo_side::{code_sub, commit_strip, run_pips, run_rows, tree_facts};
28- code_sub, commit_strip, run_pips, run_rows, tree_facts,
29-};
30 use crate::raw::raw_url;28 use crate::raw::raw_url;
31 use crate::render::emoji::emojify;29 use crate::render::emoji::emojify;
32 use crate::render::markdown::{LinkContext, render_markdown};30 use crate::render::markdown::{LinkContext, render_markdown};
@@ -351,6 +349,7 @@ pub async fn load_readme(
351 /// Submodules have no page, so their row shows the short sha. A long folder scrolls here alone.349 /// Submodules have no page, so their row shows the short sha. A long folder scrolls here alone.
352 #[component]350 #[component]
353 pub async fn tree_table(351 pub async fn tree_table(
352+ cx: &Cx,
354 rows: Vec<EntryRow>,353 rows: Vec<EntryRow>,
355 lang: Lang,354 lang: Lang,
356 #[default] current: Option<String>,355 #[default] current: Option<String>,
@@ -381,6 +380,7 @@ pub async fn tree_table(
381 /// The sheet beside a folder: its README, with Source, History and Raw as tools, or `none`.380 /// The sheet beside a folder: its README, with Source, History and Raw as tools, or `none`.
382 #[component]381 #[component]
383 pub async fn readme_sheet(382 pub async fn readme_sheet(
383+ cx: &Cx,
384 lang: Lang,384 lang: Lang,
385 owner: String,385 owner: String,
386 repo: String,386 repo: String,
@@ -404,7 +404,13 @@ pub async fn readme_sheet(
404 )404 )
405 });405 });
406 // The tools row names what is shown: the README, or the folder (the repo name at the root).406 // 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+ });
408 Ok(view! {414 Ok(view! {
409 <div class="sheet">415 <div class="sheet">
410 <div class="sheet-tools">416 <div class="sheet-tools">
@@ -427,7 +433,7 @@ pub async fn readme_sheet(
427 /// README body. Markdown HTML is embedded only from `render_markdown`; plain text is escaped. The433 /// README body. Markdown HTML is embedded only from `render_markdown`; plain text is escaped. The
428 /// file name is for screen readers: the pane head shows it.434 /// file name is for screen readers: the pane head shows it.
429 #[component]435 #[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> {
431 Ok(view! {437 Ok(view! {
432 <section class="readme">438 <section class="readme">
433 <p class="sr-only">(name)</p>439 <p class="sr-only">(name)</p>
@@ -442,11 +448,11 @@ pub async fn readme_card(name: String, markdown: bool, body: String) -> Result<i
442 448
443 #[page("/{owner}/{repo}/tree/{*rest}")]449 #[page("/{owner}/{repo}/tree/{*rest}")]
444 async fn tree_page(cx: &Cx) -> Result<impl View> {450 async fn tree_page(cx: &Cx) -> Result<impl View> {
445- let owner = path_param::<Owner>(cx);451+ let owner = owner(cx);
446- let name = path_param::<Repo>(cx);452+ let name = repo(cx);
447- let rest = path_param::<Rest>(cx).collect::<Vec<_>>().join("/");453+ let rest = rest(cx).collect::<Vec<_>>().join("/");
448 let ctx = load_repo(cx, owner, name).await?;454 let ctx = load_repo(cx, owner, name).await?;
449- let state = app_context::<AppState>(cx);455+ let state = context::<AppState>(cx);
450 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));456 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
451 let repo = &ctx.repo;457 let repo = &ctx.repo;
452 458
crates/forge-web/src/pages/user_prefs.rsmodified+2 -2
@@ -5,7 +5,7 @@
5 use http::StatusCode;5 use http::StatusCode;
6 use serde::Deserialize;6 use serde::Deserialize;
7 use topcoat::Result;7 use topcoat::Result;
8-use topcoat::context::{Cx, app_context};8+use topcoat::context::{Cx, context};
9 use topcoat::router::content::Form;9 use topcoat::router::content::Form;
10 use topcoat::router::error::bad_request;10 use topcoat::router::error::bad_request;
11 use topcoat::router::response::Response;11 use topcoat::router::response::Response;
@@ -43,7 +43,7 @@ pub fn clean_pref(key: &str, value: &str) -> std::result::Result<Option<String>,
43 #[route(POST "/-/prefs")]43 #[route(POST "/-/prefs")]
44 async fn set_pref(cx: &Cx, Form(form): Form<PrefForm>) -> Result<Response> {44 async fn set_pref(cx: &Cx, Form(form): Form<PrefForm>) -> Result<Response> {
45 let (user, _) = require_csrf(cx, &form.csrf).await?;45 let (user, _) = require_csrf(cx, &form.csrf).await?;
46- let store = &app_context::<AppState>(cx).store;46+ let store = &context::<AppState>(cx).store;
47 match clean_pref(&form.key, &form.value) {47 match clean_pref(&form.key, &form.value) {
48 Err(message) => return Err(bad_request(message).into()),48 Err(message) => return Err(bad_request(message).into()),
49 Ok(None) => store.delete_user_pref(&user.id, &form.key).await?,49 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;
13 use forge_git::wiki::{self, MAX_PAGE_BYTES, PageEdit, PageRevision, valid_page_name};13 use forge_git::wiki::{self, MAX_PAGE_BYTES, PageEdit, PageRevision, valid_page_name};
14 use serde::Deserialize;14 use serde::Deserialize;
15 use topcoat::Result;15 use topcoat::Result;
16-use topcoat::context::{Cx, app_context};16+use topcoat::context::{Cx, context};
17 use topcoat::router::content::Form;17 use topcoat::router::content::Form;
18 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};18 use topcoat::router::error::{SeeOther, forbidden, not_found, see_other};
19 use topcoat::router::{page, path_param, route};19 use topcoat::router::{page, path_param, route};
@@ -179,6 +179,7 @@ fn wiki_links(
179 /// The page list beside a wiki page: every page, the one on screen marked.179 /// The page list beside a wiki page: every page, the one on screen marked.
180 #[component]180 #[component]
181 async fn wiki_rail(181 async fn wiki_rail(
182+ cx: &Cx,
182 lang: Lang,183 lang: Lang,
183 owner: String,184 owner: String,
184 repo: String,185 repo: String,
@@ -203,6 +204,7 @@ async fn wiki_rail(
203 /// the screen follows.204 /// the screen follows.
204 #[component]205 #[component]
205 async fn wiki_sheet(206 async fn wiki_sheet(
207+ cx: &Cx,
206 #[default] title: Option<String>,208 #[default] title: Option<String>,
207 links: Vec<(String, String)>,209 links: Vec<(String, String)>,
208 #[default] live: Option<String>,210 #[default] live: Option<String>,
@@ -251,7 +253,7 @@ fn page_links(
251 }253 }
252 254
253 #[component]255 #[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> {
255 Ok(view! {257 Ok(view! {
256 <section class="sec wiki-page">258 <section class="sec wiki-page">
257 <div class="markdown-body">(Unescaped::new_unchecked(html))</div>259 <div class="markdown-body">(Unescaped::new_unchecked(html))</div>
@@ -261,6 +263,7 @@ async fn wiki_view_body(html: String) -> Result<impl View> {
261 263
262 #[component]264 #[component]
263 async fn wiki_empty_body(265 async fn wiki_empty_body(
266+ cx: &Cx,
264 lang: Lang,267 lang: Lang,
265 owner: String,268 owner: String,
266 repo: String,269 repo: String,
@@ -278,6 +281,7 @@ async fn wiki_empty_body(
278 281
279 #[component]282 #[component]
280 async fn wiki_list_body(283 async fn wiki_list_body(
284+ cx: &Cx,
281 lang: Lang,285 lang: Lang,
282 owner: String,286 owner: String,
283 repo: String,287 repo: String,
@@ -304,7 +308,7 @@ async fn wiki_list_body(
304 }308 }
305 309
306 #[component]310 #[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> {
308 Ok(view! {312 Ok(view! {
309 if rows.is_empty() {313 if rows.is_empty() {
310 empty_state(title: g::t(lang, K::NoChangesYet))314 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
321 325
322 #[component]326 #[component]
323 async fn wiki_edit_body(327 async fn wiki_edit_body(
328+ cx: &Cx,
324 lang: Lang,329 lang: Lang,
325 action: String,330 action: String,
326 csrf: String,331 csrf: String,
@@ -370,10 +375,10 @@ async fn load_page(dir: PathBuf, name: String) -> Result<(Option<String>, Option
370 375
371 #[page("/{owner}/{repo}/wiki")]376 #[page("/{owner}/{repo}/wiki")]
372 async fn wiki_home(cx: &Cx) -> Result<impl View> {377 async fn wiki_home(cx: &Cx) -> Result<impl View> {
373- let owner = path_param::<Owner>(cx);378+ let owner = owner(cx);
374- let name = path_param::<Repo>(cx);379+ let name = repo(cx);
375 let ctx = load_repo(cx, owner, name).await?;380 let ctx = load_repo(cx, owner, name).await?;
376- let state = app_context::<AppState>(cx);381+ let state = context::<AppState>(cx);
377 ensure_enabled(state, &ctx).await?;382 ensure_enabled(state, &ctx).await?;
378 let dir = wiki_dir(state, &ctx)?;383 let dir = wiki_dir(state, &ctx)?;
379 let names = page_names(dir.clone()).await?;384 let names = page_names(dir.clone()).await?;
@@ -401,7 +406,7 @@ async fn wiki_home(cx: &Cx) -> Result<impl View> {
401 };406 };
402 let links = wiki_links(lang, &owner_name, &repo_name, can_write, extra);407 let links = wiki_links(lang, &owner_name, &repo_name, can_write, extra);
403 let header = ctx.head(state, "wiki").await?;408 let header = ctx.head(state, "wiki").await?;
404- Ok(view! { cx =>409+ Ok(view! {
405 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),410 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),
406 repo_head(head: header, title: head_title)411 repo_head(head: header, title: head_title)
407 <div class="work">412 <div class="work">
@@ -421,10 +426,10 @@ async fn wiki_home(cx: &Cx) -> Result<impl View> {
421 426
422 #[page("/{owner}/{repo}/wiki/-/pages")]427 #[page("/{owner}/{repo}/wiki/-/pages")]
423 async fn wiki_pages(cx: &Cx) -> Result<impl View> {428 async fn wiki_pages(cx: &Cx) -> Result<impl View> {
424- let owner = path_param::<Owner>(cx);429+ let owner = owner(cx);
425- let name = path_param::<Repo>(cx);430+ let name = repo(cx);
426 let ctx = load_repo(cx, owner, name).await?;431 let ctx = load_repo(cx, owner, name).await?;
427- let state = app_context::<AppState>(cx);432+ let state = context::<AppState>(cx);
428 ensure_enabled(state, &ctx).await?;433 ensure_enabled(state, &ctx).await?;
429 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));434 let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user));
430 let dir = wiki_dir(state, &ctx)?;435 let dir = wiki_dir(state, &ctx)?;
@@ -440,7 +445,7 @@ async fn wiki_pages(cx: &Cx) -> Result<impl View> {
440 );445 );
441 let links = wiki_links(lang, &owner_name, &repo_name, can_write, Vec::new());446 let links = wiki_links(lang, &owner_name, &repo_name, can_write, Vec::new());
442 let header = ctx.head(state, "wiki").await?;447 let header = ctx.head(state, "wiki").await?;
443- Ok(view! { cx =>448+ Ok(view! {
444 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),449 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),
445 repo_head(head: header, title: Some(g::t(lang, K::AllPages).to_owned()))450 repo_head(head: header, title: Some(g::t(lang, K::AllPages).to_owned()))
446 wiki_sheet(links: links, live: Some(wiki_live_url(&owner_name, &repo_name)),451 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> {
452 457
453 #[page("/{owner}/{repo}/wiki/{wiki_page}")]458 #[page("/{owner}/{repo}/wiki/{wiki_page}")]
454 async fn wiki_page_view(cx: &Cx) -> Result<impl View> {459 async fn wiki_page_view(cx: &Cx) -> Result<impl View> {
455- let owner = path_param::<Owner>(cx);460+ let owner = owner(cx);
456- let repo_param = path_param::<Repo>(cx);461+ let repo_param = repo(cx);
457- let page_name = path_param::<WikiPage>(cx).to_owned();462+ let page_name = wiki_page(cx).to_owned();
458 let ctx = load_repo(cx, owner, repo_param).await?;463 let ctx = load_repo(cx, owner, repo_param).await?;
459- let state = app_context::<AppState>(cx);464+ let state = context::<AppState>(cx);
460 ensure_enabled(state, &ctx).await?;465 ensure_enabled(state, &ctx).await?;
461 if !valid_page_name(&page_name) {466 if !valid_page_name(&page_name) {
462 return Err(not_found().into());467 return Err(not_found().into());
@@ -486,7 +491,7 @@ async fn wiki_page_view(cx: &Cx) -> Result<impl View> {
486 page_links(lang, &owner_name, &repo_name, &page_name, can_write),491 page_links(lang, &owner_name, &repo_name, &page_name, can_write),
487 );492 );
488 let header = ctx.head(state, "wiki").await?;493 let header = ctx.head(state, "wiki").await?;
489- Ok(view! { cx =>494+ Ok(view! {
490 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),495 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),
491 repo_head(head: header, title: Some(page_name.replace('-', " ")))496 repo_head(head: header, title: Some(page_name.replace('-', " ")))
492 <div class="work">497 <div class="work">
@@ -501,11 +506,11 @@ async fn wiki_page_view(cx: &Cx) -> Result<impl View> {
501 506
502 #[page("/{owner}/{repo}/wiki/{wiki_page}/history")]507 #[page("/{owner}/{repo}/wiki/{wiki_page}/history")]
503 async fn wiki_page_history(cx: &Cx) -> Result<impl View> {508 async fn wiki_page_history(cx: &Cx) -> Result<impl View> {
504- let owner = path_param::<Owner>(cx);509+ let owner = owner(cx);
505- let repo_param = path_param::<Repo>(cx);510+ let repo_param = repo(cx);
506- let page_name = path_param::<WikiPage>(cx).to_owned();511+ let page_name = wiki_page(cx).to_owned();
507 let ctx = load_repo(cx, owner, repo_param).await?;512 let ctx = load_repo(cx, owner, repo_param).await?;
508- let state = app_context::<AppState>(cx);513+ let state = context::<AppState>(cx);
509 ensure_enabled(state, &ctx).await?;514 ensure_enabled(state, &ctx).await?;
510 if !valid_page_name(&page_name) {515 if !valid_page_name(&page_name) {
511 return Err(not_found().into());516 return Err(not_found().into());
@@ -536,7 +541,7 @@ async fn wiki_page_history(cx: &Cx) -> Result<impl View> {
536 )],541 )],
537 );542 );
538 let header = ctx.head(state, "wiki").await?;543 let header = ctx.head(state, "wiki").await?;
539- Ok(view! { cx =>544+ Ok(view! {
540 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),545 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),
541 repo_head(head: header, title: Some(format!("{} \u{b7} {}", page_name.replace('-', " "), g::t(lang, K::History))))546 repo_head(head: header, title: Some(format!("{} \u{b7} {}", page_name.replace('-', " "), g::t(lang, K::History))))
542 <div class="work">547 <div class="work">
@@ -558,7 +563,7 @@ async fn edit_screen(
558 content: String,563 content: String,
559 error: Option<String>,564 error: Option<String>,
560 ) -> Result<impl View> {565 ) -> Result<impl View> {
561- let state = app_context::<AppState>(cx);566+ let state = context::<AppState>(cx);
562 let (user, session) = require_user(cx).await?;567 let (user, session) = require_user(cx).await?;
563 let lang = i18n::lang(cx, Some(&user));568 let lang = i18n::lang(cx, Some(&user));
564 let dir = wiki_dir(state, &ctx)?;569 let dir = wiki_dir(state, &ctx)?;
@@ -599,7 +604,7 @@ async fn edit_screen(
599 )]604 )]
600 };605 };
601 let links = wiki_links(lang, &owner_name, &repo_name, !is_new, back_links);606 let links = wiki_links(lang, &owner_name, &repo_name, !is_new, back_links);
602- Ok(view! { cx =>607+ Ok(view! {
603 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),608 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),
604 repo_head(head: header, title: Some(head_title))609 repo_head(head: header, title: Some(head_title))
605 <div class="work">610 <div class="work">
@@ -614,10 +619,10 @@ async fn edit_screen(
614 619
615 #[page("/{owner}/{repo}/wiki/-/new")]620 #[page("/{owner}/{repo}/wiki/-/new")]
616 async fn wiki_new_page(cx: &Cx) -> Result<impl View> {621 async fn wiki_new_page(cx: &Cx) -> Result<impl View> {
617- let owner = path_param::<Owner>(cx);622+ let owner = owner(cx);
618- let repo_param = path_param::<Repo>(cx);623+ let repo_param = repo(cx);
619 let ctx = load_repo(cx, owner, repo_param).await?;624 let ctx = load_repo(cx, owner, repo_param).await?;
620- let state = app_context::<AppState>(cx);625+ let state = context::<AppState>(cx);
621 ensure_enabled(state, &ctx).await?;626 ensure_enabled(state, &ctx).await?;
622 if !ctx.can_write() {627 if !ctx.can_write() {
623 return Err(forbidden().into());628 return Err(forbidden().into());
@@ -627,11 +632,11 @@ async fn wiki_new_page(cx: &Cx) -> Result<impl View> {
627 632
628 #[page("/{owner}/{repo}/wiki/{wiki_page}/edit")]633 #[page("/{owner}/{repo}/wiki/{wiki_page}/edit")]
629 async fn wiki_edit_page(cx: &Cx) -> Result<impl View> {634 async fn wiki_edit_page(cx: &Cx) -> Result<impl View> {
630- let owner = path_param::<Owner>(cx);635+ let owner = owner(cx);
631- let repo_param = path_param::<Repo>(cx);636+ let repo_param = repo(cx);
632- let page_name = path_param::<WikiPage>(cx).to_owned();637+ let page_name = wiki_page(cx).to_owned();
633 let ctx = load_repo(cx, owner, repo_param).await?;638 let ctx = load_repo(cx, owner, repo_param).await?;
634- let state = app_context::<AppState>(cx);639+ let state = context::<AppState>(cx);
635 ensure_enabled(state, &ctx).await?;640 ensure_enabled(state, &ctx).await?;
636 if !ctx.can_write() {641 if !ctx.can_write() {
637 return Err(forbidden().into());642 return Err(forbidden().into());
@@ -646,10 +651,10 @@ async fn wiki_edit_page(cx: &Cx) -> Result<impl View> {
646 651
647 #[page(POST "/{owner}/{repo}/wiki/-/new")]652 #[page(POST "/{owner}/{repo}/wiki/-/new")]
648 async fn wiki_new_post(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View> {653 async fn wiki_new_post(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View> {
649- let owner = path_param::<Owner>(cx);654+ let owner = owner(cx);
650- let repo_param = path_param::<Repo>(cx);655+ let repo_param = repo(cx);
651 let ctx = load_repo(cx, owner, repo_param).await?;656 let ctx = load_repo(cx, owner, repo_param).await?;
652- let state = app_context::<AppState>(cx);657+ let state = context::<AppState>(cx);
653 ensure_enabled(state, &ctx).await?;658 ensure_enabled(state, &ctx).await?;
654 if !ctx.can_write() {659 if !ctx.can_write() {
655 return Err(forbidden().into());660 return Err(forbidden().into());
@@ -680,11 +685,11 @@ async fn wiki_new_post(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View>
680 685
681 #[page(POST "/{owner}/{repo}/wiki/{wiki_page}/edit")]686 #[page(POST "/{owner}/{repo}/wiki/{wiki_page}/edit")]
682 async fn wiki_edit_post(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View> {687 async fn wiki_edit_post(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View> {
683- let owner = path_param::<Owner>(cx);688+ let owner = owner(cx);
684- let repo_param = path_param::<Repo>(cx);689+ let repo_param = repo(cx);
685- let page_name = path_param::<WikiPage>(cx).to_owned();690+ let page_name = wiki_page(cx).to_owned();
686 let ctx = load_repo(cx, owner, repo_param).await?;691 let ctx = load_repo(cx, owner, repo_param).await?;
687- let state = app_context::<AppState>(cx);692+ let state = context::<AppState>(cx);
688 ensure_enabled(state, &ctx).await?;693 ensure_enabled(state, &ctx).await?;
689 if !ctx.can_write() {694 if !ctx.can_write() {
690 return Err(forbidden().into());695 return Err(forbidden().into());
@@ -709,7 +714,7 @@ enum SaveOutcome {
709 /// Writes the page as a commit guarded by the form's `base`. A conflicting or invalid save is714 /// Writes the page as a commit guarded by the form's `base`. A conflicting or invalid save is
710 /// refused with a message, and the caller shows the edit screen again with the typed text.715 /// refused with a message, and the caller shows the edit screen again with the typed text.
711 async fn save(cx: &Cx, ctx: &RepoCtx, form: &EditForm, name: &str) -> Result<SaveOutcome> {716 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);
713 let (user, _) = require_user(cx).await?;718 let (user, _) = require_user(cx).await?;
714 let lang = i18n::lang(cx, Some(&user));719 let lang = i18n::lang(cx, Some(&user));
715 if form.content.len() > MAX_PAGE_BYTES {720 if form.content.len() > MAX_PAGE_BYTES {
@@ -765,6 +770,7 @@ async fn save(cx: &Cx, ctx: &RepoCtx, form: &EditForm, name: &str) -> Result<Sav
765 /// change (`data-autosubmit`), then its hint. `enabled` is the current state.770 /// change (`data-autosubmit`), then its hint. `enabled` is the current state.
766 #[component]771 #[component]
767 pub(crate) async fn wiki_switch(772 pub(crate) async fn wiki_switch(
773+ cx: &Cx,
768 action: String,774 action: String,
769 csrf: String,775 csrf: String,
770 enabled: bool,776 enabled: bool,
@@ -783,8 +789,8 @@ pub(crate) async fn wiki_switch(
783 /// The wiki switch moved to the General settings page; the old address goes there.789 /// The wiki switch moved to the General settings page; the old address goes there.
784 #[route(GET "/{owner}/{repo}/settings/wiki")]790 #[route(GET "/{owner}/{repo}/settings/wiki")]
785 async fn wiki_settings_page(cx: &Cx) -> Result<SeeOther> {791 async fn wiki_settings_page(cx: &Cx) -> Result<SeeOther> {
786- let owner = path_param::<Owner>(cx);792+ let owner = owner(cx);
787- let repo_param = path_param::<Repo>(cx);793+ let repo_param = repo(cx);
788 Ok(see_other(repo_href(owner, repo_param, "settings", "")))794 Ok(see_other(repo_href(owner, repo_param, "settings", "")))
789 }795 }
790 796
@@ -798,14 +804,14 @@ struct WikiSettingsForm {
798 804
799 #[route(POST "/{owner}/{repo}/settings/wiki")]805 #[route(POST "/{owner}/{repo}/settings/wiki")]
800 async fn wiki_settings_post(cx: &Cx, Form(form): Form<WikiSettingsForm>) -> Result<SeeOther> {806 async fn wiki_settings_post(cx: &Cx, Form(form): Form<WikiSettingsForm>) -> Result<SeeOther> {
801- let owner = path_param::<Owner>(cx);807+ let owner = owner(cx);
802- let repo_param = path_param::<Repo>(cx);808+ let repo_param = repo(cx);
803 let ctx = load_repo(cx, owner, repo_param).await?;809 let ctx = load_repo(cx, owner, repo_param).await?;
804 let (user, _) = require_csrf(cx, &form.csrf).await?;810 let (user, _) = require_csrf(cx, &form.csrf).await?;
805 if !ctx.can_admin() {811 if !ctx.can_admin() {
806 return Err(forbidden().into());812 return Err(forbidden().into());
807 }813 }
808- let state = app_context::<AppState>(cx);814+ let state = context::<AppState>(cx);
809 let enable = form.enabled.is_some();815 let enable = form.enabled.is_some();
810 let before = state.store.wiki_enabled(&ctx.repo.id).await?;816 let before = state.store.wiki_enabled(&ctx.repo.id).await?;
811 state.store.set_wiki_enabled(&ctx.repo.id, enable).await?;817 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};
15 use forge_git::GitEnv;15 use forge_git::GitEnv;
16 use forge_git::wiki::{self, valid_page_name};16 use forge_git::wiki::{self, valid_page_name};
17 use topcoat::Result;17 use topcoat::Result;
18-use topcoat::context::{Cx, app_context};18+use topcoat::context::{Cx, context};
19 use topcoat::router::error::not_found;19 use topcoat::router::error::not_found;
20 use topcoat::router::response::Response;20 use topcoat::router::response::Response;
21 use topcoat::router::{path_param, route};21 use topcoat::router::{path_param, route};
@@ -66,8 +66,8 @@ async fn page_fingerprint(git: &GitEnv, dir: &Path, name: &str) -> Result<String
66 /// wiki's on switch.66 /// wiki's on switch.
67 #[route(GET "/{owner}/{repo}/wiki/-/events")]67 #[route(GET "/{owner}/{repo}/wiki/-/events")]
68 async fn wiki_events(cx: &Cx) -> Result<Response> {68 async fn wiki_events(cx: &Cx) -> Result<Response> {
69- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;69+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
70- let state = app_context::<AppState>(cx);70+ let state = context::<AppState>(cx);
71 ensure_enabled(state, &ctx).await?;71 ensure_enabled(state, &ctx).await?;
72 let dir = wiki_dir(state, &ctx)?;72 let dir = wiki_dir(state, &ctx)?;
73 let topic = Topic::Wiki(ctx.repo.id.clone());73 let topic = Topic::Wiki(ctx.repo.id.clone());
@@ -80,9 +80,9 @@ async fn wiki_events(cx: &Cx) -> Result<Response> {
80 /// The change stream of one wiki page, its page view and its history.80 /// The change stream of one wiki page, its page view and its history.
81 #[route(GET "/{owner}/{repo}/wiki/{wiki_page}/events")]81 #[route(GET "/{owner}/{repo}/wiki/{wiki_page}/events")]
82 async fn wiki_page_events(cx: &Cx) -> Result<Response> {82 async fn wiki_page_events(cx: &Cx) -> Result<Response> {
83- let page_name = path_param::<WikiPage>(cx).to_owned();83+ let page_name = wiki_page(cx).to_owned();
84- let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;84+ let ctx = load_repo(cx, owner(cx), repo(cx)).await?;
85- let state = app_context::<AppState>(cx);85+ let state = context::<AppState>(cx);
86 ensure_enabled(state, &ctx).await?;86 ensure_enabled(state, &ctx).await?;
87 if !valid_page_name(&page_name) {87 if !valid_page_name(&page_name) {
88 return Err(not_found().into());88 return Err(not_found().into());
crates/forge-web/src/raw.rsmodified+4 -4
@@ -17,7 +17,7 @@ use serde::Deserialize;
17 use tokio::io::AsyncReadExt;17 use tokio::io::AsyncReadExt;
18 use tokio::process::Child;18 use tokio::process::Child;
19 use tokio_util::io::ReaderStream;19 use tokio_util::io::ReaderStream;
20-use topcoat::context::{Cx, app_context};20+use topcoat::context::{Cx, context};
21 use topcoat::router::request::{headers, method};21 use topcoat::router::request::{headers, method};
22 use topcoat::router::response::Response;22 use topcoat::router::response::Response;
23 use topcoat::router::{23 use topcoat::router::{
@@ -113,8 +113,8 @@ pub fn router(state: AppState) -> Router {
113 ))113 ))
114 .route(RouteFn::new(Method::GET, "/healthz", healthz))114 .route(RouteFn::new(Method::GET, "/healthz", healthz))
115 // Responses must match the bytes behind the ETag and Content-Length.115 // Responses must match the bytes behind the ETag and Content-Length.
116- .compression(Compression::off())116+ .with(Compression::disable())
117- .app_context(state)117+ .with(state)
118 .build()118 .build()
119 }119 }
120 120
@@ -137,7 +137,7 @@ fn raw_file(cx: &Cx, _body: topcoat::router::Body) -> RouteFuture<'_> {
137 137
138 /// Serves one file. Every failure is turned into a response here, so the route never errors.138 /// Serves one file. Every failure is turned into a response here, so the route never errors.
139 async fn serve(cx: &Cx) -> Response {139 async fn serve(cx: &Cx) -> Response {
140- let state = app_context::<AppState>(cx).clone();140+ let state = context::<AppState>(cx).clone();
141 let owner = path_param_segment(cx, "owner").to_owned();141 let owner = path_param_segment(cx, "owner").to_owned();
142 let name = path_param_segment(cx, "repo").to_owned();142 let name = path_param_segment(cx, "repo").to_owned();
143 let rest = path_param_segments(cx, "rest")143 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;
13 use forge_core::{Config, Registration, Store};13 use forge_core::{Config, Registration, Store};
14 use forge_git::GitEnv;14 use forge_git::GitEnv;
15 use tokio::sync::Notify;15 use tokio::sync::Notify;
16-use topcoat::cookie::RouterBuilderCookieExt;16+use topcoat::cookie::CookieLayer;
17 use topcoat::router::tower::TowerLayer;17 use topcoat::router::tower::TowerLayer;
18 use topcoat::router::{Compression, Router, RouterBuilderDiscoverExt};18 use topcoat::router::{Compression, Router, RouterBuilderDiscoverExt};
19 19
20 use crate::pages::repo_ctx::RepoMovedLayer;20 use crate::pages::repo_ctx::RepoMovedLayer;
21-use crate::pages::settings_profile::{avatar_body_limit, org_avatar_body_limit};
22 use crate::state::AppState;21 use crate::state::AppState;
23 use crate::throttle::Throttle;22 use crate::throttle::Throttle;
24 23
@@ -105,18 +104,16 @@ pub async fn test_state(dir: &Path) -> AppState {
105 pub fn app_router(state: AppState) -> Router {104 pub fn app_router(state: AppState) -> Router {
106 Router::builder()105 Router::builder()
107 .discover()106 .discover()
108- .app_context(state)107+ .with(state)
109 .layer(crate::pages::settings_live::AccountWriteLayer)108 .layer(crate::pages::settings_live::AccountWriteLayer)
110- .cookies()109+ .layer(CookieLayer::new())
111- .layer(avatar_body_limit())
112- .layer(org_avatar_body_limit())
113 .layer(RepoMovedLayer)110 .layer(RepoMovedLayer)
114 .layer(crate::pages::repo_settings_live::RepoSettingsWriteLayer)111 .layer(crate::pages::repo_settings_live::RepoSettingsWriteLayer)
115 .layer(crate::pages::pull_live::PullWriteLayer)112 .layer(crate::pages::pull_live::PullWriteLayer)
116 .layer(crate::pages::discussion_live::DiscussionWriteLayer)113 .layer(crate::pages::discussion_live::DiscussionWriteLayer)
117 .layer(crate::pages::org_live::OrgWriteLayer)114 .layer(crate::pages::org_live::OrgWriteLayer)
118 .layer(TowerLayer::new(crate::compression::ResponseCompression))115 .layer(TowerLayer::new(crate::compression::ResponseCompression))
119- .compression(Compression::off())116+ .with(Compression::disable())
120 .build()117 .build()
121 }118 }
122 119
crates/forge-web/src/views/commit_line.rsmodified+2 -1
@@ -3,6 +3,7 @@
3 //! subject as written, like GitHub. The full subject is the `title` attribute.3 //! subject as written, like GitHub. The full subject is the `title` attribute.
4 4
5 use topcoat::Result;5 use topcoat::Result;
6+use topcoat::context::Cx;
6 use topcoat::view::{View, component, view};7 use topcoat::view::{View, component, view};
7 8
8 use crate::render::emoji::emojify;9 use crate::render::emoji::emojify;
@@ -10,7 +11,7 @@ use crate::render::emoji::emojify;
10 /// One subject on one line as it was written, header included, truncated by CSS. The full subject11 /// One subject on one line as it was written, header included, truncated by CSS. The full subject
11 /// is the `title` attribute.12 /// is the `title` attribute.
12 #[component]13 #[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> {
14 let text = emojify(&subject).into_owned();15 let text = emojify(&subject).into_owned();
15 Ok(view! {16 Ok(view! {
16 <span class="commit-line" title=(text.as_str())>17 <span class="commit-line" title=(text.as_str())>
crates/forge-web/src/views/commit_status.rsmodified+4 -1
@@ -4,6 +4,7 @@
4 4
5 use forge_core::store::commit_status::{CommitStatus, StatusState, combine};5 use forge_core::store::commit_status::{CommitStatus, StatusState, combine};
6 use topcoat::Result;6 use topcoat::Result;
7+use topcoat::context::Cx;
7 use topcoat::view::{View, component, view};8 use topcoat::view::{View, component, view};
8 9
9 use crate::i18n::Lang;10 use crate::i18n::Lang;
@@ -88,6 +89,7 @@ pub fn css(state: StatusState) -> &'static str {
88 /// no statuses.89 /// no statuses.
89 #[component]90 #[component]
90 pub async fn commit_status(91 pub async fn commit_status(
92+ cx: &Cx,
91 summary: StatusSummary,93 summary: StatusSummary,
92 #[default] lang: StatusLang,94 #[default] lang: StatusLang,
93 ) -> Result<impl View> {95 ) -> Result<impl View> {
@@ -118,6 +120,7 @@ pub async fn commit_status(
118 /// the contexts beneath it.120 /// the contexts beneath it.
119 #[component]121 #[component]
120 pub async fn checks_summary(122 pub async fn checks_summary(
123+ cx: &Cx,
121 summary: StatusSummary,124 summary: StatusSummary,
122 #[default] lang: StatusLang,125 #[default] lang: StatusLang,
123 ) -> Result<impl View> {126 ) -> Result<impl View> {
@@ -167,7 +170,7 @@ fn description_text(lang: Lang, text: &str) -> &str {
167 170
168 /// The contexts of one commit: icon, context name, description and a details link.171 /// The contexts of one commit: icon, context name, description and a details link.
169 #[component]172 #[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> {
171 Ok(view! {174 Ok(view! {
172 <ul class="status-list">175 <ul class="status-list">
173 for item in items.iter() {176 for item in items.iter() {
crates/forge-web/src/views/diff.rsmodified+20 -8
@@ -13,7 +13,7 @@ use std::collections::HashMap;
13 use forge_core::{Side, Thread};13 use forge_core::{Side, Thread};
14 use forge_git::history::{CommitDiff, DiffLimits, DiffStatus, FileDiff, LineKind};14 use forge_git::history::{CommitDiff, DiffLimits, DiffStatus, FileDiff, LineKind};
15 use topcoat::Result;15 use topcoat::Result;
16-use topcoat::context::{Cx, app_context};16+use topcoat::context::{Cx, context};
17 use topcoat::cookie::{Cookie, Cookies, SameSite, cookies, time};17 use topcoat::cookie::{Cookie, Cookies, SameSite, cookies, time};
18 use topcoat::router::request::uri;18 use topcoat::router::request::uri;
19 use topcoat::view::{View, component, view};19 use topcoat::view::{View, component, view};
@@ -111,7 +111,7 @@ impl DiffOpts {
111 }111 }
112 let split = match current_user(cx).await? {112 let split = match current_user(cx).await? {
113 Some((user, _)) => {113 Some((user, _)) => {
114- let state = app_context::<AppState>(cx);114+ let state = context::<AppState>(cx);
115 let stored = state.store.user_prefs(&user.id).await?.remove(DIFF_VIEW);115 let stored = state.store.user_prefs(&user.id).await?.remove(DIFF_VIEW);
116 match view_param.as_deref() {116 match view_param.as_deref() {
117 Some(v @ ("split" | "unified")) => {117 Some(v @ ("split" | "unified")) => {
@@ -511,6 +511,7 @@ struct NavItem {
511 #[allow(clippy::too_many_arguments)]511 #[allow(clippy::too_many_arguments)]
512 #[component]512 #[component]
513 pub async fn diff_section(513 pub async fn diff_section(
514+ cx: &Cx,
514 diff: &CommitDiff,515 diff: &CommitDiff,
515 owner: &str,516 owner: &str,
516 repo: &str,517 repo: &str,
@@ -529,7 +530,12 @@ pub async fn diff_section(
529 .files530 .files
530 .iter()531 .iter()
531 .enumerate()532 .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+ })
533 .filter(|(i, _)| opts.only.is_none_or(|only| only == *i))539 .filter(|(i, _)| opts.only.is_none_or(|only| only == *i))
534 .map(|(_, file)| file)540 .map(|(_, file)| file)
535 .collect();541 .collect();
@@ -605,7 +611,7 @@ pub async fn diff_section(
605 611
606 /// Unified or split, ignore whitespace, and the patch and diff downloads.612 /// Unified or split, ignore whitespace, and the patch and diff downloads.
607 #[component]613 #[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> {
609 let unified_on = if bar.split { "false" } else { "true" };615 let unified_on = if bar.split { "false" } else { "true" };
610 let split_on = if bar.split { "true" } else { "false" };616 let split_on = if bar.split { "true" } else { "false" };
611 let ws_on = if bar.ignore_ws { "true" } else { "false" };617 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> {
623 }629 }
624 630
625 #[component]631 #[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> {
627 let add_label = format!("+{}", file.additions);639 let add_label = format!("+{}", file.additions);
628 let del_label = format!("-{}", file.deletions);640 let del_label = format!("-{}", file.deletions);
629 let rows = file.rows;641 let rows = file.rows;
@@ -683,7 +695,7 @@ async fn diff_file(file: FileView, lang: Lang, split: bool, anchored: bool) -> R
683 /// One split row as a `<tbody>`: the two sides, then, when either has threads or an open form, a695 /// One split row as a `<tbody>`: the two sides, then, when either has threads or an open form, a
684 /// full-width row holding them. A hunk header spans the table.696 /// full-width row holding them. A hunk header spans the table.
685 #[component]697 #[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> {
687 let SplitRow {699 let SplitRow {
688 hunk,700 hunk,
689 left,701 left,
@@ -752,7 +764,7 @@ async fn diff_split_line(row: SplitRow, lang: Lang, anchored: bool) -> Result<im
752 /// One diff line as a `<tbody>`: the line itself, then, when it has threads or an open form, a764 /// One diff line as a `<tbody>`: the line itself, then, when it has threads or an open form, a
753 /// full-width row holding them.765 /// full-width row holding them.
754 #[component]766 #[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> {
756 let DiffRow {768 let DiffRow {
757 class,769 class,
758 old,770 old,
@@ -803,7 +815,7 @@ async fn diff_line(row: DiffRow, lang: Lang) -> Result<impl View> {
803 /// The inline comment form under a line. "Add single comment" posts one comment; the review815 /// The inline comment form under a line. "Add single comment" posts one comment; the review
804 /// button starts a review, or adds to the pending one.816 /// button starts a review, or adds to the pending one.
805 #[component]817 #[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> {
807 let InlineForm {819 let InlineForm {
808 action,820 action,
809 cancel_href,821 cancel_href,
crates/forge-web/src/views/find.rsmodified+2 -0
@@ -5,6 +5,7 @@
5 //! word as typed.5 //! word as typed.
6 6
7 use topcoat::Result;7 use topcoat::Result;
8+use topcoat::context::Cx;
8 use topcoat::view::{View, component, view};9 use topcoat::view::{View, component, view};
9 10
10 use crate::i18n::Lang;11 use crate::i18n::Lang;
@@ -160,6 +161,7 @@ fn distance(a: &[char], b: &[char]) -> usize {
160 /// searches as you type; an option applies the moment it is ticked.161 /// searches as you type; an option applies the moment it is ticked.
161 #[component]162 #[component]
162 pub async fn finder_field(163 pub async fn finder_field(
164+ cx: &Cx,
163 lang: Lang,165 lang: Lang,
164 finder: Finder,166 finder: Finder,
165 placeholder: &str,167 placeholder: &str,
crates/forge-web/src/views/heatmap.rsmodified+2 -0
@@ -8,6 +8,7 @@
8 //! that day's contributions under the calendar, and clicking the selected day again clears it.8 //! that day's contributions under the calendar, and clicking the selected day again clears it.
9 9
10 use std::collections::HashMap;10 use std::collections::HashMap;
11+use topcoat::context::Cx;
11 12
12 use forge_core::store::contributions::{ContributionItem, ContributionKind};13 use forge_core::store::contributions::{ContributionItem, ContributionKind};
13 use forge_core::time::stamp_to_unix;14 use forge_core::time::stamp_to_unix;
@@ -346,6 +347,7 @@ fn day_entries(lang: Lang, items: &[ContributionItem], now: i64) -> Vec<DayEntry
346 /// is the stream URL the card re-renders on; it is set on a person's overview only.347 /// is the stream URL the card re-renders on; it is set on a person's overview only.
347 #[component]348 #[component]
348 pub async fn contribution_calendar(349 pub async fn contribution_calendar(
350+ cx: &Cx,
349 calendar: Calendar,351 calendar: Calendar,
350 selected: Option<DayDetail>,352 selected: Option<DayDetail>,
351 lang: Lang,353 lang: Lang,
crates/forge-web/src/views/mod.rsmodified+26 -19
@@ -23,7 +23,7 @@ use http::header::{
23 use http::{HeaderValue, Uri};23 use http::{HeaderValue, Uri};
24 use sha2::{Digest, Sha256};24 use sha2::{Digest, Sha256};
25 use topcoat::Result;25 use topcoat::Result;
26-use topcoat::context::{Cx, try_app_context};26+use topcoat::context::{Cx, try_context};
27 use topcoat::router::request::uri;27 use topcoat::router::request::uri;
28 use topcoat::router::response::{Response, response_headers};28 use topcoat::router::response::{Response, response_headers};
29 use topcoat::router::{Body, Next, layer};29 use topcoat::router::{Body, Next, layer};
@@ -495,7 +495,7 @@ struct ProfileCorner {
495 /// waits. Its menu holds the name, notifications with their count, the settings and admin links and495 /// waits. Its menu holds the name, notifications with their count, the settings and admin links and
496 /// log out.496 /// log out.
497 #[component]497 #[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> {
499 let profile_href = user_href(&corner.username);499 let profile_href = user_href(&corner.username);
500 let profile_label = mi::t(lang, MK::YourProfile);500 let profile_label = mi::t(lang, MK::YourProfile);
501 let settings_label = o::t(lang, OK::Settings);501 let settings_label = o::t(lang, OK::Settings);
@@ -542,6 +542,7 @@ async fn profile_corner(lang: Lang, corner: ProfileCorner) -> Result<impl View>
542 /// more stylesheet link to the head (such as a repo's generated label colors).542 /// more stylesheet link to the head (such as a repo's generated label colors).
543 #[component]543 #[component]
544 pub async fn shell(544 pub async fn shell(
545+ cx: &Cx,
545 title: &str,546 title: &str,
546 viewer: Option<&(User, Session)>,547 viewer: Option<&(User, Session)>,
547 #[default] extra_stylesheet: Option<&str>,548 #[default] extra_stylesheet: Option<&str>,
@@ -552,7 +553,7 @@ pub async fn shell(
552 // The unread count, the profile corner's inbox counts, their CI runs and the items waiting on553 // The unread count, the profile corner's inbox counts, their CI runs and the items waiting on
553 // them. Signed-in only.554 // them. Signed-in only.
554 let (unread, inbox, runs) = match viewer {555 let (unread, inbox, runs) = match viewer {
555- Some((user, _)) => match try_app_context::<AppState>(__cx) {556+ Some((user, _)) => match try_context::<AppState>(cx) {
556 Some(state) => (557 Some(state) => (
557 state.store.unread_count(&user.id).await?,558 state.store.unread_count(&user.id).await?,
558 state.store.inbox_kind_counts(&user.id).await?,559 state.store.inbox_kind_counts(&user.id).await?,
@@ -567,26 +568,26 @@ pub async fn shell(
567 // stored preference saved. Anonymous visitors get the cookie. Either way the browser comes568 // stored preference saved. Anonymous visitors get the cookie. Either way the browser comes
568 // back to the page it was on.569 // back to the page it was on.
569 let theme_csrf = viewer.map(|(_, session)| session.csrf_token.clone());570 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 back = uri(cx).path_and_query().map(|p| p.as_str().to_owned());
571- let lang = i18n::lang(__cx, viewer.map(|(user, _)| user));572+ let lang = i18n::lang(cx, viewer.map(|(user, _)| user));
572 // A signed-in viewer's account preferences, read once for the banner, the tree width and the573 // A signed-in viewer's account preferences, read once for the banner, the tree width and the
573 // profile corner. Signed-out visitors keep theirs in the browser.574 // 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)) {
575 (Some((user, _)), Some(state)) => Some(state.store.user_prefs(&user.id).await?),576 (Some((user, _)), Some(state)) => Some(state.store.user_prefs(&user.id).await?),
576 _ => None,577 _ => None,
577 };578 };
578- let banner = crate::pages::banner::current(__cx, prefs.as_ref());579+ let banner = crate::pages::banner::current(cx, prefs.as_ref());
579 let sound_attr = crate::pages::settings_appearance::sound_attr(prefs.as_ref());580 let sound_attr = crate::pages::settings_appearance::sound_attr(prefs.as_ref());
580 let banner_back = back.clone().unwrap_or_else(|| "/".to_owned());581 let banner_back = back.clone().unwrap_or_else(|| "/".to_owned());
581 let dismiss_label = crate::i18n::accounts::t(lang, crate::i18n::accounts::A::Dismiss);582 let dismiss_label = crate::i18n::accounts::t(lang, crate::i18n::accounts::A::Dismiss);
582 // The admin area and the user settings swap the global links for their own list. Signed-in only.583 // The admin area and the user settings swap the global links for their own list. Signed-in only.
583 let section = if signed_in {584 let section = if signed_in {
584- section_for(lang, uri(__cx).path())585+ section_for(lang, uri(cx).path())
585 } else {586 } else {
586 None587 None
587 };588 };
588- let width = page_width(uri(__cx).path());589+ let width = page_width(uri(cx).path());
589- let theme_attr = crate::theme::data_theme(__cx, viewer.map(|(user, _)| user));590+ let theme_attr = crate::theme::data_theme(cx, viewer.map(|(user, _)| user));
590 // The relative-time wording and the server's clock, for nav.js to keep `<time data-rel>` labels current.591 // The relative-time wording and the server's clock, for nav.js to keep `<time data-rel>` labels current.
591 let rel_words_attr = rel_words(lang);592 let rel_words_attr = rel_words(lang);
592 let rel_now_attr = now_unix().to_string();593 let rel_now_attr = now_unix().to_string();
@@ -627,7 +628,7 @@ pub async fn shell(
627 };628 };
628 // The stored preference, "auto" included, drives the button: its icon, its label and the629 // The stored preference, "auto" included, drives the button: its icon, its label and the
629 // value it posts (the next preference in the cycle auto, light, dark).630 // 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));
631 let next_theme = crate::theme::next_preference(theme_pref);632 let next_theme = crate::theme::next_preference(theme_pref);
632 let theme_state = match theme_pref {633 let theme_state = match theme_pref {
633 "light" => mi::t(lang, MK::Light),634 "light" => mi::t(lang, MK::Light),
@@ -649,7 +650,7 @@ pub async fn shell(
649 let explore_label = t(lang, Key::Explore);650 let explore_label = t(lang, Key::Explore);
650 let home_label = o::t(lang, OK::Home);651 let home_label = o::t(lang, OK::Home);
651 // The path bar: one segment per part of the request path, the last one unlinked.652 // 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);
653 // A page with no place of its own in the path, such as settings, names its section and itself.654 // A page with no place of its own in the path, such as settings, names its section and itself.
654 // A page below one of the section's tabs (an account under Users) names that tab too.655 // A page below one of the section's tabs (an account under Users) names that tab too.
655 if segments.is_empty() {656 if segments.is_empty() {
@@ -658,7 +659,7 @@ pub async fn shell(
658 if section.title != title {659 if section.title != title {
659 segments.push((section.title.clone(), first));660 segments.push((section.title.clone(), first));
660 }661 }
661- let path = uri(__cx).path();662+ let path = uri(cx).path();
662 if let Some(item) = section.items.iter().find(|item| {663 if let Some(item) = section.items.iter().find(|item| {
663 path.strip_prefix(item.href.as_str())664 path.strip_prefix(item.href.as_str())
664 .is_some_and(|below| below.starts_with('/'))665 .is_some_and(|below| below.starts_with('/'))
@@ -1072,6 +1073,7 @@ pub fn section_for(lang: Lang, path: &str) -> Option<Section> {
1072 /// One row of text tabs, with `aria-current="page"` on the current one.1073 /// One row of text tabs, with `aria-current="page"` on the current one.
1073 #[component]1074 #[component]
1074 async fn section_tabs(1075 async fn section_tabs(
1076+ cx: &Cx,
1075 key: &'static str,1077 key: &'static str,
1076 label: &str,1078 label: &str,
1077 items: Vec<NavItem>,1079 items: Vec<NavItem>,
@@ -1132,7 +1134,7 @@ pub fn user_href(username: &str) -> String {
1132 /// the text to display (it differs from `login` only for the ghost account). Both are escaped1134 /// the text to display (it differs from `login` only for the ghost account). Both are escaped
1133 /// like any other interpolation.1135 /// like any other interpolation.
1134 #[component]1136 #[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> {
1136 let href = user_href(login);1138 let href = user_href(login);
1137 Ok(view! {1139 Ok(view! {
1138 <a href=(href.as_str())>(shown)</a>1140 <a href=(href.as_str())>(shown)</a>
@@ -1141,7 +1143,7 @@ pub async fn user_link(shown: &str, login: &str) -> Result<impl View> {
1141 1143
1142 /// Hidden CSRF input for a POST form.1144 /// Hidden CSRF input for a POST form.
1143 #[component]1145 #[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> {
1145 Ok(view! {1147 Ok(view! {
1146 <input type="hidden" name="csrf" value=(token)>1148 <input type="hidden" name="csrf" value=(token)>
1147 })1149 })
@@ -1149,7 +1151,7 @@ pub async fn csrf_field(token: &str) -> Result<impl View> {
1149 1151
1150 /// Inline error box.1152 /// Inline error box.
1151 #[component]1153 #[component]
1152-pub async fn alert(message: &str) -> Result<impl View> {1154+pub async fn alert(cx: &Cx, message: &str) -> Result<impl View> {
1153 Ok(view! {1155 Ok(view! {
1154 <p class="alert" role="alert">(message)</p>1156 <p class="alert" role="alert">(message)</p>
1155 })1157 })
@@ -1160,6 +1162,7 @@ pub async fn alert(message: &str) -> Result<impl View> {
1160 /// reads the same way.1162 /// reads the same way.
1161 #[component]1163 #[component]
1162 pub async fn empty_state(1164 pub async fn empty_state(
1165+ cx: &Cx,
1163 title: &str,1166 title: &str,
1164 #[default] hint: Option<&str>,1167 #[default] hint: Option<&str>,
1165 #[default] child: Child<'_>,1168 #[default] child: Child<'_>,
@@ -1194,7 +1197,7 @@ pub async fn security_headers(cx: &Cx, body: Body, next: Next<'_>) -> Result<Res
1194 headers.append(X_CONTENT_TYPE_OPTIONS, HeaderValue::from_static("nosniff"));1197 headers.append(X_CONTENT_TYPE_OPTIONS, HeaderValue::from_static("nosniff"));
1195 headers.append(REFERRER_POLICY, HeaderValue::from_static("same-origin"));1198 headers.append(REFERRER_POLICY, HeaderValue::from_static("same-origin"));
1196 headers.append(X_FRAME_OPTIONS, HeaderValue::from_static("DENY"));1199 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) {
1198 Some(state) => APP_CSP1201 Some(state) => APP_CSP
1199 .get_or_init(|| csp_header(&state.config.user_content_base_url))1202 .get_or_init(|| csp_header(&state.config.user_content_base_url))
1200 .clone(),1203 .clone(),
@@ -1327,7 +1330,7 @@ pub fn rel_words(lang: Lang) -> String {
1327 /// A live relative time for an RFC 3339 stamp: a `<time data-rel>` that nav.js re-words as the1330 /// A live relative time for an RFC 3339 stamp: a `<time data-rel>` that nav.js re-words as the
1328 /// clock moves. A stamp that does not parse renders empty.1331 /// clock moves. A stamp that does not parse renders empty.
1329 #[component]1332 #[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> {
1331 let label = forge_core::time::stamp_to_unix(stamp)1334 let label = forge_core::time::stamp_to_unix(stamp)
1332 .map_or_else(String::new, |unix| relative_time(lang, unix, now_unix()));1335 .map_or_else(String::new, |unix| relative_time(lang, unix, now_unix()));
1333 Ok(view! {1336 Ok(view! {
@@ -1337,7 +1340,7 @@ pub async fn rel_time(lang: Lang, stamp: &str) -> Result<impl View> {
1337 1340
1338 /// A live relative time, or "never" when there is no stamp.1341 /// A live relative time, or "never" when there is no stamp.
1339 #[component]1342 #[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> {
1341 Ok(view! {1344 Ok(view! {
1342 if let Some(stamp) = stamp {1345 if let Some(stamp) = stamp {
1343 rel_time(lang: lang, stamp: stamp)1346 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
1351 /// stamp is left out.1354 /// stamp is left out.
1352 #[component]1355 #[component]
1353 pub async fn added_status(1356 pub async fn added_status(
1357+ cx: &Cx,
1354 lang: Lang,1358 lang: Lang,
1355 added: Option<&str>,1359 added: Option<&str>,
1356 used: Option<&str>,1360 used: Option<&str>,
@@ -1423,6 +1427,7 @@ fn tab_more_class(on: bool) -> &'static str {
1423 /// counts shown on their tabs; a zero count (or `None`) shows the tab without one.1427 /// counts shown on their tabs; a zero count (or `None`) shows the tab without one.
1424 #[component]1428 #[component]
1425 pub async fn repo_tabs(1429 pub async fn repo_tabs(
1430+ cx: &Cx,
1426 owner: String,1431 owner: String,
1427 repo: String,1432 repo: String,
1428 default_branch: String,1433 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
1545 /// is left out.1550 /// is left out.
1546 #[component]1551 #[component]
1547 async fn ref_group(1552 async fn ref_group(
1553+ cx: &Cx,
1548 lang: Lang,1554 lang: Lang,
1549 kind: &'static str,1555 kind: &'static str,
1550 heading: &'static str,1556 heading: &'static str,
@@ -1593,6 +1599,7 @@ async fn ref_group(
1593 /// still lists the first entries of each section.1599 /// still lists the first entries of each section.
1594 #[component]1600 #[component]
1595 pub async fn ref_selector(1601 pub async fn ref_selector(
1602+ cx: &Cx,
1596 lang: Lang,1603 lang: Lang,
1597 label: &'static str,1604 label: &'static str,
1598 current: String,1605 current: String,
crates/forge-web/src/views/parts.rsmodified+11 -2
@@ -2,6 +2,7 @@
2 //! `docs/ui-language.md`.2 //! `docs/ui-language.md`.
3 3
4 use topcoat::Result;4 use topcoat::Result;
5+use topcoat::context::Cx;
5 use topcoat::view::{Child, View, ViewExt, component, view};6 use topcoat::view::{Child, View, ViewExt, component, view};
6 7
7 use crate::i18n::Lang;8 use crate::i18n::Lang;
@@ -10,7 +11,9 @@ use crate::pages::passkeys::s;
10 /// The width class of a strip segment holding `part` of `total`: `fr1` to `fr40`, since a page may11 /// The width class of a strip segment holding `part` of `total`: `fr1` to `fr40`, since a page may
11 /// not set inline styles. A segment with nothing in it still shows.12 /// not set inline styles. A segment with nothing in it still shows.
12 pub fn seg_fr(part: u64, total: u64) -> String {13 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);
14 format!("fr{}", n.clamp(1, 40))17 format!("fr{}", n.clamp(1, 40))
15 }18 }
16 19
@@ -18,6 +21,7 @@ pub fn seg_fr(part: u64, total: u64) -> String {
18 /// starts it open, as a form sent back with an error must.21 /// starts it open, as a form sent back with an error must.
19 #[component]22 #[component]
20 pub async fn reveal(23 pub async fn reveal(
24+ cx: &Cx,
21 label: &str,25 label: &str,
22 #[default] id: Option<&str>,26 #[default] id: Option<&str>,
23 #[default] open: bool,27 #[default] open: bool,
@@ -35,6 +39,7 @@ pub async fn reveal(
35 /// `fields` are the form's hidden fields besides the CSRF token, `note` says what will be lost.39 /// `fields` are the form's hidden fields besides the CSRF token, `note` says what will be lost.
36 #[component]40 #[component]
37 pub async fn confirm_act(41 pub async fn confirm_act(
42+ cx: &Cx,
38 lang: Lang,43 lang: Lang,
39 label: &str,44 label: &str,
40 action: &str,45 action: &str,
@@ -65,6 +70,7 @@ pub async fn confirm_act(
65 /// One text link that posts at once, for actions that lose nothing.70 /// One text link that posts at once, for actions that lose nothing.
66 #[component]71 #[component]
67 pub async fn post_act(72 pub async fn post_act(
73+ cx: &Cx,
68 label: &str,74 label: &str,
69 action: &str,75 action: &str,
70 csrf: &str,76 csrf: &str,
@@ -132,7 +138,7 @@ pub struct PeopleList {
132 138
133 /// The people list and its add form. The caller puts it in a sheet.139 /// The people list and its add form. The caller puts it in a sheet.
134 #[component]140 #[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> {
136 let PeopleList {142 let PeopleList {
137 lang,143 lang,
138 title,144 title,
@@ -287,6 +293,7 @@ impl SubPart {
287 /// The line under a head's title. `pips` are recent runs, oldest first, as (href, title, class).293 /// The line under a head's title. `pips` are recent runs, oldest first, as (href, title, class).
288 #[component]294 #[component]
289 pub async fn head_sub(295 pub async fn head_sub(
296+ cx: &Cx,
290 parts: Vec<SubPart>,297 parts: Vec<SubPart>,
291 #[default] pips: Vec<(String, String, &'static str)>,298 #[default] pips: Vec<(String, String, &'static str)>,
292 ) -> Result<impl View> {299 ) -> Result<impl View> {
@@ -323,6 +330,7 @@ pub async fn head_sub(
323 /// beside it (`child`), then the sub line. Every page starts with one. Section tabs follow it.330 /// beside it (`child`), then the sub line. Every page starts with one. Section tabs follow it.
324 #[component]331 #[component]
325 pub async fn head(332 pub async fn head(
333+ cx: &Cx,
326 title: &str,334 title: &str,
327 #[default] sub: Vec<SubPart>,335 #[default] sub: Vec<SubPart>,
328 #[default] live: Option<&str>,336 #[default] live: Option<&str>,
@@ -354,6 +362,7 @@ pub struct RailItem {
354 /// for a filter.362 /// for a filter.
355 #[component]363 #[component]
356 pub async fn rail(364 pub async fn rail(
365+ cx: &Cx,
357 label: &str,366 label: &str,
358 items: Vec<RailItem>,367 items: Vec<RailItem>,
359 #[default] heading: Option<&str>,368 #[default] heading: Option<&str>,
crates/forge-web/src/views/repo_list.rsmodified+6 -3
@@ -4,6 +4,7 @@
4 use forge_core::Visibility;4 use forge_core::Visibility;
5 use forge_core::store::ListedRepo;5 use forge_core::store::ListedRepo;
6 use topcoat::Result;6 use topcoat::Result;
7+use topcoat::context::Cx;
7 use topcoat::view::{View, component, view};8 use topcoat::view::{View, component, view};
8 9
9 use crate::i18n::orgs::{self as g, K};10 use crate::i18n::orgs::{self as g, K};
@@ -14,7 +15,8 @@ use crate::views::repo_href;
14 /// The fact a row leads with when the repo is private ("Private · "); public says nothing, it is15 /// The fact a row leads with when the repo is private ("Private · "); public says nothing, it is
15 /// the usual case.16 /// the usual case.
16 pub fn private_fact(lang: Lang, visibility: Visibility) -> Option<String> {17 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)))
18 }20 }
19 21
20 /// One listed repo, formatted for display.22 /// One listed repo, formatted for display.
@@ -45,7 +47,7 @@ impl RepoRow {
45 47
46 /// The repo rows: name, a one-line description, then Private (when it is), stars and the last update.48 /// The repo rows: name, a one-line description, then Private (when it is), stars and the last update.
47 #[component]49 #[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> {
49 let (before, after) = g::updated_parts(lang);51 let (before, after) = g::updated_parts(lang);
50 Ok(view! {52 Ok(view! {
51 <ul class="repo-list">53 <ul class="repo-list">
@@ -79,7 +81,7 @@ pub struct SortLink {
79 81
80 /// The "Sort by" chips.82 /// The "Sort by" chips.
81 #[component]83 #[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> {
83 Ok(view! {85 Ok(view! {
84 <nav class="sort" aria-label=(g::t(lang, K::SortNav))>86 <nav class="sort" aria-label=(g::t(lang, K::SortNav))>
85 <span class="hint">(g::t(lang, K::SortBy))</span>87 <span class="hint">(g::t(lang, K::SortBy))</span>
@@ -137,6 +139,7 @@ fn page_numbers(page: u64, pages: u64) -> Vec<Option<u64>> {
137 /// page.139 /// page.
138 #[component]140 #[component]
139 pub async fn pager(141 pub async fn pager(
142+ cx: &Cx,
140 page: u64,143 page: u64,
141 pages: u64,144 pages: u64,
142 links: Vec<PageLink>,145 links: Vec<PageLink>,
crates/forge-web/src/views/review_thread.rsmodified+7 -2
@@ -5,6 +5,7 @@
5 5
6 use std::collections::HashMap;6 use std::collections::HashMap;
7 use std::sync::Arc;7 use std::sync::Arc;
8+use topcoat::context::Cx;
8 9
9 use forge_core::suggestions::{Part, hunk_line, split_body};10 use forge_core::suggestions::{Part, hunk_line, split_body};
10 use forge_core::{ReviewComment, Thread};11 use forge_core::{ReviewComment, Thread};
@@ -167,6 +168,7 @@ fn comment_row(
167 /// `conversation` and tells the POST routes which tab to redirect to.168 /// `conversation` and tells the POST routes which tab to redirect to.
168 #[component]169 #[component]
169 pub async fn review_thread(170 pub async fn review_thread(
171+ cx: &Cx,
170 thread: Thread,172 thread: Thread,
171 ctx: ThreadCtx,173 ctx: ThreadCtx,
172 show_hunk: bool,174 show_hunk: bool,
@@ -181,6 +183,7 @@ pub async fn review_thread(
181 /// One thread with its strings in `lang`. See `review_thread` for the arguments.183 /// One thread with its strings in `lang`. See `review_thread` for the arguments.
182 #[component]184 #[component]
183 pub async fn review_thread_in(185 pub async fn review_thread_in(
186+ cx: &Cx,
184 lang: Lang,187 lang: Lang,
185 thread: Thread,188 thread: Thread,
186 ctx: ThreadCtx,189 ctx: ThreadCtx,
@@ -261,7 +264,7 @@ pub async fn review_thread_in(
261 /// The diff hunk, the comments, then the thread's tools and reply form. Split into siblings so264 /// The diff hunk, the comments, then the thread's tools and reply form. Split into siblings so
262 /// each component's view stays small enough to type-check.265 /// each component's view stays small enough to type-check.
263 #[component]266 #[component]
264-async fn thread_parts(parts: ThreadParts) -> Result<impl View> {267+async fn thread_parts(cx: &Cx, parts: ThreadParts) -> Result<impl View> {
265 let ThreadParts {268 let ThreadParts {
266 hunk,269 hunk,
267 comments,270 comments,
@@ -313,7 +316,7 @@ struct ThreadFooter {
313 /// The resolve button, and Reply, which opens its form in place. Each is empty when the viewer316 /// The resolve button, and Reply, which opens its form in place. Each is empty when the viewer
314 /// may not use it.317 /// may not use it.
315 #[component]318 #[component]
316-async fn thread_footer(footer: ThreadFooter) -> Result<impl View> {319+async fn thread_footer(cx: &Cx, footer: ThreadFooter) -> Result<impl View> {
317 let ThreadFooter {320 let ThreadFooter {
318 resolve_action,321 resolve_action,
319 resolve_value,322 resolve_value,
@@ -351,6 +354,7 @@ async fn thread_footer(footer: ThreadFooter) -> Result<impl View> {
351 354
352 #[component]355 #[component]
353 async fn thread_comment(356 async fn thread_comment(
357+ cx: &Cx,
354 comment: CommentRow,358 comment: CommentRow,
355 csrf: String,359 csrf: String,
356 return_to: String,360 return_to: String,
@@ -404,6 +408,7 @@ async fn thread_comment(
404 /// lines, the Apply control when it applies, and a note when it is outdated.408 /// lines, the Apply control when it applies, and a note when it is outdated.
405 #[component]409 #[component]
406 async fn comment_part(410 async fn comment_part(
411+ cx: &Cx,
407 part: PartRow,412 part: PartRow,
408 csrf: String,413 csrf: String,
409 return_to: String,414 return_to: String,
crates/forge-web/src/views/timeline.rsmodified+2 -0
@@ -4,6 +4,7 @@
4 4
5 use forge_core::ci::RunState;5 use forge_core::ci::RunState;
6 use topcoat::Result;6 use topcoat::Result;
7+use topcoat::context::Cx;
7 use topcoat::view::{View, component, view};8 use topcoat::view::{View, component, view};
8 9
9 use super::{repo_href, short_oid};10 use super::{repo_href, short_oid};
@@ -54,6 +55,7 @@ struct BarView {
54 /// counts the bars drawn.55 /// counts the bars drawn.
55 #[component]56 #[component]
56 pub async fn history_strip(57 pub async fn history_strip(
58+ cx: &Cx,
57 lang: Lang,59 lang: Lang,
58 owner: String,60 owner: String,
59 repo: String,61 repo: String,