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 commitfe7f9a01ea677d578d6653047e5cd80008f15720Parent: 29a1eb3All checks have passed
Show checks
ci/buildSucceededDetails
- 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.lock +73 -68
- Cargo.toml +1 -1
- crates/forge-core/src/store/migrate.rs +8 -2
- crates/forge-core/src/tz.rs +5 -1
- crates/forge-e2e/tests/e2e/browse_e2e.rs +5 -1
- crates/forge-e2e/tests/e2e/community_i18n_e2e.rs +2 -8
- crates/forge-e2e/tests/e2e/pulls_e2e.rs +2 -1
- crates/forge-e2e/tests/e2e/repo_rename_e2e.rs +3 -1
- crates/forge-e2e/tests/e2e/repo_settings_e2e.rs +17 -4
- crates/forge-e2e/tests/e2e/repo_transfer_e2e.rs +9 -3
- crates/forge-web-base/src/accent.rs +9 -1
- crates/forge-web-base/src/compression.rs +1 -1
- crates/forge-web-base/src/i18n/admin.rs +2 -6
- crates/forge-web-base/src/i18n/issues.rs +3 -1
- crates/forge-web-base/src/render/markdown.rs +8 -2
- crates/forge-web/src/api/gitea.rs +23 -32
- crates/forge-web/src/api/packages.rs +22 -42
- crates/forge-web/src/api/releases.rs +24 -38
- crates/forge-web/src/api/statuses.rs +7 -21
- crates/forge-web/src/auth.rs +5 -5
- crates/forge-web/src/boot.rs +4 -6
- crates/forge-web/src/ci/api.rs +19 -19
- crates/forge-web/src/client_ip.rs +2 -2
- crates/forge-web/src/git_http.rs +8 -8
- crates/forge-web/src/internal.rs +7 -7
- crates/forge-web/src/lfs/routes.rs +15 -15
- crates/forge-web/src/main.rs +1 -1
- crates/forge-web/src/oci/auth.rs +2 -2
- crates/forge-web/src/oci/mod.rs +5 -5
- crates/forge-web/src/pages/activity.rs +3 -3
- crates/forge-web/src/pages/admin_backups.rs +11 -7
- crates/forge-web/src/pages/admin_health.rs +8 -5
- crates/forge-web/src/pages/admin_mail.rs +6 -5
- crates/forge-web/src/pages/admin_replication.rs +6 -5
- crates/forge-web/src/pages/admin_runners.rs +39 -37
- crates/forge-web/src/pages/admin_server.rs +10 -9
- crates/forge-web/src/pages/admin_user_detail.rs +10 -8
- crates/forge-web/src/pages/admin_users.rs +11 -8
- crates/forge-web/src/pages/archive.rs +5 -5
- crates/forge-web/src/pages/assets.rs +38 -20
- crates/forge-web/src/pages/audit_log.rs +27 -10
- crates/forge-web/src/pages/authoring.rs +11 -11
- crates/forge-web/src/pages/avatars.rs +6 -3
- crates/forge-web/src/pages/banner.rs +3 -3
- crates/forge-web/src/pages/blame.rs +11 -8
- crates/forge-web/src/pages/blob.rs +11 -7
- crates/forge-web/src/pages/branches.rs +12 -10
- crates/forge-web/src/pages/ci_badge.rs +4 -4
- crates/forge-web/src/pages/ci_fail.rs +15 -8
- crates/forge-web/src/pages/ci_job.rs +19 -18
- crates/forge-web/src/pages/ci_runs.rs +81 -57
- crates/forge-web/src/pages/ci_tests.rs +4 -1
- crates/forge-web/src/pages/code_live.rs +4 -4
- crates/forge-web/src/pages/code_search.rs +4 -4
- crates/forge-web/src/pages/commit.rs +6 -6
- crates/forge-web/src/pages/commits.rs +5 -5
- crates/forge-web/src/pages/compare.rs +14 -14
- crates/forge-web/src/pages/discussion_actions.rs +31 -31
- crates/forge-web/src/pages/discussion_live.rs +7 -7
- crates/forge-web/src/pages/discussion_settings.rs +10 -4
- crates/forge-web/src/pages/discussion_view.rs +11 -7
- crates/forge-web/src/pages/discussions.rs +11 -10
- crates/forge-web/src/pages/edit_history.rs +10 -13
- crates/forge-web/src/pages/explore.rs +25 -10
- crates/forge-web/src/pages/finder.rs +6 -5
- crates/forge-web/src/pages/forgot.rs +7 -6
- crates/forge-web/src/pages/fork.rs +4 -4
- crates/forge-web/src/pages/home.rs +5 -5
- crates/forge-web/src/pages/import.rs +44 -30
- crates/forge-web/src/pages/invites.rs +3 -2
- crates/forge-web/src/pages/issue_meta.rs +25 -19
- crates/forge-web/src/pages/issue_parts.rs +42 -14
- crates/forge-web/src/pages/issue_pin.rs +6 -5
- crates/forge-web/src/pages/issue_pin_tests.rs +4 -1
- crates/forge-web/src/pages/issue_view.rs +31 -31
- crates/forge-web/src/pages/issues_list.rs +17 -11
- crates/forge-web/src/pages/issues_live.rs +6 -6
- crates/forge-web/src/pages/labels_css.rs +4 -4
- crates/forge-web/src/pages/labels_page.rs +24 -31
- crates/forge-web/src/pages/login.rs +15 -8
- crates/forge-web/src/pages/media.rs +2 -2
- crates/forge-web/src/pages/merge_queue.rs +16 -18
- crates/forge-web/src/pages/milestones_page.rs +28 -31
- crates/forge-web/src/pages/needs_you.rs +4 -4
- crates/forge-web/src/pages/new_repo.rs +7 -6
- crates/forge-web/src/pages/not_found_page.rs +2 -2
- crates/forge-web/src/pages/notifications.rs +47 -29
- crates/forge-web/src/pages/org_ctx.rs +4 -3
- crates/forge-web/src/pages/org_live.rs +11 -11
- crates/forge-web/src/pages/org_members.rs +20 -11
- crates/forge-web/src/pages/org_new.rs +6 -5
- crates/forge-web/src/pages/org_settings.rs +14 -13
- crates/forge-web/src/pages/org_teams.rs +30 -28
- crates/forge-web/src/pages/packages.rs +11 -11
- crates/forge-web/src/pages/packages_oci.rs +2 -1
- crates/forge-web/src/pages/palette.rs +2 -2
- crates/forge-web/src/pages/passkeys.rs +14 -9
- crates/forge-web/src/pages/passkeys_tests.rs +4 -1
- crates/forge-web/src/pages/profile.rs +22 -9
- crates/forge-web/src/pages/profile_pins.rs +6 -5
- crates/forge-web/src/pages/pull_branch.rs +5 -4
- crates/forge-web/src/pages/pull_files.rs +16 -14
- crates/forge-web/src/pages/pull_flow.rs +11 -11
- crates/forge-web/src/pages/pull_live.rs +7 -7
- crates/forge-web/src/pages/pull_reviews.rs +40 -40
- crates/forge-web/src/pages/pull_view.rs +21 -20
- crates/forge-web/src/pages/pulls_list.rs +16 -10
- crates/forge-web/src/pages/pulls_merge.rs +4 -4
- crates/forge-web/src/pages/push.rs +12 -12
- crates/forge-web/src/pages/reactions.rs +4 -4
- crates/forge-web/src/pages/ref_live.rs +4 -4
- crates/forge-web/src/pages/refs.rs +5 -5
- crates/forge-web/src/pages/register.rs +7 -5
- crates/forge-web/src/pages/releases.rs +45 -40
- crates/forge-web/src/pages/releases_live.rs +6 -6
- crates/forge-web/src/pages/repo.rs +14 -6
- crates/forge-web/src/pages/repo_collaborators.rs +14 -13
- crates/forge-web/src/pages/repo_ctx.rs +6 -3
- crates/forge-web/src/pages/repo_mirrors.rs +27 -23
- crates/forge-web/src/pages/repo_rename.rs +15 -15
- crates/forge-web/src/pages/repo_scrub.rs +6 -6
- crates/forge-web/src/pages/repo_secrets.rs +12 -10
- crates/forge-web/src/pages/repo_security.rs +8 -7
- crates/forge-web/src/pages/repo_settings.rs +87 -41
- crates/forge-web/src/pages/repo_settings_live.rs +7 -7
- crates/forge-web/src/pages/repo_side.rs +3 -2
- crates/forge-web/src/pages/repo_transfer.rs +14 -10
- crates/forge-web/src/pages/repo_webhooks.rs +37 -31
- crates/forge-web/src/pages/review_requests.rs +11 -7
- crates/forge-web/src/pages/settings_appearance.rs +6 -6
- crates/forge-web/src/pages/settings_export.rs +27 -13
- crates/forge-web/src/pages/settings_gpg.rs +5 -4
- crates/forge-web/src/pages/settings_keys.rs +6 -4
- crates/forge-web/src/pages/settings_live.rs +4 -4
- crates/forge-web/src/pages/settings_notifications.rs +4 -4
- crates/forge-web/src/pages/settings_profile.rs +10 -18
- crates/forge-web/src/pages/settings_security.rs +15 -15
- crates/forge-web/src/pages/settings_sessions.rs +4 -4
- crates/forge-web/src/pages/settings_tokens.rs +5 -4
- crates/forge-web/src/pages/setup.rs +4 -3
- crates/forge-web/src/pages/shell_events.rs +2 -2
- crates/forge-web/src/pages/snippet_raw.rs +2 -2
- crates/forge-web/src/pages/snippets.rs +24 -18
- crates/forge-web/src/pages/snippets_live.rs +4 -4
- crates/forge-web/src/pages/star.rs +4 -4
- crates/forge-web/src/pages/theme_cookie.rs +2 -2
- crates/forge-web/src/pages/tree.rs +16 -10
- crates/forge-web/src/pages/user_prefs.rs +2 -2
- crates/forge-web/src/pages/wiki.rs +49 -43
- crates/forge-web/src/pages/wiki_live.rs +6 -6
- crates/forge-web/src/raw.rs +4 -4
- crates/forge-web/src/test_support.rs +4 -7
- crates/forge-web/src/views/commit_line.rs +2 -1
- crates/forge-web/src/views/commit_status.rs +4 -1
- crates/forge-web/src/views/diff.rs +20 -8
- crates/forge-web/src/views/find.rs +2 -0
- crates/forge-web/src/views/heatmap.rs +2 -0
- crates/forge-web/src/views/mod.rs +26 -19
- crates/forge-web/src/views/parts.rs +11 -2
- crates/forge-web/src/views/repo_list.rs +6 -3
- crates/forge-web/src/views/review_thread.rs +7 -2
- crates/forge-web/src/views/timeline.rs +2 -0
Cargo.lockmodified+73 -68
| @@ -242,12 +242,6 @@ version = "1.0.105" | ||
| 242 | 242 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 243 | 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 | 245 | [[package]] |
| 252 | 246 | name = "arc-swap" |
| 253 | 247 | version = "1.9.5" |
| @@ -3396,17 +3390,6 @@ dependencies = [ | ||
| 3396 | 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 | 3393 | [[package]] |
| 3411 | 3394 | name = "html5ever" |
| 3412 | 3395 | version = "0.40.1" |
| @@ -4146,7 +4129,6 @@ dependencies = [ | ||
| 4146 | 4129 | "fastrand", |
| 4147 | 4130 | "futures-io", |
| 4148 | 4131 | "futures-util", |
| 4149 | - "hostname", | |
| 4150 | 4132 | "httpdate", |
| 4151 | 4133 | "idna", |
| 4152 | 4134 | "mime", |
| @@ -7180,9 +7162,9 @@ checksum = "009dbb7700f11c55ef83aebbe4c0e9cf1f1ac0844bd8d6f00dc38f302026e13a" | ||
| 7180 | 7162 | |
| 7181 | 7163 | [[package]] |
| 7182 | 7164 | name = "topcoat" |
| 7183 | -version = "0.11.0" | |
| 7165 | +version = "0.12.1" | |
| 7184 | 7166 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 7185 | -checksum = "70b5093d8133b513742b7461a28d374107b8bf9168aa60f4f567ad89acd2ed9e" | |
| 7167 | +checksum = "16bfbdbedee481dc7a9e89ed7c5be0a8fda008d6170fe9012c220590297eb4b9" | |
| 7186 | 7168 | dependencies = [ |
| 7187 | 7169 | "futures-util", |
| 7188 | 7170 | "inventory", |
| @@ -7190,13 +7172,14 @@ dependencies = [ | ||
| 7190 | 7172 | "tokio", |
| 7191 | 7173 | "tokio-tungstenite", |
| 7192 | 7174 | "topcoat-asset", |
| 7175 | + "topcoat-asset-macro", | |
| 7193 | 7176 | "topcoat-cookie", |
| 7194 | 7177 | "topcoat-core", |
| 7195 | 7178 | "topcoat-core-macro", |
| 7196 | 7179 | "topcoat-font", |
| 7197 | 7180 | "topcoat-font-macro", |
| 7198 | 7181 | "topcoat-l10n", |
| 7199 | - "topcoat-mail", | |
| 7182 | + "topcoat-metadata", | |
| 7200 | 7183 | "topcoat-router", |
| 7201 | 7184 | "topcoat-router-macro", |
| 7202 | 7185 | "topcoat-runtime", |
| @@ -7208,9 +7191,9 @@ dependencies = [ | ||
| 7208 | 7191 | |
| 7209 | 7192 | [[package]] |
| 7210 | 7193 | name = "topcoat-asset" |
| 7211 | -version = "0.11.0" | |
| 7194 | +version = "0.12.1" | |
| 7212 | 7195 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 7213 | -checksum = "ac70debf9eee62714ce45416eae27b283c3a44a0f9ebcb2ac088fda48b533f3e" | |
| 7196 | +checksum = "14de3c5734f7bb8ffc85ae33baa00e7dafee22978d02ef13e2ce3ad992fb1bc8" | |
| 7214 | 7197 | dependencies = [ |
| 7215 | 7198 | "http", |
| 7216 | 7199 | "memchr", |
| @@ -7225,11 +7208,34 @@ dependencies = [ | ||
| 7225 | 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 | 7234 | [[package]] |
| 7229 | 7235 | name = "topcoat-cookie" |
| 7230 | -version = "0.11.0" | |
| 7236 | +version = "0.12.1" | |
| 7231 | 7237 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 7232 | -checksum = "df79aba10192abe21fbd01dfcb46bb04dab5ae64adb4432d9f078eb05f94e6a5" | |
| 7238 | +checksum = "7fa34d585203cb080afce31749310bf5d9f238491636806d875726c7faebe10c" | |
| 7233 | 7239 | dependencies = [ |
| 7234 | 7240 | "cookie", |
| 7235 | 7241 | "getrandom 0.2.17", |
| @@ -7242,11 +7248,10 @@ dependencies = [ | ||
| 7242 | 7248 | |
| 7243 | 7249 | [[package]] |
| 7244 | 7250 | name = "topcoat-core" |
| 7245 | -version = "0.11.0" | |
| 7251 | +version = "0.12.1" | |
| 7246 | 7252 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 7247 | -checksum = "ffff49b885744cdb89ee158c5d81cc8c619692bd9f4ab3cae92ad1adc0ce612e" | |
| 7253 | +checksum = "121a7616ec29bc5525a4a580554c3d5330ce4314655a13d0d8d10cc1a083fc7a" | |
| 7248 | 7254 | dependencies = [ |
| 7249 | - "anymap3", | |
| 7250 | 7255 | "base64 0.22.1", |
| 7251 | 7256 | "elsa", |
| 7252 | 7257 | "http", |
| @@ -7258,9 +7263,9 @@ dependencies = [ | ||
| 7258 | 7263 | |
| 7259 | 7264 | [[package]] |
| 7260 | 7265 | name = "topcoat-core-grammar" |
| 7261 | -version = "0.11.0" | |
| 7266 | +version = "0.12.1" | |
| 7262 | 7267 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 7263 | -checksum = "b788a2010234cd29fc050268e52ceb393d2124b20f669a83d8f61a9dbf895bb6" | |
| 7268 | +checksum = "6d2326406a37c4eb212d60bc421589f3b600f50ca440b8e39dbdb7f7d032cb8a" | |
| 7264 | 7269 | dependencies = [ |
| 7265 | 7270 | "proc-macro-crate", |
| 7266 | 7271 | "proc-macro2", |
| @@ -7270,9 +7275,9 @@ dependencies = [ | ||
| 7270 | 7275 | |
| 7271 | 7276 | [[package]] |
| 7272 | 7277 | name = "topcoat-core-macro" |
| 7273 | -version = "0.11.0" | |
| 7278 | +version = "0.12.1" | |
| 7274 | 7279 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 7275 | -checksum = "3e3786bf2ee2c8b4f728d3fb53c41f639aa66583788b3135acbd63c11458b25b" | |
| 7280 | +checksum = "020d81b3dfe852b7b5e44bbb2079c6b1346d6dfe50bc267e5d5a05c40bf5d9a4" | |
| 7276 | 7281 | dependencies = [ |
| 7277 | 7282 | "quote", |
| 7278 | 7283 | "syn 3.0.10", |
| @@ -7281,9 +7286,9 @@ dependencies = [ | ||
| 7281 | 7286 | |
| 7282 | 7287 | [[package]] |
| 7283 | 7288 | name = "topcoat-font" |
| 7284 | -version = "0.11.0" | |
| 7289 | +version = "0.12.1" | |
| 7285 | 7290 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 7286 | -checksum = "caa4656294aac116def1e7633f03117a84b65126c503242793ff4adc78577fb8" | |
| 7291 | +checksum = "5e4382e452ddefff5b03cee1b3c84bcd36783e50afd2fea1e21fc9b41807142e" | |
| 7287 | 7292 | dependencies = [ |
| 7288 | 7293 | "heck", |
| 7289 | 7294 | "inventory", |
| @@ -7298,9 +7303,9 @@ dependencies = [ | ||
| 7298 | 7303 | |
| 7299 | 7304 | [[package]] |
| 7300 | 7305 | name = "topcoat-font-grammar" |
| 7301 | -version = "0.11.0" | |
| 7306 | +version = "0.12.1" | |
| 7302 | 7307 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 7303 | -checksum = "b462fae28641a1bb24eab1fa9c473520389ca690331ca53fd6143d5b2746045e" | |
| 7308 | +checksum = "d6159e8e361f19367ddb11de5e5ff9b04f92d91e0c46ef9b1a076404d83fcfe8" | |
| 7304 | 7309 | dependencies = [ |
| 7305 | 7310 | "proc-macro2", |
| 7306 | 7311 | "quote", |
| @@ -7311,9 +7316,9 @@ dependencies = [ | ||
| 7311 | 7316 | |
| 7312 | 7317 | [[package]] |
| 7313 | 7318 | name = "topcoat-font-macro" |
| 7314 | -version = "0.11.0" | |
| 7319 | +version = "0.12.1" | |
| 7315 | 7320 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 7316 | -checksum = "40776cd3087aaea5e0c8b597126b1c09dbfb0d69833088d7f3b229305bbbb87f" | |
| 7321 | +checksum = "7e3d3a71216cec0a27497716d4559e34245e61328f6e04fc2a2bac3b80679b31" | |
| 7317 | 7322 | dependencies = [ |
| 7318 | 7323 | "quote", |
| 7319 | 7324 | "syn 3.0.10", |
| @@ -7322,10 +7327,11 @@ dependencies = [ | ||
| 7322 | 7327 | |
| 7323 | 7328 | [[package]] |
| 7324 | 7329 | name = "topcoat-l10n" |
| 7325 | -version = "0.11.0" | |
| 7330 | +version = "0.12.1" | |
| 7326 | 7331 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 7327 | -checksum = "34da63b3a5aea3d6c243d9fa8c98ca79b181b985f6a0a042f630672f54d12e9e" | |
| 7332 | +checksum = "d877822424504842f90d9f018dbaa61be2d52071653bc0f0921652ef925fdabd" | |
| 7328 | 7333 | dependencies = [ |
| 7334 | + "http", | |
| 7329 | 7335 | "icu_locale", |
| 7330 | 7336 | "icu_locale_core", |
| 7331 | 7337 | "topcoat-core", |
| @@ -7333,24 +7339,24 @@ dependencies = [ | ||
| 7333 | 7339 | ] |
| 7334 | 7340 | |
| 7335 | 7341 | [[package]] |
| 7336 | -name = "topcoat-mail" | |
| 7337 | -version = "0.11.0" | |
| 7342 | +name = "topcoat-metadata" | |
| 7343 | +version = "0.12.1" | |
| 7338 | 7344 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 7339 | -checksum = "54a13c10c6399d9eb9b0bde38bd3d947eba56ddfaea99d9a4f971b74b6a651db" | |
| 7345 | +checksum = "bf250ddbaea17bd63c7d6f124ce8f883dee44ece584cfab979ec33a87a030875" | |
| 7340 | 7346 | dependencies = [ |
| 7341 | - "lettre", | |
| 7342 | - "thiserror 2.0.21", | |
| 7343 | - "time", | |
| 7347 | + "topcoat-asset", | |
| 7344 | 7348 | "topcoat-core", |
| 7349 | + "topcoat-core-macro", | |
| 7345 | 7350 | "topcoat-router", |
| 7346 | 7351 | "topcoat-view", |
| 7352 | + "topcoat-view-macro", | |
| 7347 | 7353 | ] |
| 7348 | 7354 | |
| 7349 | 7355 | [[package]] |
| 7350 | 7356 | name = "topcoat-router" |
| 7351 | -version = "0.11.0" | |
| 7357 | +version = "0.12.1" | |
| 7352 | 7358 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 7353 | -checksum = "b9488065b08f293208b0f1aeb6667d5836b66c12dfced5e330f9a8f1d7f1ca1a" | |
| 7359 | +checksum = "c86534384925992375ac979e9b5af7e4086119803b4586c6ac9bca814e814ed2" | |
| 7354 | 7360 | dependencies = [ |
| 7355 | 7361 | "bytes", |
| 7356 | 7362 | "form_urlencoded", |
| @@ -7384,11 +7390,10 @@ dependencies = [ | ||
| 7384 | 7390 | |
| 7385 | 7391 | [[package]] |
| 7386 | 7392 | name = "topcoat-router-grammar" |
| 7387 | -version = "0.11.0" | |
| 7393 | +version = "0.12.1" | |
| 7388 | 7394 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 7389 | -checksum = "ac3f51fa1a1e538bd34e02f88ebba554ac5931e55c688303a58a8e78123dfb04" | |
| 7395 | +checksum = "0aa0f6bb59f921cdde73395cc526374d8a553d3285c3f4ac8086c40bedc5be3a" | |
| 7390 | 7396 | dependencies = [ |
| 7391 | - "heck", | |
| 7392 | 7397 | "proc-macro2", |
| 7393 | 7398 | "quote", |
| 7394 | 7399 | "syn 3.0.10", |
| @@ -7397,9 +7402,9 @@ dependencies = [ | ||
| 7397 | 7402 | |
| 7398 | 7403 | [[package]] |
| 7399 | 7404 | name = "topcoat-router-macro" |
| 7400 | -version = "0.11.0" | |
| 7405 | +version = "0.12.1" | |
| 7401 | 7406 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 7402 | -checksum = "3c1b56d3bf19d54bddf300d6d57ca754531d7ad5481afca0b2302ac33f5d43af" | |
| 7407 | +checksum = "71ddd5e527cdab30c73293f907e8f40ef16c421484bb7bad107ecd967a6b98c3" | |
| 7403 | 7408 | dependencies = [ |
| 7404 | 7409 | "quote", |
| 7405 | 7410 | "syn 3.0.10", |
| @@ -7408,9 +7413,9 @@ dependencies = [ | ||
| 7408 | 7413 | |
| 7409 | 7414 | [[package]] |
| 7410 | 7415 | name = "topcoat-runtime" |
| 7411 | -version = "0.11.0" | |
| 7416 | +version = "0.12.1" | |
| 7412 | 7417 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 7413 | -checksum = "03b22136b99694b349a950cd757387a04b080fdb131eecdd51d0511e1a45ebf5" | |
| 7418 | +checksum = "3e8f8651d36f003dd85a6a36ff5e1161b01af1cc5ae5baa38e649bda3605037a" | |
| 7414 | 7419 | dependencies = [ |
| 7415 | 7420 | "futures-util", |
| 7416 | 7421 | "pin-project-lite", |
| @@ -7419,6 +7424,7 @@ dependencies = [ | ||
| 7419 | 7424 | "serde_json", |
| 7420 | 7425 | "tokio", |
| 7421 | 7426 | "topcoat-asset", |
| 7427 | + "topcoat-asset-macro", | |
| 7422 | 7428 | "topcoat-core", |
| 7423 | 7429 | "topcoat-router", |
| 7424 | 7430 | "topcoat-view", |
| @@ -7427,9 +7433,9 @@ dependencies = [ | ||
| 7427 | 7433 | |
| 7428 | 7434 | [[package]] |
| 7429 | 7435 | name = "topcoat-runtime-grammar" |
| 7430 | -version = "0.11.0" | |
| 7436 | +version = "0.12.1" | |
| 7431 | 7437 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 7432 | -checksum = "ab93a83c38a045a4f541c2e548d30ba5dfdd3173c18de8b1c7b049709c29db97" | |
| 7438 | +checksum = "1650432fe7adeab5aa815b84245c29c3ea5390a3b4a41d7cc2868e8f60f6277b" | |
| 7433 | 7439 | dependencies = [ |
| 7434 | 7440 | "proc-macro2", |
| 7435 | 7441 | "quote", |
| @@ -7443,9 +7449,9 @@ dependencies = [ | ||
| 7443 | 7449 | |
| 7444 | 7450 | [[package]] |
| 7445 | 7451 | name = "topcoat-runtime-macro" |
| 7446 | -version = "0.11.0" | |
| 7452 | +version = "0.12.1" | |
| 7447 | 7453 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 7448 | -checksum = "5acb1db0bdba3c36e4f80f7ef530945779a1b0294b1087e7d877e33005da6283" | |
| 7454 | +checksum = "f4ea7a5b61e948d702a5cb6727c38a3b0c934b630cc003971ca86a9262c16b0c" | |
| 7449 | 7455 | dependencies = [ |
| 7450 | 7456 | "quote", |
| 7451 | 7457 | "syn 3.0.10", |
| @@ -7454,9 +7460,9 @@ dependencies = [ | ||
| 7454 | 7460 | |
| 7455 | 7461 | [[package]] |
| 7456 | 7462 | name = "topcoat-session" |
| 7457 | -version = "0.11.0" | |
| 7463 | +version = "0.12.1" | |
| 7458 | 7464 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 7459 | -checksum = "2325c30a484b1b1b6f5012b50bc18994d37c33c6bd2f71be8ff509b591a17457" | |
| 7465 | +checksum = "d705011dbdf07ea9e3f74397f177cf3224a2fa0ff600a2514c11837ef04e1858" | |
| 7460 | 7466 | dependencies = [ |
| 7461 | 7467 | "base64 0.22.1", |
| 7462 | 7468 | "getrandom 0.4.3", |
| @@ -7465,15 +7471,14 @@ dependencies = [ | ||
| 7465 | 7471 | "tokio", |
| 7466 | 7472 | "topcoat-cookie", |
| 7467 | 7473 | "topcoat-core", |
| 7468 | - "topcoat-router", | |
| 7469 | 7474 | "web-time", |
| 7470 | 7475 | ] |
| 7471 | 7476 | |
| 7472 | 7477 | [[package]] |
| 7473 | 7478 | name = "topcoat-view" |
| 7474 | -version = "0.11.0" | |
| 7479 | +version = "0.12.1" | |
| 7475 | 7480 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 7476 | -checksum = "db4553b91f30e30c71c2bd95ae8e931a33326c6ffb604663b9d214008f12947c" | |
| 7481 | +checksum = "654e102f97a4c26ba9b7deb72bdac45c8587ced30480b431155a56a935d12e86" | |
| 7477 | 7482 | dependencies = [ |
| 7478 | 7483 | "futures-core", |
| 7479 | 7484 | "futures-util", |
| @@ -7487,9 +7492,9 @@ dependencies = [ | ||
| 7487 | 7492 | |
| 7488 | 7493 | [[package]] |
| 7489 | 7494 | name = "topcoat-view-grammar" |
| 7490 | -version = "0.11.0" | |
| 7495 | +version = "0.12.1" | |
| 7491 | 7496 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 7492 | -checksum = "75dd093ffc848370da4cce7670ccdfd4e98eab48e178d5d0da5509f747d85ca6" | |
| 7497 | +checksum = "28e348a794d04565ee00e7899f215c02db9acf0711bb8eefbba2ffa14bc72a5c" | |
| 7493 | 7498 | dependencies = [ |
| 7494 | 7499 | "heck", |
| 7495 | 7500 | "proc-macro2", |
| @@ -7501,9 +7506,9 @@ dependencies = [ | ||
| 7501 | 7506 | |
| 7502 | 7507 | [[package]] |
| 7503 | 7508 | name = "topcoat-view-macro" |
| 7504 | -version = "0.11.0" | |
| 7509 | +version = "0.12.1" | |
| 7505 | 7510 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 7506 | -checksum = "ffa1688d165704f08d58c03710453d0d39553292bea61b18be7959a996c3e39b" | |
| 7511 | +checksum = "eed1edf71f2fe9f5edf9dcfa2ec3e55b9bae443c015497f80347f82cf6b7af8d" | |
| 7507 | 7512 | dependencies = [ |
| 7508 | 7513 | "quote", |
| 7509 | 7514 | "syn 3.0.10", |
Cargo.tomlmodified+1 -1
| @@ -82,7 +82,7 @@ multer = "3.1.0" | ||
| 82 | 82 | lettre = { version = "0.11.24", default-features = false, features = ["smtp-transport", "builder", "tokio1-rustls", "ring", "webpki-roots", "pool"] } |
| 83 | 83 | |
| 84 | 84 | # 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 | 87 | # ssh server |
| 88 | 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 | 117 | include_str!("../../migrations/0070_pull_viewed_files.sql"), |
| 118 | 118 | ), |
| 119 | 119 | (71, include_str!("../../migrations/0071_ci_job_steps.sql")), |
| 120 | - (72, include_str!("../../migrations/0072_ember_anvil_default.sql")), | |
| 121 | - (73, include_str!("../../migrations/0073_sage_ink_default.sql")), | |
| 120 | + ( | |
| 121 | + 72, | |
| 122 | + include_str!("../../migrations/0072_ember_anvil_default.sql"), | |
| 123 | + ), | |
| 124 | + ( | |
| 125 | + 73, | |
| 126 | + include_str!("../../migrations/0073_sage_ink_default.sql"), | |
| 127 | + ), | |
| 122 | 128 | ]; |
| 123 | 129 | |
| 124 | 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 | 23 | /// it. `None` at the edge of the range jiff can represent. Unknown zones fall back to UTC. |
| 24 | 24 | pub fn day_span(date: civil::Date, tz: &str) -> Option<(i64, i64)> { |
| 25 | 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 | 31 | let next = date |
| 28 | 32 | .tomorrow() |
| 29 | 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 | 127 | /// Checks the latest commit in a repo page's head line: its short sha linking to the commit, no |
| 128 | 128 | /// subject, and the commit count label. |
| 129 | 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 | 135 | let shas = element_texts(body, ".head-sub a.mono"); |
| 132 | 136 | assert_eq!(shas.len(), 1, "{what}: the head line must show the sha"); |
| 133 | 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 | 50 | assert_eq!(turkish.status().as_u16(), 200); |
| 51 | 51 | let body = turkish.text().await.expect("read body"); |
| 52 | 52 | assert!(body.contains("<html lang=\"tr\""), "html lang is tr"); |
| 53 | - assert!( | |
| 54 | - body.contains("<h1>Parçacıklar</h1>"), | |
| 55 | - "Turkish heading" | |
| 56 | - ); | |
| 53 | + assert!(body.contains("<h1>Parçacıklar</h1>"), "Turkish heading"); | |
| 57 | 54 | assert!( |
| 58 | 55 | body.contains("Gösterilecek parçacık yok."), |
| 59 | 56 | "Turkish empty state" |
| @@ -67,9 +64,6 @@ async fn snippets_page_follows_the_browser_language() { | ||
| 67 | 64 | .await |
| 68 | 65 | .expect("GET /snippets (en)"); |
| 69 | 66 | let body = english.text().await.expect("read body"); |
| 70 | - assert!( | |
| 71 | - body.contains("<h1>Snippets</h1>"), | |
| 72 | - "English heading" | |
| 73 | - ); | |
| 67 | + assert!(body.contains("<h1>Snippets</h1>"), "English heading"); | |
| 74 | 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 | 23 | /// Text of the first state badge on a page, e.g. `Open`, `Closed` or `Merged`. |
| 24 | 24 | fn state_badge(body: &str) -> String { |
| 25 | 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 | 28 | doc.select(&selector) |
| 28 | 29 | .next() |
| 29 | 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 | 388 | 200, |
| 389 | 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 | 394 | assert!(offered.body.contains("Pending transfer to carol")); |
| 393 | 395 | let inbox = http.get("/notifications", Some(&carol)).await; |
| 394 | 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 | 249 | // The home page is the signed-in viewer's own page, not a redirect. |
| 250 | 250 | let home = http.get("/", Some(&bob)).await; |
| 251 | 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 | 257 | // An admin who does not own the repo can delete it. |
| 255 | 258 | let admin_page = http.get("/bob/priv/settings", Some(&tahinli)).await; |
| @@ -523,7 +526,11 @@ async fn branch_protection_end_to_end() { | ||
| 523 | 526 | let updated = http |
| 524 | 527 | .post_form( |
| 525 | 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 | 534 | Some(&bob), |
| 528 | 535 | ) |
| 529 | 536 | .await; |
| @@ -538,7 +545,10 @@ async fn branch_protection_end_to_end() { | ||
| 538 | 545 | ) |
| 539 | 546 | .await; |
| 540 | 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 | 552 | let page = http |
| 543 | 553 | .get("/bob/app/settings?section=branches", Some(&bob)) |
| 544 | 554 | .await; |
| @@ -864,7 +874,10 @@ async fn general_settings_end_to_end() { | ||
| 864 | 874 | page.body |
| 865 | 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 | 882 | // Description: control characters are stripped and it shows on the repo header. |
| 870 | 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 | 148 | offered.header(LOCATION).as_deref(), |
| 149 | 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 | 154 | assert!(status.body.contains("Pending transfer to carol")); |
| 153 | 155 | // Carol cannot read the private repo, yet the inbox offers her the actions. |
| 154 | 156 | assert_eq!(http.get("/bob/priv", Some(&carol)).await.status, 404); |
| 155 | 157 | let declined = act_from(&http, &carol, "/notifications", "/decline").await; |
| 156 | 158 | assert_eq!(declined.status, 303, "decline: {}", declined.body); |
| 157 | 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 | 163 | assert!(!after.body.contains("Pending transfer")); |
| 160 | 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 | 171 | cancelled.header(LOCATION).as_deref(), |
| 168 | 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 | 177 | assert!(!after.body.contains("Pending transfer")); |
| 172 | 178 | |
| 173 | 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 | 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 | 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 | 201 | .route(RouteFn::new(Method::GET, "/tahinli/demo/blob.bin", binary)) |
| 202 | 202 | .layer(TowerLayer::new(ResponseCompression)) |
| 203 | - .compression(Compression::off()) | |
| 203 | + .with(Compression::disable()) | |
| 204 | 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 | 368 | (RunnerEnabledNotice, Tr) => "Çalıştırıcı etkinleştirildi.", |
| 369 | 369 | (Runners, En) => "Runners", |
| 370 | 370 | (Runners, Tr) => "Çalıştırıcılar", |
| 371 | - (ScheduledBackupsOff, En) => { | |
| 372 | - "Scheduled backups are off." | |
| 373 | - } | |
| 374 | - (ScheduledBackupsOff, Tr) => { | |
| 375 | - "Zamanlanmış yedeklemeler kapalı." | |
| 376 | - } | |
| 371 | + (ScheduledBackupsOff, En) => "Scheduled backups are off.", | |
| 372 | + (ScheduledBackupsOff, Tr) => "Zamanlanmış yedeklemeler kapalı.", | |
| 377 | 373 | (SecurityLogTitle, En) => "Security log", |
| 378 | 374 | (SecurityLogTitle, Tr) => "Güvenlik günlüğü", |
| 379 | 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 | 674 | /// Several label additions in one run: "added labels a, b and c". `names` holds at least two. |
| 675 | 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 | 679 | let list = match lang { |
| 678 | 680 | Lang::En => match rest.is_empty() { |
| 679 | 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 | 390 | Some(n) => new_node( |
| 391 | 391 | arena, |
| 392 | 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 | 398 | None => new_node( |
| 396 | 399 | arena, |
| 397 | 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 | 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 | 25 | use http::HeaderMap; |
| 26 | 26 | use http::header::{AUTHORIZATION, HeaderName, HeaderValue}; |
| 27 | 27 | use serde_json::{Value, json}; |
| 28 | -use topcoat::context::{Cx, app_context}; | |
| 28 | +use topcoat::context::{Cx, context}; | |
| 29 | 29 | use topcoat::router::request::{headers, uri}; |
| 30 | 30 | use topcoat::router::response::Response; |
| 31 | 31 | use topcoat::router::{StatusCode, path_param, route}; |
| @@ -108,7 +108,7 @@ fn effective_headers(cx: &Cx) -> HeaderMap { | ||
| 108 | 108 | |
| 109 | 109 | /// Who is asking, and the raw token they used (for the clone URL of a private repo). |
| 110 | 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 | 112 | let map = effective_headers(cx); |
| 113 | 113 | let actor = api::authenticate(state, client_ip(cx), &map).await?; |
| 114 | 114 | let token = api::presented_token(&map).flatten(); |
| @@ -122,16 +122,9 @@ struct Ctx { | ||
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | async fn read_ctx(cx: &Cx) -> Result<Ctx, Refusal> { |
| 125 | - let state = app_context::<AppState>(cx); | |
| 125 | + let state = context::<AppState>(cx); | |
| 126 | 126 | let (actor, token) = caller(cx).await?; |
| 127 | - let repo = api::load_repo( | |
| 128 | - state, | |
| 129 | - actor.as_ref(), | |
| 130 | - path_param::<Owner>(cx), | |
| 131 | - path_param::<Repo>(cx), | |
| 132 | - Action::Read, | |
| 133 | - ) | |
| 134 | - .await?; | |
| 127 | + let repo = api::load_repo(state, actor.as_ref(), owner(cx), repo(cx), Action::Read).await?; | |
| 135 | 128 | Ok(Ctx { |
| 136 | 129 | repo, |
| 137 | 130 | token: actor.and(token), |
| @@ -178,7 +171,7 @@ pub fn slice<T>(items: Vec<T>, pg: &Paging) -> (Vec<T>, usize) { | ||
| 178 | 171 | pub fn page_response(cx: &Cx, items: Vec<Value>, total: usize, pg: &Paging) -> Response { |
| 179 | 172 | let mut res = api::json(StatusCode::OK, &Value::Array(items)); |
| 180 | 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 | 175 | let base = state.config.base_url.trim_end_matches('/'); |
| 183 | 176 | let mut rest = String::new(); |
| 184 | 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 | 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 | 227 | Ok(api::json( |
| 235 | 228 | StatusCode::OK, |
| 236 | 229 | &json!({ "version": GITEA_VERSION }), |
| @@ -238,7 +231,7 @@ async fn version_route(_cx: &Cx) -> topcoat::Result<Response> { | ||
| 238 | 231 | } |
| 239 | 232 | |
| 240 | 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 | 235 | Ok(api::json( |
| 243 | 236 | StatusCode::OK, |
| 244 | 237 | &json!({ |
| @@ -302,7 +295,7 @@ pub async fn repo_json( | ||
| 302 | 295 | |
| 303 | 296 | #[route(GET "/api/v1/repos/{owner}/{repo}")] |
| 304 | 297 | async fn get_repo(cx: &Cx) -> topcoat::Result<Response> { |
| 305 | - let state = app_context::<AppState>(cx); | |
| 298 | + let state = context::<AppState>(cx); | |
| 306 | 299 | let ctx = match read_ctx(cx).await { |
| 307 | 300 | Ok(ctx) => ctx, |
| 308 | 301 | Err(res) => return Ok(*res), |
| @@ -336,7 +329,7 @@ fn label_json(base: &str, repo: &CoreRepo, label: &Label) -> Value { | ||
| 336 | 329 | |
| 337 | 330 | #[route(GET "/api/v1/repos/{owner}/{repo}/labels")] |
| 338 | 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 | 333 | let ctx = match read_ctx(cx).await { |
| 341 | 334 | Ok(ctx) => ctx, |
| 342 | 335 | Err(res) => return Ok(*res), |
| @@ -389,7 +382,7 @@ fn state_filter(cx: &Cx) -> Result<Option<IssueState>, Refusal> { | ||
| 389 | 382 | |
| 390 | 383 | #[route(GET "/api/v1/repos/{owner}/{repo}/milestones")] |
| 391 | 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 | 386 | let ctx = match read_ctx(cx).await { |
| 394 | 387 | Ok(ctx) => ctx, |
| 395 | 388 | Err(res) => return Ok(*res), |
| @@ -495,7 +488,7 @@ fn filter_of(cx: &Cx, pg: &Paging) -> Result<IssueFilter, Refusal> { | ||
| 495 | 488 | |
| 496 | 489 | #[route(GET "/api/v1/repos/{owner}/{repo}/issues")] |
| 497 | 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 | 492 | let ctx = match read_ctx(cx).await { |
| 500 | 493 | Ok(ctx) => ctx, |
| 501 | 494 | Err(res) => return Ok(*res), |
| @@ -572,13 +565,13 @@ fn comment_json( | ||
| 572 | 565 | |
| 573 | 566 | #[route(GET "/api/v1/repos/{owner}/{repo}/issues/{index}/comments")] |
| 574 | 567 | async fn issue_comments(cx: &Cx) -> topcoat::Result<Response> { |
| 575 | - let state = app_context::<AppState>(cx); | |
| 568 | + let state = context::<AppState>(cx); | |
| 576 | 569 | let ctx = match read_ctx(cx).await { |
| 577 | 570 | Ok(ctx) => ctx, |
| 578 | 571 | Err(res) => return Ok(*res), |
| 579 | 572 | }; |
| 580 | 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 | 575 | let all = state |
| 583 | 576 | .store |
| 584 | 577 | .list_comments(&issue.id) |
| @@ -634,13 +627,13 @@ async fn reactions_json( | ||
| 634 | 627 | |
| 635 | 628 | #[route(GET "/api/v1/repos/{owner}/{repo}/issues/{index}/reactions")] |
| 636 | 629 | async fn issue_reactions(cx: &Cx) -> topcoat::Result<Response> { |
| 637 | - let state = app_context::<AppState>(cx); | |
| 630 | + let state = context::<AppState>(cx); | |
| 638 | 631 | let ctx = match read_ctx(cx).await { |
| 639 | 632 | Ok(ctx) => ctx, |
| 640 | 633 | Err(res) => return Ok(*res), |
| 641 | 634 | }; |
| 642 | 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 | 637 | let all = reactions_json( |
| 645 | 638 | state, |
| 646 | 639 | &ctx, |
| @@ -659,15 +652,13 @@ async fn issue_reactions(cx: &Cx) -> topcoat::Result<Response> { | ||
| 659 | 652 | |
| 660 | 653 | #[route(GET "/api/v1/repos/{owner}/{repo}/issues/comments/{id}/reactions")] |
| 661 | 654 | async fn comment_reactions(cx: &Cx) -> topcoat::Result<Response> { |
| 662 | - let state = app_context::<AppState>(cx); | |
| 655 | + let state = context::<AppState>(cx); | |
| 663 | 656 | let ctx = match read_ctx(cx).await { |
| 664 | 657 | Ok(ctx) => ctx, |
| 665 | 658 | Err(res) => return Ok(*res), |
| 666 | 659 | }; |
| 667 | 660 | let result: Result<Response, Refusal> = async { |
| 668 | - let id: i64 = path_param::<Id>(cx) | |
| 669 | - .parse() | |
| 670 | - .map_err(|_| bad("invalid comment id"))?; | |
| 661 | + let id: i64 = id(cx).parse().map_err(|_| bad("invalid comment id"))?; | |
| 671 | 662 | let (number, position) = |
| 672 | 663 | split_comment_id(id).ok_or_else(|| not_found("comment not found"))?; |
| 673 | 664 | let issue = issue_row(state, &ctx.repo, &number.to_string()).await?; |
| @@ -803,7 +794,7 @@ async fn pull_json( | ||
| 803 | 794 | |
| 804 | 795 | #[route(GET "/api/v1/repos/{owner}/{repo}/pulls")] |
| 805 | 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 | 798 | let ctx = match read_ctx(cx).await { |
| 808 | 799 | Ok(ctx) => ctx, |
| 809 | 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 | 885 | #[route(GET "/api/v1/repos/{owner}/{repo}/pulls/{index}/reviews")] |
| 895 | 886 | async fn pull_reviews(cx: &Cx) -> topcoat::Result<Response> { |
| 896 | - let state = app_context::<AppState>(cx); | |
| 887 | + let state = context::<AppState>(cx); | |
| 897 | 888 | let ctx = match read_ctx(cx).await { |
| 898 | 889 | Ok(ctx) => ctx, |
| 899 | 890 | Err(res) => return Ok(*res), |
| 900 | 891 | }; |
| 901 | 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 | 894 | let reviews = state |
| 904 | 895 | .store |
| 905 | 896 | .list_reviews(&issue.id) |
| @@ -967,14 +958,14 @@ fn review_comment_json(ctx: &Ctx, number: i64, c: &ReviewComment) -> Value { | ||
| 967 | 958 | |
| 968 | 959 | #[route(GET "/api/v1/repos/{owner}/{repo}/pulls/{index}/reviews/{review_id}/comments")] |
| 969 | 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 | 962 | let ctx = match read_ctx(cx).await { |
| 972 | 963 | Ok(ctx) => ctx, |
| 973 | 964 | Err(res) => return Ok(*res), |
| 974 | 965 | }; |
| 975 | 966 | let result: Result<Response, Refusal> = async { |
| 976 | - let issue = pull_issue(state, &ctx.repo, path_param::<Index>(cx)).await?; | |
| 977 | - let raw = path_param::<ReviewId>(cx); | |
| 967 | + let issue = pull_issue(state, &ctx.repo, index(cx)).await?; | |
| 968 | + let raw = review_id(cx); | |
| 978 | 969 | let reviews = state |
| 979 | 970 | .store |
| 980 | 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 | 13 | use http_body::Frame; |
| 14 | 14 | use http_body_util::StreamBody; |
| 15 | 15 | use serde_json::{Value, json}; |
| 16 | -use topcoat::context::{Cx, app_context}; | |
| 16 | +use topcoat::context::{Cx, context}; | |
| 17 | 17 | use topcoat::router::request::headers; |
| 18 | 18 | use topcoat::router::response::Response; |
| 19 | 19 | use topcoat::router::{Body, StatusCode, path_param, route}; |
| @@ -33,7 +33,7 @@ path_param!(version); | ||
| 33 | 33 | /// The caller of a registry request. Reads with a token that lacks the scope are served as |
| 34 | 34 | /// anonymous, so a token made for another purpose cannot break a public install. Writes refuse. |
| 35 | 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 | 37 | let normalized = bare_token_as_bearer(headers(cx)); |
| 38 | 38 | let (user, token_id, scopes) = |
| 39 | 39 | match api::authenticate_token(state, client_ip(cx), &normalized).await { |
| @@ -120,8 +120,8 @@ fn text(body: String) -> Response { | ||
| 120 | 120 | |
| 121 | 121 | /// Loads the registry owner named in the path, as the caller may see it. A missing owner is 404. |
| 122 | 122 | async fn owner_of(cx: &Cx) -> Result<User, Refusal> { |
| 123 | - let state = app_context::<AppState>(cx); | |
| 124 | - match package_ops::owner_named(state, path_param::<Owner>(cx)).await { | |
| 123 | + let state = context::<AppState>(cx); | |
| 124 | + match package_ops::owner_named(state, owner(cx)).await { | |
| 125 | 125 | Ok(Some(found)) => Ok(found), |
| 126 | 126 | Ok(_) => Err(Box::new(failure(PackageError::NotFound))), |
| 127 | 127 | Err(e) => Err(Box::new(failure(e))), |
| @@ -130,7 +130,7 @@ async fn owner_of(cx: &Cx) -> Result<User, Refusal> { | ||
| 130 | 130 | |
| 131 | 131 | #[route(GET "/api/packages/{owner}/cargo/config.json")] |
| 132 | 132 | async fn config(cx: &Cx) -> topcoat::Result<Response> { |
| 133 | - let state = app_context::<AppState>(cx); | |
| 133 | + let state = context::<AppState>(cx); | |
| 134 | 134 | if let Err(res) = caller(cx, false).await { |
| 135 | 135 | return Ok(*res); |
| 136 | 136 | } |
| @@ -164,7 +164,7 @@ async fn index_long(cx: &Cx) -> topcoat::Result<Response> { | ||
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | async fn index_response(cx: &Cx) -> Response { |
| 167 | - let state = app_context::<AppState>(cx); | |
| 167 | + let state = context::<AppState>(cx); | |
| 168 | 168 | let actor = match caller(cx, false).await { |
| 169 | 169 | Ok(actor) => actor, |
| 170 | 170 | Err(res) => return *res, |
| @@ -173,13 +173,11 @@ async fn index_response(cx: &Cx) -> Response { | ||
| 173 | 173 | Ok(owner) => owner, |
| 174 | 174 | Err(res) => return *res, |
| 175 | 175 | }; |
| 176 | - let package = | |
| 177 | - match package_ops::readable_package(state, actor.as_ref(), &owner, path_param::<Name>(cx)) | |
| 178 | - .await | |
| 179 | - { | |
| 180 | - Ok(package) => package, | |
| 181 | - Err(e) => return failure(e), | |
| 182 | - }; | |
| 176 | + let package = match package_ops::readable_package(state, actor.as_ref(), &owner, name(cx)).await | |
| 177 | + { | |
| 178 | + Ok(package) => package, | |
| 179 | + Err(e) => return failure(e), | |
| 180 | + }; | |
| 183 | 181 | match package_ops::index_file(state, &package).await { |
| 184 | 182 | Ok(body) => text(body), |
| 185 | 183 | Err(e) => failure(e), |
| @@ -189,7 +187,7 @@ async fn index_response(cx: &Cx) -> Response { | ||
| 189 | 187 | /// The `.crate` file of one version, streamed from the blob store. |
| 190 | 188 | #[route(GET "/api/packages/{owner}/cargo/download/{name}/{version}")] |
| 191 | 189 | async fn download(cx: &Cx) -> topcoat::Result<Response> { |
| 192 | - let state = app_context::<AppState>(cx); | |
| 190 | + let state = context::<AppState>(cx); | |
| 193 | 191 | let actor = match caller(cx, false).await { |
| 194 | 192 | Ok(actor) => actor, |
| 195 | 193 | Err(res) => return Ok(*res), |
| @@ -198,18 +196,11 @@ async fn download(cx: &Cx) -> topcoat::Result<Response> { | ||
| 198 | 196 | Ok(owner) => owner, |
| 199 | 197 | Err(res) => return Ok(*res), |
| 200 | 198 | }; |
| 201 | - let read = match package_ops::download( | |
| 202 | - state, | |
| 203 | - actor.as_ref(), | |
| 204 | - &owner, | |
| 205 | - path_param::<Name>(cx), | |
| 206 | - path_param::<Version>(cx), | |
| 207 | - ) | |
| 208 | - .await | |
| 209 | - { | |
| 210 | - Ok(read) => read, | |
| 211 | - Err(e) => return Ok(failure(e)), | |
| 212 | - }; | |
| 199 | + let read = | |
| 200 | + match package_ops::download(state, actor.as_ref(), &owner, name(cx), version(cx)).await { | |
| 201 | + Ok(read) => read, | |
| 202 | + Err(e) => return Ok(failure(e)), | |
| 203 | + }; | |
| 213 | 204 | let chunks = read.stream.map(|chunk| chunk.map(Frame::data)); |
| 214 | 205 | let mut res = Response::new(Body::new(StreamBody::new(chunks))); |
| 215 | 206 | *res.status_mut() = StatusCode::OK; |
| @@ -226,7 +217,7 @@ async fn download(cx: &Cx) -> topcoat::Result<Response> { | ||
| 226 | 217 | /// length-prefixed `.crate`. It is read whole, up to the publish limit. |
| 227 | 218 | #[route(PUT "/api/packages/{owner}/cargo/api/v1/crates/new")] |
| 228 | 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 | 221 | let actor = match caller(cx, true).await { |
| 231 | 222 | Ok(Some(actor)) => actor, |
| 232 | 223 | Ok(None) => { |
| @@ -271,7 +262,7 @@ async fn unyank(cx: &Cx) -> topcoat::Result<Response> { | ||
| 271 | 262 | } |
| 272 | 263 | |
| 273 | 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 | 266 | let actor = match caller(cx, true).await { |
| 276 | 267 | Ok(Some(actor)) => actor, |
| 277 | 268 | Ok(None) => { |
| @@ -286,16 +277,7 @@ async fn set_yank(cx: &Cx, yanked: bool) -> topcoat::Result<Response> { | ||
| 286 | 277 | Ok(owner) => owner, |
| 287 | 278 | Err(res) => return Ok(*res), |
| 288 | 279 | }; |
| 289 | - match package_ops::set_yanked( | |
| 290 | - state, | |
| 291 | - &owner, | |
| 292 | - &actor, | |
| 293 | - path_param::<Name>(cx), | |
| 294 | - path_param::<Version>(cx), | |
| 295 | - yanked, | |
| 296 | - ) | |
| 297 | - .await | |
| 298 | - { | |
| 280 | + match package_ops::set_yanked(state, &owner, &actor, name(cx), version(cx), yanked).await { | |
| 299 | 281 | Ok(()) => Ok(api::json(StatusCode::OK, &json!({ "ok": true }))), |
| 300 | 282 | Err(e) => Ok(failure(e)), |
| 301 | 283 | } |
| @@ -305,7 +287,7 @@ async fn set_yank(cx: &Cx, yanked: bool) -> topcoat::Result<Response> { | ||
| 305 | 287 | /// an org, its owners. Read-only: adding or removing owners is done in the forge. |
| 306 | 288 | #[route(GET "/api/packages/{owner}/cargo/api/v1/crates/{name}/owners")] |
| 307 | 289 | async fn owners(cx: &Cx) -> topcoat::Result<Response> { |
| 308 | - let state = app_context::<AppState>(cx); | |
| 290 | + let state = context::<AppState>(cx); | |
| 309 | 291 | let actor = match caller(cx, false).await { |
| 310 | 292 | Ok(actor) => actor, |
| 311 | 293 | Err(res) => return Ok(*res), |
| @@ -314,9 +296,7 @@ async fn owners(cx: &Cx) -> topcoat::Result<Response> { | ||
| 314 | 296 | Ok(owner) => owner, |
| 315 | 297 | Err(res) => return Ok(*res), |
| 316 | 298 | }; |
| 317 | - if let Err(e) = | |
| 318 | - package_ops::readable_package(state, actor.as_ref(), &owner, path_param::<Name>(cx)).await | |
| 319 | - { | |
| 299 | + if let Err(e) = package_ops::readable_package(state, actor.as_ref(), &owner, name(cx)).await { | |
| 320 | 300 | return Ok(failure(e)); |
| 321 | 301 | } |
| 322 | 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 | 13 | use http::header::CONTENT_TYPE; |
| 14 | 14 | use serde::Deserialize; |
| 15 | 15 | use serde_json::{Value, json}; |
| 16 | -use topcoat::context::{Cx, app_context}; | |
| 16 | +use topcoat::context::{Cx, context}; | |
| 17 | 17 | use topcoat::router::request::headers; |
| 18 | 18 | use topcoat::router::response::Response; |
| 19 | 19 | use topcoat::router::{Body, StatusCode, path_param, route}; |
| @@ -55,7 +55,7 @@ struct PatchBody { | ||
| 55 | 55 | |
| 56 | 56 | #[route(GET "/api/v1/repos/{owner}/{repo}/releases")] |
| 57 | 57 | async fn list_releases(cx: &Cx) -> topcoat::Result<Response> { |
| 58 | - let state = app_context::<AppState>(cx); | |
| 58 | + let state = context::<AppState>(cx); | |
| 59 | 59 | let (repo, can_write) = match read_context(cx).await { |
| 60 | 60 | Ok(found) => found, |
| 61 | 61 | Err(res) => return Ok(*res), |
| @@ -82,17 +82,17 @@ async fn list_releases(cx: &Cx) -> topcoat::Result<Response> { | ||
| 82 | 82 | /// Gitea's `GET .../releases/{id}/assets/{attachment_id}`: one asset of one release. |
| 83 | 83 | #[route(GET "/api/v1/repos/{owner}/{repo}/releases/{id}/assets/{asset}")] |
| 84 | 84 | async fn get_asset(cx: &Cx) -> topcoat::Result<Response> { |
| 85 | - let state = app_context::<AppState>(cx); | |
| 85 | + let state = context::<AppState>(cx); | |
| 86 | 86 | let (repo, can_write) = match read_context(cx).await { |
| 87 | 87 | Ok(found) => found, |
| 88 | 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 | 91 | Ok(release) if can_write || !release.draft => release, |
| 92 | 92 | Ok(_) => return Ok(not_found()), |
| 93 | 93 | Err(res) => return Ok(*res), |
| 94 | 94 | }; |
| 95 | - let wanted = path_param::<Asset>(cx); | |
| 95 | + let wanted = asset(cx); | |
| 96 | 96 | let assets = match state.store.list_release_assets(&release.id).await { |
| 97 | 97 | Ok(assets) => assets, |
| 98 | 98 | Err(e) => return Ok(*api::internal(e)), |
| @@ -112,12 +112,12 @@ async fn get_asset(cx: &Cx) -> topcoat::Result<Response> { | ||
| 112 | 112 | |
| 113 | 113 | #[route(GET "/api/v1/repos/{owner}/{repo}/releases/tags/{tag}")] |
| 114 | 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 | 116 | let (repo, can_write) = match read_context(cx).await { |
| 117 | 117 | Ok(found) => found, |
| 118 | 118 | Err(res) => return Ok(*res), |
| 119 | 119 | }; |
| 120 | - let tag_name = path_param::<Tag>(cx); | |
| 120 | + let tag_name = tag(cx); | |
| 121 | 121 | let release = match state.store.release_by_tag(&repo.id, tag_name).await { |
| 122 | 122 | Ok(Some(release)) if can_write || !release.draft => release, |
| 123 | 123 | Ok(_) => return Ok(not_found()), |
| @@ -131,7 +131,7 @@ async fn get_release_by_tag(cx: &Cx) -> topcoat::Result<Response> { | ||
| 131 | 131 | |
| 132 | 132 | #[route(POST "/api/v1/repos/{owner}/{repo}/releases")] |
| 133 | 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 | 135 | let (repo, user) = match write_context(cx).await { |
| 136 | 136 | Ok(found) => found, |
| 137 | 137 | Err(res) => return Ok(*res), |
| @@ -176,12 +176,12 @@ async fn create_release(cx: &Cx, body: Body) -> topcoat::Result<Response> { | ||
| 176 | 176 | |
| 177 | 177 | #[route(PATCH "/api/v1/repos/{owner}/{repo}/releases/{id}")] |
| 178 | 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 | 180 | let (repo, user) = match write_context(cx).await { |
| 181 | 181 | Ok(found) => found, |
| 182 | 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 | 185 | Ok(release) => release, |
| 186 | 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 | 219 | #[route(DELETE "/api/v1/repos/{owner}/{repo}/releases/{id}")] |
| 220 | 220 | async fn delete_release(cx: &Cx) -> topcoat::Result<Response> { |
| 221 | - let state = app_context::<AppState>(cx); | |
| 221 | + let state = context::<AppState>(cx); | |
| 222 | 222 | let (repo, user) = match write_context(cx).await { |
| 223 | 223 | Ok(found) => found, |
| 224 | 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 | 227 | Ok(release) => release, |
| 228 | 228 | Err(res) => return Ok(*res), |
| 229 | 229 | }; |
| @@ -236,12 +236,12 @@ async fn delete_release(cx: &Cx) -> topcoat::Result<Response> { | ||
| 236 | 236 | /// Streams the raw request body into an asset. `201` for a new name, `200` when it replaces one. |
| 237 | 237 | #[route(PUT "/api/v1/repos/{owner}/{repo}/releases/{id}/assets/{asset}")] |
| 238 | 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 | 240 | let (repo, user) = match write_context(cx).await { |
| 241 | 241 | Ok(found) => found, |
| 242 | 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 | 245 | Ok(release) => release, |
| 246 | 246 | Err(res) => return Ok(*res), |
| 247 | 247 | }; |
| @@ -264,7 +264,7 @@ async fn upload_asset(cx: &Cx, body: Body) -> topcoat::Result<Response> { | ||
| 264 | 264 | &repo, |
| 265 | 265 | &release, |
| 266 | 266 | &user, |
| 267 | - path_param::<Asset>(cx), | |
| 267 | + asset(cx), | |
| 268 | 268 | content_type.as_deref(), |
| 269 | 269 | stream, |
| 270 | 270 | max_bytes, |
| @@ -287,17 +287,17 @@ async fn upload_asset(cx: &Cx, body: Body) -> topcoat::Result<Response> { | ||
| 287 | 287 | |
| 288 | 288 | #[route(DELETE "/api/v1/repos/{owner}/{repo}/releases/{id}/assets/{asset}")] |
| 289 | 289 | async fn delete_asset(cx: &Cx) -> topcoat::Result<Response> { |
| 290 | - let state = app_context::<AppState>(cx); | |
| 290 | + let state = context::<AppState>(cx); | |
| 291 | 291 | let (repo, _user) = match write_context(cx).await { |
| 292 | 292 | Ok(found) => found, |
| 293 | 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 | 296 | Ok(release) => release, |
| 297 | 297 | Err(res) => return Ok(*res), |
| 298 | 298 | }; |
| 299 | 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 | 301 | if gitea::is_numeric(&asset) |
| 302 | 302 | && let Ok(assets) = state.store.list_release_assets(&release.id).await |
| 303 | 303 | && let Some(found) = assets |
| @@ -318,21 +318,14 @@ const MAX_JSON_BYTES: usize = 64 * 1024; | ||
| 318 | 318 | /// Authenticates an optional caller and loads the repo for reading. Also reports whether the |
| 319 | 319 | /// caller may write, which decides whether drafts are visible. |
| 320 | 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 | 322 | let actor = api::authenticate(state, client_ip(cx), headers(cx)).await?; |
| 323 | - let repo = api::load_repo( | |
| 324 | - state, | |
| 325 | - actor.as_ref(), | |
| 326 | - path_param::<Owner>(cx), | |
| 327 | - path_param::<Repo>(cx), | |
| 328 | - Action::Read, | |
| 329 | - ) | |
| 330 | - .await?; | |
| 323 | + let repo = api::load_repo(state, actor.as_ref(), owner(cx), repo(cx), Action::Read).await?; | |
| 331 | 324 | let can_write = api::load_repo( |
| 332 | 325 | state, |
| 333 | 326 | actor.as_ref(), |
| 334 | - path_param::<Owner>(cx), | |
| 335 | - path_param::<Repo>(cx), | |
| 327 | + owner(cx), | |
| 328 | + self::repo(cx), | |
| 336 | 329 | Action::Write, |
| 337 | 330 | ) |
| 338 | 331 | .await |
| @@ -342,16 +335,9 @@ async fn read_context(cx: &Cx) -> Result<(CoreRepo, bool), Refusal> { | ||
| 342 | 335 | |
| 343 | 336 | /// Authenticates a required caller with write access and loads the repo. |
| 344 | 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 | 339 | let actor = api::authenticate(state, client_ip(cx), headers(cx)).await?; |
| 347 | - let repo = api::load_repo( | |
| 348 | - state, | |
| 349 | - actor.as_ref(), | |
| 350 | - path_param::<Owner>(cx), | |
| 351 | - path_param::<Repo>(cx), | |
| 352 | - Action::Write, | |
| 353 | - ) | |
| 354 | - .await?; | |
| 340 | + let repo = api::load_repo(state, actor.as_ref(), owner(cx), repo(cx), Action::Write).await?; | |
| 355 | 341 | match actor { |
| 356 | 342 | Some(user) => Ok((repo, user)), |
| 357 | 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 | 8 | use forge_core::store::commit_status::{CommitStatus, DEFAULT_CONTEXT, StatusState, combine}; |
| 9 | 9 | use serde::Deserialize; |
| 10 | 10 | use serde_json::{Value, json}; |
| 11 | -use topcoat::context::{Cx, app_context}; | |
| 11 | +use topcoat::context::{Cx, context}; | |
| 12 | 12 | use topcoat::router::request::headers; |
| 13 | 13 | use topcoat::router::response::Response; |
| 14 | 14 | use topcoat::router::{Body, StatusCode, path_param, route}; |
| @@ -35,19 +35,12 @@ struct ReportBody { | ||
| 35 | 35 | |
| 36 | 36 | #[route(POST "/api/v1/repos/{owner}/{repo}/statuses/{sha}")] |
| 37 | 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 | 39 | let actor = match api::authenticate(state, client_ip(cx), headers(cx)).await { |
| 40 | 40 | Ok(actor) => actor, |
| 41 | 41 | Err(res) => return Ok(*res), |
| 42 | 42 | }; |
| 43 | - let repo = match api::load_repo( | |
| 44 | - state, | |
| 45 | - actor.as_ref(), | |
| 46 | - path_param::<Owner>(cx), | |
| 47 | - path_param::<Repo>(cx), | |
| 48 | - Action::Write, | |
| 49 | - ) | |
| 50 | - .await | |
| 43 | + let repo = match api::load_repo(state, actor.as_ref(), owner(cx), repo(cx), Action::Write).await | |
| 51 | 44 | { |
| 52 | 45 | Ok(repo) => repo, |
| 53 | 46 | Err(res) => return Ok(*res), |
| @@ -55,7 +48,7 @@ async fn report_status(cx: &Cx, body: Body) -> topcoat::Result<Response> { | ||
| 55 | 48 | let Some(user) = actor else { |
| 56 | 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 | 52 | return Ok(not_a_full_sha()); |
| 60 | 53 | }; |
| 61 | 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 | 111 | #[route(GET "/api/v1/repos/{owner}/{repo}/commits/{sha}/statuses")] |
| 119 | 112 | async fn list_statuses(cx: &Cx) -> topcoat::Result<Response> { |
| 120 | - let state = app_context::<AppState>(cx); | |
| 113 | + let state = context::<AppState>(cx); | |
| 121 | 114 | let actor = match api::authenticate(state, client_ip(cx), headers(cx)).await { |
| 122 | 115 | Ok(actor) => actor, |
| 123 | 116 | Err(res) => return Ok(*res), |
| 124 | 117 | }; |
| 125 | - let repo = match api::load_repo( | |
| 126 | - state, | |
| 127 | - actor.as_ref(), | |
| 128 | - path_param::<Owner>(cx), | |
| 129 | - path_param::<Repo>(cx), | |
| 130 | - Action::Read, | |
| 131 | - ) | |
| 132 | - .await | |
| 118 | + let repo = match api::load_repo(state, actor.as_ref(), owner(cx), repo(cx), Action::Read).await | |
| 133 | 119 | { |
| 134 | 120 | Ok(repo) => repo, |
| 135 | 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 | 124 | return Ok(not_a_full_sha()); |
| 139 | 125 | }; |
| 140 | 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 | 13 | use forge_core::{Session, Store, User, secret, totp}; |
| 14 | 14 | use tokio::sync::Semaphore; |
| 15 | 15 | use topcoat::Result; |
| 16 | -use topcoat::context::{Cx, app_context}; | |
| 16 | +use topcoat::context::{Cx, context}; | |
| 17 | 17 | use topcoat::cookie::{Cookie, Cookies, SameSite, cookies, time}; |
| 18 | 18 | use topcoat::router::error::{forbidden, see_other}; |
| 19 | 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 | 54 | let Some(cookie) = session_jar(cx).get(SESSION_COOKIE) else { |
| 55 | 55 | return Ok(None); |
| 56 | 56 | }; |
| 57 | - let store = &app_context::<AppState>(cx).store; | |
| 57 | + let store = &context::<AppState>(cx).store; | |
| 58 | 58 | let Some(session) = store |
| 59 | 59 | .session_by_token_hash(&hash_token(cookie.value())) |
| 60 | 60 | .await? |
| @@ -76,7 +76,7 @@ pub async fn current_user(cx: &Cx) -> forge_core::Result<Option<(User, Session)> | ||
| 76 | 76 | |
| 77 | 77 | /// Creates a session for `user` and sets the session cookie on the response. |
| 78 | 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 | 80 | let token = new_session_token(); |
| 81 | 81 | let addr = client_addr(cx).to_string(); |
| 82 | 82 | let session = store |
| @@ -90,7 +90,7 @@ pub async fn login(cx: &Cx, user: &User) -> forge_core::Result<Session> { | ||
| 90 | 90 | ) |
| 91 | 91 | .await?; |
| 92 | 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 | 94 | .live |
| 95 | 95 | .bump(&crate::live::Topic::Account(user.id.clone())); |
| 96 | 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 | 109 | /// Deletes the session row and clears the cookie. |
| 110 | 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 | 112 | state.store.delete_session(&session.id).await?; |
| 113 | 113 | // The user's other tabs may show this session (a page that now leaves for the login page). |
| 114 | 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 | 18 | use tokio::signal::unix::{SignalKind, signal}; |
| 19 | 19 | use tokio::sync::Notify; |
| 20 | 20 | use tokio::sync::watch; |
| 21 | -use topcoat::cookie::RouterBuilderCookieExt; | |
| 21 | +use topcoat::cookie::CookieLayer; | |
| 22 | 22 | use topcoat::router::tower::TowerLayer; |
| 23 | 23 | use topcoat::router::{Compression, Router, RouterBuilderDiscoverExt, RouterService}; |
| 24 | 24 | |
| @@ -169,11 +169,9 @@ pub async fn serve( | ||
| 169 | 169 | // `ResponseCompression` compresses text responses only and skips git, LFS, raw and archive paths. |
| 170 | 170 | let public: Router = Router::builder() |
| 171 | 171 | .discover() |
| 172 | - .app_context(state.clone()) | |
| 172 | + .with(state.clone()) | |
| 173 | 173 | .layer(crate::pages::settings_live::AccountWriteLayer) |
| 174 | - .cookies() | |
| 175 | - .layer(crate::pages::settings_profile::avatar_body_limit()) | |
| 176 | - .layer(crate::pages::settings_profile::org_avatar_body_limit()) | |
| 174 | + .layer(CookieLayer::new()) | |
| 177 | 175 | .layer(crate::pages::repo_ctx::RepoMovedLayer) |
| 178 | 176 | .layer(crate::pages::pull_live::PullWriteLayer) |
| 179 | 177 | .layer(crate::pages::discussion_live::DiscussionWriteLayer) |
| @@ -181,7 +179,7 @@ pub async fn serve( | ||
| 181 | 179 | .layer(crate::pages::repo_settings_live::RepoSettingsWriteLayer) |
| 182 | 180 | .layer(crate::pages::not_found_page::NotFoundLayer) |
| 183 | 181 | .layer(TowerLayer::new(crate::compression::ResponseCompression)) |
| 184 | - .compression(Compression::off()) | |
| 182 | + .with(Compression::disable()) | |
| 185 | 183 | .build(); |
| 186 | 184 | let internal_router = internal::router(state.clone()); |
| 187 | 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 | 22 | use http::header::HeaderValue; |
| 23 | 23 | use serde_json::json; |
| 24 | 24 | use std::collections::BTreeMap; |
| 25 | -use topcoat::context::{Cx, app_context}; | |
| 25 | +use topcoat::context::{Cx, context}; | |
| 26 | 26 | use topcoat::router::request::headers; |
| 27 | 27 | use topcoat::router::response::Response; |
| 28 | 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 | 147 | #[route(POST "/api/v1/ci/runners/register")] |
| 148 | 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 | 150 | let request: RegisterRequest = match json_body(body).await { |
| 151 | 151 | Ok(request) => request, |
| 152 | 152 | Err(res) => return Ok(*res), |
| @@ -189,7 +189,7 @@ async fn register(cx: &Cx, body: Body) -> topcoat::Result<Response> { | ||
| 189 | 189 | |
| 190 | 190 | #[route(POST "/api/v1/ci/runners/claim")] |
| 191 | 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 | 193 | // The labels in the request are ignored: the labels stored at registration are used, plus the |
| 194 | 194 | // arch and OS the runner reports, so `runs_on = ["aarch64"]` needs no admin to type a label. |
| 195 | 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 | 330 | /// number the forge wants for this boot id, so the runner resends what was lost. |
| 331 | 331 | #[route(POST "/api/v1/ci/runners/log")] |
| 332 | 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 | 334 | let runner = match runner_from(state, headers(cx)).await { |
| 335 | 335 | Ok(runner) => runner, |
| 336 | 336 | Err(res) => return Ok(*res), |
| @@ -364,7 +364,7 @@ async fn runner_log(cx: &Cx, body: Body) -> topcoat::Result<Response> { | ||
| 364 | 364 | /// page. Answers 204 with no body. |
| 365 | 365 | #[route(POST "/api/v1/ci/runners/metrics")] |
| 366 | 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 | 368 | let runner = match runner_from(state, headers(cx)).await { |
| 369 | 369 | Ok(runner) => runner, |
| 370 | 370 | Err(res) => return Ok(*res), |
| @@ -397,7 +397,7 @@ async fn runner_metrics(cx: &Cx, body: Body) -> topcoat::Result<Response> { | ||
| 397 | 397 | /// starts, applies them to its in-memory config, then reports its effective config here. |
| 398 | 398 | #[route(GET "/api/v1/ci/runners/config")] |
| 399 | 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 | 401 | let runner = match runner_from(state, headers(cx)).await { |
| 402 | 402 | Ok(runner) => runner, |
| 403 | 403 | Err(res) => return Ok(*res), |
| @@ -407,7 +407,7 @@ async fn runner_config_get(cx: &Cx) -> topcoat::Result<Response> { | ||
| 407 | 407 | |
| 408 | 408 | #[route(PUT "/api/v1/ci/runners/config")] |
| 409 | 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 | 411 | let runner = match runner_from(state, headers(cx)).await { |
| 412 | 412 | Ok(runner) => runner, |
| 413 | 413 | Err(res) => return Ok(*res), |
| @@ -557,7 +557,7 @@ fn idle_text(skips: &QueueSkips, free: Option<u64>) -> Option<String> { | ||
| 557 | 557 | /// The running binary, for a runner that updates itself. 404 unless self-update is enabled. |
| 558 | 558 | #[route(GET "/api/v1/ci/runners/binary")] |
| 559 | 559 | async fn runner_binary(cx: &Cx) -> topcoat::Result<Response> { |
| 560 | - let state = app_context::<AppState>(cx); | |
| 560 | + let state = context::<AppState>(cx); | |
| 561 | 561 | if let Err(res) = runner_from(state, headers(cx)).await { |
| 562 | 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 | 769 | #[route(POST "/api/v1/ci/jobs/{job_id}/heartbeat")] |
| 770 | 770 | async fn heartbeat(cx: &Cx) -> topcoat::Result<Response> { |
| 771 | - let state = app_context::<AppState>(cx); | |
| 772 | - let job = match job_from(state, headers(cx), path_param::<JobId>(cx)).await { | |
| 771 | + let state = context::<AppState>(cx); | |
| 772 | + let job = match job_from(state, headers(cx), job_id(cx)).await { | |
| 773 | 773 | Ok(job) => job, |
| 774 | 774 | Err(res) => return Ok(*res), |
| 775 | 775 | }; |
| @@ -845,9 +845,9 @@ enum LogWrite { | ||
| 845 | 845 | |
| 846 | 846 | #[route(POST "/api/v1/ci/jobs/{job_id}/logs")] |
| 847 | 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 | 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 | 851 | Ok(job) => job, |
| 852 | 852 | Err(res) => return Ok(*res), |
| 853 | 853 | }; |
| @@ -1037,12 +1037,12 @@ async fn store_log_bytes( | ||
| 1037 | 1037 | |
| 1038 | 1038 | #[route(PUT "/api/v1/ci/jobs/{job_id}/artifacts/{artifact_name}")] |
| 1039 | 1039 | async fn upload_artifact(cx: &Cx, body: Body) -> topcoat::Result<Response> { |
| 1040 | - let state = app_context::<AppState>(cx); | |
| 1041 | - let job = match job_from(state, headers(cx), path_param::<JobId>(cx)).await { | |
| 1040 | + let state = context::<AppState>(cx); | |
| 1041 | + let job = match job_from(state, headers(cx), job_id(cx)).await { | |
| 1042 | 1042 | Ok(job) => job, |
| 1043 | 1043 | Err(res) => return Ok(*res), |
| 1044 | 1044 | }; |
| 1045 | - let name = path_param::<ArtifactName>(cx); | |
| 1045 | + let name = artifact_name(cx); | |
| 1046 | 1046 | if !valid_artifact_name(name) { |
| 1047 | 1047 | return Ok(api::error( |
| 1048 | 1048 | StatusCode::UNPROCESSABLE_ENTITY, |
| @@ -1187,8 +1187,8 @@ fn upload_failure(e: CoreError, interrupted: bool) -> Refusal { | ||
| 1187 | 1187 | |
| 1188 | 1188 | #[route(POST "/api/v1/ci/jobs/{job_id}/finish")] |
| 1189 | 1189 | async fn finish(cx: &Cx, body: Body) -> topcoat::Result<Response> { |
| 1190 | - let state = app_context::<AppState>(cx); | |
| 1191 | - let job = match job_from(state, headers(cx), path_param::<JobId>(cx)).await { | |
| 1190 | + let state = context::<AppState>(cx); | |
| 1191 | + let job = match job_from(state, headers(cx), job_id(cx)).await { | |
| 1192 | 1192 | Ok(job) => job, |
| 1193 | 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 | 1211 | #[route(POST "/api/v1/ci/jobs/{job_id}/requeue")] |
| 1212 | 1212 | async fn requeue(cx: &Cx, body: Body) -> topcoat::Result<Response> { |
| 1213 | - let state = app_context::<AppState>(cx); | |
| 1214 | - let job = match job_from(state, headers(cx), path_param::<JobId>(cx)).await { | |
| 1213 | + let state = context::<AppState>(cx); | |
| 1214 | + let job = match job_from(state, headers(cx), job_id(cx)).await { | |
| 1215 | 1215 | Ok(job) => job, |
| 1216 | 1216 | Err(res) => return Ok(*res), |
| 1217 | 1217 | }; |
crates/forge-web/src/client_ip.rsmodified+2 -2
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; |
| 9 | 9 | |
| 10 | 10 | use ipnet::IpNet; |
| 11 | -use topcoat::context::{Cx, app_context}; | |
| 11 | +use topcoat::context::{Cx, context}; | |
| 12 | 12 | use topcoat::router::request::{headers, remote_addr}; |
| 13 | 13 | |
| 14 | 14 | use crate::state::AppState; |
| @@ -24,7 +24,7 @@ pub fn client_ip(cx: &Cx) -> IpAddr { | ||
| 24 | 24 | /// The exact client address for this request, normalized but not bucketed, for display and audit. |
| 25 | 25 | /// Unix-socket requests map to the unspecified address. |
| 26 | 26 | pub fn client_addr(cx: &Cx) -> IpAddr { |
| 27 | - let live = app_context::<AppState>(cx).live(); | |
| 27 | + let live = context::<AppState>(cx).live(); | |
| 28 | 28 | let trusted = &live.trusted_proxies; |
| 29 | 29 | let peer = remote_addr(cx).map(|addr| addr.ip()); |
| 30 | 30 | let forwarded = headers(cx) |
crates/forge-web/src/git_http.rsmodified+8 -8
| @@ -2,7 +2,7 @@ | ||
| 2 | 2 | //! Streams bodies to and from `git <svc> --stateless-rpc`; gzip request bodies are decoded. |
| 3 | 3 | //! |
| 4 | 4 | //! 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 | 7 | use std::net::IpAddr; |
| 8 | 8 | use std::time::Instant; |
| @@ -20,7 +20,7 @@ use http_body_util::StreamBody; | ||
| 20 | 20 | use tokio::io::AsyncReadExt; |
| 21 | 21 | use tokio::process::{Child, ChildStdin}; |
| 22 | 22 | use tokio_util::io::{ReaderStream, StreamReader}; |
| 23 | -use topcoat::context::{Cx, app_context}; | |
| 23 | +use topcoat::context::{Cx, context}; | |
| 24 | 24 | use topcoat::router::request::headers; |
| 25 | 25 | use topcoat::router::response::Response; |
| 26 | 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 | 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 | 50 | let headers = headers(cx); |
| 51 | - let owner = path_param::<Owner>(cx); | |
| 52 | - let repo_name = path_param::<Repo>(cx); | |
| 51 | + let owner = owner(cx); | |
| 52 | + let repo_name = repo(cx); | |
| 53 | 53 | |
| 54 | 54 | let (actor, repo, path) = |
| 55 | 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 | 102 | /// Shared body of the two POST routes: authorize, spawn `git <svc> --stateless-rpc`, pipe the |
| 103 | 103 | /// request body into its stdin and stream its stdout back. |
| 104 | 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 | 106 | let headers = headers(cx); |
| 107 | - let owner = path_param::<Owner>(cx); | |
| 108 | - let repo_name = path_param::<Repo>(cx); | |
| 107 | + let owner = owner(cx); | |
| 108 | + let repo_name = repo(cx); | |
| 109 | 109 | |
| 110 | 110 | let (actor, repo, path) = |
| 111 | 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 | 14 | use forge_core::{Repo, Role, Store}; |
| 15 | 15 | use forge_git::{GitCommand, GitEnv}; |
| 16 | 16 | use serde::{Deserialize, Serialize}; |
| 17 | -use topcoat::context::{Cx, app_context}; | |
| 17 | +use topcoat::context::{Cx, context}; | |
| 18 | 18 | use topcoat::router::content::Json; |
| 19 | 19 | use topcoat::router::error::{bad_request, forbidden}; |
| 20 | 20 | use topcoat::router::request::headers; |
| @@ -121,7 +121,7 @@ pub fn router(state: AppState) -> Router { | ||
| 121 | 121 | "/internal/admin/live", |
| 122 | 122 | admin_live, |
| 123 | 123 | )) |
| 124 | - .app_context(state) | |
| 124 | + .with(state) | |
| 125 | 125 | .build() |
| 126 | 126 | } |
| 127 | 127 | |
| @@ -144,7 +144,7 @@ async fn hook_endpoint( | ||
| 144 | 144 | body: Body, |
| 145 | 145 | stage: Stage, |
| 146 | 146 | ) -> topcoat::Result<topcoat::router::response::Response> { |
| 147 | - let state = app_context::<AppState>(cx); | |
| 147 | + let state = context::<AppState>(cx); | |
| 148 | 148 | let presented = headers(cx) |
| 149 | 149 | .get(TOKEN_HEADER) |
| 150 | 150 | .and_then(|v| v.to_str().ok()) |
| @@ -219,7 +219,7 @@ struct AdminLiveRequest { | ||
| 219 | 219 | /// `POST /internal/admin/live`. Wakes the open pages of the running server for a write made by |
| 220 | 220 | /// another process (the admin CLI). The body is small and the answer carries no data. |
| 221 | 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 | 223 | if !admin_authorized(cx, state) { |
| 224 | 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 | 262 | /// `POST /internal/admin/lfs-gc`. The body is ignored. |
| 263 | 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 | 265 | if !admin_authorized(cx, state) { |
| 266 | 266 | return Err(forbidden().into()); |
| 267 | 267 | } |
| @@ -306,7 +306,7 @@ fn admin_authorized(cx: &Cx, state: &AppState) -> bool { | ||
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 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 | 310 | if !admin_authorized(cx, state) { |
| 311 | 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 | 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 | 352 | if !admin_authorized(cx, state) { |
| 353 | 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 | 21 | use sha2::{Digest, Sha256}; |
| 22 | 22 | use tokio::io::AsyncWriteExt; |
| 23 | 23 | use tokio_util::io::ReaderStream; |
| 24 | -use topcoat::context::{Cx, app_context}; | |
| 24 | +use topcoat::context::{Cx, context}; | |
| 25 | 25 | use topcoat::router::request::headers; |
| 26 | 26 | use topcoat::router::response::Response; |
| 27 | 27 | use topcoat::router::{Body, HeaderMap, StatusCode, path_param, route, to_bytes}; |
| @@ -74,10 +74,10 @@ struct VerifyRequest { | ||
| 74 | 74 | |
| 75 | 75 | #[route(POST "/{owner}/{repo}/info/lfs/objects/batch")] |
| 76 | 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 | 78 | let headers = headers(cx); |
| 79 | - let owner = path_param::<Owner>(cx); | |
| 80 | - let name = path_param::<Repo>(cx); | |
| 79 | + let owner = owner(cx); | |
| 80 | + let name = repo(cx); | |
| 81 | 81 | |
| 82 | 82 | let bytes = to_bytes(body, MAX_BATCH_BYTES).await?; |
| 83 | 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 | 195 | #[route(GET "/{owner}/{repo}/info/lfs/objects/{oid}")] |
| 196 | 196 | async fn get_object(cx: &Cx) -> topcoat::Result<Response> { |
| 197 | - let state = app_context::<AppState>(cx); | |
| 197 | + let state = context::<AppState>(cx); | |
| 198 | 198 | let headers = headers(cx); |
| 199 | - let owner = path_param::<Owner>(cx); | |
| 200 | - let name = path_param::<Repo>(cx); | |
| 201 | - let oid = path_param::<Oid>(cx); | |
| 199 | + let owner = owner(cx); | |
| 200 | + let name = repo(cx); | |
| 201 | + let oid = oid(cx); | |
| 202 | 202 | if !is_valid_oid(oid) { |
| 203 | 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 | 235 | #[route(PUT "/{owner}/{repo}/info/lfs/objects/{oid}")] |
| 236 | 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 | 238 | let headers = headers(cx); |
| 239 | - let owner = path_param::<Owner>(cx); | |
| 240 | - let name = path_param::<Repo>(cx); | |
| 241 | - let oid = path_param::<Oid>(cx); | |
| 239 | + let owner = owner(cx); | |
| 240 | + let name = repo(cx); | |
| 241 | + let oid = oid(cx); | |
| 242 | 242 | if !is_valid_oid(oid) { |
| 243 | 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 | 276 | #[route(POST "/{owner}/{repo}/info/lfs/objects/verify")] |
| 277 | 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 | 279 | let headers = headers(cx); |
| 280 | - let owner = path_param::<Owner>(cx); | |
| 281 | - let name = path_param::<Repo>(cx); | |
| 280 | + let owner = owner(cx); | |
| 281 | + let name = repo(cx); | |
| 282 | 282 | |
| 283 | 283 | let repo = match authorize(state, client_ip(cx), headers, owner, name, Action::Write).await { |
| 284 | 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 | 77 | const DEFAULT_CONFIG: &str = "config/forge.toml"; |
| 78 | 78 | |
| 79 | 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 | 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 | 9 | use forge_core::oci as rules; |
| 10 | 10 | use forge_core::packages::{KIND_OCI, Package}; |
| 11 | 11 | use http::header::{AUTHORIZATION, HeaderValue, WWW_AUTHENTICATE}; |
| 12 | -use topcoat::context::{Cx, app_context}; | |
| 12 | +use topcoat::context::{Cx, context}; | |
| 13 | 13 | use topcoat::router::StatusCode; |
| 14 | 14 | use topcoat::router::request::headers; |
| 15 | 15 | use topcoat::router::response::Response; |
| @@ -42,7 +42,7 @@ pub struct Target { | ||
| 42 | 42 | /// verified here; anything else goes to the personal access token check the API uses. A bad |
| 43 | 43 | /// credential is a 401 with the challenge, so the client can ask again. |
| 44 | 44 | pub async fn caller(cx: &Cx) -> Result<Caller, Refusal> { |
| 45 | - let state = app_context::<AppState>(cx); | |
| 45 | + let state = context::<AppState>(cx); | |
| 46 | 46 | let headers = headers(cx); |
| 47 | 47 | let Some(value) = headers.get(AUTHORIZATION).and_then(|v| v.to_str().ok()) else { |
| 48 | 48 | return Ok(Caller { user: None }); |
crates/forge-web/src/oci/mod.rsmodified+5 -5
| @@ -19,7 +19,7 @@ pub mod manifests; | ||
| 19 | 19 | use forge_core::oci as rules; |
| 20 | 20 | use http::header::{CONTENT_TYPE, HeaderValue}; |
| 21 | 21 | use serde_json::{Value, json}; |
| 22 | -use topcoat::context::{Cx, app_context}; | |
| 22 | +use topcoat::context::{Cx, context}; | |
| 23 | 23 | use topcoat::router::request::{headers, method, uri}; |
| 24 | 24 | use topcoat::router::response::Response; |
| 25 | 25 | use topcoat::router::{Body, StatusCode, path_param, route}; |
| @@ -105,7 +105,7 @@ fn query_value(pairs: &[(String, String)], key: &str) -> Option<String> { | ||
| 105 | 105 | /// `GET /v2/`: the probe. A caller with valid credentials gets 200; anyone else the challenge. |
| 106 | 106 | #[route(GET "/v2/")] |
| 107 | 107 | async fn root(cx: &Cx) -> topcoat::Result<Response> { |
| 108 | - let state = app_context::<AppState>(cx); | |
| 108 | + let state = context::<AppState>(cx); | |
| 109 | 109 | Ok(match auth::caller(cx).await { |
| 110 | 110 | Ok(Caller { user: Some(_) }) => json_response(StatusCode::OK, &json!({})), |
| 111 | 111 | Ok(_) => auth::challenge(state, None), |
| @@ -117,7 +117,7 @@ async fn root(cx: &Cx) -> topcoat::Result<Response> { | ||
| 117 | 117 | /// short-lived bearer token. Anonymous callers get an anonymous token, which reads public images. |
| 118 | 118 | #[route(GET "/v2/token")] |
| 119 | 119 | async fn token(cx: &Cx) -> topcoat::Result<Response> { |
| 120 | - let state = app_context::<AppState>(cx); | |
| 120 | + let state = context::<AppState>(cx); | |
| 121 | 121 | let caller = match auth::caller(cx).await { |
| 122 | 122 | Ok(caller) => caller, |
| 123 | 123 | Err(res) => return Ok(*res), |
| @@ -168,8 +168,8 @@ async fn delete_v2(cx: &Cx, body: Body) -> topcoat::Result<Response> { | ||
| 168 | 168 | /// Routes a request below `/v2/` to its operation. The caller is resolved first, so every answer |
| 169 | 169 | /// about a repository comes from the same identity. |
| 170 | 170 | async fn dispatch(cx: &Cx, body: Body) -> Response { |
| 171 | - let state = app_context::<AppState>(cx); | |
| 172 | - let segments: Vec<String> = path_param::<Rest>(cx).map(str::to_owned).collect(); | |
| 171 | + let state = context::<AppState>(cx); | |
| 172 | + let segments: Vec<String> = rest(cx).map(str::to_owned).collect(); | |
| 173 | 173 | let mut parts: Vec<&str> = segments.iter().map(String::as_str).collect(); |
| 174 | 174 | while parts.last() == Some(&"") { |
| 175 | 175 | parts.pop(); |
crates/forge-web/src/pages/activity.rsmodified+3 -3
| @@ -9,7 +9,7 @@ use forge_core::{Reason, User}; | ||
| 9 | 9 | use http::header::{CACHE_CONTROL, CONTENT_TYPE, X_CONTENT_TYPE_OPTIONS}; |
| 10 | 10 | use serde_json::{Value, json}; |
| 11 | 11 | use topcoat::Result; |
| 12 | -use topcoat::context::{Cx, app_context}; | |
| 12 | +use topcoat::context::{Cx, context}; | |
| 13 | 13 | use topcoat::router::response::Response; |
| 14 | 14 | use topcoat::router::{Body, HeaderValue, StatusCode, route}; |
| 15 | 15 | |
| @@ -108,7 +108,7 @@ async fn activity(cx: &Cx) -> Result<Response> { | ||
| 108 | 108 | *res.status_mut() = StatusCode::UNAUTHORIZED; |
| 109 | 109 | return Ok(res); |
| 110 | 110 | }; |
| 111 | - let state = app_context::<AppState>(cx); | |
| 111 | + let state = context::<AppState>(cx); | |
| 112 | 112 | let body = activity_json(state, &user).await?; |
| 113 | 113 | let mut response = Response::new(Body::from(body.to_string().into_bytes())); |
| 114 | 114 | let headers = response.headers_mut(); |
| @@ -131,7 +131,7 @@ async fn activity_stream(cx: &Cx) -> Result<Response> { | ||
| 131 | 131 | *res.status_mut() = StatusCode::UNAUTHORIZED; |
| 132 | 132 | return Ok(res); |
| 133 | 133 | }; |
| 134 | - let state = app_context::<AppState>(cx).clone(); | |
| 134 | + let state = context::<AppState>(cx).clone(); | |
| 135 | 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 | 12 | use forge_core::{AuditAction, Error, Store, User}; |
| 13 | 13 | use serde::Deserialize; |
| 14 | 14 | use topcoat::Result; |
| 15 | -use topcoat::context::{Cx, app_context}; | |
| 15 | +use topcoat::context::{Cx, context}; | |
| 16 | 16 | use topcoat::router::content::Form; |
| 17 | 17 | use topcoat::router::error::{forbidden, see_other}; |
| 18 | 18 | use topcoat::router::response::Response; |
| @@ -109,7 +109,7 @@ fn run_row(run: &BackupRun, lang: Lang) -> RunRow { | ||
| 109 | 109 | |
| 110 | 110 | /// The rail of the Backups tab: Backups and Replication. |
| 111 | 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 | 113 | let items = vec![ |
| 114 | 114 | RailItem { |
| 115 | 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 | 132 | #[component] |
| 133 | 133 | async fn backups_view( |
| 134 | + cx: &Cx, | |
| 134 | 135 | lang: Lang, |
| 135 | 136 | csrf: String, |
| 136 | 137 | enabled: bool, |
| @@ -213,7 +214,7 @@ async fn runs_fingerprint(store: &Store, running: Option<RunKind>) -> Result<Str | ||
| 213 | 214 | #[route(GET "/admin/backups/events")] |
| 214 | 215 | async fn backups_events(cx: &Cx) -> Result<Response> { |
| 215 | 216 | admin_only(cx).await?; |
| 216 | - let state = app_context::<AppState>(cx); | |
| 217 | + let state = context::<AppState>(cx); | |
| 217 | 218 | let store = state.store.clone(); |
| 218 | 219 | let jobs = state.jobs.clone(); |
| 219 | 220 | stream_changes( |
| @@ -233,7 +234,7 @@ async fn backups_events(cx: &Cx) -> Result<Response> { | ||
| 233 | 234 | async fn backups_page(cx: &Cx) -> Result<impl View> { |
| 234 | 235 | let viewer = admin_only(cx).await?; |
| 235 | 236 | let query = query_params::<NoticeQuery>(cx)?; |
| 236 | - let state = app_context::<AppState>(cx); | |
| 237 | + let state = context::<AppState>(cx); | |
| 237 | 238 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 238 | 239 | let runs = state.store.recent_runs(RUN_LIMIT).await?; |
| 239 | 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 | 256 | return Err(forbidden().into()); |
| 256 | 257 | } |
| 257 | 258 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 258 | - let state = app_context::<AppState>(cx); | |
| 259 | + let state = context::<AppState>(cx); | |
| 259 | 260 | let notice = notice_of( |
| 260 | 261 | lang, |
| 261 | 262 | save_topic( |
| @@ -289,7 +290,7 @@ async fn start_run(cx: &Cx, csrf: String, kind: RunKind) -> Result<Response> { | ||
| 289 | 290 | return Err(forbidden().into()); |
| 290 | 291 | } |
| 291 | 292 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 292 | - let state = app_context::<AppState>(cx); | |
| 293 | + let state = context::<AppState>(cx); | |
| 293 | 294 | let notice = match launch(cx, state, &viewer.0, kind, lang).await { |
| 294 | 295 | Ok(()) => g::started_notice(lang, kind), |
| 295 | 296 | Err(e) => match e { |
| @@ -548,7 +549,10 @@ mod tests { | ||
| 548 | 549 | assert_eq!(status, 200); |
| 549 | 550 | assert!(body.contains("schedule")); |
| 550 | 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 | 556 | assert!( |
| 553 | 557 | !body.contains("SECRET-TOKEN"), |
| 554 | 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 | 14 | use forge_core::time::stamp_to_unix; |
| 15 | 15 | use tokio::process::Command; |
| 16 | 16 | use topcoat::Result; |
| 17 | -use topcoat::context::{Cx, app_context}; | |
| 17 | +use topcoat::context::{Cx, context}; | |
| 18 | 18 | use topcoat::router::response::Response; |
| 19 | 19 | use topcoat::router::{page, query_params, route}; |
| 20 | 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 | 25 | use crate::i18n::alerts as alert_text; |
| 24 | 26 | use crate::i18n::{self, Lang}; |
| 25 | 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 | 467 | /// The alert's raised time as a live relative time, worded per language. |
| 466 | 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 | 470 | Ok(view! { |
| 469 | 471 | if matches!(lang, Lang::Tr) { |
| 470 | 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 | 479 | #[component] |
| 478 | 480 | async fn health_view( |
| 481 | + cx: &Cx, | |
| 479 | 482 | lang: Lang, |
| 480 | 483 | health: Health, |
| 481 | 484 | alerts: Vec<AlertRow>, |
| @@ -579,7 +582,7 @@ async fn health_view( | ||
| 579 | 582 | async fn health_page(cx: &Cx) -> Result<impl View> { |
| 580 | 583 | let viewer = admin_only(cx).await?; |
| 581 | 584 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 582 | - let state = app_context::<AppState>(cx); | |
| 585 | + let state = context::<AppState>(cx); | |
| 583 | 586 | let query = query_params::<HealthQuery>(cx)?; |
| 584 | 587 | let health = gather(state, lang).await?; |
| 585 | 588 | let all = alert_rows(state, lang).await?; |
| @@ -644,7 +647,7 @@ async fn health_fingerprint(state: &AppState) -> Result<String> { | ||
| 644 | 647 | #[route(GET "/admin/health/events")] |
| 645 | 648 | async fn health_events(cx: &Cx) -> Result<Response> { |
| 646 | 649 | admin_only(cx).await?; |
| 647 | - let state = app_context::<AppState>(cx).clone(); | |
| 650 | + let state = context::<AppState>(cx).clone(); | |
| 648 | 651 | stream_changes(cx, crate::live::admin(), &[Topic::AdminHealth], move || { |
| 649 | 652 | let state = state.clone(); |
| 650 | 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 | 19 | use serde::Deserialize; |
| 20 | 20 | use tokio::sync::watch; |
| 21 | 21 | use topcoat::Result; |
| 22 | -use topcoat::context::{Cx, app_context}; | |
| 22 | +use topcoat::context::{Cx, context}; | |
| 23 | 23 | use topcoat::router::content::Form; |
| 24 | 24 | use topcoat::router::content::sse::Event; |
| 25 | 25 | use topcoat::router::error::{forbidden, see_other}; |
| @@ -199,6 +199,7 @@ async fn page_data( | ||
| 199 | 199 | |
| 200 | 200 | #[component] |
| 201 | 201 | async fn mail_view( |
| 202 | + cx: &Cx, | |
| 202 | 203 | lang: Lang, |
| 203 | 204 | csrf: String, |
| 204 | 205 | data: PageData, |
| @@ -332,7 +333,7 @@ async fn mail_view( | ||
| 332 | 333 | async fn mail_page(cx: &Cx) -> Result<impl View> { |
| 333 | 334 | let viewer = admin_only(cx).await?; |
| 334 | 335 | let query = query_params::<NoticeQuery>(cx)?; |
| 335 | - let state = app_context::<AppState>(cx); | |
| 336 | + let state = context::<AppState>(cx); | |
| 336 | 337 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 337 | 338 | let tab = if query.tab.as_deref() == Some("queue") { |
| 338 | 339 | Tab::Queue |
| @@ -398,7 +399,7 @@ async fn mail_save(cx: &Cx, Form(form): Form<SettingsForm>) -> Result<Response> | ||
| 398 | 399 | return Err(forbidden().into()); |
| 399 | 400 | } |
| 400 | 401 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 401 | - let state = app_context::<AppState>(cx); | |
| 402 | + let state = context::<AppState>(cx); | |
| 402 | 403 | let saved = save_settings(cx, state, &viewer.0, &form, lang).await; |
| 403 | 404 | let transport = if form.transport.is_empty() { |
| 404 | 405 | Ok(None) |
| @@ -488,7 +489,7 @@ async fn mail_test(cx: &Cx, Form(form): Form<TestForm>) -> Result<Response> { | ||
| 488 | 489 | return Err(forbidden().into()); |
| 489 | 490 | } |
| 490 | 491 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 491 | - let state = app_context::<AppState>(cx); | |
| 492 | + let state = context::<AppState>(cx); | |
| 492 | 493 | let notice = match queue_test(cx, state, &viewer.0, lang).await { |
| 493 | 494 | Ok(()) => g::t(lang, K::TestQueued).to_owned(), |
| 494 | 495 | Err(Error::Invalid(message)) => message, |
| @@ -577,7 +578,7 @@ async fn queue_action(cx: &Cx, form: QueueForm, action: QueueAction) -> Result<R | ||
| 577 | 578 | return Err(forbidden().into()); |
| 578 | 579 | } |
| 579 | 580 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 580 | - let state = app_context::<AppState>(cx); | |
| 581 | + let state = context::<AppState>(cx); | |
| 581 | 582 | let now = now_stamp(); |
| 582 | 583 | let (done, notice) = match action { |
| 583 | 584 | QueueAction::Retry => { |
crates/forge-web/src/pages/admin_replication.rsmodified+6 -5
| @@ -16,7 +16,7 @@ use forge_core::time::stamp_ago; | ||
| 16 | 16 | use forge_core::{AuditAction, Error}; |
| 17 | 17 | use serde::Deserialize; |
| 18 | 18 | use topcoat::Result; |
| 19 | -use topcoat::context::{Cx, app_context}; | |
| 19 | +use topcoat::context::{Cx, context}; | |
| 20 | 20 | use topcoat::router::content::Form; |
| 21 | 21 | use topcoat::router::error::{forbidden, see_other}; |
| 22 | 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 | 230 | #[component] |
| 231 | 231 | async fn replication_view( |
| 232 | + cx: &Cx, | |
| 232 | 233 | lang: Lang, |
| 233 | 234 | csrf: String, |
| 234 | 235 | data: PageData, |
| @@ -352,7 +353,7 @@ async fn page_fingerprint(state: &AppState) -> Result<String> { | ||
| 352 | 353 | #[route(GET "/admin/replication/events")] |
| 353 | 354 | async fn replication_events(cx: &Cx) -> Result<Response> { |
| 354 | 355 | admin_only(cx).await?; |
| 355 | - let state = app_context::<AppState>(cx).clone(); | |
| 356 | + let state = context::<AppState>(cx).clone(); | |
| 356 | 357 | stream_changes( |
| 357 | 358 | cx, |
| 358 | 359 | crate::live::admin(), |
| @@ -425,7 +426,7 @@ async fn replication_page(cx: &Cx) -> Result<impl View> { | ||
| 425 | 426 | let viewer = admin_only(cx).await?; |
| 426 | 427 | let query = query_params::<NoticeQuery>(cx)?; |
| 427 | 428 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 428 | - let state = app_context::<AppState>(cx); | |
| 429 | + let state = context::<AppState>(cx); | |
| 429 | 430 | let mut data = page_data(state, lang).await?; |
| 430 | 431 | let list = repo_list(&mut data, query); |
| 431 | 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 | 445 | return Err(forbidden().into()); |
| 445 | 446 | } |
| 446 | 447 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 447 | - let state = app_context::<AppState>(cx); | |
| 448 | + let state = context::<AppState>(cx); | |
| 448 | 449 | let notice = notice_of( |
| 449 | 450 | lang, |
| 450 | 451 | save_topic( |
| @@ -474,7 +475,7 @@ async fn replication_reconcile(cx: &Cx, Form(form): Form<ReconcileForm>) -> Resu | ||
| 474 | 475 | return Err(forbidden().into()); |
| 475 | 476 | } |
| 476 | 477 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 477 | - let state = app_context::<AppState>(cx); | |
| 478 | + let state = context::<AppState>(cx); | |
| 478 | 479 | let notice = match reconcile_now(cx, state, &viewer.0, lang).await { |
| 479 | 480 | Ok(()) => g::t(lang, K::ReconcileStarted).to_owned(), |
| 480 | 481 | Err(Error::Config(message)) => message, |
crates/forge-web/src/pages/admin_runners.rsmodified+39 -37
| @@ -17,7 +17,7 @@ use serde::Deserialize; | ||
| 17 | 17 | use time::OffsetDateTime; |
| 18 | 18 | use time::format_description::well_known::Rfc3339; |
| 19 | 19 | use topcoat::Result; |
| 20 | -use topcoat::context::{Cx, app_context}; | |
| 20 | +use topcoat::context::{Cx, context}; | |
| 21 | 21 | use topcoat::router::content::Form; |
| 22 | 22 | use topcoat::router::error::{SeeOther, forbidden, see_other}; |
| 23 | 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 | 63 | /// Extra notice words: (word, English, Turkish, is an error). |
| 64 | 64 | const EXTRA_NOTICES: [(&str, &str, &str, bool); 8] = [ |
| 65 | - ( | |
| 66 | - "saved", | |
| 67 | - "Saved.", | |
| 68 | - "Kaydedildi.", | |
| 69 | - false, | |
| 70 | - ), | |
| 71 | - ( | |
| 72 | - "saved-restart", | |
| 73 | - "Saved.", | |
| 74 | - "Kaydedildi.", | |
| 75 | - false, | |
| 76 | - ), | |
| 65 | + ("saved", "Saved.", "Kaydedildi.", false), | |
| 66 | + ("saved-restart", "Saved.", "Kaydedildi.", false), | |
| 77 | 67 | ( |
| 78 | 68 | "reset", |
| 79 | 69 | "Override removed.", |
| @@ -322,6 +312,7 @@ fn register_command(base_url: &str, token: &str) -> String { | ||
| 322 | 312 | |
| 323 | 313 | #[component] |
| 324 | 314 | async fn runners_view( |
| 315 | + cx: &Cx, | |
| 325 | 316 | lang: Lang, |
| 326 | 317 | csrf: String, |
| 327 | 318 | rows: Vec<RunnerRow>, |
| @@ -388,6 +379,7 @@ fn list_href(page: u64, notice: &str) -> String { | ||
| 388 | 379 | /// that are not destructive, so the confirm button is soft. |
| 389 | 380 | #[component] |
| 390 | 381 | pub(crate) async fn confirm_post( |
| 382 | + cx: &Cx, | |
| 391 | 383 | lang: Lang, |
| 392 | 384 | csrf: &str, |
| 393 | 385 | action: &str, |
| @@ -433,6 +425,7 @@ fn disable_message(lang: Lang, name: &str) -> String { | ||
| 433 | 425 | /// pending the control shows that instead, and the runner clears it by coming back with a new id. |
| 434 | 426 | #[component] |
| 435 | 427 | async fn restart_control( |
| 428 | + cx: &Cx, | |
| 436 | 429 | lang: Lang, |
| 437 | 430 | csrf: &str, |
| 438 | 431 | action: &str, |
| @@ -461,7 +454,7 @@ const PIP_MAX: u32 = 16; | ||
| 461 | 454 | |
| 462 | 455 | /// The load of a runner: the jobs running, as a pip per concurrency slot, or a meter past `PIP_MAX`. |
| 463 | 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 | 458 | let running_text = running.to_string(); |
| 466 | 459 | let meter_max = max.max(1).to_string(); |
| 467 | 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 | 487 | #[component] |
| 495 | -async fn token_view( | |
| 496 | - lang: Lang, | |
| 497 | - token: String, | |
| 498 | - command: String, | |
| 499 | -) -> Result<impl View> { | |
| 488 | +async fn token_view(cx: &Cx, lang: Lang, token: String, command: String) -> Result<impl View> { | |
| 500 | 489 | Ok(view! { |
| 501 | 490 | head(title: g::t(lang, K::RegistrationToken)) |
| 502 | 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 | 511 | let viewer = admin_only(cx).await?; |
| 523 | 512 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 524 | 513 | let query = query_params::<RunnersQuery>(cx)?; |
| 525 | - let state = app_context::<AppState>(cx); | |
| 514 | + let state = context::<AppState>(cx); | |
| 526 | 515 | let tz = viewer.0.timezone.clone(); |
| 527 | 516 | let now = now_unix(); |
| 528 | 517 | let all: Vec<RunnerRow> = state |
| @@ -566,7 +555,7 @@ async fn runner_token_create(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<impl | ||
| 566 | 555 | if !check_csrf(&viewer.1, &form.csrf) { |
| 567 | 556 | return Err(forbidden().into()); |
| 568 | 557 | } |
| 569 | - let state = app_context::<AppState>(cx); | |
| 558 | + let state = context::<AppState>(cx); | |
| 570 | 559 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 571 | 560 | let ttl_hours = state.live().ci.registration_token_hours; |
| 572 | 561 | let token = match state |
| @@ -617,8 +606,8 @@ async fn runner_set_disabled(cx: &Cx, Form(form): Form<DisableForm>) -> Result<S | ||
| 617 | 606 | if !check_csrf(&viewer.1, &form.csrf) { |
| 618 | 607 | return Err(forbidden().into()); |
| 619 | 608 | } |
| 620 | - let id = path_param::<RunnerId>(cx); | |
| 621 | - let state = app_context::<AppState>(cx); | |
| 609 | + let id = runner_id(cx); | |
| 610 | + let state = context::<AppState>(cx); | |
| 622 | 611 | if runner_named(state, id).await?.is_none() { |
| 623 | 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 | 625 | if !check_csrf(&viewer.1, &form.csrf) { |
| 637 | 626 | return Err(forbidden().into()); |
| 638 | 627 | } |
| 639 | - let id = path_param::<RunnerId>(cx); | |
| 640 | - let state = app_context::<AppState>(cx); | |
| 628 | + let id = runner_id(cx); | |
| 629 | + let state = context::<AppState>(cx); | |
| 641 | 630 | let Some(runner) = runner_named(state, id).await? else { |
| 642 | 631 | return Ok(back_to_list("missing")); |
| 643 | 632 | }; |
| @@ -816,10 +805,18 @@ fn field_text(lang: Lang, key: &str) -> &'static str { | ||
| 816 | 805 | "limits.cpus" => s(lang, "CPU limit", "CPU sınırı"), |
| 817 | 806 | "limits.pids" => s(lang, "Process limit", "İşlem sınırı"), |
| 818 | 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 | 813 | "limits.job_disk_gb" => s(lang, "Disk per job (GB)", "İş başına disk (GB)"), |
| 821 | 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 | 820 | "sandbox.userns" => s(lang, "User namespaces", "Kullanıcı ad alanları"), |
| 824 | 821 | "name" => s(lang, "Name", "Ad"), |
| 825 | 822 | "url" => s(lang, "Forge URL", "Forge adresi"), |
| @@ -1371,6 +1368,7 @@ fn current(on: bool) -> Option<&'static str> { | ||
| 1371 | 1368 | |
| 1372 | 1369 | #[component] |
| 1373 | 1370 | async fn runner_detail_view( |
| 1371 | + cx: &Cx, | |
| 1374 | 1372 | lang: Lang, |
| 1375 | 1373 | csrf: String, |
| 1376 | 1374 | runner: CiRunner, |
| @@ -1418,7 +1416,11 @@ async fn runner_detail_view( | ||
| 1418 | 1416 | let slots = row.concurrency.parse::<u32>().unwrap_or(0); |
| 1419 | 1417 | let mut sub = vec![SubPart::text(row.state_text)]; |
| 1420 | 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 | 1425 | let jobs_href = format!("{}?tab=jobs", row.detail_href); |
| 1424 | 1426 | let save_action = format!("{}/settings", row.detail_href); |
| @@ -1644,8 +1646,8 @@ async fn runner_detail_view( | ||
| 1644 | 1646 | async fn runner_detail_page(cx: &Cx) -> Result<impl View> { |
| 1645 | 1647 | let viewer = admin_only(cx).await?; |
| 1646 | 1648 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 1647 | - let state = app_context::<AppState>(cx); | |
| 1648 | - let id = path_param::<RunnerId>(cx); | |
| 1649 | + let state = context::<AppState>(cx); | |
| 1650 | + let id = runner_id(cx); | |
| 1649 | 1651 | let Some(runner) = runner_named(state, id).await? else { |
| 1650 | 1652 | return Err(back_to_list("missing").into()); |
| 1651 | 1653 | }; |
| @@ -1683,8 +1685,8 @@ async fn runner_save_settings( | ||
| 1683 | 1685 | if !check_csrf(&viewer.1, form.get("csrf").map_or("", String::as_str)) { |
| 1684 | 1686 | return Err(forbidden().into()); |
| 1685 | 1687 | } |
| 1686 | - let id = path_param::<RunnerId>(cx); | |
| 1687 | - let state = app_context::<AppState>(cx); | |
| 1688 | + let id = runner_id(cx); | |
| 1689 | + let state = context::<AppState>(cx); | |
| 1688 | 1690 | let tab = tab_slug(form.get("tab").map(String::as_str)); |
| 1689 | 1691 | let back = |notice: &str| { |
| 1690 | 1692 | see_other(format!( |
| @@ -1756,7 +1758,7 @@ async fn runner_save_settings( | ||
| 1756 | 1758 | #[route(GET "/admin/runners/events")] |
| 1757 | 1759 | async fn runners_events(cx: &Cx) -> Result<Response> { |
| 1758 | 1760 | admin_only(cx).await?; |
| 1759 | - let state = app_context::<AppState>(cx); | |
| 1761 | + let state = context::<AppState>(cx); | |
| 1760 | 1762 | let wake = state.ci_live.subscribe_runners(); |
| 1761 | 1763 | let events = futures_util::stream::unfold(wake, |mut wake| async move { |
| 1762 | 1764 | wake.changed().await.ok()?; |
| @@ -1776,8 +1778,8 @@ async fn runner_set_config(cx: &Cx, Form(form): Form<ConfigForm>) -> Result<SeeO | ||
| 1776 | 1778 | if !check_csrf(&viewer.1, &form.csrf) { |
| 1777 | 1779 | return Err(forbidden().into()); |
| 1778 | 1780 | } |
| 1779 | - let id = path_param::<RunnerId>(cx); | |
| 1780 | - let state = app_context::<AppState>(cx); | |
| 1781 | + let id = runner_id(cx); | |
| 1782 | + let state = context::<AppState>(cx); | |
| 1781 | 1783 | let back = |notice: &str| { |
| 1782 | 1784 | if form.back == "detail" { |
| 1783 | 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 | 1853 | if !check_csrf(&viewer.1, &form.csrf) { |
| 1852 | 1854 | return Err(forbidden().into()); |
| 1853 | 1855 | } |
| 1854 | - let id = path_param::<RunnerId>(cx); | |
| 1855 | - let state = app_context::<AppState>(cx); | |
| 1856 | + let id = runner_id(cx); | |
| 1857 | + let state = context::<AppState>(cx); | |
| 1856 | 1858 | let back = |notice: &str| { |
| 1857 | 1859 | if form.back == "detail" { |
| 1858 | 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 | 21 | use futures_util::StreamExt; |
| 22 | 22 | use serde::Deserialize; |
| 23 | 23 | use topcoat::Result; |
| 24 | -use topcoat::context::{Cx, app_context}; | |
| 24 | +use topcoat::context::{Cx, context}; | |
| 25 | 25 | use topcoat::router::content::Form; |
| 26 | 26 | use topcoat::router::error::{forbidden, see_other}; |
| 27 | 27 | use topcoat::router::response::Response; |
| @@ -546,7 +546,7 @@ pub(crate) fn with_notice(back: &str, notice: &str) -> String { | ||
| 546 | 546 | /// The hidden form that resets one setting: the rows' "Reset to file value" buttons post to it by |
| 547 | 547 | /// id. It goes outside the forms that save, since a form cannot hold another. |
| 548 | 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 | 550 | Ok(view! { |
| 551 | 551 | <form id="srv-reset" method="post" action="/admin/server/reset"> |
| 552 | 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 | 558 | /// The rows of a settings topic, one line each. The caller's form holds them. |
| 559 | 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 | 561 | Ok(view! { |
| 562 | 562 | for r in rows.iter() { |
| 563 | 563 | srv_row(lang: lang, row: r) |
| @@ -584,7 +584,7 @@ async fn search_hits( | ||
| 584 | 584 | /// One setting on one line: its name, then its control (or its value when it cannot be changed |
| 585 | 585 | /// here), then what to know about it. Every control is the same width, so the notes line up. |
| 586 | 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 | 588 | let id = format!("srv-{}", row.key); |
| 589 | 589 | let input = format!("srv-{}-in", row.key); |
| 590 | 590 | Ok(view! { |
| @@ -619,7 +619,7 @@ async fn srv_row(lang: Lang, row: &Row) -> Result<impl View> { | ||
| 619 | 619 | |
| 620 | 620 | /// The facts after a setting's control: its kind, whether a restart is needed, and its override. |
| 621 | 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 | 623 | Ok(view! { |
| 624 | 624 | <span class="srv-hints"> |
| 625 | 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 | 645 | #[component] |
| 646 | 646 | async fn server_view( |
| 647 | + cx: &Cx, | |
| 647 | 648 | lang: Lang, |
| 648 | 649 | csrf: String, |
| 649 | 650 | page: &'static SrvPage, |
| @@ -738,7 +739,7 @@ async fn server_view( | ||
| 738 | 739 | async fn server_page(cx: &Cx) -> Result<impl View> { |
| 739 | 740 | let viewer = admin_only(cx).await?; |
| 740 | 741 | let query = query_params::<ServerQuery>(cx)?; |
| 741 | - let state = app_context::<AppState>(cx); | |
| 742 | + let state = context::<AppState>(cx); | |
| 742 | 743 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 743 | 744 | let slug = query.cat.as_deref().or(query.tab.as_deref()).unwrap_or(""); |
| 744 | 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 | 770 | return Err(forbidden().into()); |
| 770 | 771 | } |
| 771 | 772 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 772 | - let state = app_context::<AppState>(cx); | |
| 773 | + let state = context::<AppState>(cx); | |
| 773 | 774 | let page = form |
| 774 | 775 | .get("tab") |
| 775 | 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 | 842 | if !check_csrf(&viewer.1, &form.csrf) { |
| 842 | 843 | return Err(forbidden().into()); |
| 843 | 844 | } |
| 844 | - let state = app_context::<AppState>(cx); | |
| 845 | + let state = context::<AppState>(cx); | |
| 845 | 846 | let group = Group::parse(&form.tab).unwrap_or(Group::General); |
| 846 | 847 | audit::record( |
| 847 | 848 | &state.store, |
| @@ -909,7 +910,7 @@ async fn server_reset(cx: &Cx, Form(form): Form<ResetForm>) -> Result<Response> | ||
| 909 | 910 | return Err(forbidden().into()); |
| 910 | 911 | } |
| 911 | 912 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 912 | - let state = app_context::<AppState>(cx); | |
| 913 | + let state = context::<AppState>(cx); | |
| 913 | 914 | let notice = match reset(cx, state, &viewer.0, &form.key).await { |
| 914 | 915 | Ok(()) => g::t(lang, K::SrvResetDone).to_owned(), |
| 915 | 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 | 10 | use forge_core::{AuditAction, Store, User}; |
| 11 | 11 | use serde::Deserialize; |
| 12 | 12 | use topcoat::Result; |
| 13 | -use topcoat::context::{Cx, app_context}; | |
| 13 | +use topcoat::context::{Cx, context}; | |
| 14 | 14 | use topcoat::router::content::Form; |
| 15 | 15 | use topcoat::router::error::{forbidden, not_found, see_other}; |
| 16 | 16 | use topcoat::router::response::Response; |
| @@ -88,7 +88,7 @@ fn is_ghost(user: &User) -> bool { | ||
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | async fn load(cx: &Cx) -> Result<Detail> { |
| 91 | - let store = &app_context::<AppState>(cx).store; | |
| 91 | + let store = &context::<AppState>(cx).store; | |
| 92 | 92 | let id = path_param_segment(cx, "user_id").to_owned(); |
| 93 | 93 | let Some(target) = store.user_by_id(&id).await? else { |
| 94 | 94 | return Err(not_found().into()); |
| @@ -161,6 +161,7 @@ fn local_stamp(stamp: &str, tz: &str) -> String { | ||
| 161 | 161 | |
| 162 | 162 | #[component] |
| 163 | 163 | async fn detail_body( |
| 164 | + cx: &Cx, | |
| 164 | 165 | lang: Lang, |
| 165 | 166 | csrf: &str, |
| 166 | 167 | viewer_id: &str, |
| @@ -445,6 +446,7 @@ async fn detail_body( | ||
| 445 | 446 | /// delete, which opens the page that says what goes with it. |
| 446 | 447 | #[component] |
| 447 | 448 | async fn org_body( |
| 449 | + cx: &Cx, | |
| 448 | 450 | lang: Lang, |
| 449 | 451 | org: User, |
| 450 | 452 | members: Vec<(User, OrgMemberRole)>, |
| @@ -564,7 +566,7 @@ async fn account_fingerprint(store: &Store, user_id: &str) -> Result<String> { | ||
| 564 | 566 | async fn detail_events(cx: &Cx) -> Result<Response> { |
| 565 | 567 | admin_only(cx).await?; |
| 566 | 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 | 570 | let topic = Topic::AdminUser(id.clone()); |
| 569 | 571 | stream_changes(cx, crate::live::admin(), &[topic], move || { |
| 570 | 572 | let store = store.clone(); |
| @@ -579,7 +581,7 @@ async fn detail_page(cx: &Cx) -> Result<impl View> { | ||
| 579 | 581 | let viewer = admin_only(cx).await?; |
| 580 | 582 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 581 | 583 | let query = query_params::<DoneQuery>(cx)?; |
| 582 | - let store = &app_context::<AppState>(cx).store; | |
| 584 | + let store = &context::<AppState>(cx).store; | |
| 583 | 585 | let id = path_param_segment(cx, "user_id").to_owned(); |
| 584 | 586 | let org = match store.user_by_id(&id).await? { |
| 585 | 587 | Some(user) if user.is_org() => { |
| @@ -625,7 +627,7 @@ async fn perform(cx: &Cx, form: &ActionForm, action: Action) -> Result<(Outcome, | ||
| 625 | 627 | return Err(forbidden().into()); |
| 626 | 628 | } |
| 627 | 629 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 628 | - let state = app_context::<AppState>(cx); | |
| 630 | + let state = context::<AppState>(cx); | |
| 629 | 631 | let store = &state.store; |
| 630 | 632 | let detail = load(cx).await?; |
| 631 | 633 | let target = &detail.target; |
| @@ -661,7 +663,7 @@ async fn perform(cx: &Cx, form: &ActionForm, action: Action) -> Result<(Outcome, | ||
| 661 | 663 | Ok(()) => { |
| 662 | 664 | // A suspension ends the user's sessions: their open tabs must see it. |
| 663 | 665 | crate::pages::settings_live::bump_account( |
| 664 | - app_context::<AppState>(cx), | |
| 666 | + context::<AppState>(cx), | |
| 665 | 667 | &target.id, |
| 666 | 668 | ); |
| 667 | 669 | audit( |
| @@ -748,8 +750,8 @@ async fn perform(cx: &Cx, form: &ActionForm, action: Action) -> Result<(Outcome, | ||
| 748 | 750 | |
| 749 | 751 | /// Redirects to the detail page after a success, or renders it with a message. |
| 750 | 752 | async fn respond(cx: &Cx, form: ActionForm, action: Action) -> Result<impl View> { |
| 751 | - // `view!` expects the `__cx` binding that `#[page]` provides. | |
| 752 | - let __cx = cx; | |
| 753 | + // `view!` expects the `cx` binding that `#[page]` provides. | |
| 754 | + let cx = cx; | |
| 753 | 755 | let (outcome, detail) = perform(cx, &form, action).await?; |
| 754 | 756 | let viewer = admin_only(cx).await?; |
| 755 | 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 | 7 | use forge_core::{AuditAction, Session, Store, User}; |
| 8 | 8 | use serde::Deserialize; |
| 9 | 9 | use topcoat::Result; |
| 10 | -use topcoat::context::{Cx, app_context}; | |
| 10 | +use topcoat::context::{Cx, context}; | |
| 11 | 11 | use topcoat::router::content::Form; |
| 12 | 12 | use topcoat::router::error::{forbidden, not_found, see_other}; |
| 13 | 13 | use topcoat::router::response::Response; |
| @@ -168,6 +168,7 @@ impl UserRow { | ||
| 168 | 168 | |
| 169 | 169 | #[component] |
| 170 | 170 | async fn users_view( |
| 171 | + cx: &Cx, | |
| 171 | 172 | lang: Lang, |
| 172 | 173 | csrf: &str, |
| 173 | 174 | users: Vec<User>, |
| @@ -289,7 +290,7 @@ async fn users_view( | ||
| 289 | 290 | |
| 290 | 291 | /// The rail of the Users tab: Users and Invites. `current` is `users` or `invites`. |
| 291 | 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 | 294 | let items = vec![ |
| 294 | 295 | RailItem { |
| 295 | 296 | name: g::t(lang, K::Users).to_owned(), |
| @@ -333,7 +334,7 @@ async fn list_fingerprint(store: &Store) -> topcoat::Result<String> { | ||
| 333 | 334 | #[route(GET "/admin/users/events")] |
| 334 | 335 | async fn users_events(cx: &Cx) -> Result<Response> { |
| 335 | 336 | admin_only(cx).await?; |
| 336 | - let store = app_context::<AppState>(cx).store.clone(); | |
| 337 | + let store = context::<AppState>(cx).store.clone(); | |
| 337 | 338 | stream_changes(cx, crate::live::admin(), &[Topic::AdminUsers], move || { |
| 338 | 339 | let store = store.clone(); |
| 339 | 340 | async move { list_fingerprint(&store).await } |
| @@ -346,7 +347,7 @@ async fn users_page(cx: &Cx) -> Result<impl View> { | ||
| 346 | 347 | let viewer = admin_only(cx).await?; |
| 347 | 348 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 348 | 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 | 351 | let csrf = viewer.1.csrf_token.clone(); |
| 351 | 352 | let title = g::t(lang, K::Users); |
| 352 | 353 | Ok(view! { |
| @@ -361,7 +362,7 @@ async fn users_create(cx: &Cx, Form(form): Form<CreateUserForm>) -> Result<impl | ||
| 361 | 362 | return Err(forbidden().into()); |
| 362 | 363 | } |
| 363 | 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 | 367 | // Ok(Ok(user)) created; Ok(Err(message)) rejected with a user-facing message. |
| 367 | 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 | 489 | #[component] |
| 489 | 490 | async fn delete_body( |
| 491 | + cx: &Cx, | |
| 490 | 492 | lang: Lang, |
| 491 | 493 | csrf: &str, |
| 492 | 494 | target: User, |
| @@ -555,6 +557,7 @@ async fn delete_body( | ||
| 555 | 557 | /// An organization is not a person: this points at its own settings instead of offering a delete. |
| 556 | 558 | #[component] |
| 557 | 559 | async fn org_delete_note( |
| 560 | + cx: &Cx, | |
| 558 | 561 | lang: Lang, |
| 559 | 562 | target: User, |
| 560 | 563 | repos: Vec<String>, |
| @@ -593,7 +596,7 @@ async fn org_delete_note( | ||
| 593 | 596 | async fn user_delete_page(cx: &Cx) -> Result<impl View> { |
| 594 | 597 | let viewer = admin_only(cx).await?; |
| 595 | 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 | 600 | let target_id = path_param_segment(cx, "user_id").to_owned(); |
| 598 | 601 | let Some(target) = store.user_by_id(&target_id).await? else { |
| 599 | 602 | return Err(not_found().into()); |
| @@ -632,7 +635,7 @@ async fn user_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<impl View> | ||
| 632 | 635 | return Err(forbidden().into()); |
| 633 | 636 | } |
| 634 | 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 | 639 | let target_id = path_param_segment(cx, "user_id").to_owned(); |
| 637 | 640 | let Some(target) = store.user_by_id(&target_id).await? else { |
| 638 | 641 | return Err(not_found().into()); |
| @@ -654,7 +657,7 @@ async fn user_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<impl View> | ||
| 654 | 657 | match store.delete_user(&target.id, &ghost.id).await { |
| 655 | 658 | Ok(_) => { |
| 656 | 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 | 661 | audit::record( |
| 659 | 662 | store, |
| 660 | 663 | Some(cx), |
crates/forge-web/src/pages/archive.rsmodified+5 -5
| @@ -17,7 +17,7 @@ use tokio::process::Child; | ||
| 17 | 17 | use tokio::sync::{OwnedSemaphorePermit, Semaphore}; |
| 18 | 18 | use tokio_util::io::ReaderStream; |
| 19 | 19 | use topcoat::Result; |
| 20 | -use topcoat::context::{Cx, app_context}; | |
| 20 | +use topcoat::context::{Cx, context}; | |
| 21 | 21 | use topcoat::router::error::not_found; |
| 22 | 22 | use topcoat::router::response::Response; |
| 23 | 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 | 74 | #[route(GET "/{owner}/{repo}/archive/{*rest}")] |
| 75 | 75 | async fn archive(cx: &Cx) -> Result<Response> { |
| 76 | - let owner = path_param::<Owner>(cx); | |
| 77 | - let name = path_param::<Repo>(cx); | |
| 78 | - let rest = path_param::<Rest>(cx).collect::<Vec<_>>().join("/"); | |
| 76 | + let owner = owner(cx); | |
| 77 | + let name = repo(cx); | |
| 78 | + let rest = rest(cx).collect::<Vec<_>>().join("/"); | |
| 79 | 79 | let Some((reference, format)) = split_format(&rest) else { |
| 80 | 80 | return Err(not_found().into()); |
| 81 | 81 | }; |
| 82 | 82 | |
| 83 | 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 | 86 | let repo_dir = ctx.path.clone(); |
| 87 | 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 | 134 | const OFFLINE_JS: &str = include_str!("../../assets/offline.js"); |
| 135 | 135 | |
| 136 | 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 | 138 | let mut headers = HeaderMap::new(); |
| 139 | 139 | headers.insert( |
| 140 | 140 | header::CONTENT_TYPE, |
| @@ -150,7 +150,7 @@ async fn offline_html() -> Result<(StatusCode, HeaderMap, &'static str)> { | ||
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 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 | 154 | let mut headers = HeaderMap::new(); |
| 155 | 155 | headers.insert( |
| 156 | 156 | header::CONTENT_TYPE, |
| @@ -216,42 +216,42 @@ const FONT_CACHE: &str = "public, max-age=31536000, immutable"; | ||
| 216 | 216 | const LICENSE_CACHE: &str = "public, max-age=86400"; |
| 217 | 217 | |
| 218 | 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 | 220 | Ok(bytes_response(FIGTREE_LATIN, "font/woff2", FONT_CACHE)) |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 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 | 225 | Ok(bytes_response(FIGTREE_LATIN_EXT, "font/woff2", FONT_CACHE)) |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 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 | 230 | Ok(bytes_response(ARCHIVO_LATIN, "font/woff2", FONT_CACHE)) |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 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 | 235 | Ok(bytes_response(ARCHIVO_LATIN_EXT, "font/woff2", FONT_CACHE)) |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 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 | 240 | Ok(bytes_response(PLEX_MONO_400, "font/woff2", FONT_CACHE)) |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 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 | 245 | Ok(bytes_response(PLEX_MONO_500, "font/woff2", FONT_CACHE)) |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 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 | 250 | Ok(bytes_response(PLEX_MONO_600, "font/woff2", FONT_CACHE)) |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 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 | 255 | Ok(bytes_response( |
| 256 | 256 | PLEX_MONO_400_ITALIC, |
| 257 | 257 | "font/woff2", |
| @@ -260,7 +260,7 @@ async fn plex_mono_400_italic() -> Result<Bytes> { | ||
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 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 | 264 | Ok(bytes_response( |
| 265 | 265 | FIGTREE_LICENSE, |
| 266 | 266 | "text/plain; charset=utf-8", |
| @@ -269,7 +269,7 @@ async fn figtree_license() -> Result<Bytes> { | ||
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 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 | 273 | Ok(bytes_response( |
| 274 | 274 | ARCHIVO_LICENSE, |
| 275 | 275 | "text/plain; charset=utf-8", |
| @@ -278,7 +278,7 @@ async fn archivo_license() -> Result<Bytes> { | ||
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 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 | 282 | Ok(bytes_response( |
| 283 | 283 | PLEX_MONO_LICENSE, |
| 284 | 284 | "text/plain; charset=utf-8", |
| @@ -288,13 +288,16 @@ async fn plex_mono_license() -> Result<Bytes> { | ||
| 288 | 288 | |
| 289 | 289 | #[cfg(test)] |
| 290 | 290 | mod tests { |
| 291 | - use topcoat::cookie::RouterBuilderCookieExt; | |
| 291 | + use topcoat::cookie::CookieLayer; | |
| 292 | 292 | use topcoat::router::request::Request; |
| 293 | 293 | use topcoat::router::{Body, Router, RouterBuilderDiscoverExt, to_bytes}; |
| 294 | 294 | |
| 295 | 295 | #[tokio::test] |
| 296 | 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 | 301 | // Bundled fonts are immutable woff2 files. |
| 299 | 302 | for uri in [ |
| 300 | 303 | "/assets/fonts/figtree-5.3.0-latin-wght.woff2", |
| @@ -347,7 +350,10 @@ mod tests { | ||
| 347 | 350 | |
| 348 | 351 | #[tokio::test] |
| 349 | 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 | 357 | let req = Request::builder() |
| 352 | 358 | .method("GET") |
| 353 | 359 | .uri(crate::views::STYLESHEET_HREF) |
| @@ -373,7 +379,10 @@ mod tests { | ||
| 373 | 379 | |
| 374 | 380 | #[tokio::test] |
| 375 | 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 | 386 | // Each bundle is immutable under its own type. Its body holds the marker, when one is given. |
| 378 | 387 | for (uri, kind, marker) in [ |
| 379 | 388 | (crate::views::STYLESHEET_HREF, "text/css; charset=utf-8", ""), |
| @@ -422,7 +431,10 @@ mod tests { | ||
| 422 | 431 | #[tokio::test] |
| 423 | 432 | async fn alive_stream_sends_retry_first() { |
| 424 | 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 | 438 | let req = Request::builder() |
| 427 | 439 | .method("GET") |
| 428 | 440 | .uri("/-/alive") |
| @@ -447,7 +459,10 @@ mod tests { | ||
| 447 | 459 | |
| 448 | 460 | #[tokio::test] |
| 449 | 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 | 466 | for (uri, kind) in [ |
| 452 | 467 | ("/assets/offline.html", "text/html"), |
| 453 | 468 | ("/assets/offline.js", "text/javascript"), |
| @@ -471,7 +486,10 @@ mod tests { | ||
| 471 | 486 | |
| 472 | 487 | #[tokio::test] |
| 473 | 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 | 493 | let req = Request::builder() |
| 476 | 494 | .method("GET") |
| 477 | 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 | 8 | use forge_core::{AuditAction, AuditEntry, AuditFilter, Store}; |
| 9 | 9 | use topcoat::Result; |
| 10 | -use topcoat::context::{Cx, app_context}; | |
| 10 | +use topcoat::context::{Cx, context}; | |
| 11 | 11 | use topcoat::router::response::Response; |
| 12 | 12 | use topcoat::router::{page, query_params, route}; |
| 13 | 13 | use topcoat::view::{View, component, view}; |
| @@ -84,7 +84,11 @@ impl Span { | ||
| 84 | 84 | fn from_query(query: &AuditQuery) -> Span { |
| 85 | 85 | let clean = |v: &Option<String>| v.clone().unwrap_or_default().trim().to_owned(); |
| 86 | 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 | 92 | let (from, to) = if when == "custom" { |
| 89 | 93 | (clean(&query.from), clean(&query.to)) |
| 90 | 94 | } else { |
| @@ -396,6 +400,7 @@ fn nav_for( | ||
| 396 | 400 | /// The search and the action filter, in one GET form to `action`. |
| 397 | 401 | #[component] |
| 398 | 402 | async fn log_tools( |
| 403 | + cx: &Cx, | |
| 399 | 404 | lang: Lang, |
| 400 | 405 | form_action: &str, |
| 401 | 406 | finder: Finder, |
| @@ -451,6 +456,7 @@ async fn log_tools( | ||
| 451 | 456 | /// The facts of one entry after its name: time, then whatever `show` asks for. |
| 452 | 457 | #[component] |
| 453 | 458 | async fn entry_facts( |
| 459 | + cx: &Cx, | |
| 454 | 460 | lang: Lang, |
| 455 | 461 | row: RowView, |
| 456 | 462 | show_actor: bool, |
| @@ -477,7 +483,12 @@ async fn entry_facts( | ||
| 477 | 483 | } |
| 478 | 484 | |
| 479 | 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 | 492 | Ok(view! { |
| 482 | 493 | if groups.is_empty() { |
| 483 | 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 | 507 | /// One entry on its own line. |
| 497 | 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 | 510 | let row = group.rows.remove(0); |
| 500 | 511 | let name = row.name.clone(); |
| 501 | 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 | 521 | /// A run of entries: one row with the count and what they share, which opens to list each one |
| 511 | 522 | /// with what differs. |
| 512 | 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 | 525 | let count = group.rows.len().to_string(); |
| 515 | 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 | 531 | let details = group |
| 518 | 532 | .shared_details() |
| 519 | 533 | .map(str::to_owned) |
| @@ -568,6 +582,7 @@ async fn group_row(lang: Lang, mut group: Group, show_actor: bool) -> Result<imp | ||
| 568 | 582 | /// One entry inside an opened run: its time and what the run's row does not already say. |
| 569 | 583 | #[component] |
| 570 | 584 | async fn item_line( |
| 585 | + cx: &Cx, | |
| 571 | 586 | lang: Lang, |
| 572 | 587 | row: RowView, |
| 573 | 588 | show_target: bool, |
| @@ -583,6 +598,7 @@ async fn item_line( | ||
| 583 | 598 | |
| 584 | 599 | #[component] |
| 585 | 600 | async fn admin_audit_view( |
| 601 | + cx: &Cx, | |
| 586 | 602 | lang: Lang, |
| 587 | 603 | live: String, |
| 588 | 604 | finder: Finder, |
| @@ -612,6 +628,7 @@ async fn admin_audit_view( | ||
| 612 | 628 | |
| 613 | 629 | #[component] |
| 614 | 630 | async fn own_log_view( |
| 631 | + cx: &Cx, | |
| 615 | 632 | lang: Lang, |
| 616 | 633 | items: Vec<RailItem>, |
| 617 | 634 | finder: Finder, |
| @@ -662,7 +679,7 @@ async fn admin_audit_page(cx: &Cx) -> Result<impl View> { | ||
| 662 | 679 | let viewer = admin_only(cx).await?; |
| 663 | 680 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 664 | 681 | let query = query_params::<AuditQuery>(cx)?; |
| 665 | - let store = &app_context::<AppState>(cx).store; | |
| 682 | + let store = &context::<AppState>(cx).store; | |
| 666 | 683 | let (finder, action, actor) = query_parts(query); |
| 667 | 684 | let span = Span::from_query(query); |
| 668 | 685 | |
| @@ -734,7 +751,7 @@ async fn admin_audit_events(cx: &Cx) -> Result<Response> { | ||
| 734 | 751 | let query = query_params::<AuditQuery>(cx)?; |
| 735 | 752 | let action = query.action.clone().unwrap_or_default().trim().to_owned(); |
| 736 | 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 | 755 | stream_changes(cx, crate::live::admin(), &[Topic::AdminAudit], move || { |
| 739 | 756 | let store = store.clone(); |
| 740 | 757 | let action = action.clone(); |
| @@ -749,7 +766,7 @@ async fn own_log_page(cx: &Cx) -> Result<impl View> { | ||
| 749 | 766 | let viewer = require_user(cx).await?; |
| 750 | 767 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 751 | 768 | let query = query_params::<AuditQuery>(cx)?; |
| 752 | - let store = &app_context::<AppState>(cx).store; | |
| 769 | + let store = &context::<AppState>(cx).store; | |
| 753 | 770 | let (finder, action, _) = query_parts(query); |
| 754 | 771 | let span = Span::from_query(query); |
| 755 | 772 | let mut filter = AuditFilter { |
| @@ -768,7 +785,7 @@ async fn own_log_page(cx: &Cx) -> Result<impl View> { | ||
| 768 | 785 | let mut params = keep_params(&finder, &action, ""); |
| 769 | 786 | params.extend(span.params()); |
| 770 | 787 | let nav = nav_for(page, pages, "/settings/security/log", ¶ms); |
| 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 | 789 | let title = g::t(lang, K::SecurityLogTitle); |
| 773 | 790 | Ok(view! { |
| 774 | 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 | 16 | use serde::Deserialize; |
| 17 | 17 | use serde_json::json; |
| 18 | 18 | use topcoat::Result; |
| 19 | -use topcoat::context::{Cx, app_context}; | |
| 19 | +use topcoat::context::{Cx, context}; | |
| 20 | 20 | use topcoat::router::content::Form; |
| 21 | 21 | use topcoat::router::error::{bad_request, forbidden, not_found}; |
| 22 | 22 | use topcoat::router::request::{headers, uri}; |
| @@ -121,8 +121,8 @@ fn fail(status: StatusCode, message: &str) -> Response { | ||
| 121 | 121 | /// comment can attach), and the repo must not be archived. |
| 122 | 122 | #[route(POST "/{owner}/{repo}/attachments")] |
| 123 | 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?; | |
| 125 | - let state = app_context::<AppState>(cx); | |
| 124 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 125 | + let state = context::<AppState>(cx); | |
| 126 | 126 | if ctx.repo.archived { |
| 127 | 127 | return Err(forbidden().into()); |
| 128 | 128 | } |
| @@ -228,11 +228,11 @@ async fn upload(cx: &Cx, body: Body) -> Result<Response> { | ||
| 228 | 228 | /// Serves an attachment to anyone who can read its repo; everyone else gets 404. |
| 229 | 229 | #[route(GET "/attachments/{id}/{name}")] |
| 230 | 230 | async fn download(cx: &Cx) -> Result<Response> { |
| 231 | - let state = app_context::<AppState>(cx); | |
| 232 | - let Some(att) = state.store.attachment(path_param::<Id>(cx)).await? else { | |
| 231 | + let state = context::<AppState>(cx); | |
| 232 | + let Some(att) = state.store.attachment(id(cx)).await? else { | |
| 233 | 233 | return Err(not_found().into()); |
| 234 | 234 | }; |
| 235 | - if att.name != path_param::<Name>(cx) { | |
| 235 | + if att.name != name(cx) { | |
| 236 | 236 | return Err(not_found().into()); |
| 237 | 237 | } |
| 238 | 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 | 289 | /// `kind=issue` lists issues and pull requests by number or title. |
| 290 | 290 | #[route(GET "/{owner}/{repo}/suggest")] |
| 291 | 291 | async fn suggest(cx: &Cx) -> Result<Response> { |
| 292 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 293 | - let state = app_context::<AppState>(cx); | |
| 292 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 293 | + let state = context::<AppState>(cx); | |
| 294 | 294 | if ctx.viewer.is_none() { |
| 295 | 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 | 366 | async fn toggle(cx: &Cx, kind: ItemKind, form: TaskForm) -> Result<Response> { |
| 367 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 368 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 367 | + let number = parse_number(number(cx))?; | |
| 368 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 369 | 369 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 370 | - let state = app_context::<AppState>(cx); | |
| 370 | + let state = context::<AppState>(cx); | |
| 371 | 371 | let item = item_for(state, &ctx, kind, number).await?; |
| 372 | 372 | let Ok(index) = form.index.parse::<usize>() else { |
| 373 | 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 | 9 | use sha2::{Digest, Sha256}; |
| 10 | 10 | use topcoat::Result; |
| 11 | -use topcoat::context::{Cx, app_context}; | |
| 11 | +use topcoat::context::{Cx, context}; | |
| 12 | 12 | use topcoat::router::request::headers; |
| 13 | 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 | 96 | .get(IF_NONE_MATCH) |
| 97 | 97 | .and_then(|v| v.to_str().ok()) |
| 98 | 98 | .map(str::to_owned); |
| 99 | - let store = &app_context::<AppState>(cx).store; | |
| 99 | + let store = &context::<AppState>(cx).store; | |
| 100 | 100 | |
| 101 | 101 | let Some(user) = store.user_by_username(&name).await? else { |
| 102 | 102 | return Ok(( |
| @@ -155,7 +155,10 @@ mod tests { | ||
| 155 | 155 | assert_eq!(svg, super::default_svg("<")); |
| 156 | 156 | let url = super::default_data_url("<"); |
| 157 | 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 | 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 | 11 | use forge_core::token::hash_token; |
| 12 | 12 | use serde::Deserialize; |
| 13 | 13 | use topcoat::Result; |
| 14 | -use topcoat::context::{Cx, app_context, try_app_context}; | |
| 14 | +use topcoat::context::{Cx, context, try_context}; | |
| 15 | 15 | use topcoat::cookie::{Cookie, Cookies, SameSite, cookies, time}; |
| 16 | 16 | use topcoat::router::content::Form; |
| 17 | 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 | 66 | /// The banner for this request, read from the live settings. `prefs` is a signed-in viewer's |
| 67 | 67 | /// account preferences; without them the dismissal comes from the cookie. |
| 68 | 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 | 70 | let live = state.live(); |
| 71 | 71 | if live.banner.message.trim().is_empty() { |
| 72 | 72 | return None; |
| @@ -90,7 +90,7 @@ struct DismissForm { | ||
| 90 | 90 | async fn dismiss(cx: &Cx, Form(form): Form<DismissForm>) -> Result<SeeOther> { |
| 91 | 91 | let hash_ok = form.hash.len() == 16 && form.hash.bytes().all(|b| b.is_ascii_hexdigit()); |
| 92 | 92 | if hash_ok && let Some((user, _)) = current_user(cx).await? { |
| 93 | - app_context::<AppState>(cx) | |
| 93 | + context::<AppState>(cx) | |
| 94 | 94 | .store |
| 95 | 95 | .set_user_pref(&user.id, BANNER_PREF, &form.hash) |
| 96 | 96 | .await?; |
crates/forge-web/src/pages/blame.rsmodified+11 -8
| @@ -7,7 +7,7 @@ use std::time::Duration; | ||
| 7 | 7 | use forge_git::blame::{Blame, blame}; |
| 8 | 8 | use forge_git::browse::EntryKind; |
| 9 | 9 | use topcoat::Result; |
| 10 | -use topcoat::context::{Cx, app_context}; | |
| 10 | +use topcoat::context::{Cx, context}; | |
| 11 | 11 | use topcoat::router::error::not_found; |
| 12 | 12 | use topcoat::router::{page, path_param}; |
| 13 | 13 | use topcoat::view::{Unescaped, View, component, view}; |
| @@ -16,10 +16,10 @@ use crate::i18n::browse as b; | ||
| 16 | 16 | use crate::i18n::code::{self as g, K}; |
| 17 | 17 | use crate::i18n::{self, Lang}; |
| 18 | 18 | use crate::pages::blob::{Line, text_lines}; |
| 19 | +use crate::pages::passkeys::s; | |
| 19 | 20 | use crate::pages::ref_live; |
| 20 | 21 | use crate::pages::repo::repo_head; |
| 21 | 22 | use crate::pages::repo_ctx::load_repo; |
| 22 | -use crate::pages::passkeys::s; | |
| 23 | 23 | use crate::pages::tree::{MAX_BLOB_BYTES, read_file, resolve}; |
| 24 | 24 | use crate::render::emoji::emojify; |
| 25 | 25 | use crate::state::AppState; |
| @@ -103,7 +103,7 @@ fn build_rows( | ||
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 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 | 107 | Ok(view! { |
| 108 | 108 | <div class="file-view"> |
| 109 | 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 | 142 | #[page("/{owner}/{repo}/blame/{*rest}")] |
| 143 | 143 | async fn blame_page(cx: &Cx) -> Result<impl View> { |
| 144 | - let owner = path_param::<Owner>(cx); | |
| 145 | - let name = path_param::<Repo>(cx); | |
| 146 | - let rest = path_param::<Rest>(cx).collect::<Vec<_>>().join("/"); | |
| 144 | + let owner = owner(cx); | |
| 145 | + let name = repo(cx); | |
| 146 | + let rest = rest(cx).collect::<Vec<_>>().join("/"); | |
| 147 | 147 | |
| 148 | 148 | let ctx = load_repo(cx, owner, name).await?; |
| 149 | - let state = app_context::<AppState>(cx); | |
| 149 | + let state = context::<AppState>(cx); | |
| 150 | 150 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user)); |
| 151 | 151 | let repo = &ctx.repo; |
| 152 | 152 | |
| @@ -199,7 +199,10 @@ async fn blame_page(cx: &Cx) -> Result<impl View> { | ||
| 199 | 199 | ); |
| 200 | 200 | // Blame sits beside the file's source: a markdown file's plain view, any other file's own page. |
| 201 | 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 | 206 | Some("md" | "markdown") |
| 204 | 207 | ); |
| 205 | 208 | let source_href = if markdown { |
crates/forge-web/src/pages/blob.rsmodified+11 -7
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | |
| 5 | 5 | use forge_git::browse::EntryKind; |
| 6 | 6 | use topcoat::Result; |
| 7 | -use topcoat::context::{Cx, app_context}; | |
| 7 | +use topcoat::context::{Cx, context}; | |
| 8 | 8 | use topcoat::router::error::not_found; |
| 9 | 9 | use topcoat::router::{page, path_param, query_params}; |
| 10 | 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 | 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 | 95 | Ok(view! { |
| 96 | 96 | <div class="file-view"> |
| 97 | 97 | <table class="file-table"> |
| @@ -116,13 +116,13 @@ async fn file_table(lines: Vec<Line>) -> Result<impl View> { | ||
| 116 | 116 | |
| 117 | 117 | #[page("/{owner}/{repo}/blob/{*rest}")] |
| 118 | 118 | async fn blob_page(cx: &Cx) -> Result<impl View> { |
| 119 | - let owner = path_param::<Owner>(cx); | |
| 120 | - let name = path_param::<Repo>(cx); | |
| 121 | - let rest = path_param::<Rest>(cx).collect::<Vec<_>>().join("/"); | |
| 119 | + let owner = owner(cx); | |
| 120 | + let name = repo(cx); | |
| 121 | + let rest = rest(cx).collect::<Vec<_>>().join("/"); | |
| 122 | 122 | let plain = query_params::<BlobQuery>(cx)?.plain.as_deref() == Some("1"); |
| 123 | 123 | |
| 124 | 124 | let ctx = load_repo(cx, owner, name).await?; |
| 125 | - let state = app_context::<AppState>(cx); | |
| 125 | + let state = context::<AppState>(cx); | |
| 126 | 126 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user)); |
| 127 | 127 | let repo = &ctx.repo; |
| 128 | 128 | |
| @@ -262,7 +262,11 @@ async fn blob_page(cx: &Cx) -> Result<impl View> { | ||
| 262 | 262 | let mut views: Vec<(&'static str, String, bool)> = Vec::new(); |
| 263 | 263 | if is_markdown { |
| 264 | 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 | 270 | } else if is_text { |
| 267 | 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 | 9 | use forge_git::browse::{self, RefKind}; |
| 10 | 10 | use serde::Deserialize; |
| 11 | 11 | use topcoat::Result; |
| 12 | -use topcoat::context::{Cx, app_context}; | |
| 12 | +use topcoat::context::{Cx, context}; | |
| 13 | 13 | use topcoat::cookie::{Cookie, Cookies, SameSite, cookies}; |
| 14 | 14 | use topcoat::router::content::Form; |
| 15 | 15 | use topcoat::router::error::{SeeOther, forbidden, see_other}; |
| @@ -102,6 +102,7 @@ struct BranchRow { | ||
| 102 | 102 | |
| 103 | 103 | #[component] |
| 104 | 104 | async fn new_branch_form( |
| 105 | + cx: &Cx, | |
| 105 | 106 | lang: Lang, |
| 106 | 107 | action: String, |
| 107 | 108 | csrf: String, |
| @@ -134,6 +135,7 @@ async fn new_branch_form( | ||
| 134 | 135 | |
| 135 | 136 | #[component] |
| 136 | 137 | async fn branch_table( |
| 138 | + cx: &Cx, | |
| 137 | 139 | rows: Vec<BranchRow>, |
| 138 | 140 | lang: Lang, |
| 139 | 141 | csrf: String, |
| @@ -175,10 +177,10 @@ async fn branch_table( | ||
| 175 | 177 | |
| 176 | 178 | #[page("/{owner}/{repo}/branches")] |
| 177 | 179 | async fn branches_page(cx: &Cx) -> Result<impl View> { |
| 178 | - let owner = path_param::<Owner>(cx); | |
| 179 | - let name = path_param::<Repo>(cx); | |
| 180 | + let owner = owner(cx); | |
| 181 | + let name = repo(cx); | |
| 180 | 182 | let ctx = load_repo(cx, owner, name).await?; |
| 181 | - let state = app_context::<AppState>(cx); | |
| 183 | + let state = context::<AppState>(cx); | |
| 182 | 184 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user)); |
| 183 | 185 | let repo = &ctx.repo; |
| 184 | 186 | let now = now_unix(); |
| @@ -322,14 +324,14 @@ fn back(cx: &Cx, ctx: &RepoCtx, word: &'static str) -> SeeOther { | ||
| 322 | 324 | /// A protection rule that only accepts pull requests keeps the name closed to direct creation. |
| 323 | 325 | #[route(POST "/{owner}/{repo}/branches")] |
| 324 | 326 | async fn branch_create(cx: &Cx, Form(form): Form<CreateForm>) -> Result<SeeOther> { |
| 325 | - let owner = path_param::<Owner>(cx); | |
| 326 | - let name = path_param::<Repo>(cx); | |
| 327 | + let owner = owner(cx); | |
| 328 | + let name = repo(cx); | |
| 327 | 329 | let ctx = load_repo(cx, owner, name).await?; |
| 328 | 330 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 329 | 331 | if !ctx.can_write() { |
| 330 | 332 | return Err(forbidden().into()); |
| 331 | 333 | } |
| 332 | - let state = app_context::<AppState>(cx); | |
| 334 | + let state = context::<AppState>(cx); | |
| 333 | 335 | let branch = form.name.trim().to_owned(); |
| 334 | 336 | let from = match form.from.trim() { |
| 335 | 337 | "" => ctx.repo.default_branch.clone(), |
| @@ -382,14 +384,14 @@ async fn branch_create(cx: &Cx, Form(form): Form<CreateForm>) -> Result<SeeOther | ||
| 382 | 384 | /// branches whose protection forbids deletion are refused. |
| 383 | 385 | #[route(POST "/{owner}/{repo}/branches/delete")] |
| 384 | 386 | async fn branch_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther> { |
| 385 | - let owner = path_param::<Owner>(cx); | |
| 386 | - let name = path_param::<Repo>(cx); | |
| 387 | + let owner = owner(cx); | |
| 388 | + let name = repo(cx); | |
| 387 | 389 | let ctx = load_repo(cx, owner, name).await?; |
| 388 | 390 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 389 | 391 | if !ctx.can_write() { |
| 390 | 392 | return Err(forbidden().into()); |
| 391 | 393 | } |
| 392 | - let state = app_context::<AppState>(cx); | |
| 394 | + let state = context::<AppState>(cx); | |
| 393 | 395 | let branch = form.name.trim().to_owned(); |
| 394 | 396 | if branch == ctx.repo.default_branch { |
| 395 | 397 | return Ok(back(cx, &ctx, "default")); |
crates/forge-web/src/pages/ci_badge.rsmodified+4 -4
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | use forge_core::ci::{JobState, RunState}; |
| 12 | 12 | use http::header::{CACHE_CONTROL, CONTENT_TYPE}; |
| 13 | 13 | use topcoat::Result; |
| 14 | -use topcoat::context::{Cx, app_context}; | |
| 14 | +use topcoat::context::{Cx, context}; | |
| 15 | 15 | use topcoat::router::request::uri; |
| 16 | 16 | use topcoat::router::response::Response; |
| 17 | 17 | use topcoat::router::{Body, HeaderValue, StatusCode, path_param, route}; |
| @@ -205,10 +205,10 @@ fn badge_query(cx: &Cx) -> BadgeQuery { | ||
| 205 | 205 | /// uses, so a private repo the viewer cannot read is a 404. |
| 206 | 206 | #[route(GET "/{owner}/{repo}/badge.svg")] |
| 207 | 207 | async fn ci_badge(cx: &Cx) -> Result<Response> { |
| 208 | - let owner = path_param::<Owner>(cx); | |
| 209 | - let name = path_param::<Repo>(cx); | |
| 208 | + let owner = owner(cx); | |
| 209 | + let name = repo(cx); | |
| 210 | 210 | let ctx = load_repo(cx, owner, name).await?; |
| 211 | - let state = app_context::<AppState>(cx); | |
| 211 | + let state = context::<AppState>(cx); | |
| 212 | 212 | let query = badge_query(cx); |
| 213 | 213 | let branch = query |
| 214 | 214 | .branch |
crates/forge-web/src/pages/ci_fail.rsmodified+15 -8
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | //! not stored, so the failed job is the unit. The log is untrusted: its lines are rendered as text. |
| 4 | 4 | |
| 5 | 5 | use topcoat::Result; |
| 6 | +use topcoat::context::Cx; | |
| 6 | 7 | use topcoat::view::{View, component, view}; |
| 7 | 8 | |
| 8 | 9 | use crate::ci::log_path; |
| @@ -59,14 +60,20 @@ impl FailFirst { | ||
| 59 | 60 | /// The `file:line` in a compiler's or test's lines around an error: the first word that ends in |
| 60 | 61 | /// digits after a colon and holds a dot. |
| 61 | 62 | fn place_in(lines: &[String]) -> Option<String> { |
| 62 | - lines.iter().flat_map(|line| line.split_whitespace()).find_map(|word| { | |
| 63 | - let word = word.trim_matches(|c: char| matches!(c, '(' | ')' | ',')); | |
| 64 | - let mut parts = word.split(':'); | |
| 65 | - let file = parts.next()?; | |
| 66 | - let line = parts.next()?; | |
| 67 | - (file.contains('.') && !file.contains("::") && !line.is_empty() && line.bytes().all(|b| b.is_ascii_digit())) | |
| 63 | + lines | |
| 64 | + .iter() | |
| 65 | + .flat_map(|line| line.split_whitespace()) | |
| 66 | + .find_map(|word| { | |
| 67 | + let word = word.trim_matches(|c: char| matches!(c, '(' | ')' | ',')); | |
| 68 | + let mut parts = word.split(':'); | |
| 69 | + let file = parts.next()?; | |
| 70 | + let line = parts.next()?; | |
| 71 | + (file.contains('.') | |
| 72 | + && !file.contains("::") | |
| 73 | + && !line.is_empty() | |
| 74 | + && line.bytes().all(|b| b.is_ascii_digit())) | |
| 68 | 75 | .then(|| format!("{}:{line}", file.rsplit('/').next().unwrap_or(file))) |
| 69 | - }) | |
| 76 | + }) | |
| 70 | 77 | } |
| 71 | 78 | |
| 72 | 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 | 115 | /// The failure row, pinned above the log, which opens at the first error line: why it failed, the |
| 109 | 116 | /// place in the code, and a link to that line in the job's log. |
| 110 | 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 | 119 | let line_href = fail.line_no.map(|no| format!("{}#L{no}", fail.job_href)); |
| 113 | 120 | let why = if fail.message.is_empty() { |
| 114 | 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 | 21 | use tokio::io::{AsyncReadExt, AsyncSeekExt, SeekFrom}; |
| 22 | 22 | use tokio::sync::watch; |
| 23 | 23 | use topcoat::Result; |
| 24 | -use topcoat::context::{Cx, app_context}; | |
| 24 | +use topcoat::context::{Cx, context}; | |
| 25 | 25 | use topcoat::router::content::sse::{Event, last_event_id}; |
| 26 | 26 | use topcoat::router::error::not_found; |
| 27 | 27 | use topcoat::router::request::uri; |
| @@ -419,6 +419,7 @@ async fn job_fingerprint_now(store: &Store, job_id: &str) -> Result<Option<Strin | ||
| 419 | 419 | /// follows its artifacts and log too. The log tail carries the offset its text ends at. |
| 420 | 420 | #[component] |
| 421 | 421 | async fn job_body( |
| 422 | + cx: &Cx, | |
| 422 | 423 | head: RepoHead, |
| 423 | 424 | lang: Lang, |
| 424 | 425 | job: JobView, |
| @@ -521,12 +522,12 @@ async fn job_body( | ||
| 521 | 522 | /// One job: its state, the last 512 KiB of its log and its artifacts. |
| 522 | 523 | #[page("/{owner}/{repo}/ci/jobs/{job_id}")] |
| 523 | 524 | async fn job_page(cx: &Cx) -> Result<impl View> { |
| 524 | - let owner = path_param::<Owner>(cx); | |
| 525 | - let name = path_param::<Repo>(cx); | |
| 526 | - let id = path_param::<JobId>(cx).to_owned(); | |
| 525 | + let owner = owner(cx); | |
| 526 | + let name = repo(cx); | |
| 527 | + let id = job_id(cx).to_owned(); | |
| 527 | 528 | let ctx = load_repo(cx, owner, name).await?; |
| 528 | 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 | 531 | let (job, run) = job_of(state, &ctx, &id).await?; |
| 531 | 532 | let Tail { |
| 532 | 533 | text: log, |
| @@ -633,11 +634,11 @@ const LOG_EVENT_BYTES: u64 = 64 * 1024; | ||
| 633 | 634 | /// this job (see `CiLive`), so a finished page still hears about deleted artifacts or logs. |
| 634 | 635 | #[route(GET "/{owner}/{repo}/ci/jobs/{job_id}/events")] |
| 635 | 636 | async fn job_events(cx: &Cx) -> Result<Response> { |
| 636 | - let owner = path_param::<Owner>(cx); | |
| 637 | - let name = path_param::<Repo>(cx); | |
| 638 | - let id = path_param::<JobId>(cx).to_owned(); | |
| 637 | + let owner = owner(cx); | |
| 638 | + let name = repo(cx); | |
| 639 | + let id = job_id(cx).to_owned(); | |
| 639 | 640 | let ctx = load_repo(cx, owner, name).await?; |
| 640 | - let state = app_context::<AppState>(cx); | |
| 641 | + let state = context::<AppState>(cx); | |
| 641 | 642 | let (job, _) = job_of(state, &ctx, &id).await?; |
| 642 | 643 | let offset = last_event_id(cx) |
| 643 | 644 | .and_then(|id| id.parse::<u64>().ok()) |
| @@ -797,11 +798,11 @@ async fn read_log( | ||
| 797 | 798 | /// is terminal. |
| 798 | 799 | #[route(GET "/{owner}/{repo}/ci/jobs/{job_id}/log.txt")] |
| 799 | 800 | async fn job_log(cx: &Cx) -> Result<Response> { |
| 800 | - let owner = path_param::<Owner>(cx); | |
| 801 | - let name = path_param::<Repo>(cx); | |
| 802 | - let id = path_param::<JobId>(cx).to_owned(); | |
| 801 | + let owner = owner(cx); | |
| 802 | + let name = repo(cx); | |
| 803 | + let id = job_id(cx).to_owned(); | |
| 803 | 804 | let ctx = load_repo(cx, owner, name).await?; |
| 804 | - let state = app_context::<AppState>(cx); | |
| 805 | + let state = context::<AppState>(cx); | |
| 805 | 806 | let (job, _) = job_of(state, &ctx, &id).await?; |
| 806 | 807 | let path = log_path(&state.config.data_dir, &job.id); |
| 807 | 808 | let chunks = follow_log( |
| @@ -834,12 +835,12 @@ async fn job_log(cx: &Cx) -> Result<Response> { | ||
| 834 | 835 | /// Downloads an artifact of a job as an attachment. |
| 835 | 836 | #[route(GET "/{owner}/{repo}/ci/jobs/{job_id}/artifacts/{artifact_name}")] |
| 836 | 837 | async fn artifact_download(cx: &Cx) -> Result<Response> { |
| 837 | - let owner = path_param::<Owner>(cx); | |
| 838 | - let name = path_param::<Repo>(cx); | |
| 839 | - let id = path_param::<JobId>(cx).to_owned(); | |
| 840 | - let file_name = path_param::<ArtifactName>(cx).to_owned(); | |
| 838 | + let owner = owner(cx); | |
| 839 | + let name = repo(cx); | |
| 840 | + let id = job_id(cx).to_owned(); | |
| 841 | + let file_name = artifact_name(cx).to_owned(); | |
| 841 | 842 | let ctx = load_repo(cx, owner, name).await?; |
| 842 | - let state = app_context::<AppState>(cx); | |
| 843 | + let state = context::<AppState>(cx); | |
| 843 | 844 | let (job, _) = job_of(state, &ctx, &id).await?; |
| 844 | 845 | let Some(artifact) = state.store.artifact(&job.id, &file_name).await? else { |
| 845 | 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 | 23 | use tokio::io::{AsyncReadExt, AsyncSeekExt, SeekFrom}; |
| 24 | 24 | use tokio::sync::watch; |
| 25 | 25 | use topcoat::Result; |
| 26 | -use topcoat::context::{Cx, app_context}; | |
| 26 | +use topcoat::context::{Cx, context}; | |
| 27 | 27 | use topcoat::router::content::Form; |
| 28 | 28 | use topcoat::router::content::sse::{Event, KeepAlive, Sse}; |
| 29 | 29 | use topcoat::router::error::{SeeOther, forbidden, not_found, see_other}; |
| @@ -1408,7 +1408,10 @@ fn job_steps( | ||
| 1408 | 1408 | }) |
| 1409 | 1409 | }) |
| 1410 | 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 | 1415 | for (step, elapsed) in steps.iter().zip(elapsed_of) { |
| 1413 | 1416 | let state = step.state(job.state); |
| 1414 | 1417 | let running = state == StepState::Running; |
| @@ -1593,6 +1596,7 @@ async fn usernames( | ||
| 1593 | 1596 | /// A small form that POSTs the CSRF token to `action`, with one button. |
| 1594 | 1597 | #[component] |
| 1595 | 1598 | async fn action_button( |
| 1599 | + cx: &Cx, | |
| 1596 | 1600 | action: String, |
| 1597 | 1601 | csrf: String, |
| 1598 | 1602 | label: &'static str, |
| @@ -1628,11 +1632,11 @@ async fn runs_split( | ||
| 1628 | 1632 | job: Option<&str>, |
| 1629 | 1633 | step: Option<i64>, |
| 1630 | 1634 | ) -> Result<SplitPage> { |
| 1631 | - let owner = path_param::<Owner>(cx); | |
| 1632 | - let name = path_param::<Repo>(cx); | |
| 1635 | + let owner = owner(cx); | |
| 1636 | + let name = repo(cx); | |
| 1633 | 1637 | let ctx = load_repo(cx, owner, name).await?; |
| 1634 | 1638 | let lang = i18n::lang(cx, viewer_user(&ctx)); |
| 1635 | - let state = app_context::<AppState>(cx); | |
| 1639 | + let state = context::<AppState>(cx); | |
| 1636 | 1640 | let title = title_of(&ctx); |
| 1637 | 1641 | let base = ci_href(&title); |
| 1638 | 1642 | let page = page_from_query(cx); |
| @@ -1743,7 +1747,9 @@ async fn runs_split( | ||
| 1743 | 1747 | }, |
| 1744 | 1748 | href: row_href(run.number), |
| 1745 | 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 | 1753 | "true" |
| 1748 | 1754 | } else { |
| 1749 | 1755 | "false" |
| @@ -1937,8 +1943,16 @@ async fn run_detail( | ||
| 1937 | 1943 | } else { |
| 1938 | 1944 | None |
| 1939 | 1945 | }; |
| 1940 | - let gantt = (!jobs.is_empty()) | |
| 1941 | - .then(|| gantt(&jobs, origin_of(run, now), run_end(run, now), now, lang, picked)); | |
| 1946 | + let gantt = (!jobs.is_empty()).then(|| { | |
| 1947 | + gantt( | |
| 1948 | + &jobs, | |
| 1949 | + origin_of(run, now), | |
| 1950 | + run_end(run, now), | |
| 1951 | + now, | |
| 1952 | + lang, | |
| 1953 | + picked, | |
| 1954 | + ) | |
| 1955 | + }); | |
| 1942 | 1956 | let writer = header.writer_csrf.is_some(); |
| 1943 | 1957 | let rerunnable = writer && header.reachable; |
| 1944 | 1958 | let mut lines = Vec::with_capacity(jobs.len()); |
| @@ -2099,7 +2113,11 @@ async fn run_detail( | ||
| 2099 | 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 | 2122 | Ok(RunDetail { |
| 2105 | 2123 | number: run.number, |
| @@ -2181,7 +2199,7 @@ fn query_value(cx: &Cx, key: &str) -> Option<String> { | ||
| 2181 | 2199 | |
| 2182 | 2200 | /// The head's one action on the runs list: Run workflow, for a writer. Its form sits in its menu. |
| 2183 | 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 | 2203 | Ok(view! { |
| 2186 | 2204 | if let Some(form) = list.manual.as_ref() { |
| 2187 | 2205 | <details class="menu ci-tool"> |
| @@ -2208,7 +2226,7 @@ async fn ci_menus(lang: Lang, list: &ListView) -> Result<impl View> { | ||
| 2208 | 2226 | /// The runs list: one sheet with its tools row, one line per run (each opens the run's page) and the |
| 2209 | 2227 | /// pager. The live list keeps its classes for the page script. |
| 2210 | 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 | 2230 | let ListView { |
| 2213 | 2231 | badge, |
| 2214 | 2232 | total, |
| @@ -2295,6 +2313,7 @@ async fn runs_sheet(lang: Lang, list: &ListView) -> Result<impl View> { | ||
| 2295 | 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 | 2314 | #[component] |
| 2297 | 2315 | async fn runs_body( |
| 2316 | + cx: &Cx, | |
| 2298 | 2317 | head: RepoHead, |
| 2299 | 2318 | lang: Lang, |
| 2300 | 2319 | notice: Option<(&'static str, bool)>, |
| @@ -2328,7 +2347,7 @@ async fn runs_body( | ||
| 2328 | 2347 | /// line of each job, and its artifacts. The list route draws it on the right, and the run page draws it |
| 2329 | 2348 | /// in its Timeline tab. |
| 2330 | 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 | 2351 | Ok(view! { |
| 2333 | 2352 | if let Some(g) = run.gantt.as_ref() { |
| 2334 | 2353 | <div class="ci-gantt-scroll"> |
| @@ -2426,12 +2445,15 @@ async fn run_timeline(lang: Lang, run: &RunDetail) -> Result<impl View> { | ||
| 2426 | 2445 | /// `all_href` adds the All |
| 2427 | 2446 | /// runs link, which the run page needs; the list page has the runs beside it. |
| 2428 | 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 | 2454 | let cancel_action = format!("{}/cancel", run.action_base); |
| 2431 | - let rerun_failed_shown = run.writer_csrf.is_some() | |
| 2432 | - && run.can_rerun_failed | |
| 2433 | - && !run.can_approve | |
| 2434 | - && !run.can_cancel; | |
| 2455 | + let rerun_failed_shown = | |
| 2456 | + run.writer_csrf.is_some() && run.can_rerun_failed && !run.can_approve && !run.can_cancel; | |
| 2435 | 2457 | Ok(view! { |
| 2436 | 2458 | <section class="head"> |
| 2437 | 2459 | <div class="head-title"> |
| @@ -2493,7 +2515,7 @@ async fn run_head(lang: Lang, run: &RunDetail, all_href: Option<String>) -> Resu | ||
| 2493 | 2515 | /// The jobs of a run with more than one job: one `.job-row` each, its name, its tick and a mini strip |
| 2494 | 2516 | /// of its steps. The selected job's row is marked; its steps are the strip under the head. |
| 2495 | 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 | 2519 | Ok(view! { |
| 2498 | 2520 | if run.jobs.len() > 1 { |
| 2499 | 2521 | <div class="jobs ci-tl-list"> |
| @@ -2532,7 +2554,7 @@ async fn run_jobs(lang: Lang, run: &RunDetail) -> Result<impl View> { | ||
| 2532 | 2554 | /// The steps of the selected job, one `.seg` each: a step's name, its time and its state. A step the |
| 2533 | 2555 | /// URL picks is marked, and a step with its log opens that part of the log. |
| 2534 | 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 | 2558 | let job = run.jobs.iter().find(|job| job.selected); |
| 2537 | 2559 | Ok(view! { |
| 2538 | 2560 | if let Some(job) = job { |
| @@ -2567,7 +2589,7 @@ async fn run_strip(run: &RunDetail) -> Result<impl View> { | ||
| 2567 | 2589 | |
| 2568 | 2590 | /// The run's artifacts: the zip of all of them and one download line each. |
| 2569 | 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 | 2593 | Ok(view! { |
| 2572 | 2594 | if !run.artifacts.is_empty() { |
| 2573 | 2595 | <div class="sec"> |
| @@ -2592,6 +2614,7 @@ async fn run_artifacts(lang: Lang, run: &RunDetail) -> Result<impl View> { | ||
| 2592 | 2614 | /// log on `--bg` (or the config errors and the fail-first block above it). The timeline is the other tab. |
| 2593 | 2615 | #[component] |
| 2594 | 2616 | async fn run_log( |
| 2617 | + cx: &Cx, | |
| 2595 | 2618 | lang: Lang, |
| 2596 | 2619 | run: &RunDetail, |
| 2597 | 2620 | timeline: bool, |
| @@ -2681,6 +2704,7 @@ async fn run_log( | ||
| 2681 | 2704 | /// history. The live region wraps all of it, so the page re-renders when a run or a job changes. |
| 2682 | 2705 | #[component] |
| 2683 | 2706 | async fn run_body( |
| 2707 | + cx: &Cx, | |
| 2684 | 2708 | head: RepoHead, |
| 2685 | 2709 | lang: Lang, |
| 2686 | 2710 | notice: Option<(&'static str, bool)>, |
| @@ -2745,7 +2769,7 @@ async fn runs_list_page(cx: &Cx) -> Result<impl View> { | ||
| 2745 | 2769 | /// A run that is not on the list page is still shown. |
| 2746 | 2770 | #[page("/{owner}/{repo}/ci/runs/{run_number}")] |
| 2747 | 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 | 2773 | let wanted = job_from_query(cx); |
| 2750 | 2774 | let wanted_step = step_from_query(cx); |
| 2751 | 2775 | let SplitPage { |
| @@ -2761,7 +2785,7 @@ async fn run_page(cx: &Cx) -> Result<impl View> { | ||
| 2761 | 2785 | let Some(run) = detail else { |
| 2762 | 2786 | return Err(not_found().into()); |
| 2763 | 2787 | }; |
| 2764 | - let state = app_context::<AppState>(cx); | |
| 2788 | + let state = context::<AppState>(cx); | |
| 2765 | 2789 | let bars = dock_bars(state, &ctx).await; |
| 2766 | 2790 | let owner = ctx.repo.owner_name.clone(); |
| 2767 | 2791 | let repo = ctx.repo.name.clone(); |
| @@ -2798,10 +2822,10 @@ pub(crate) async fn dock_bars(state: &AppState, ctx: &RepoCtx) -> Vec<StripBar> | ||
| 2798 | 2822 | /// created or changed state. Nothing is sent on connect, since the page was just rendered. |
| 2799 | 2823 | #[route(GET "/{owner}/{repo}/ci/events")] |
| 2800 | 2824 | async fn runs_events(cx: &Cx) -> Result<Response> { |
| 2801 | - let owner = path_param::<Owner>(cx); | |
| 2802 | - let name = path_param::<Repo>(cx); | |
| 2825 | + let owner = owner(cx); | |
| 2826 | + let name = repo(cx); | |
| 2803 | 2827 | let ctx = load_repo(cx, owner, name).await?; |
| 2804 | - let state = app_context::<AppState>(cx); | |
| 2828 | + let state = context::<AppState>(cx); | |
| 2805 | 2829 | // Subscribed before the response is sent, so a change after this point is sent. |
| 2806 | 2830 | let wake = state.ci_live.subscribe_repo(&ctx.repo.id); |
| 2807 | 2831 | events_response(cx, repo_changes(wake)) |
| @@ -2810,12 +2834,12 @@ async fn runs_events(cx: &Cx) -> Result<Response> { | ||
| 2810 | 2834 | /// Starts a manual run on a branch. Writers only. The branch must be one of the repo's branches. |
| 2811 | 2835 | #[route(POST "/{owner}/{repo}/ci")] |
| 2812 | 2836 | async fn manual_run_post(cx: &Cx, Form(form): Form<ManualForm>) -> Result<SeeOther> { |
| 2813 | - let owner = path_param::<Owner>(cx); | |
| 2814 | - let name = path_param::<Repo>(cx); | |
| 2837 | + let owner = owner(cx); | |
| 2838 | + let name = repo(cx); | |
| 2815 | 2839 | let ctx = load_repo(cx, owner, name).await?; |
| 2816 | 2840 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 2817 | 2841 | require_write(&ctx)?; |
| 2818 | - let state = app_context::<AppState>(cx); | |
| 2842 | + let state = context::<AppState>(cx); | |
| 2819 | 2843 | let title = title_of(&ctx); |
| 2820 | 2844 | let branch = form.branch.trim(); |
| 2821 | 2845 | let refs = load_refs(ctx.path.clone()).await?; |
| @@ -2948,7 +2972,7 @@ impl StreamSlot { | ||
| 2948 | 2972 | /// A slot for this request's client, or `None` when a cap is reached. Without the app state |
| 2949 | 2973 | /// (unit tests of a bare router) nothing is counted. |
| 2950 | 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 | 2976 | return Some(StreamSlot { ip: None }); |
| 2953 | 2977 | } |
| 2954 | 2978 | let ip = crate::client_ip::client_ip(cx); |
| @@ -3023,11 +3047,11 @@ pub(crate) fn events_response( | ||
| 3023 | 3047 | /// or to one of its jobs, so the page can render its rows again. |
| 3024 | 3048 | #[route(GET "/{owner}/{repo}/ci/runs/{run_number}/events")] |
| 3025 | 3049 | async fn run_events(cx: &Cx) -> Result<Response> { |
| 3026 | - let owner = path_param::<Owner>(cx); | |
| 3027 | - let name = path_param::<Repo>(cx); | |
| 3028 | - let number = path_param::<RunNumber>(cx).to_owned(); | |
| 3050 | + let owner = owner(cx); | |
| 3051 | + let name = repo(cx); | |
| 3052 | + let number = run_number(cx).to_owned(); | |
| 3029 | 3053 | let ctx = load_repo(cx, owner, name).await?; |
| 3030 | - let state = app_context::<AppState>(cx); | |
| 3054 | + let state = context::<AppState>(cx); | |
| 3031 | 3055 | let run = run_of(state, &ctx, &number).await?; |
| 3032 | 3056 | // Subscribed before the status is read, so a change in between is sent. |
| 3033 | 3057 | let wake = state.ci_live.subscribe_run(&run.id); |
| @@ -3055,13 +3079,13 @@ async fn run_events(cx: &Cx) -> Result<Response> { | ||
| 3055 | 3079 | /// get a cancel request that their runner sees on its next heartbeat. |
| 3056 | 3080 | #[route(POST "/{owner}/{repo}/ci/runs/{run_number}/cancel")] |
| 3057 | 3081 | async fn run_cancel(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { |
| 3058 | - let owner = path_param::<Owner>(cx); | |
| 3059 | - let name = path_param::<Repo>(cx); | |
| 3060 | - let number = path_param::<RunNumber>(cx).to_owned(); | |
| 3082 | + let owner = owner(cx); | |
| 3083 | + let name = repo(cx); | |
| 3084 | + let number = run_number(cx).to_owned(); | |
| 3061 | 3085 | let ctx = load_repo(cx, owner, name).await?; |
| 3062 | 3086 | require_csrf(cx, &form.csrf).await?; |
| 3063 | 3087 | require_write(&ctx)?; |
| 3064 | - let state = app_context::<AppState>(cx); | |
| 3088 | + let state = context::<AppState>(cx); | |
| 3065 | 3089 | let run = run_of(state, &ctx, &number).await?; |
| 3066 | 3090 | let href = run_href(&title_of(&ctx), run.number); |
| 3067 | 3091 | if run_finished(&run.state) { |
| @@ -3076,13 +3100,13 @@ async fn run_cancel(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { | ||
| 3076 | 3100 | /// Approves a run that waits for approval: its jobs are queued. Anything else is refused. |
| 3077 | 3101 | #[route(POST "/{owner}/{repo}/ci/runs/{run_number}/approve")] |
| 3078 | 3102 | async fn run_approve(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { |
| 3079 | - let owner = path_param::<Owner>(cx); | |
| 3080 | - let name = path_param::<Repo>(cx); | |
| 3081 | - let number = path_param::<RunNumber>(cx).to_owned(); | |
| 3103 | + let owner = owner(cx); | |
| 3104 | + let name = repo(cx); | |
| 3105 | + let number = run_number(cx).to_owned(); | |
| 3082 | 3106 | let ctx = load_repo(cx, owner, name).await?; |
| 3083 | 3107 | require_csrf(cx, &form.csrf).await?; |
| 3084 | 3108 | require_write(&ctx)?; |
| 3085 | - let state = app_context::<AppState>(cx); | |
| 3109 | + let state = context::<AppState>(cx); | |
| 3086 | 3110 | let run = run_of(state, &ctx, &number).await?; |
| 3087 | 3111 | let href = run_href(&title_of(&ctx), run.number); |
| 3088 | 3112 | if run.state != RunState::WaitingApproval { |
| @@ -3097,13 +3121,13 @@ async fn run_approve(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { | ||
| 3097 | 3121 | /// Starts a new run with the same commit, ref, trigger and job specs, then opens it. |
| 3098 | 3122 | #[route(POST "/{owner}/{repo}/ci/runs/{run_number}/rerun")] |
| 3099 | 3123 | async fn run_rerun(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { |
| 3100 | - let owner = path_param::<Owner>(cx); | |
| 3101 | - let name = path_param::<Repo>(cx); | |
| 3102 | - let number = path_param::<RunNumber>(cx).to_owned(); | |
| 3124 | + let owner = owner(cx); | |
| 3125 | + let name = repo(cx); | |
| 3126 | + let number = run_number(cx).to_owned(); | |
| 3103 | 3127 | let ctx = load_repo(cx, owner, name).await?; |
| 3104 | 3128 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 3105 | 3129 | require_write(&ctx)?; |
| 3106 | - let state = app_context::<AppState>(cx); | |
| 3130 | + let state = context::<AppState>(cx); | |
| 3107 | 3131 | let run = run_of(state, &ctx, &number).await?; |
| 3108 | 3132 | if !commit_reachable_for(&ctx.path, &run.commit_oid).await? { |
| 3109 | 3133 | return Ok(notice_redirect( |
| @@ -3123,13 +3147,13 @@ async fn run_rerun(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { | ||
| 3123 | 3147 | /// jobs that depend on them. The specs are the originals. |
| 3124 | 3148 | #[route(POST "/{owner}/{repo}/ci/runs/{run_number}/rerun-failed")] |
| 3125 | 3149 | async fn run_rerun_failed(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { |
| 3126 | - let owner = path_param::<Owner>(cx); | |
| 3127 | - let name = path_param::<Repo>(cx); | |
| 3128 | - let number = path_param::<RunNumber>(cx).to_owned(); | |
| 3150 | + let owner = owner(cx); | |
| 3151 | + let name = repo(cx); | |
| 3152 | + let number = run_number(cx).to_owned(); | |
| 3129 | 3153 | let ctx = load_repo(cx, owner, name).await?; |
| 3130 | 3154 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 3131 | 3155 | require_write(&ctx)?; |
| 3132 | - let state = app_context::<AppState>(cx); | |
| 3156 | + let state = context::<AppState>(cx); | |
| 3133 | 3157 | let run = run_of(state, &ctx, &number).await?; |
| 3134 | 3158 | let href = run_href(&title_of(&ctx), run.number); |
| 3135 | 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 | 3183 | /// originals. |
| 3160 | 3184 | #[route(POST "/{owner}/{repo}/ci/jobs/{job_id}/rerun")] |
| 3161 | 3185 | async fn job_rerun(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { |
| 3162 | - let owner = path_param::<Owner>(cx); | |
| 3163 | - let name = path_param::<Repo>(cx); | |
| 3164 | - let id = path_param::<JobId>(cx).to_owned(); | |
| 3186 | + let owner = owner(cx); | |
| 3187 | + let name = repo(cx); | |
| 3188 | + let id = job_id(cx).to_owned(); | |
| 3165 | 3189 | let ctx = load_repo(cx, owner, name).await?; |
| 3166 | 3190 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 3167 | 3191 | require_write(&ctx)?; |
| 3168 | - let state = app_context::<AppState>(cx); | |
| 3192 | + let state = context::<AppState>(cx); | |
| 3169 | 3193 | let Some(job) = state.store.job_by_id(&id).await? else { |
| 3170 | 3194 | return Err(not_found().into()); |
| 3171 | 3195 | }; |
| @@ -3225,11 +3249,11 @@ fn zip_path(job: &str, artifact: &str) -> String { | ||
| 3225 | 3249 | #[route(GET "/{owner}/{repo}/ci/runs/{run_number}/artifacts.zip")] |
| 3226 | 3250 | async fn run_artifacts_zip(cx: &Cx) -> Result<Response> { |
| 3227 | 3251 | use futures_util::TryStreamExt; |
| 3228 | - let owner = path_param::<Owner>(cx); | |
| 3229 | - let name = path_param::<Repo>(cx); | |
| 3230 | - let number = path_param::<RunNumber>(cx).to_owned(); | |
| 3252 | + let owner = owner(cx); | |
| 3253 | + let name = repo(cx); | |
| 3254 | + let number = run_number(cx).to_owned(); | |
| 3231 | 3255 | let ctx = load_repo(cx, owner, name).await?; |
| 3232 | - let state = app_context::<AppState>(cx); | |
| 3256 | + let state = context::<AppState>(cx); | |
| 3233 | 3257 | let run = run_of(state, &ctx, &number).await?; |
| 3234 | 3258 | let href = run_href(&title_of(&ctx), run.number); |
| 3235 | 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 | 261 | let run = run_with(&fx, &["build"], false).await; |
| 262 | 262 | let run_url = format!("{RUN_BASE}/runs/{}", run.number); |
| 263 | 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 | 268 | assert!(writer.text().contains(">Cancel<"), "writer sees cancel"); |
| 266 | 269 | let reader = get(&fx.app, &run_url, Some(&cookie_for("dave-token"))).await; |
| 267 | 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 | 16 | use forge_core::{Repo as RepoRecord, User, Visibility}; |
| 17 | 17 | use forge_git::browse::{RefInfo, RefKind}; |
| 18 | 18 | use topcoat::Result; |
| 19 | -use topcoat::context::{Cx, app_context}; | |
| 19 | +use topcoat::context::{Cx, context}; | |
| 20 | 20 | use topcoat::router::response::Response; |
| 21 | 21 | use topcoat::router::{path_param, query_params, route}; |
| 22 | 22 | |
| @@ -161,13 +161,13 @@ async fn home_fingerprint( | ||
| 161 | 161 | /// repo gets the same 404 as the page. |
| 162 | 162 | #[route(GET "/{owner}/{repo}/events")] |
| 163 | 163 | async fn repo_events(cx: &Cx) -> Result<Response> { |
| 164 | - let owner = path_param::<Owner>(cx); | |
| 165 | - let name = path_param::<Repo>(cx); | |
| 164 | + let owner = owner(cx); | |
| 165 | + let name = repo(cx); | |
| 166 | 166 | let query = query_params::<LiveQuery>(cx)?; |
| 167 | 167 | let branch = query.ref_name.clone().unwrap_or_default(); |
| 168 | 168 | let home = query.home.as_deref() == Some("1"); |
| 169 | 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 | 171 | let repo_id = ctx.repo.id.clone(); |
| 172 | 172 | let mut topics = vec![ |
| 173 | 173 | Topic::Repo(repo_id.clone()), |
crates/forge-web/src/pages/code_search.rsmodified+4 -4
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | use forge_git::browse; |
| 7 | 7 | use forge_git::search::{GrepHit, GrepOptions, GrepResult, grep}; |
| 8 | 8 | use topcoat::Result; |
| 9 | -use topcoat::context::{Cx, app_context}; | |
| 9 | +use topcoat::context::{Cx, context}; | |
| 10 | 10 | use topcoat::router::error::not_found; |
| 11 | 11 | use topcoat::router::{page, path_param, query_params}; |
| 12 | 12 | use topcoat::view::{View, view}; |
| @@ -132,12 +132,12 @@ fn group_hits( | ||
| 132 | 132 | |
| 133 | 133 | #[page("/{owner}/{repo}/search")] |
| 134 | 134 | async fn search_page(cx: &Cx) -> Result<impl View> { |
| 135 | - let owner = path_param::<Owner>(cx); | |
| 136 | - let name = path_param::<Repo>(cx); | |
| 135 | + let owner = owner(cx); | |
| 136 | + let name = repo(cx); | |
| 137 | 137 | let query = query_params::<SearchQuery>(cx)?; |
| 138 | 138 | |
| 139 | 139 | let ctx = load_repo(cx, owner, name).await?; |
| 140 | - let state = app_context::<AppState>(cx); | |
| 140 | + let state = context::<AppState>(cx); | |
| 141 | 141 | let repo_name = ctx.repo.name.clone(); |
| 142 | 142 | let owner_name = ctx.repo.owner_name.clone(); |
| 143 | 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 | 5 | use forge_git::history; |
| 6 | 6 | use forge_git::trailers; |
| 7 | 7 | use topcoat::Result; |
| 8 | -use topcoat::context::{Cx, app_context}; | |
| 8 | +use topcoat::context::{Cx, context}; | |
| 9 | 9 | use topcoat::router::error::{content_too_large, not_found}; |
| 10 | 10 | use topcoat::router::{page, path_param, route}; |
| 11 | 11 | use topcoat::view::{View, view}; |
| @@ -95,15 +95,15 @@ impl Download { | ||
| 95 | 95 | |
| 96 | 96 | #[page("/{owner}/{repo}/commit/{oid}")] |
| 97 | 97 | async fn commit_page(cx: &Cx) -> Result<impl View> { |
| 98 | - let owner = path_param::<Owner>(cx); | |
| 99 | - let name = path_param::<Repo>(cx); | |
| 100 | - let (rev, download) = Download::split(path_param::<Oid>(cx)); | |
| 98 | + let owner = owner(cx); | |
| 99 | + let name = repo(cx); | |
| 100 | + let (rev, download) = Download::split(oid(cx)); | |
| 101 | 101 | if !is_hex_prefix(rev) { |
| 102 | 102 | return Err(not_found().into()); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | let ctx = load_repo(cx, owner, name).await?; |
| 106 | - let state = app_context::<AppState>(cx); | |
| 106 | + let state = context::<AppState>(cx); | |
| 107 | 107 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user)); |
| 108 | 108 | |
| 109 | 109 | let repo_dir = ctx.path.clone(); |
| @@ -360,7 +360,7 @@ async fn commit_page(cx: &Cx) -> Result<impl View> { | ||
| 360 | 360 | |
| 361 | 361 | /// Other methods on a commit path get a plain 404. |
| 362 | 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 | 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 | 11 | use forge_git::history; |
| 12 | 12 | use jiff::{Timestamp, civil}; |
| 13 | 13 | use topcoat::Result; |
| 14 | -use topcoat::context::{Cx, app_context}; | |
| 14 | +use topcoat::context::{Cx, context}; | |
| 15 | 15 | use topcoat::router::error::{bad_request, not_found}; |
| 16 | 16 | use topcoat::router::{page, path_param, query_params}; |
| 17 | 17 | use topcoat::view::{View, view}; |
| @@ -241,9 +241,9 @@ impl CommitRow { | ||
| 241 | 241 | |
| 242 | 242 | #[page("/{owner}/{repo}/commits/{*rest}")] |
| 243 | 243 | async fn commits_page(cx: &Cx) -> Result<impl View> { |
| 244 | - let owner = path_param::<Owner>(cx); | |
| 245 | - let name = path_param::<Repo>(cx); | |
| 246 | - let rest = path_param::<Rest>(cx).collect::<Vec<_>>().join("/"); | |
| 244 | + let owner = owner(cx); | |
| 245 | + let name = repo(cx); | |
| 246 | + let rest = rest(cx).collect::<Vec<_>>().join("/"); | |
| 247 | 247 | let query = query_params::<CommitsQuery>(cx)?; |
| 248 | 248 | let page_no = query.page.unwrap_or(1); |
| 249 | 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 | 253 | let ctx = load_repo(cx, owner, name).await?; |
| 254 | - let state = app_context::<AppState>(cx); | |
| 254 | + let state = context::<AppState>(cx); | |
| 255 | 255 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user)); |
| 256 | 256 | |
| 257 | 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 | 19 | use forge_git::repo::repo_path; |
| 20 | 20 | use serde::Deserialize; |
| 21 | 21 | use topcoat::Result; |
| 22 | -use topcoat::context::{Cx, app_context}; | |
| 22 | +use topcoat::context::{Cx, context}; | |
| 23 | 23 | use topcoat::router::content::Form; |
| 24 | 24 | use topcoat::router::error::{bad_request, forbidden, not_found, see_other}; |
| 25 | 25 | use topcoat::router::{page, path_param, query_params}; |
| @@ -236,7 +236,7 @@ async fn compare_view( | ||
| 236 | 236 | draft: Option<(String, String)>, |
| 237 | 237 | error: Option<String>, |
| 238 | 238 | ) -> Result<impl View> { |
| 239 | - let state = app_context::<AppState>(cx); | |
| 239 | + let state = context::<AppState>(cx); | |
| 240 | 240 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user)); |
| 241 | 241 | let owner = ctx.repo.owner_name.clone(); |
| 242 | 242 | let name = ctx.repo.name.clone(); |
| @@ -328,7 +328,7 @@ async fn compare_view( | ||
| 328 | 328 | |
| 329 | 329 | let mut header = ctx.head(state, "commits").await?; |
| 330 | 330 | header.live = ref_live::live_url(&ctx.repo.owner_name, &ctx.repo.name); |
| 331 | - let __cx = cx; | |
| 331 | + let cx = cx; | |
| 332 | 332 | Ok(view! { |
| 333 | 333 | shell(title: title.as_str(), viewer: ctx.viewer.as_ref(), |
| 334 | 334 | repo_head(head: header, title: Some(compare_title)) |
| @@ -410,7 +410,7 @@ async fn compare_view( | ||
| 410 | 410 | |
| 411 | 411 | /// The picker: base and head fields as a plain GET form, with the repo's branches suggested. |
| 412 | 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 | 414 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user)); |
| 415 | 415 | let path = ctx.path.clone(); |
| 416 | 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 | 423 | let action = repo_href(&ctx.repo.owner_name, &ctx.repo.name, "compare", ""); |
| 424 | 424 | let mut header = ctx.head(state, "commits").await?; |
| 425 | 425 | header.live = ref_live::live_url(&ctx.repo.owner_name, &ctx.repo.name); |
| 426 | - let __cx = cx; | |
| 426 | + let cx = cx; | |
| 427 | 427 | Ok(view! { |
| 428 | 428 | shell(title: title.as_str(), viewer: ctx.viewer.as_ref(), |
| 429 | 429 | repo_head(head: header, title: Some(g::t(lang, K::CompareBranches).to_owned())) |
| @@ -460,8 +460,8 @@ struct PickerQuery { | ||
| 460 | 460 | /// Picker at `/{owner}/{repo}/compare`. Both fields filled in redirect to the comparison. |
| 461 | 461 | #[page("/{owner}/{repo}/compare")] |
| 462 | 462 | async fn compare_picker(cx: &Cx) -> Result<impl View> { |
| 463 | - let owner = path_param::<Owner>(cx); | |
| 464 | - let name = path_param::<Repo>(cx); | |
| 463 | + let owner = owner(cx); | |
| 464 | + let name = repo(cx); | |
| 465 | 465 | let query = query_params::<PickerQuery>(cx)?; |
| 466 | 466 | let ctx = load_repo(cx, owner, name).await?; |
| 467 | 467 | let base = query.base.clone().unwrap_or_default(); |
| @@ -485,12 +485,12 @@ async fn compare_picker(cx: &Cx) -> Result<impl View> { | ||
| 485 | 485 | /// Comparison at `/{owner}/{repo}/compare/{base}...{head}`. |
| 486 | 486 | #[page("/{owner}/{repo}/compare/{*spec}")] |
| 487 | 487 | async fn compare_page(cx: &Cx) -> Result<impl View> { |
| 488 | - let owner = path_param::<Owner>(cx); | |
| 489 | - let name = path_param::<Repo>(cx); | |
| 490 | - let full_spec = path_param::<Spec>(cx).collect::<Vec<_>>().join("/"); | |
| 488 | + let owner = owner(cx); | |
| 489 | + let name = repo(cx); | |
| 490 | + let full_spec = spec(cx).collect::<Vec<_>>().join("/"); | |
| 491 | 491 | let (spec, download) = Download::split(&full_spec); |
| 492 | 492 | let ctx = load_repo(cx, owner, name).await?; |
| 493 | - let state = app_context::<AppState>(cx); | |
| 493 | + let state = context::<AppState>(cx); | |
| 494 | 494 | let Some((base, head)) = spec.split_once("...") else { |
| 495 | 495 | return Err(not_found().into()); |
| 496 | 496 | }; |
| @@ -551,13 +551,13 @@ struct PullForm { | ||
| 551 | 551 | /// Opens a pull request from a comparison: `POST /{owner}/{repo}/pulls`. |
| 552 | 552 | #[page(POST "/{owner}/{repo}/pulls")] |
| 553 | 553 | async fn pull_create(cx: &Cx, Form(form): Form<PullForm>) -> Result<impl View> { |
| 554 | - let owner = path_param::<Owner>(cx); | |
| 555 | - let name = path_param::<Repo>(cx); | |
| 554 | + let owner = owner(cx); | |
| 555 | + let name = repo(cx); | |
| 556 | 556 | let ctx = load_repo(cx, owner, name).await?; |
| 557 | 557 | let (user, session) = require_user(cx).await?; |
| 558 | 558 | check_write(&ctx, &session, &form.csrf)?; |
| 559 | 559 | let lang = i18n::lang(cx, Some(&user)); |
| 560 | - let state = app_context::<AppState>(cx); | |
| 560 | + let state = context::<AppState>(cx); | |
| 561 | 561 | |
| 562 | 562 | let Some(cmp) = resolve_comparison(state, &ctx, &form.base, &form.head).await? else { |
| 563 | 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 | 9 | use forge_core::{AuditAction, Reaction, ReactionTarget}; |
| 10 | 10 | use serde::Deserialize; |
| 11 | 11 | use topcoat::Result; |
| 12 | -use topcoat::context::{Cx, app_context}; | |
| 12 | +use topcoat::context::{Cx, context}; | |
| 13 | 13 | use topcoat::router::content::Form; |
| 14 | 14 | use topcoat::router::error::{SeeOther, bad_request, forbidden, not_found, see_other}; |
| 15 | 15 | use topcoat::router::{page, path_param, route}; |
| @@ -86,12 +86,12 @@ async fn own_comment( | ||
| 86 | 86 | |
| 87 | 87 | #[page(POST "/{owner}/{repo}/discussions/{number}/comments")] |
| 88 | 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?; | |
| 90 | - let state = app_context::<AppState>(cx); | |
| 89 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 90 | + let state = context::<AppState>(cx); | |
| 91 | 91 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 92 | 92 | let lang = i18n::lang(cx, Some(&user)); |
| 93 | 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 | 95 | if !may_converse(&ctx, discussion.locked) { |
| 96 | 96 | return Err(forbidden().into()); |
| 97 | 97 | } |
| @@ -111,7 +111,7 @@ async fn discussion_comment(cx: &Cx, Form(form): Form<ActionForm>) -> Result<imp | ||
| 111 | 111 | Ok(comment) => comment, |
| 112 | 112 | Err(e) => { |
| 113 | 113 | let message = refusal_message(e)?; |
| 114 | - return Ok(view! { cx => | |
| 114 | + return Ok(view! { | |
| 115 | 115 | shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(), |
| 116 | 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 | 133 | #[page(POST "/{owner}/{repo}/discussions/{number}/edit")] |
| 134 | 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?; | |
| 136 | - let state = app_context::<AppState>(cx); | |
| 135 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 136 | + let state = context::<AppState>(cx); | |
| 137 | 137 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 138 | 138 | let lang = i18n::lang(cx, Some(&user)); |
| 139 | 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 | 141 | if ctx.repo.archived || !is_author(&ctx, &discussion.author_id) { |
| 142 | 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 | 148 | .await |
| 149 | 149 | { |
| 150 | 150 | let message = refusal_message(e)?; |
| 151 | - return Ok(view! { cx => | |
| 151 | + return Ok(view! { | |
| 152 | 152 | shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(), |
| 153 | 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 | 177 | /// Deletes the discussion with its comments. Its author only. |
| 178 | 178 | #[route(POST "/{owner}/{repo}/discussions/{number}/delete")] |
| 179 | 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?; | |
| 181 | - let state = app_context::<AppState>(cx); | |
| 180 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 181 | + let state = context::<AppState>(cx); | |
| 182 | 182 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 183 | 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 | 185 | if ctx.repo.archived || !is_author(&ctx, &discussion.author_id) { |
| 186 | 186 | return Err(forbidden().into()); |
| 187 | 187 | } |
| @@ -205,11 +205,11 @@ async fn discussion_delete(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeO | ||
| 205 | 205 | /// Locks (`locked=1`) or unlocks (`locked=0`) a discussion. Triage holders only. |
| 206 | 206 | #[route(POST "/{owner}/{repo}/discussions/{number}/lock")] |
| 207 | 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?; | |
| 209 | - let state = app_context::<AppState>(cx); | |
| 208 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 209 | + let state = context::<AppState>(cx); | |
| 210 | 210 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 211 | 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 | 213 | if !can_triage(&ctx) { |
| 214 | 214 | return Err(forbidden().into()); |
| 215 | 215 | } |
| @@ -233,12 +233,12 @@ async fn discussion_lock(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOth | ||
| 233 | 233 | /// Triage holder may do it. |
| 234 | 234 | #[page(POST "/{owner}/{repo}/discussions/{number}/answer")] |
| 235 | 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?; | |
| 237 | - let state = app_context::<AppState>(cx); | |
| 236 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 237 | + let state = context::<AppState>(cx); | |
| 238 | 238 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 239 | 239 | let lang = i18n::lang(cx, Some(&user)); |
| 240 | 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 | 242 | if ctx.repo.archived || !(can_triage(&ctx) || is_author(&ctx, &discussion.author_id)) { |
| 243 | 243 | return Err(forbidden().into()); |
| 244 | 244 | } |
| @@ -256,7 +256,7 @@ async fn discussion_answer(cx: &Cx, Form(form): Form<ActionForm>) -> Result<impl | ||
| 256 | 256 | .await |
| 257 | 257 | { |
| 258 | 258 | let message = refusal_message(e)?; |
| 259 | - return Ok(view! { cx => | |
| 259 | + return Ok(view! { | |
| 260 | 260 | shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(), |
| 261 | 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 | 279 | #[page(POST "/{owner}/{repo}/discussions/{number}/comments/{comment_id}/edit")] |
| 280 | 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?; | |
| 282 | - let state = app_context::<AppState>(cx); | |
| 281 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 282 | + let state = context::<AppState>(cx); | |
| 283 | 283 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 284 | 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 | 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 | 288 | let base = base_of(&ctx, discussion.number); |
| 289 | 289 | if let Err(e) = state |
| 290 | 290 | .store |
| @@ -292,7 +292,7 @@ async fn discussion_comment_edit(cx: &Cx, Form(form): Form<ActionForm>) -> Resul | ||
| 292 | 292 | .await |
| 293 | 293 | { |
| 294 | 294 | let message = refusal_message(e)?; |
| 295 | - return Ok(view! { cx => | |
| 295 | + return Ok(view! { | |
| 296 | 296 | shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(), |
| 297 | 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 | 321 | #[route(POST "/{owner}/{repo}/discussions/{number}/comments/{comment_id}/delete")] |
| 322 | 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?; | |
| 324 | - let state = app_context::<AppState>(cx); | |
| 323 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 324 | + let state = context::<AppState>(cx); | |
| 325 | 325 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 326 | 326 | ensure_enabled(state, &ctx).await?; |
| 327 | - let discussion = discussion_by_number(state, &ctx, path_param::<Number>(cx)).await?; | |
| 328 | - let comment = own_comment(state, &ctx, &discussion.id, path_param::<CommentId>(cx)).await?; | |
| 327 | + let discussion = discussion_by_number(state, &ctx, number(cx)).await?; | |
| 328 | + let comment = own_comment(state, &ctx, &discussion.id, comment_id(cx)).await?; | |
| 329 | 329 | state.store.delete_discussion_comment(&comment.id).await?; |
| 330 | 330 | audit_discussion( |
| 331 | 331 | cx, |
| @@ -343,11 +343,11 @@ async fn discussion_comment_delete(cx: &Cx, Form(form): Form<ActionForm>) -> Res | ||
| 343 | 343 | /// comments (`target_kind=discussion_comment`). |
| 344 | 344 | #[route(POST "/{owner}/{repo}/discussions/{number}/reactions")] |
| 345 | 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?; | |
| 347 | - let state = app_context::<AppState>(cx); | |
| 346 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 347 | + let state = context::<AppState>(cx); | |
| 348 | 348 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 349 | 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 | 351 | if !may_converse(&ctx, discussion.locked) { |
| 352 | 352 | return Err(forbidden().into()); |
| 353 | 353 | } |
crates/forge-web/src/pages/discussion_live.rsmodified+7 -7
| @@ -13,7 +13,7 @@ | ||
| 13 | 13 | //! that is not there. |
| 14 | 14 | |
| 15 | 15 | use topcoat::Result; |
| 16 | -use topcoat::context::{Cx, app_context}; | |
| 16 | +use topcoat::context::{Cx, context}; | |
| 17 | 17 | use topcoat::router::request::{method, uri}; |
| 18 | 18 | use topcoat::router::response::Response; |
| 19 | 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 | 40 | /// The change stream of the discussion list. |
| 41 | 41 | #[route(GET "/{owner}/{repo}/discussions/live")] |
| 42 | 42 | async fn discussions_live(cx: &Cx) -> Result<Response> { |
| 43 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 44 | - let state = app_context::<AppState>(cx); | |
| 43 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 44 | + let state = context::<AppState>(cx); | |
| 45 | 45 | ensure_enabled(state, &ctx).await?; |
| 46 | 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 | 49 | /// The change stream of one discussion page. |
| 50 | 50 | #[route(GET "/{owner}/{repo}/discussions/{number}/live")] |
| 51 | 51 | async fn discussion_live(cx: &Cx) -> Result<Response> { |
| 52 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 53 | - let state = app_context::<AppState>(cx); | |
| 52 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 53 | + let state = context::<AppState>(cx); | |
| 54 | 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 | 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 | 128 | /// through unchanged, so a refused write (an error or a redirect) bumps too: the page re-reads and |
| 129 | 129 | /// agrees. |
| 130 | 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 | 132 | let topics = match written(cx) { |
| 133 | 133 | Some(target) => topics_of(state, target).await, |
| 134 | 134 | None => Vec::new(), |
crates/forge-web/src/pages/discussion_settings.rsmodified+10 -4
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | use forge_core::AuditAction; |
| 6 | 6 | use serde::Deserialize; |
| 7 | 7 | use topcoat::Result; |
| 8 | -use topcoat::context::{Cx, app_context}; | |
| 8 | +use topcoat::context::{Cx, context}; | |
| 9 | 9 | use topcoat::router::content::Form; |
| 10 | 10 | use topcoat::router::error::{SeeOther, forbidden, see_other}; |
| 11 | 11 | use topcoat::router::{path_param, route}; |
| @@ -26,6 +26,7 @@ path_param!(repo); | ||
| 26 | 26 | /// the form on change (`data-autosubmit`); an unchecked box sends no `enabled`, which the handler reads as off. |
| 27 | 27 | #[component] |
| 28 | 28 | pub(crate) async fn discussions_switch( |
| 29 | + cx: &Cx, | |
| 29 | 30 | lang: Lang, |
| 30 | 31 | action: String, |
| 31 | 32 | csrf: String, |
| @@ -53,13 +54,13 @@ struct ToggleForm { | ||
| 53 | 54 | |
| 54 | 55 | #[route(POST "/{owner}/{repo}/settings/discussions")] |
| 55 | 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 | 58 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 58 | 59 | if !ctx.can_admin() { |
| 59 | 60 | return Err(forbidden().into()); |
| 60 | 61 | } |
| 61 | 62 | let enabled = form.enabled == "1"; |
| 62 | - let state = app_context::<AppState>(cx); | |
| 63 | + let state = context::<AppState>(cx); | |
| 63 | 64 | state |
| 64 | 65 | .store |
| 65 | 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 | 86 | serde_json::Value::Null, |
| 86 | 87 | ) |
| 87 | 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 | 8 | use forge_core::discussions::{Discussion, DiscussionCategory, DiscussionComment}; |
| 9 | 9 | use forge_core::{ReactionMap, ReactionTarget}; |
| 10 | 10 | use topcoat::Result; |
| 11 | -use topcoat::context::{Cx, app_context}; | |
| 11 | +use topcoat::context::{Cx, context}; | |
| 12 | 12 | use topcoat::router::{page, path_param}; |
| 13 | 13 | use topcoat::view::{Unescaped, View, component, view}; |
| 14 | 14 | |
| @@ -151,7 +151,7 @@ fn comment_view( | ||
| 151 | 151 | |
| 152 | 152 | /// One comment, with its reactions and the forms the viewer may use. |
| 153 | 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 | 155 | let CommentView { |
| 156 | 156 | lang, |
| 157 | 157 | anchor, |
| @@ -246,7 +246,11 @@ async fn comment_article(item: CommentView) -> Result<impl View> { | ||
| 246 | 246 | |
| 247 | 247 | /// A top-level comment with its replies indented under it. |
| 248 | 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 | 254 | Ok(view! { |
| 251 | 255 | <div class="discussion-thread"> |
| 252 | 256 | comment_article(item: root) |
| @@ -263,9 +267,9 @@ async fn comment_thread(root: CommentView, replies: Vec<CommentView>) -> Result< | ||
| 263 | 267 | |
| 264 | 268 | #[page("/{owner}/{repo}/discussions/{number}")] |
| 265 | 269 | async fn discussion_show(cx: &Cx) -> Result<impl View> { |
| 266 | - let number = path_param::<Number>(cx); | |
| 267 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 268 | - let state = app_context::<AppState>(cx); | |
| 270 | + let number = number(cx); | |
| 271 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 272 | + let state = context::<AppState>(cx); | |
| 269 | 273 | ensure_enabled(state, &ctx).await?; |
| 270 | 274 | let discussion = discussion_by_number(state, &ctx, number).await?; |
| 271 | 275 | discussion_page(cx, state, ctx, discussion).await |
| @@ -415,7 +419,7 @@ async fn discussion_page( | ||
| 415 | 419 | sub.push(SubPart::link(author.clone(), author_profile.clone())); |
| 416 | 420 | sub.push(SubPart::text(opened.relative.clone())); |
| 417 | 421 | sub.push(SubPart::text(comments_label)); |
| 418 | - Ok(view! { cx => | |
| 422 | + Ok(view! { | |
| 419 | 423 | shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(), |
| 420 | 424 | repo_head(head: header, title: Some(discussion.title.clone()), sub: sub, |
| 421 | 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 | 10 | use forge_core::{Action, AuditAction, Role, User, authorize}; |
| 11 | 11 | use topcoat::Result; |
| 12 | -use topcoat::context::{Cx, app_context}; | |
| 12 | +use topcoat::context::{Cx, context}; | |
| 13 | 13 | use topcoat::router::content::RawForm; |
| 14 | 14 | use topcoat::router::error::{bad_request, forbidden, not_found, see_other}; |
| 15 | 15 | use topcoat::router::{StatusCode, page, path_param, query_params}; |
| @@ -225,11 +225,11 @@ fn row_view( | ||
| 225 | 225 | |
| 226 | 226 | #[page("/{owner}/{repo}/discussions")] |
| 227 | 227 | async fn discussions_list_page(cx: &Cx) -> Result<impl View> { |
| 228 | - let owner = path_param::<Owner>(cx); | |
| 229 | - let name = path_param::<Repo>(cx); | |
| 228 | + let owner = owner(cx); | |
| 229 | + let name = repo(cx); | |
| 230 | 230 | let query = query_params::<ListQuery>(cx)?; |
| 231 | 231 | let ctx = load_repo(cx, owner, name).await?; |
| 232 | - let state = app_context::<AppState>(cx); | |
| 232 | + let state = context::<AppState>(cx); | |
| 233 | 233 | ensure_enabled(state, &ctx).await?; |
| 234 | 234 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user)); |
| 235 | 235 | |
| @@ -373,6 +373,7 @@ struct DraftDiscussion { | ||
| 373 | 373 | |
| 374 | 374 | #[component] |
| 375 | 375 | async fn new_discussion_body( |
| 376 | + cx: &Cx, | |
| 376 | 377 | lang: Lang, |
| 377 | 378 | head: RepoHead, |
| 378 | 379 | csrf: String, |
| @@ -416,10 +417,10 @@ async fn new_discussion_body( | ||
| 416 | 417 | |
| 417 | 418 | #[page("/{owner}/{repo}/discussions/new")] |
| 418 | 419 | async fn discussion_new_page(cx: &Cx) -> Result<impl View> { |
| 419 | - let owner = path_param::<Owner>(cx); | |
| 420 | - let name = path_param::<Repo>(cx); | |
| 420 | + let owner = owner(cx); | |
| 421 | + let name = repo(cx); | |
| 421 | 422 | let ctx = load_repo(cx, owner, name).await?; |
| 422 | - let state = app_context::<AppState>(cx); | |
| 423 | + let state = context::<AppState>(cx); | |
| 423 | 424 | ensure_enabled(state, &ctx).await?; |
| 424 | 425 | let viewer = require_user(cx).await?; |
| 425 | 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 | 445 | #[page(POST "/{owner}/{repo}/discussions/new")] |
| 445 | 446 | async fn discussion_create(cx: &Cx, RawForm(raw): RawForm) -> Result<impl View> { |
| 446 | - let owner = path_param::<Owner>(cx); | |
| 447 | - let name = path_param::<Repo>(cx); | |
| 447 | + let owner = owner(cx); | |
| 448 | + let name = repo(cx); | |
| 448 | 449 | let ctx = load_repo(cx, owner, name).await?; |
| 449 | - let state = app_context::<AppState>(cx); | |
| 450 | + let state = context::<AppState>(cx); | |
| 450 | 451 | ensure_enabled(state, &ctx).await?; |
| 451 | 452 | let fields = form_pairs(&raw[..]); |
| 452 | 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 | 10 | use forge_core::{EditVersion, Issue, Thread}; |
| 11 | 11 | use similar::{ChangeTag, TextDiff}; |
| 12 | 12 | use topcoat::Result; |
| 13 | -use topcoat::context::{Cx, app_context}; | |
| 13 | +use topcoat::context::{Cx, context}; | |
| 14 | 14 | use topcoat::router::error::not_found; |
| 15 | 15 | use topcoat::router::{page, path_param}; |
| 16 | 16 | use topcoat::view::{View, component, view}; |
| @@ -174,7 +174,7 @@ async fn history_page( | ||
| 174 | 174 | ) -> Result<impl View> { |
| 175 | 175 | let target = target.as_str(); |
| 176 | 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 | 178 | let owner = ctx.repo.owner_name.clone(); |
| 179 | 179 | let name = ctx.repo.name.clone(); |
| 180 | 180 | let number = item.number; |
| @@ -229,17 +229,14 @@ async fn history_page( | ||
| 229 | 229 | let heading = g::history_heading(lang, what); |
| 230 | 230 | let back_label = g::back_to_item(lang, number); |
| 231 | 231 | let count_label = g::earlier_versions(lang, entries.len()); |
| 232 | - let sub = vec![ | |
| 233 | - SubPart::link(back_label, back), | |
| 234 | - SubPart::text(count_label), | |
| 235 | - ]; | |
| 232 | + let sub = vec![SubPart::link(back_label, back), SubPart::text(count_label)]; | |
| 236 | 233 | // A history follows its item: a new edit adds a version to the list. |
| 237 | 234 | let live = match kind_item { |
| 238 | 235 | ItemKind::Issue => item_live_url(&owner, &name, number), |
| 239 | 236 | ItemKind::Pull => pull_live_url(&owner, &name, number), |
| 240 | 237 | }; |
| 241 | 238 | |
| 242 | - Ok(view! { cx => | |
| 239 | + Ok(view! { | |
| 243 | 240 | shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(), |
| 244 | 241 | repo_head(head: header, title: Some(heading), sub: sub) |
| 245 | 242 | <div class="work" data-live=(live.as_str()) data-live-now=""> |
| @@ -260,7 +257,7 @@ async fn history_page( | ||
| 260 | 257 | |
| 261 | 258 | /// One version: the editor and time, the title change if any, the diff and the raw text. |
| 262 | 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 | 261 | let HistoryEntry { |
| 265 | 262 | editor, |
| 266 | 263 | when, |
| @@ -315,11 +312,11 @@ fn parse_kind(raw: &str) -> Result<&'static str> { | ||
| 315 | 312 | } |
| 316 | 313 | |
| 317 | 314 | async fn history_route(cx: &Cx, item_kind: ItemKind) -> Result<impl View> { |
| 318 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 319 | - let target_kind = parse_kind(path_param::<Kind>(cx))?; | |
| 320 | - let target = path_param::<TargetId>(cx).to_owned(); | |
| 321 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 322 | - let state = app_context::<AppState>(cx); | |
| 315 | + let number = parse_number(number(cx))?; | |
| 316 | + let target_kind = parse_kind(kind(cx))?; | |
| 317 | + let target = target_id(cx).to_owned(); | |
| 318 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 319 | + let state = context::<AppState>(cx); | |
| 323 | 320 | let item = item_for(state, &ctx, item_kind, number).await?; |
| 324 | 321 | 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 | 4 | //! page fits the window. `explore` is a reserved username, so this |
| 5 | 5 | //! route cannot collide with a profile. |
| 6 | 6 | |
| 7 | -use forge_core::{Repo, User}; | |
| 8 | 7 | use forge_core::store::RepoSort; |
| 8 | +use forge_core::{Repo, User}; | |
| 9 | 9 | use topcoat::Result; |
| 10 | -use topcoat::context::{Cx, app_context}; | |
| 10 | +use topcoat::context::{Cx, context}; | |
| 11 | 11 | use topcoat::router::response::Response; |
| 12 | 12 | use topcoat::router::{page, query_params, route}; |
| 13 | 13 | use topcoat::view::{View, component, view}; |
| @@ -16,13 +16,13 @@ use crate::auth::current_user; | ||
| 16 | 16 | use crate::i18n::orgs::{self as g, K}; |
| 17 | 17 | use crate::i18n::{self, Lang}; |
| 18 | 18 | use crate::live::{Topic, stream_changes}; |
| 19 | +use crate::pages::issues_list::list_href; | |
| 19 | 20 | use crate::state::AppState; |
| 21 | +use crate::views::find::{Finder, finder_field}; | |
| 20 | 22 | use crate::views::parts::head; |
| 21 | 23 | use crate::views::repo_list::{ |
| 22 | 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 | 26 | use crate::views::{now_unix, shell}; |
| 27 | 27 | |
| 28 | 28 | const PER_PAGE: u64 = 12; |
| @@ -162,7 +162,7 @@ async fn explore_page(cx: &Cx) -> Result<impl View> { | ||
| 162 | 162 | let live = explore_href(&finder, sort, page).replacen("/explore?", "/explore/events?", 1); |
| 163 | 163 | let viewer = current_user(cx).await?; |
| 164 | 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 | 166 | let on_orgs = orgs_tab(query); |
| 167 | 167 | let (listed, repo_total) = listing(state, &finder, sort, page).await?; |
| 168 | 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 | 206 | pager_links(page, pages, |n| explore_href(&finder, sort, n)) |
| 207 | 207 | }; |
| 208 | 208 | let tabs = vec![ |
| 209 | - (g::t(lang, K::Repositories), explore_href(&Finder::default(), sort, 1), repos_all, !on_orgs), | |
| 210 | - (g::t(lang, K::Organizations), orgs_href(&Finder::default(), 1), orgs_all, on_orgs), | |
| 209 | + ( | |
| 210 | + g::t(lang, K::Repositories), | |
| 211 | + explore_href(&Finder::default(), sort, 1), | |
| 212 | + repos_all, | |
| 213 | + !on_orgs, | |
| 214 | + ), | |
| 215 | + ( | |
| 216 | + g::t(lang, K::Organizations), | |
| 217 | + orgs_href(&Finder::default(), 1), | |
| 218 | + orgs_all, | |
| 219 | + on_orgs, | |
| 220 | + ), | |
| 211 | 221 | ]; |
| 212 | 222 | let title = g::t(lang, K::Explore); |
| 213 | 223 | |
| 214 | - Ok(view! { cx => | |
| 224 | + Ok(view! { | |
| 215 | 225 | shell(title: title, viewer: viewer.as_ref(), |
| 216 | 226 | explore_body(finder: finder, sort: sort, sort_links: sort_links, rows: rows, |
| 217 | 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 | 237 | let query = query_params::<ExploreQuery>(cx)?; |
| 228 | 238 | let (finder, sort, page) = listing_args(query); |
| 229 | 239 | let on_orgs = orgs_tab(query); |
| 230 | - let state = app_context::<AppState>(cx).clone(); | |
| 240 | + let state = context::<AppState>(cx).clone(); | |
| 231 | 241 | stream_changes(cx, &state.live.clone(), &[Topic::Explore], move || { |
| 232 | 242 | let state = state.clone(); |
| 233 | 243 | let finder = finder.clone(); |
| @@ -263,6 +273,7 @@ async fn explore_fingerprint( | ||
| 263 | 273 | |
| 264 | 274 | #[component] |
| 265 | 275 | async fn explore_body( |
| 276 | + cx: &Cx, | |
| 266 | 277 | finder: Finder, |
| 267 | 278 | sort: &'static str, |
| 268 | 279 | sort_links: Vec<SortLink>, |
| @@ -277,7 +288,11 @@ async fn explore_body( | ||
| 277 | 288 | on_orgs: bool, |
| 278 | 289 | tabs: Vec<(&'static str, String, u64, bool)>, |
| 279 | 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 | 296 | let has_search = !finder.is_empty(); |
| 282 | 297 | let (links, prev, next) = nav; |
| 283 | 298 | let clear_href = if on_orgs { |
crates/forge-web/src/pages/finder.rsmodified+6 -5
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | use forge_git::history; |
| 6 | 6 | use http::header::{CACHE_CONTROL, CONTENT_TYPE}; |
| 7 | 7 | use topcoat::Result; |
| 8 | -use topcoat::context::{Cx, app_context}; | |
| 8 | +use topcoat::context::{Cx, context}; | |
| 9 | 9 | use topcoat::router::error::not_found; |
| 10 | 10 | use topcoat::router::response::Response; |
| 11 | 11 | use topcoat::router::{Body, HeaderValue, path_param, route}; |
| @@ -28,6 +28,7 @@ pub const MAX_PATHS: usize = 20_000; | ||
| 28 | 28 | /// The "Go to file" button and its dialog for the tree at `ref_name`. |
| 29 | 29 | #[component] |
| 30 | 30 | pub async fn file_finder( |
| 31 | + cx: &Cx, | |
| 31 | 32 | lang: Lang, |
| 32 | 33 | owner: String, |
| 33 | 34 | repo: String, |
| @@ -58,11 +59,11 @@ pub async fn file_finder( | ||
| 58 | 59 | /// `{"ref": ..., "commit": ..., "paths": [...], "truncated": bool}` for the tree at the ref. |
| 59 | 60 | #[route(GET "/{owner}/{repo}/paths/{*rest}")] |
| 60 | 61 | async fn tree_paths(cx: &Cx) -> Result<Response> { |
| 61 | - let owner = path_param::<Owner>(cx); | |
| 62 | - let name = path_param::<Repo>(cx); | |
| 63 | - let rest = path_param::<Rest>(cx).collect::<Vec<_>>().join("/"); | |
| 62 | + let owner = owner(cx); | |
| 63 | + let name = repo(cx); | |
| 64 | + let rest = rest(cx).collect::<Vec<_>>().join("/"); | |
| 64 | 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 | 68 | let Some((ref_name, commit, path)) = resolve(ctx.path.clone(), rest).await? else { |
| 68 | 69 | return Err(not_found().into()); |
crates/forge-web/src/pages/forgot.rsmodified+7 -6
| @@ -8,7 +8,7 @@ use std::time::Instant; | ||
| 8 | 8 | use forge_core::AuditAction; |
| 9 | 9 | use serde::Deserialize; |
| 10 | 10 | use topcoat::Result; |
| 11 | -use topcoat::context::{Cx, app_context}; | |
| 11 | +use topcoat::context::{Cx, context}; | |
| 12 | 12 | use topcoat::router::content::Form; |
| 13 | 13 | use topcoat::router::error::forbidden; |
| 14 | 14 | use topcoat::router::{page, path_param_segment}; |
| @@ -57,7 +57,7 @@ enum ResetMode { | ||
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 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 | 61 | Ok(view! { |
| 62 | 62 | head(title: t(lang, Key::ForgotTitle)) |
| 63 | 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 | 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 | 78 | Ok(view! { |
| 79 | 79 | head(title: t(lang, Key::ForgotTitle)) |
| 80 | 80 | <div class="sheet fit"> |
| @@ -110,7 +110,7 @@ async fn forgot_submit(cx: &Cx, Form(form): Form<ForgotForm>) -> Result<impl Vie | ||
| 110 | 110 | if !check_pre_csrf(cx, &form.precsrf) { |
| 111 | 111 | return Err(forbidden().into()); |
| 112 | 112 | } |
| 113 | - let state = app_context::<AppState>(cx); | |
| 113 | + let state = context::<AppState>(cx); | |
| 114 | 114 | let lang = i18n::lang(cx, None); |
| 115 | 115 | let address = form.email.trim().to_owned(); |
| 116 | 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 | 144 | #[component] |
| 145 | 145 | async fn reset_body( |
| 146 | + cx: &Cx, | |
| 146 | 147 | lang: Lang, |
| 147 | 148 | token: &str, |
| 148 | 149 | precsrf: &str, |
| @@ -188,7 +189,7 @@ async fn reset_body( | ||
| 188 | 189 | |
| 189 | 190 | #[page("/reset/{token}")] |
| 190 | 191 | async fn reset_page(cx: &Cx) -> Result<impl View> { |
| 191 | - let state = app_context::<AppState>(cx); | |
| 192 | + let state = context::<AppState>(cx); | |
| 192 | 193 | let lang = i18n::lang(cx, None); |
| 193 | 194 | let token = path_param_segment(cx, "token").to_owned(); |
| 194 | 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 | 208 | if !check_pre_csrf(cx, &form.precsrf) { |
| 208 | 209 | return Err(forbidden().into()); |
| 209 | 210 | } |
| 210 | - let state = app_context::<AppState>(cx); | |
| 211 | + let state = context::<AppState>(cx); | |
| 211 | 212 | let lang = i18n::lang(cx, None); |
| 212 | 213 | let token = path_param_segment(cx, "token").to_owned(); |
| 213 | 214 | let mut mode = ResetMode::Form; |
crates/forge-web/src/pages/fork.rsmodified+4 -4
| @@ -8,7 +8,7 @@ use forge_core::AuditAction; | ||
| 8 | 8 | use forge_git::repo::{fork_bare, repo_path}; |
| 9 | 9 | use serde::Deserialize; |
| 10 | 10 | use topcoat::Result; |
| 11 | -use topcoat::context::{Cx, app_context}; | |
| 11 | +use topcoat::context::{Cx, context}; | |
| 12 | 12 | use topcoat::router::content::Form; |
| 13 | 13 | use topcoat::router::error::{SeeOther, see_other}; |
| 14 | 14 | use topcoat::router::{path_param, route}; |
| @@ -30,11 +30,11 @@ struct ForkForm { | ||
| 30 | 30 | |
| 31 | 31 | #[route(POST "/{owner}/{repo}/fork")] |
| 32 | 32 | async fn fork_post(cx: &Cx, Form(form): Form<ForkForm>) -> Result<SeeOther> { |
| 33 | - let owner = path_param::<Owner>(cx); | |
| 34 | - let name = path_param::<Repo>(cx); | |
| 33 | + let owner = owner(cx); | |
| 34 | + let name = repo(cx); | |
| 35 | 35 | let source = load_repo(cx, owner, name).await?; |
| 36 | 36 | let (viewer, _) = require_csrf(cx, &form.csrf).await?; |
| 37 | - let state = app_context::<AppState>(cx); | |
| 37 | + let state = context::<AppState>(cx); | |
| 38 | 38 | let source_repo = &source.repo; |
| 39 | 39 | |
| 40 | 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 | 7 | use forge_core::store::RepoSort; |
| 8 | 8 | use forge_core::store::repo_listing::RepoScope; |
| 9 | 9 | use topcoat::Result; |
| 10 | -use topcoat::context::{Cx, app_context}; | |
| 10 | +use topcoat::context::{Cx, context}; | |
| 11 | 11 | use topcoat::router::page; |
| 12 | 12 | use topcoat::view::{View, component, view}; |
| 13 | 13 | |
| @@ -24,7 +24,7 @@ use crate::pages::repo_settings::{notice_banner_for, take_notice}; | ||
| 24 | 24 | use crate::state::AppState; |
| 25 | 25 | use crate::views::parts::head; |
| 26 | 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 | 29 | /// Rows a topic lists on the home page, before its link to the full list. |
| 30 | 30 | const TOPIC_ROWS: usize = 5; |
| @@ -54,7 +54,7 @@ struct SignedHome { | ||
| 54 | 54 | |
| 55 | 55 | #[page("/")] |
| 56 | 56 | async fn home(cx: &Cx) -> Result<impl View> { |
| 57 | - let state = app_context::<AppState>(cx); | |
| 57 | + let state = context::<AppState>(cx); | |
| 58 | 58 | let viewer = current_user(cx).await?; |
| 59 | 59 | let lang = i18n::lang(cx, viewer.as_ref().map(|(user, _)| user)); |
| 60 | 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 | 198 | /// The signed-in home: the head's actions, then the two topics on one sheet. |
| 199 | 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 | 201 | let SignedHome { |
| 202 | 202 | needs, |
| 203 | 203 | repos, |
| @@ -257,7 +257,7 @@ async fn signed_home(lang: Lang, data: SignedHome, may_org: bool) -> Result<impl | ||
| 257 | 257 | |
| 258 | 258 | /// The visitor's landing: the wordmark's tagline and the way in. |
| 259 | 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 | 261 | Ok(view! { |
| 262 | 262 | head(title: "forge", |
| 263 | 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 | 10 | use futures_util::stream; |
| 11 | 11 | use serde::Deserialize; |
| 12 | 12 | use topcoat::Result; |
| 13 | -use topcoat::context::{Cx, app_context}; | |
| 13 | +use topcoat::context::{Cx, context}; | |
| 14 | 14 | use topcoat::router::content::Form; |
| 15 | 15 | use topcoat::router::error::{SeeOther, not_found, see_other}; |
| 16 | 16 | use topcoat::router::response::Response; |
| @@ -165,7 +165,7 @@ fn token_of(raw: &str) -> Option<String> { | ||
| 165 | 165 | // ---- shared pieces ---- |
| 166 | 166 | |
| 167 | 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 | 169 | let create = active == "create"; |
| 170 | 170 | let import = active == "import"; |
| 171 | 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 | 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 | 183 | let git = format!("{base}?source=git"); |
| 184 | 184 | let github = format!("{base}?source=github"); |
| 185 | 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 | 200 | /// Public or private, as two switches with what each means under it. Shared with the create page. |
| 201 | 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 | 203 | Ok(view! { |
| 204 | 204 | <div class="field"> |
| 205 | 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 | 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 | 216 | Ok(view! { |
| 217 | 217 | <div class="field" role="group" aria-labelledby="import-what"> |
| 218 | 218 | <span class="field-label" id="import-what">(g::t(lang, K::WhatToImport))</span> |
| @@ -283,6 +283,7 @@ impl Draft { | ||
| 283 | 283 | |
| 284 | 284 | #[component] |
| 285 | 285 | async fn import_form( |
| 286 | + cx: &Cx, | |
| 286 | 287 | lang: Lang, |
| 287 | 288 | username: String, |
| 288 | 289 | csrf: &str, |
| @@ -391,6 +392,7 @@ async fn import_form( | ||
| 391 | 392 | /// The GET import page: the form. Past imports are on the Import history tab. |
| 392 | 393 | #[component] |
| 393 | 394 | async fn import_home( |
| 395 | + cx: &Cx, | |
| 394 | 396 | lang: Lang, |
| 395 | 397 | username: String, |
| 396 | 398 | csrf: String, |
| @@ -405,6 +407,7 @@ async fn import_home( | ||
| 405 | 407 | /// The import form again after a rejected submit. |
| 406 | 408 | #[component] |
| 407 | 409 | async fn import_error_body( |
| 410 | + cx: &Cx, | |
| 408 | 411 | lang: Lang, |
| 409 | 412 | username: String, |
| 410 | 413 | csrf: String, |
| @@ -423,10 +426,10 @@ async fn import_page(cx: &Cx) -> Result<impl View> { | ||
| 423 | 426 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 424 | 427 | let query = query_params::<SourceQuery>(cx)?; |
| 425 | 428 | let source = source_of(query.source.as_deref()); |
| 426 | - let state = app_context::<AppState>(cx); | |
| 429 | + let state = context::<AppState>(cx); | |
| 427 | 430 | let owners = owner_choices(state, &viewer.0).await?; |
| 428 | 431 | let csrf = viewer.1.csrf_token.clone(); |
| 429 | - Ok(view! { cx => | |
| 432 | + Ok(view! { | |
| 430 | 433 | shell(title: g::t(lang, K::ImportTitle), viewer: Some(&viewer), |
| 431 | 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 | 443 | match start_single(cx, &viewer.0, lang, source, &form).await? { |
| 441 | 444 | Ok(job_id) => Err(see_other(format!("/import/{job_id}")).into()), |
| 442 | 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 | 447 | let csrf = viewer.1.csrf_token.clone(); |
| 445 | 448 | let draft = Draft::from_form(&form, source); |
| 446 | - Ok(view! { cx => | |
| 449 | + Ok(view! { | |
| 447 | 450 | shell(title: g::t(lang, K::ImportTitle), viewer: Some(&viewer), |
| 448 | 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 | 463 | source: Source, |
| 461 | 464 | form: &ImportForm, |
| 462 | 465 | ) -> Result<std::result::Result<String, String>> { |
| 463 | - let state = app_context::<AppState>(cx); | |
| 466 | + let state = context::<AppState>(cx); | |
| 464 | 467 | let Some((remote, instance)) = parse_remote(source, &form.remote, &form.instance) else { |
| 465 | 468 | let message = if has_instance(source) && form.remote.trim().starts_with("http") { |
| 466 | 469 | g::t(lang, K::ErrBadInstance) |
| @@ -526,7 +529,7 @@ async fn begin( | ||
| 526 | 529 | visibility: Visibility, |
| 527 | 530 | spec: JobSpec, |
| 528 | 531 | ) -> Result<std::result::Result<String, String>> { |
| 529 | - let state = app_context::<AppState>(cx); | |
| 532 | + let state = context::<AppState>(cx); | |
| 530 | 533 | let lang = i18n::lang(cx, Some(actor)); |
| 531 | 534 | let name = match forge_core::names::validate_name(name) { |
| 532 | 535 | Ok(name) => name, |
| @@ -589,6 +592,7 @@ async fn begin( | ||
| 589 | 592 | |
| 590 | 593 | #[component] |
| 591 | 594 | async fn bulk_form( |
| 595 | + cx: &Cx, | |
| 592 | 596 | lang: Lang, |
| 593 | 597 | username: String, |
| 594 | 598 | csrf: &str, |
| @@ -652,6 +656,7 @@ struct Listed { | ||
| 652 | 656 | |
| 653 | 657 | #[component] |
| 654 | 658 | async fn bulk_select( |
| 659 | + cx: &Cx, | |
| 655 | 660 | lang: Lang, |
| 656 | 661 | username: String, |
| 657 | 662 | csrf: &str, |
| @@ -748,9 +753,9 @@ async fn bulk_page(cx: &Cx) -> Result<impl View> { | ||
| 748 | 753 | Source::Git => Source::GitHub, |
| 749 | 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 | 757 | let csrf = viewer.1.csrf_token.clone(); |
| 753 | - Ok(view! { cx => | |
| 758 | + Ok(view! { | |
| 754 | 759 | shell(title: g::t(lang, K::BulkTitle), viewer: Some(&viewer), |
| 755 | 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 | 795 | async fn bulk_submit(cx: &Cx, Form(form): Form<BulkForm>) -> Result<impl View> { |
| 791 | 796 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 792 | 797 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 793 | - let state = app_context::<AppState>(cx); | |
| 798 | + let state = context::<AppState>(cx); | |
| 794 | 799 | let source = match source_of(Some(&form.source)) { |
| 795 | 800 | Source::Git => Source::GitHub, |
| 796 | 801 | other => other, |
| @@ -849,7 +854,7 @@ async fn bulk_submit(cx: &Cx, Form(form): Form<BulkForm>) -> Result<impl View> { | ||
| 849 | 854 | (None, Some((echo, repos))) |
| 850 | 855 | } |
| 851 | 856 | }; |
| 852 | - Ok(view! { cx => | |
| 857 | + Ok(view! { | |
| 853 | 858 | shell(title: g::t(lang, K::BulkTitle), viewer: Some(&viewer), |
| 854 | 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 | 863 | /// The bulk page body: the picker once a listing exists, the lookup form otherwise. |
| 859 | 864 | #[component] |
| 860 | 865 | async fn bulk_stage( |
| 866 | + cx: &Cx, | |
| 861 | 867 | lang: Lang, |
| 862 | 868 | username: String, |
| 863 | 869 | csrf: &str, |
| @@ -885,7 +891,7 @@ async fn run_bulk( | ||
| 885 | 891 | instance: &str, |
| 886 | 892 | form: &BulkForm, |
| 887 | 893 | ) -> Result<std::convert::Infallible> { |
| 888 | - let state = app_context::<AppState>(cx); | |
| 894 | + let state = context::<AppState>(cx); | |
| 889 | 895 | let mut picked: Vec<(usize, &String)> = form |
| 890 | 896 | .extra |
| 891 | 897 | .iter() |
| @@ -1025,7 +1031,7 @@ async fn load_job_rows( | ||
| 1025 | 1031 | |
| 1026 | 1032 | /// The import job rows, shared by the Import history page and the recent list on the Import tab. |
| 1027 | 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 | 1035 | Ok(view! { |
| 1030 | 1036 | <div> |
| 1031 | 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 | 1053 | #[component] |
| 1048 | 1054 | async fn jobs_list( |
| 1055 | + cx: &Cx, | |
| 1049 | 1056 | lang: Lang, |
| 1050 | 1057 | username: String, |
| 1051 | 1058 | jobs: Vec<(ImportJob, Option<Repo>)>, |
| @@ -1108,7 +1115,7 @@ async fn jobs_fingerprint(state: &AppState, user_id: &str) -> Result<String> { | ||
| 1108 | 1115 | #[route(GET "/import/events")] |
| 1109 | 1116 | async fn jobs_events(cx: &Cx) -> Result<Response> { |
| 1110 | 1117 | let viewer = require_user(cx).await?; |
| 1111 | - let state = app_context::<AppState>(cx).clone(); | |
| 1118 | + let state = context::<AppState>(cx).clone(); | |
| 1112 | 1119 | let user_id = viewer.0.id.clone(); |
| 1113 | 1120 | stream_changes( |
| 1114 | 1121 | cx, |
| @@ -1130,7 +1137,7 @@ const HISTORY_ROWS: u64 = 10; | ||
| 1130 | 1137 | async fn jobs_page(cx: &Cx) -> Result<impl View> { |
| 1131 | 1138 | let viewer = require_user(cx).await?; |
| 1132 | 1139 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 1133 | - let state = app_context::<AppState>(cx); | |
| 1140 | + let state = context::<AppState>(cx); | |
| 1134 | 1141 | let query = query_params::<JobsQuery>(cx)?; |
| 1135 | 1142 | let all = state.store.list_import_jobs(&viewer.0.id, 1000).await?; |
| 1136 | 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 | 1164 | .clone() |
| 1158 | 1165 | .filter(|s| !s.is_empty() && s.len() < 2000) |
| 1159 | 1166 | .map(|s| g::bulk_skipped(lang, &s)); |
| 1160 | - Ok(view! { cx => | |
| 1167 | + Ok(view! { | |
| 1161 | 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 | 1172 | #[component] |
| 1166 | 1173 | async fn job_view( |
| 1174 | + cx: &Cx, | |
| 1167 | 1175 | lang: Lang, |
| 1168 | 1176 | username: String, |
| 1169 | 1177 | csrf: &str, |
| @@ -1256,8 +1264,8 @@ async fn job_view( | ||
| 1256 | 1264 | |
| 1257 | 1265 | /// The job when the viewer owns it. Anyone else gets 404. |
| 1258 | 1266 | async fn owned_job(cx: &Cx, viewer: &User) -> Result<ImportJob> { |
| 1259 | - let id = path_param::<JobId>(cx).to_owned(); | |
| 1260 | - let state = app_context::<AppState>(cx); | |
| 1267 | + let id = job_id(cx).to_owned(); | |
| 1268 | + let state = context::<AppState>(cx); | |
| 1261 | 1269 | match state.store.import_job(&id).await? { |
| 1262 | 1270 | Some(job) if job.user_id == viewer.id => Ok(job), |
| 1263 | 1271 | _ => Err(not_found().into()), |
| @@ -1268,13 +1276,13 @@ async fn owned_job(cx: &Cx, viewer: &User) -> Result<ImportJob> { | ||
| 1268 | 1276 | async fn job_page(cx: &Cx) -> Result<impl View> { |
| 1269 | 1277 | let viewer = require_user(cx).await?; |
| 1270 | 1278 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 1271 | - let state = app_context::<AppState>(cx); | |
| 1279 | + let state = context::<AppState>(cx); | |
| 1272 | 1280 | let job = owned_job(cx, &viewer.0).await?; |
| 1273 | 1281 | let repo = job_repo(state, Some(&viewer.0), &job).await?; |
| 1274 | 1282 | let log = state.store.list_import_events(&job.id, 200).await?; |
| 1275 | 1283 | let csrf = viewer.1.csrf_token.clone(); |
| 1276 | 1284 | let title = job.source_ref.clone(); |
| 1277 | - Ok(view! { cx => | |
| 1285 | + Ok(view! { | |
| 1278 | 1286 | shell(title: title.as_str(), viewer: Some(&viewer), |
| 1279 | 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 | 1295 | let viewer = require_user(cx).await?; |
| 1288 | 1296 | let job = owned_job(cx, &viewer.0).await?; |
| 1289 | 1297 | let query = query_params::<SeenQuery>(cx)?; |
| 1290 | - let state = app_context::<AppState>(cx); | |
| 1298 | + let state = context::<AppState>(cx); | |
| 1291 | 1299 | let seen = query.v.clone().unwrap_or_default(); |
| 1292 | 1300 | // Subscribed before the job is read again below, so a change in between is not lost. |
| 1293 | 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 | 1383 | #[route(POST "/import/{job_id}/retry")] |
| 1376 | 1384 | async fn job_retry(cx: &Cx, Form(form): Form<RetryForm>) -> Result<SeeOther> { |
| 1377 | 1385 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 1378 | - let state = app_context::<AppState>(cx); | |
| 1386 | + let state = context::<AppState>(cx); | |
| 1379 | 1387 | let job = owned_job(cx, &viewer.0).await?; |
| 1380 | 1388 | let href = format!("/import/{}", job.id); |
| 1381 | 1389 | retry_job(state, job, &form.token).await?; |
| @@ -1414,7 +1422,13 @@ fn source_label(raw: &str) -> &'static str { | ||
| 1414 | 1422 | } |
| 1415 | 1423 | |
| 1416 | 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 | 1432 | let count = rows.len(); |
| 1419 | 1433 | let empty = rows.is_empty(); |
| 1420 | 1434 | Ok(view! { |
| @@ -1462,10 +1476,10 @@ async fn retry_list(lang: Lang, username: String, csrf: &str, rows: Vec<(ImportJ | ||
| 1462 | 1476 | async fn retry_page(cx: &Cx) -> Result<impl View> { |
| 1463 | 1477 | let viewer = require_user(cx).await?; |
| 1464 | 1478 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 1465 | - let state = app_context::<AppState>(cx); | |
| 1479 | + let state = context::<AppState>(cx); | |
| 1466 | 1480 | let rows = retry_candidates(state, &viewer.0).await?; |
| 1467 | 1481 | let csrf = viewer.1.csrf_token.clone(); |
| 1468 | - Ok(view! { cx => | |
| 1482 | + Ok(view! { | |
| 1469 | 1483 | shell(title: g::t(lang, K::RetryFailedTitle), viewer: Some(&viewer), |
| 1470 | 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 | 1499 | #[route(POST "/import/retry")] |
| 1486 | 1500 | async fn retry_submit(cx: &Cx, Form(form): Form<RetrySelectedForm>) -> Result<SeeOther> { |
| 1487 | 1501 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 1488 | - let state = app_context::<AppState>(cx); | |
| 1502 | + let state = context::<AppState>(cx); | |
| 1489 | 1503 | let mut picked: Vec<(usize, &String)> = form |
| 1490 | 1504 | .extra |
| 1491 | 1505 | .iter() |
crates/forge-web/src/pages/invites.rsmodified+3 -2
| @@ -6,7 +6,7 @@ use forge_core::store::validate_email; | ||
| 6 | 6 | use forge_core::{AuditAction, Registration}; |
| 7 | 7 | use serde::Deserialize; |
| 8 | 8 | use topcoat::Result; |
| 9 | -use topcoat::context::{Cx, app_context}; | |
| 9 | +use topcoat::context::{Cx, context}; | |
| 10 | 10 | use topcoat::router::content::Form; |
| 11 | 11 | use topcoat::router::error::forbidden; |
| 12 | 12 | use topcoat::router::page; |
| @@ -31,6 +31,7 @@ struct InviteForm { | ||
| 31 | 31 | |
| 32 | 32 | #[component] |
| 33 | 33 | async fn invite_body( |
| 34 | + cx: &Cx, | |
| 34 | 35 | lang: Lang, |
| 35 | 36 | csrf: &str, |
| 36 | 37 | notice: Option<&'static str>, |
| @@ -78,7 +79,7 @@ async fn invites_submit(cx: &Cx, Form(form): Form<InviteForm>) -> Result<impl Vi | ||
| 78 | 79 | if !check_csrf(&viewer.1, &form.csrf) { |
| 79 | 80 | return Err(forbidden().into()); |
| 80 | 81 | } |
| 81 | - let state = app_context::<AppState>(cx); | |
| 82 | + let state = context::<AppState>(cx); | |
| 82 | 83 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 83 | 84 | let address = form.email.trim().to_owned(); |
| 84 | 85 | let mut notice = None; |
crates/forge-web/src/pages/issue_meta.rsmodified+25 -19
| @@ -9,7 +9,7 @@ use forge_core::User; | ||
| 9 | 9 | use forge_core::authz::{Action, authorize}; |
| 10 | 10 | use forge_core::issues::{Issue, Label}; |
| 11 | 11 | use topcoat::Result; |
| 12 | -use topcoat::context::{Cx, app_context}; | |
| 12 | +use topcoat::context::{Cx, context}; | |
| 13 | 13 | use topcoat::router::content::RawForm; |
| 14 | 14 | use topcoat::router::error::{forbidden, not_found, see_other}; |
| 15 | 15 | use topcoat::router::{page, path_param}; |
| @@ -85,7 +85,12 @@ pub(crate) fn refusal_message(e: forge_core::Error) -> Result<String> { | ||
| 85 | 85 | /// Links between the issue-adjacent pages of a repo: Issues, Labels and Milestones. The one named |
| 86 | 86 | /// by `active` is the current page. |
| 87 | 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 | 94 | let issues = format!("/{title}/issues"); |
| 90 | 95 | let labels = format!("/{title}/labels"); |
| 91 | 96 | let milestones = format!("/{title}/milestones"); |
| @@ -170,7 +175,7 @@ pub(crate) async fn item_from_path( | ||
| 170 | 175 | let Some(n) = number.parse::<i64>().ok() else { |
| 171 | 176 | return Err(not_found().into()); |
| 172 | 177 | }; |
| 173 | - let store = &app_context::<AppState>(cx).store; | |
| 178 | + let store = &context::<AppState>(cx).store; | |
| 174 | 179 | let found = match kind { |
| 175 | 180 | ItemKind::Issue => store.issue_by_number(&ctx.repo.id, n).await?, |
| 176 | 181 | ItemKind::Pull => store |
| @@ -197,6 +202,7 @@ pub(crate) fn item_href(ctx: &RepoCtx, kind: ItemKind, number: i64) -> String { | ||
| 197 | 202 | /// The error box with a link back to where the action came from, in the viewer's language. |
| 198 | 203 | #[component] |
| 199 | 204 | pub(crate) async fn action_error_at( |
| 205 | + cx: &Cx, | |
| 200 | 206 | lang: Lang, |
| 201 | 207 | message: String, |
| 202 | 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 | 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?; | |
| 228 | - let item = item_from_path(cx, &ctx, kind, path_param::<Number>(cx)).await?; | |
| 233 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 234 | + let item = item_from_path(cx, &ctx, kind, number(cx)).await?; | |
| 229 | 235 | let user = triage_guard(cx, &ctx, &form_field(&fields, "csrf")).await?; |
| 230 | 236 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u)); |
| 231 | 237 | let ids = form_all(&fields, "label"); |
| 232 | 238 | let back = item_href(&ctx, kind, item.number); |
| 233 | - let state = app_context::<AppState>(cx); | |
| 239 | + let state = context::<AppState>(cx); | |
| 234 | 240 | let pull = matches!(kind, ItemKind::Pull); |
| 235 | 241 | let before = item_labels(state, &item.id).await; |
| 236 | 242 | let result = state.store.set_issue_labels(&item.id, &user.id, &ids).await; |
| 237 | 243 | if let Err(e) = result { |
| 238 | 244 | let message = refusal_message(e)?; |
| 239 | - return Ok(view! { cx => | |
| 245 | + return Ok(view! { | |
| 240 | 246 | shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(), |
| 241 | 247 | action_error_at(lang: lang, message: message, back: back)) |
| 242 | 248 | }); |
| @@ -264,8 +270,8 @@ async fn assignees_save( | ||
| 264 | 270 | kind: ItemKind, |
| 265 | 271 | fields: Vec<(String, String)>, |
| 266 | 272 | ) -> Result<impl View> { |
| 267 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 268 | - let item = item_from_path(cx, &ctx, kind, path_param::<Number>(cx)).await?; | |
| 273 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 274 | + let item = item_from_path(cx, &ctx, kind, number(cx)).await?; | |
| 269 | 275 | let user = triage_guard(cx, &ctx, &form_field(&fields, "csrf")).await?; |
| 270 | 276 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u)); |
| 271 | 277 | let usernames: Vec<String> = form_field(&fields, "assignees") |
| @@ -275,7 +281,7 @@ async fn assignees_save( | ||
| 275 | 281 | .map(str::to_owned) |
| 276 | 282 | .collect(); |
| 277 | 283 | let back = item_href(&ctx, kind, item.number); |
| 278 | - let state = app_context::<AppState>(cx); | |
| 284 | + let state = context::<AppState>(cx); | |
| 279 | 285 | let pull = matches!(kind, ItemKind::Pull); |
| 280 | 286 | let before = assignee_names(state, &item.id).await; |
| 281 | 287 | let result = state |
| @@ -284,7 +290,7 @@ async fn assignees_save( | ||
| 284 | 290 | .await; |
| 285 | 291 | if let Err(e) = result { |
| 286 | 292 | let message = refusal_message(e)?; |
| 287 | - return Ok(view! { cx => | |
| 293 | + return Ok(view! { | |
| 288 | 294 | shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(), |
| 289 | 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 | 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?; | |
| 339 | - let item = item_from_path(cx, &ctx, kind, path_param::<Number>(cx)).await?; | |
| 344 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 345 | + let item = item_from_path(cx, &ctx, kind, number(cx)).await?; | |
| 340 | 346 | let user = triage_guard(cx, &ctx, &form_field(&fields, "csrf")).await?; |
| 341 | 347 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u)); |
| 342 | 348 | let locked = form_field(&fields, "locked") == "1"; |
| 343 | 349 | let reason = form_field(&fields, "reason"); |
| 344 | 350 | let back = item_href(&ctx, kind, item.number); |
| 345 | - let state = app_context::<AppState>(cx); | |
| 351 | + let state = context::<AppState>(cx); | |
| 346 | 352 | let result = state |
| 347 | 353 | .store |
| 348 | 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 | 357 | Ok(changed) => changed, |
| 352 | 358 | Err(e) => { |
| 353 | 359 | let message = refusal_message(e)?; |
| 354 | - return Ok(view! { cx => | |
| 360 | + return Ok(view! { | |
| 355 | 361 | shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(), |
| 356 | 362 | action_error_at(lang: lang, message: message, back: back)) |
| 357 | 363 | }); |
| @@ -383,14 +389,14 @@ async fn milestone_save( | ||
| 383 | 389 | kind: ItemKind, |
| 384 | 390 | fields: Vec<(String, String)>, |
| 385 | 391 | ) -> Result<impl View> { |
| 386 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 387 | - let item = item_from_path(cx, &ctx, kind, path_param::<Number>(cx)).await?; | |
| 392 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 393 | + let item = item_from_path(cx, &ctx, kind, number(cx)).await?; | |
| 388 | 394 | let user = triage_guard(cx, &ctx, &form_field(&fields, "csrf")).await?; |
| 389 | 395 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u)); |
| 390 | 396 | let milestone_id = form_field(&fields, "milestone_id"); |
| 391 | 397 | let milestone = (!milestone_id.is_empty()).then_some(milestone_id.as_str()); |
| 392 | 398 | let back = item_href(&ctx, kind, item.number); |
| 393 | - let state = app_context::<AppState>(cx); | |
| 399 | + let state = context::<AppState>(cx); | |
| 394 | 400 | let before = match item.milestone_id.as_deref() { |
| 395 | 401 | Some(id) => milestone_title(state, &ctx.repo.id, id).await, |
| 396 | 402 | None => None, |
| @@ -401,7 +407,7 @@ async fn milestone_save( | ||
| 401 | 407 | .await; |
| 402 | 408 | if let Err(e) = result { |
| 403 | 409 | let message = refusal_message(e)?; |
| 404 | - return Ok(view! { cx => | |
| 410 | + return Ok(view! { | |
| 405 | 411 | shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(), |
| 406 | 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 | 4 | //! On a pull request the timeline also holds its submitted reviews, each with its threads. |
| 5 | 5 | |
| 6 | 6 | use std::collections::HashSet; |
| 7 | +use topcoat::context::Cx; | |
| 7 | 8 | |
| 8 | 9 | use forge_core::{Action, Comment, Issue, IssueEvent, IssueState, Session, StateReason, User}; |
| 9 | 10 | use forge_core::{Reaction, ReactionSummary, ReactionTarget}; |
| @@ -25,13 +26,13 @@ use crate::pages::repo_ctx::RepoCtx; | ||
| 25 | 26 | use crate::pages::tree::link_context; |
| 26 | 27 | use crate::render::markdown::{LinkContext, render_markdown}; |
| 27 | 28 | use crate::state::AppState; |
| 29 | +use crate::views::parts::{confirm_act, post_act, reveal}; | |
| 28 | 30 | use crate::views::review_thread::{ThreadCtx, review_thread_in}; |
| 29 | 31 | use crate::views::user_facing_message; |
| 30 | 32 | use crate::views::{ |
| 31 | - alert, avatar_url, avatar_url_unknown, display_name, iso_time, now_unix, relative_time, repo_href, short_oid, | |
| 32 | - user_href, user_link, | |
| 33 | + alert, avatar_url, avatar_url_unknown, display_name, iso_time, now_unix, relative_time, | |
| 34 | + repo_href, short_oid, user_href, user_link, | |
| 33 | 35 | }; |
| 34 | -use crate::views::parts::{confirm_act, post_act, reveal}; | |
| 35 | 36 | use crate::webhooks::emit::{Sender, emit_comment, emit_item_action}; |
| 36 | 37 | |
| 37 | 38 | /// 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 | 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 | 438 | let CommentView { |
| 438 | 439 | anchor, |
| 439 | 440 | author, |
| @@ -499,7 +500,7 @@ pub(crate) async fn comment_item(lang: Lang, item: CommentView) -> Result<impl V | ||
| 499 | 500 | |
| 500 | 501 | /// The reaction row under an item or comment: the buttons, then the picker when the viewer may react. |
| 501 | 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 | 504 | let ReactionBar { |
| 504 | 505 | chips, |
| 505 | 506 | picker, |
| @@ -519,7 +520,11 @@ pub(crate) async fn reaction_row(lang: Lang, bar: ReactionBar) -> Result<impl Vi | ||
| 519 | 520 | |
| 520 | 521 | /// The React tool: a word that opens the reaction options in place. |
| 521 | 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 | 528 | Ok(view! { |
| 524 | 529 | <details class="reaction-picker"> |
| 525 | 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 | 540 | /// One reaction button. Enabled buttons are POST forms that toggle the viewer's reaction; the |
| 536 | 541 | /// others only show the emoji and count. |
| 537 | 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 | 544 | let ReactionButton { |
| 540 | 545 | action, |
| 541 | 546 | csrf, |
| @@ -581,7 +586,7 @@ pub(crate) async fn reaction_button(button: ReactionButton) -> Result<impl View> | ||
| 581 | 586 | } |
| 582 | 587 | |
| 583 | 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 | 590 | let EventLine { |
| 586 | 591 | actor, |
| 587 | 592 | when, |
| @@ -617,8 +622,11 @@ pub(crate) async fn event_item(line: EventLine) -> Result<impl View> { | ||
| 617 | 622 | /// Consecutive events by one actor, one line: the actor, each event's words joined with " · ", then |
| 618 | 623 | /// the time of the last one. |
| 619 | 624 | #[component] |
| 620 | -pub(crate) async fn event_run(lines: Vec<EventLine>) -> Result<impl View> { | |
| 621 | - let actor = lines.first().map(|line| line.actor.clone()).unwrap_or_default(); | |
| 625 | +pub(crate) async fn event_run(cx: &Cx, lines: Vec<EventLine>) -> Result<impl View> { | |
| 626 | + let actor = lines | |
| 627 | + .first() | |
| 628 | + .map(|line| line.actor.clone()) | |
| 629 | + .unwrap_or_default(); | |
| 622 | 630 | let when = lines.last().map(|line| line.when.clone()); |
| 623 | 631 | Ok(view! { |
| 624 | 632 | <div class="thread-event"> |
| @@ -663,7 +671,7 @@ fn dismissed_verb(lang: Lang, from: Option<ReviewState>) -> &'static str { | ||
| 663 | 671 | |
| 664 | 672 | /// One submitted review: the reviewer, the verb, the dismissal reason, the body, then its threads. |
| 665 | 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 | 675 | let ReviewView { |
| 668 | 676 | anchor, |
| 669 | 677 | author, |
| @@ -705,7 +713,7 @@ pub(crate) async fn review_item(lang: Lang, review: ReviewView) -> Result<impl V | ||
| 705 | 713 | } |
| 706 | 714 | |
| 707 | 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 | 717 | Ok(view! { |
| 710 | 718 | match entry { |
| 711 | 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 | 727 | /// The body followed by every timeline entry. |
| 720 | 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 | 734 | let Discussion { body, entries, .. } = discussion; |
| 723 | 735 | Ok(view! { |
| 724 | 736 | <div class="issue-timeline"> |
| @@ -1023,7 +1035,15 @@ pub(crate) fn reaction_bar_for( | ||
| 1023 | 1035 | .collect(); |
| 1024 | 1036 | let picker = Reaction::ALL |
| 1025 | 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 | 1047 | .collect(); |
| 1028 | 1048 | Some(ReactionBar { |
| 1029 | 1049 | chips, |
| @@ -1219,6 +1239,7 @@ pub(crate) async fn load_sidebar(state: &AppState, repo_id: &str, item: &Issue) | ||
| 1219 | 1239 | |
| 1220 | 1240 | #[component] |
| 1221 | 1241 | pub(crate) async fn labels_box( |
| 1242 | + cx: &Cx, | |
| 1222 | 1243 | lang: Lang, |
| 1223 | 1244 | write: bool, |
| 1224 | 1245 | action: String, |
| @@ -1266,6 +1287,7 @@ pub(crate) async fn labels_box( | ||
| 1266 | 1287 | |
| 1267 | 1288 | #[component] |
| 1268 | 1289 | pub(crate) async fn assignees_box( |
| 1290 | + cx: &Cx, | |
| 1269 | 1291 | lang: Lang, |
| 1270 | 1292 | write: bool, |
| 1271 | 1293 | action: String, |
| @@ -1312,6 +1334,7 @@ pub(crate) async fn assignees_box( | ||
| 1312 | 1334 | |
| 1313 | 1335 | #[component] |
| 1314 | 1336 | pub(crate) async fn milestone_box( |
| 1337 | + cx: &Cx, | |
| 1315 | 1338 | lang: Lang, |
| 1316 | 1339 | write: bool, |
| 1317 | 1340 | action: String, |
| @@ -1358,6 +1381,7 @@ pub(crate) async fn milestone_box( | ||
| 1358 | 1381 | /// triage holders. Locking is one of the tools at the foot of the sidebar (`item_tools`). |
| 1359 | 1382 | #[component] |
| 1360 | 1383 | pub(crate) async fn lock_box( |
| 1384 | + cx: &Cx, | |
| 1361 | 1385 | lang: Lang, |
| 1362 | 1386 | write: bool, |
| 1363 | 1387 | action: String, |
| @@ -1395,6 +1419,7 @@ pub(crate) async fn lock_box( | ||
| 1395 | 1419 | /// reason. `pin` is the pin action when the issue is not pinned and the viewer may pin it. |
| 1396 | 1420 | #[component] |
| 1397 | 1421 | pub(crate) async fn item_tools( |
| 1422 | + cx: &Cx, | |
| 1398 | 1423 | lang: Lang, |
| 1399 | 1424 | pin: Option<String>, |
| 1400 | 1425 | lock: Option<String>, |
| @@ -1439,6 +1464,7 @@ pub(crate) async fn item_tools( | ||
| 1439 | 1464 | /// `(pinned, action)` for an issue; the pinned row sits in the page (`pin_box`). |
| 1440 | 1465 | #[component] |
| 1441 | 1466 | pub(crate) async fn item_sidebar( |
| 1467 | + cx: &Cx, | |
| 1442 | 1468 | lang: Lang, |
| 1443 | 1469 | write: bool, |
| 1444 | 1470 | base: String, |
| @@ -1492,6 +1518,7 @@ pub(crate) const COMMENT_FORM: &str = "item-comment"; | ||
| 1492 | 1518 | /// and is given only when the viewer may close the item. |
| 1493 | 1519 | #[component] |
| 1494 | 1520 | pub(crate) async fn item_head_tools( |
| 1521 | + cx: &Cx, | |
| 1495 | 1522 | lang: Lang, |
| 1496 | 1523 | close: Option<(bool, String)>, |
| 1497 | 1524 | notify: Option<NotifyBox>, |
| @@ -1523,6 +1550,7 @@ pub(crate) async fn item_head_tools( | ||
| 1523 | 1550 | /// readers only. |
| 1524 | 1551 | #[component] |
| 1525 | 1552 | pub(crate) async fn comment_form( |
| 1553 | + cx: &Cx, | |
| 1526 | 1554 | lang: Lang, |
| 1527 | 1555 | action: String, |
| 1528 | 1556 | csrf: String, |
crates/forge-web/src/pages/issue_pin.rsmodified+6 -5
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | use serde::Deserialize; |
| 7 | 7 | use serde_json::Value as Json; |
| 8 | 8 | use topcoat::Result; |
| 9 | -use topcoat::context::{Cx, app_context}; | |
| 9 | +use topcoat::context::{Cx, context}; | |
| 10 | 10 | use topcoat::router::content::Form; |
| 11 | 11 | use topcoat::router::error::{bad_request, see_other}; |
| 12 | 12 | use topcoat::router::{page, path_param}; |
| @@ -37,8 +37,8 @@ struct PinForm { | ||
| 37 | 37 | |
| 38 | 38 | #[page(POST "/{owner}/{repo}/issues/{number}/pin")] |
| 39 | 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?; | |
| 41 | - let issue = item_from_path(cx, &ctx, ItemKind::Issue, path_param::<Number>(cx)).await?; | |
| 40 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 41 | + let issue = item_from_path(cx, &ctx, ItemKind::Issue, number(cx)).await?; | |
| 42 | 42 | let user = triage_guard(cx, &ctx, &form.csrf).await?; |
| 43 | 43 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u)); |
| 44 | 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 | 47 | _ => return Err(bad_request("pinned must be 1 or 0").into()), |
| 48 | 48 | }; |
| 49 | 49 | let back = item_href(&ctx, ItemKind::Issue, issue.number); |
| 50 | - let state = app_context::<AppState>(cx); | |
| 50 | + let state = context::<AppState>(cx); | |
| 51 | 51 | let result = if pin { |
| 52 | 52 | state.store.pin_issue(&ctx.repo.id, &issue.id).await |
| 53 | 53 | } else { |
| @@ -66,7 +66,7 @@ async fn issue_pin_save(cx: &Cx, Form(form): Form<PinForm>) -> Result<impl View> | ||
| 66 | 66 | } |
| 67 | 67 | Err(e) => { |
| 68 | 68 | let message = refusal_message(e)?; |
| 69 | - return Ok(view! { cx => | |
| 69 | + return Ok(view! { | |
| 70 | 70 | shell(title: g::t(lang, K::CouldNotSave), viewer: ctx.viewer.as_ref(), |
| 71 | 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 | 79 | /// Pinning is a tool at the foot of the sidebar (`item_tools`). |
| 80 | 80 | #[component] |
| 81 | 81 | pub(crate) async fn pin_box( |
| 82 | + cx: &Cx, | |
| 82 | 83 | lang: Lang, |
| 83 | 84 | write: bool, |
| 84 | 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 | 328 | .contains(&format!("/tahinli/forge/issues/{number}\"")), |
| 329 | 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 | 335 | let list_at = reply.body.find("class=\"line issue-row\"").expect("list"); |
| 333 | 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 | 9 | use forge_core::{validate_body, validate_title}; |
| 10 | 10 | use serde::Deserialize; |
| 11 | 11 | use topcoat::Result; |
| 12 | -use topcoat::context::{Cx, app_context}; | |
| 12 | +use topcoat::context::{Cx, context}; | |
| 13 | 13 | use topcoat::router::content::Form; |
| 14 | 14 | use topcoat::router::error::{SeeOther, forbidden, not_found, see_other}; |
| 15 | 15 | use topcoat::router::{page, path_param, route}; |
| @@ -49,7 +49,7 @@ async fn issue_page( | ||
| 49 | 49 | error: Option<String>, |
| 50 | 50 | ) -> Result<impl View> { |
| 51 | 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 | 53 | let owner = ctx.repo.owner_name.clone(); |
| 54 | 54 | let name = ctx.repo.name.clone(); |
| 55 | 55 | let number = issue.number; |
| @@ -104,7 +104,7 @@ async fn issue_page( | ||
| 104 | 104 | let live_href = item_live_url(&owner, &name, number); |
| 105 | 105 | |
| 106 | 106 | let header = ctx.head(state, "issues").await?; |
| 107 | - Ok(view! { cx => | |
| 107 | + Ok(view! { | |
| 108 | 108 | shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(), extra_stylesheet: Some(labels_href.as_str()), |
| 109 | 109 | repo_head(head: header, title: Some(issue.title.clone()), sub: sub, |
| 110 | 110 | <span class="num">(number_label.as_str())</span> |
| @@ -134,9 +134,9 @@ async fn issue_page( | ||
| 134 | 134 | |
| 135 | 135 | #[page("/{owner}/{repo}/issues/{number}")] |
| 136 | 136 | async fn issue_show(cx: &Cx) -> Result<impl View> { |
| 137 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 138 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 139 | - let state = app_context::<AppState>(cx); | |
| 137 | + let number = parse_number(number(cx))?; | |
| 138 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 139 | + let state = context::<AppState>(cx); | |
| 140 | 140 | let Some(issue) = state.store.issue_by_number(&ctx.repo.id, number).await? else { |
| 141 | 141 | if state |
| 142 | 142 | .store |
| @@ -161,11 +161,11 @@ async fn issue_show(cx: &Cx) -> Result<impl View> { | ||
| 161 | 161 | /// reopen; without that the request is 403 and nothing is written. |
| 162 | 162 | #[page(POST "/{owner}/{repo}/issues/{number}/comment")] |
| 163 | 163 | async fn issue_comment(cx: &Cx, Form(form): Form<CommentForm>) -> Result<impl View> { |
| 164 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 165 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 164 | + let number = parse_number(number(cx))?; | |
| 165 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 166 | 166 | let (user, session) = require_user(cx).await?; |
| 167 | 167 | check_write(&ctx, &session, &form.csrf)?; |
| 168 | - let state = app_context::<AppState>(cx); | |
| 168 | + let state = context::<AppState>(cx); | |
| 169 | 169 | let issue = issue_for(state, &ctx, number).await?; |
| 170 | 170 | let lang = i18n::lang(cx, Some(&user)); |
| 171 | 171 | match post_comment(lang, state, &ctx, &user, &issue, false, &form).await? { |
| @@ -205,7 +205,7 @@ async fn edit_item_page( | ||
| 205 | 205 | error: Option<String>, |
| 206 | 206 | ) -> Result<impl View> { |
| 207 | 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 | 209 | let owner = ctx.repo.owner_name.clone(); |
| 210 | 210 | let name = ctx.repo.name.clone(); |
| 211 | 211 | let csrf = csrf_of(&ctx); |
| @@ -215,7 +215,7 @@ async fn edit_item_page( | ||
| 215 | 215 | let page_title = g::edit_title(lang, number, &format!("{owner}/{name}")); |
| 216 | 216 | let heading = g::edit_heading(lang, kind == ItemKind::Pull, number); |
| 217 | 217 | let header = ctx.head(state, kind_tab(kind)).await?; |
| 218 | - Ok(view! { cx => | |
| 218 | + Ok(view! { | |
| 219 | 219 | shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(), |
| 220 | 220 | repo_head(head: header, title: Some(heading)) |
| 221 | 221 | <div class="sheet fit"> |
| @@ -252,10 +252,10 @@ fn kind_tab(kind: ItemKind) -> &'static str { | ||
| 252 | 252 | |
| 253 | 253 | /// Shows the edit form. Only the author or Triage; anyone else is 403. |
| 254 | 254 | async fn item_edit_form(cx: &Cx, kind: ItemKind) -> Result<impl View> { |
| 255 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 256 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 255 | + let number = parse_number(number(cx))?; | |
| 256 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 257 | 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 | 259 | if !may_change(&ctx, &item.author_id) { |
| 260 | 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 | 265 | /// Saves the title and body. Only the author or Triage; the store records the edit history. |
| 266 | 266 | async fn item_edit_save(cx: &Cx, kind: ItemKind, form: IssueForm) -> Result<impl View> { |
| 267 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 268 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 267 | + let number = parse_number(number(cx))?; | |
| 268 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 269 | 269 | let (user, session) = require_user(cx).await?; |
| 270 | 270 | check_write(&ctx, &session, &form.csrf)?; |
| 271 | - let state = app_context::<AppState>(cx); | |
| 271 | + let state = context::<AppState>(cx); | |
| 272 | 272 | let item = item_for(state, &ctx, kind, number).await?; |
| 273 | 273 | if !may_change(&ctx, &item.author_id) { |
| 274 | 274 | return Err(forbidden().into()); |
| @@ -313,7 +313,7 @@ async fn edit_comment_page( | ||
| 313 | 313 | error: Option<String>, |
| 314 | 314 | ) -> Result<impl View> { |
| 315 | 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 | 317 | let owner = ctx.repo.owner_name.clone(); |
| 318 | 318 | let name = ctx.repo.name.clone(); |
| 319 | 319 | let csrf = csrf_of(&ctx); |
| @@ -330,7 +330,7 @@ async fn edit_comment_page( | ||
| 330 | 330 | ); |
| 331 | 331 | let page_title = g::edit_comment_title(lang, number, &format!("{owner}/{name}")); |
| 332 | 332 | let header = ctx.head(state, kind_tab(kind)).await?; |
| 333 | - Ok(view! { cx => | |
| 333 | + Ok(view! { | |
| 334 | 334 | shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(), |
| 335 | 335 | repo_head(head: header, title: Some(g::t(lang, K::EditComment).to_owned())) |
| 336 | 336 | <div class="sheet fit"> |
| @@ -355,12 +355,12 @@ async fn edit_comment_page( | ||
| 355 | 355 | |
| 356 | 356 | /// Shows the edit form for a comment. Its author or Triage; anyone else is 403. |
| 357 | 357 | async fn item_comment_edit_form(cx: &Cx, kind: ItemKind) -> Result<impl View> { |
| 358 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 359 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 358 | + let number = parse_number(number(cx))?; | |
| 359 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 360 | 360 | require_user(cx).await?; |
| 361 | - let state = app_context::<AppState>(cx); | |
| 361 | + let state = context::<AppState>(cx); | |
| 362 | 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 | 364 | if !may_change(&ctx, &comment.author_id) { |
| 365 | 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 | 379 | /// Saves an edited comment. Its author or Triage; the store records the previous body. |
| 380 | 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))?; | |
| 382 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 381 | + let number = parse_number(number(cx))?; | |
| 382 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 383 | 383 | let (user, session) = require_user(cx).await?; |
| 384 | 384 | check_write(&ctx, &session, &form.csrf)?; |
| 385 | - let state = app_context::<AppState>(cx); | |
| 385 | + let state = context::<AppState>(cx); | |
| 386 | 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 | 388 | if !may_change(&ctx, &comment.author_id) { |
| 389 | 389 | return Err(forbidden().into()); |
| 390 | 390 | } |
| @@ -446,13 +446,13 @@ struct CsrfForm { | ||
| 446 | 446 | |
| 447 | 447 | /// Deletes one comment: its author or Triage. The item's comment count goes down. |
| 448 | 448 | async fn item_comment_delete(cx: &Cx, kind: ItemKind, form: CsrfForm) -> Result<SeeOther> { |
| 449 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 450 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 449 | + let number = parse_number(number(cx))?; | |
| 450 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 451 | 451 | let (user, session) = require_user(cx).await?; |
| 452 | 452 | check_write(&ctx, &session, &form.csrf)?; |
| 453 | - let state = app_context::<AppState>(cx); | |
| 453 | + let state = context::<AppState>(cx); | |
| 454 | 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 | 456 | if !may_change(&ctx, &comment.author_id) { |
| 457 | 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 | 9 | IssueFilter, IssueListItem, IssueSort, IssueState, validate_body, validate_title, |
| 10 | 10 | }; |
| 11 | 11 | use topcoat::Result; |
| 12 | -use topcoat::context::{Cx, app_context}; | |
| 12 | +use topcoat::context::{Cx, context}; | |
| 13 | 13 | use topcoat::router::content::RawForm; |
| 14 | 14 | use topcoat::router::error::{forbidden, see_other}; |
| 15 | 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 | 440 | #[page("/{owner}/{repo}/issues")] |
| 441 | 441 | async fn issues_list_page(cx: &Cx) -> Result<impl View> { |
| 442 | - let owner = path_param::<Owner>(cx); | |
| 443 | - let name = path_param::<Repo>(cx); | |
| 442 | + let owner = owner(cx); | |
| 443 | + let name = repo(cx); | |
| 444 | 444 | let query = query_params::<ListQuery>(cx)?; |
| 445 | 445 | let ctx = load_repo(cx, owner, name).await?; |
| 446 | - let state = app_context::<AppState>(cx); | |
| 446 | + let state = context::<AppState>(cx); | |
| 447 | 447 | let sel = Selection::parse(query); |
| 448 | 448 | let search_value = sel.search_text(); |
| 449 | 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 | 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 | 508 | let clear_href = list_href(&base, &[("state", sel.state)]); |
| 504 | 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 | 750 | /// chooser (`chooser` is `Some`) or the form. |
| 746 | 751 | #[component] |
| 747 | 752 | async fn new_issue_body( |
| 753 | + cx: &Cx, | |
| 748 | 754 | lang: Lang, |
| 749 | 755 | head: RepoHead, |
| 750 | 756 | csrf: String, |
| @@ -814,8 +820,8 @@ async fn new_issue_body( | ||
| 814 | 820 | |
| 815 | 821 | #[page("/{owner}/{repo}/issues/new")] |
| 816 | 822 | async fn new_issue_page(cx: &Cx) -> Result<impl View> { |
| 817 | - let owner = path_param::<Owner>(cx); | |
| 818 | - let name = path_param::<Repo>(cx); | |
| 823 | + let owner = owner(cx); | |
| 824 | + let name = repo(cx); | |
| 819 | 825 | let query = query_params::<NewIssueQuery>(cx)?; |
| 820 | 826 | let ctx = load_repo(cx, owner, name).await?; |
| 821 | 827 | let viewer = require_user(cx).await?; |
| @@ -823,7 +829,7 @@ async fn new_issue_page(cx: &Cx) -> Result<impl View> { | ||
| 823 | 829 | if ctx.repo.archived { |
| 824 | 830 | return Err(forbidden().into()); |
| 825 | 831 | } |
| 826 | - let state = app_context::<AppState>(cx); | |
| 832 | + let state = context::<AppState>(cx); | |
| 827 | 833 | let header = ctx.head(state, "issues").await?; |
| 828 | 834 | let title = g::new_issue_title(lang, &format!("{}/{}", ctx.repo.owner_name, ctx.repo.name)); |
| 829 | 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 | 878 | #[page(POST "/{owner}/{repo}/issues/new")] |
| 873 | 879 | async fn new_issue_submit(cx: &Cx, RawForm(raw): RawForm) -> Result<impl View> { |
| 874 | - let owner = path_param::<Owner>(cx); | |
| 875 | - let name = path_param::<Repo>(cx); | |
| 880 | + let owner = owner(cx); | |
| 881 | + let name = repo(cx); | |
| 876 | 882 | let ctx = load_repo(cx, owner, name).await?; |
| 877 | 883 | let fields = form_pairs(&raw[..]); |
| 878 | 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 | 886 | if ctx.repo.archived { |
| 881 | 887 | return Err(forbidden().into()); |
| 882 | 888 | } |
| 883 | - let state = app_context::<AppState>(cx); | |
| 889 | + let state = context::<AppState>(cx); | |
| 884 | 890 | let typed_title = form_field(&fields, "title"); |
| 885 | 891 | let typed_body = form_field(&fields, "body"); |
| 886 | 892 | let picked = form_all(&fields, "label"); |
crates/forge-web/src/pages/issues_live.rsmodified+6 -6
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | //! repo, or an issue that is not there, gets the same 404 as the page. |
| 7 | 7 | |
| 8 | 8 | use topcoat::Result; |
| 9 | -use topcoat::context::{Cx, app_context}; | |
| 9 | +use topcoat::context::{Cx, context}; | |
| 10 | 10 | use topcoat::router::error::not_found; |
| 11 | 11 | use topcoat::router::response::Response; |
| 12 | 12 | use topcoat::router::{path_param, route}; |
| @@ -33,17 +33,17 @@ pub fn item_live_url(owner: &str, repo: &str, number: i64) -> String { | ||
| 33 | 33 | /// The change stream of the issue list, labels and milestones pages. |
| 34 | 34 | #[route(GET "/{owner}/{repo}/issues/live")] |
| 35 | 35 | async fn issues_live(cx: &Cx) -> Result<Response> { |
| 36 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 37 | - let state = app_context::<AppState>(cx); | |
| 36 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 37 | + let state = context::<AppState>(cx); | |
| 38 | 38 | stream_wakes(cx, &state.live, &[Topic::RepoIssues(ctx.repo.id.clone())]) |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /// The change stream of one issue page. |
| 42 | 42 | #[route(GET "/{owner}/{repo}/issues/{number}/live")] |
| 43 | 43 | async fn issue_live(cx: &Cx) -> Result<Response> { |
| 44 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 45 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 46 | - let state = app_context::<AppState>(cx); | |
| 44 | + let number = parse_number(number(cx))?; | |
| 45 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 46 | + let state = context::<AppState>(cx); | |
| 47 | 47 | let Some(issue) = state.store.issue_by_number(&ctx.repo.id, number).await? else { |
| 48 | 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 | 14 | use sha2::{Digest, Sha256}; |
| 15 | 15 | use topcoat::Result; |
| 16 | -use topcoat::context::{Cx, app_context}; | |
| 16 | +use topcoat::context::{Cx, context}; | |
| 17 | 17 | use topcoat::router::request::headers; |
| 18 | 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 | 79 | #[route(GET "/{owner}/{repo}/labels.css")] |
| 80 | 80 | async fn labels_css(cx: &Cx) -> Result<(StatusCode, HeaderMap, String)> { |
| 81 | - let owner = path_param::<Owner>(cx); | |
| 82 | - let name = path_param::<Repo>(cx); | |
| 81 | + let owner = owner(cx); | |
| 82 | + let name = repo(cx); | |
| 83 | 83 | let ctx = load_repo(cx, owner, name).await?; |
| 84 | 84 | let if_none_match = headers(cx) |
| 85 | 85 | .get(IF_NONE_MATCH) |
| 86 | 86 | .and_then(|v| v.to_str().ok()) |
| 87 | 87 | .map(str::to_owned); |
| 88 | - let state = app_context::<AppState>(cx); | |
| 88 | + let state = context::<AppState>(cx); | |
| 89 | 89 | |
| 90 | 90 | let labels = state.store.list_labels(&ctx.repo.id).await?; |
| 91 | 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 | 7 | use serde::Deserialize; |
| 8 | 8 | use topcoat::Result; |
| 9 | -use topcoat::context::{Cx, app_context}; | |
| 9 | +use topcoat::context::{Cx, context}; | |
| 10 | 10 | use topcoat::router::content::Form; |
| 11 | 11 | use topcoat::router::error::see_other; |
| 12 | 12 | use topcoat::router::{page, path_param, query_params}; |
| @@ -80,6 +80,7 @@ fn labels_href(title: &str) -> String { | ||
| 80 | 80 | /// The header, the label list and, for triage holders, the forms. |
| 81 | 81 | #[component] |
| 82 | 82 | async fn labels_body( |
| 83 | + cx: &Cx, | |
| 83 | 84 | lang: Lang, |
| 84 | 85 | frame: RepoFrame, |
| 85 | 86 | rows: Vec<LabelRow>, |
| @@ -184,19 +185,19 @@ async fn labels_body( | ||
| 184 | 185 | /// Gets the labels page. Hidden repos are 404 (checked in `load_repo`). |
| 185 | 186 | #[page("/{owner}/{repo}/labels")] |
| 186 | 187 | async fn labels_page(cx: &Cx) -> Result<impl View> { |
| 187 | - let owner = path_param::<Owner>(cx); | |
| 188 | - let name = path_param::<Repo>(cx); | |
| 188 | + let owner = owner(cx); | |
| 189 | + let name = repo(cx); | |
| 189 | 190 | let query = query_params::<LabelsQuery>(cx)?; |
| 190 | 191 | let ctx = load_repo(cx, owner, name).await?; |
| 191 | 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 | 194 | let labels = store.list_labels(&ctx.repo.id).await?; |
| 194 | 195 | let counts: HashMap<String, i64> = store |
| 195 | 196 | .label_open_counts(&ctx.repo.id) |
| 196 | 197 | .await? |
| 197 | 198 | .into_iter() |
| 198 | 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 | 201 | let title = frame.title.clone(); |
| 201 | 202 | let all: Vec<LabelRow> = labels |
| 202 | 203 | .into_iter() |
| @@ -243,21 +244,19 @@ async fn labels_page(cx: &Cx) -> Result<impl View> { | ||
| 243 | 244 | /// Creates a label. A duplicate name is shown on the error page. |
| 244 | 245 | #[page(POST "/{owner}/{repo}/labels")] |
| 245 | 246 | async fn label_create(cx: &Cx, Form(form): Form<LabelForm>) -> Result<impl View> { |
| 246 | - let owner = path_param::<Owner>(cx); | |
| 247 | - let name = path_param::<Repo>(cx); | |
| 247 | + let owner = owner(cx); | |
| 248 | + let name = repo(cx); | |
| 248 | 249 | let ctx = load_repo(cx, owner, name).await?; |
| 249 | 250 | triage_guard(cx, &ctx, &form.csrf).await?; |
| 250 | 251 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u)); |
| 251 | 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 | 254 | .store |
| 254 | 255 | .create_label(&ctx.repo.id, &form.name, &form.color, &form.description) |
| 255 | 256 | .await; |
| 256 | 257 | match result { |
| 257 | 258 | Ok(_) => { |
| 258 | - app_context::<AppState>(cx) | |
| 259 | - .live | |
| 260 | - .bump_repo_issues(&ctx.repo.id); | |
| 259 | + context::<AppState>(cx).live.bump_repo_issues(&ctx.repo.id); | |
| 261 | 260 | Err(see_other(back).into()) |
| 262 | 261 | } |
| 263 | 262 | Err(e) => { |
| @@ -273,22 +272,20 @@ async fn label_create(cx: &Cx, Form(form): Form<LabelForm>) -> Result<impl View> | ||
| 273 | 272 | /// Updates a label's name, color and description. |
| 274 | 273 | #[page(POST "/{owner}/{repo}/labels/{label_id}")] |
| 275 | 274 | async fn label_update(cx: &Cx, Form(form): Form<LabelForm>) -> Result<impl View> { |
| 276 | - let owner = path_param::<Owner>(cx); | |
| 277 | - let name = path_param::<Repo>(cx); | |
| 278 | - let id = path_param::<LabelId>(cx); | |
| 275 | + let owner = owner(cx); | |
| 276 | + let name = repo(cx); | |
| 277 | + let id = label_id(cx); | |
| 279 | 278 | let ctx = load_repo(cx, owner, name).await?; |
| 280 | 279 | triage_guard(cx, &ctx, &form.csrf).await?; |
| 281 | 280 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u)); |
| 282 | 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 | 283 | .store |
| 285 | 284 | .update_label(&ctx.repo.id, id, &form.name, &form.color, &form.description) |
| 286 | 285 | .await; |
| 287 | 286 | match result { |
| 288 | 287 | Ok(()) => { |
| 289 | - app_context::<AppState>(cx) | |
| 290 | - .live | |
| 291 | - .bump_repo_issues(&ctx.repo.id); | |
| 288 | + context::<AppState>(cx).live.bump_repo_issues(&ctx.repo.id); | |
| 292 | 289 | Err(see_other(back).into()) |
| 293 | 290 | } |
| 294 | 291 | Err(e) => { |
| @@ -305,21 +302,19 @@ async fn label_update(cx: &Cx, Form(form): Form<LabelForm>) -> Result<impl View> | ||
| 305 | 302 | /// exist are skipped, so a repeated submit adds nothing. |
| 306 | 303 | #[page(POST "/{owner}/{repo}/labels/defaults")] |
| 307 | 304 | async fn label_defaults(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<impl View> { |
| 308 | - let owner = path_param::<Owner>(cx); | |
| 309 | - let name = path_param::<Repo>(cx); | |
| 305 | + let owner = owner(cx); | |
| 306 | + let name = repo(cx); | |
| 310 | 307 | let ctx = load_repo(cx, owner, name).await?; |
| 311 | 308 | triage_guard(cx, &ctx, &form.csrf).await?; |
| 312 | 309 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u)); |
| 313 | 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 | 312 | .store |
| 316 | 313 | .create_default_labels(&ctx.repo.id) |
| 317 | 314 | .await; |
| 318 | 315 | match result { |
| 319 | 316 | Ok(_) => { |
| 320 | - app_context::<AppState>(cx) | |
| 321 | - .live | |
| 322 | - .bump_repo_issues(&ctx.repo.id); | |
| 317 | + context::<AppState>(cx).live.bump_repo_issues(&ctx.repo.id); | |
| 323 | 318 | Err(see_other(back).into()) |
| 324 | 319 | } |
| 325 | 320 | Err(e) => { |
| @@ -335,22 +330,20 @@ async fn label_defaults(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<impl View | ||
| 335 | 330 | /// Deletes a label and its links to issues. |
| 336 | 331 | #[page(POST "/{owner}/{repo}/labels/{label_id}/delete")] |
| 337 | 332 | async fn label_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<impl View> { |
| 338 | - let owner = path_param::<Owner>(cx); | |
| 339 | - let name = path_param::<Repo>(cx); | |
| 340 | - let id = path_param::<LabelId>(cx); | |
| 333 | + let owner = owner(cx); | |
| 334 | + let name = repo(cx); | |
| 335 | + let id = label_id(cx); | |
| 341 | 336 | let ctx = load_repo(cx, owner, name).await?; |
| 342 | 337 | triage_guard(cx, &ctx, &form.csrf).await?; |
| 343 | 338 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u)); |
| 344 | 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 | 341 | .store |
| 347 | 342 | .delete_label(&ctx.repo.id, id) |
| 348 | 343 | .await; |
| 349 | 344 | match result { |
| 350 | 345 | Ok(()) => { |
| 351 | - app_context::<AppState>(cx) | |
| 352 | - .live | |
| 353 | - .bump_repo_issues(&ctx.repo.id); | |
| 346 | + context::<AppState>(cx).live.bump_repo_issues(&ctx.repo.id); | |
| 354 | 347 | Err(see_other(back).into()) |
| 355 | 348 | } |
| 356 | 349 | Err(e) => { |
crates/forge-web/src/pages/login.rsmodified+15 -8
| @@ -8,7 +8,7 @@ use http::header::{HeaderValue, RETRY_AFTER}; | ||
| 8 | 8 | use serde::Deserialize; |
| 9 | 9 | use serde_json::json; |
| 10 | 10 | use topcoat::Result; |
| 11 | -use topcoat::context::{Cx, app_context}; | |
| 11 | +use topcoat::context::{Cx, context}; | |
| 12 | 12 | use topcoat::router::content::Form; |
| 13 | 13 | use topcoat::router::error::{SeeOther, forbidden, see_other}; |
| 14 | 14 | use topcoat::router::{HeaderMap, StatusCode, page, query_params, route}; |
| @@ -71,6 +71,7 @@ struct TwoFactorForm { | ||
| 71 | 71 | |
| 72 | 72 | #[component] |
| 73 | 73 | async fn login_form( |
| 74 | + cx: &Cx, | |
| 74 | 75 | lang: Lang, |
| 75 | 76 | next: &str, |
| 76 | 77 | username: &str, |
| @@ -120,8 +121,9 @@ async fn login_page(cx: &Cx) -> Result<impl View> { | ||
| 120 | 121 | let next = safe_next(next.as_deref()).to_owned(); |
| 121 | 122 | let precsrf = pre_csrf_token(cx); |
| 122 | 123 | let lang = i18n::lang(cx, None); |
| 123 | - let passkeys = passkeys_available(app_context::<AppState>(cx)); | |
| 124 | - let can_register = app_context::<AppState>(cx).live().registration == forge_core::Registration::Open; | |
| 124 | + let passkeys = passkeys_available(context::<AppState>(cx)); | |
| 125 | + let can_register = | |
| 126 | + context::<AppState>(cx).live().registration == forge_core::Registration::Open; | |
| 125 | 127 | Ok(view! { |
| 126 | 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 | 135 | if !check_pre_csrf(cx, &form.precsrf) { |
| 134 | 136 | return Err(forbidden().into()); |
| 135 | 137 | } |
| 136 | - let state = app_context::<AppState>(cx); | |
| 138 | + let state = context::<AppState>(cx); | |
| 137 | 139 | let lang = i18n::lang(cx, None); |
| 138 | 140 | let limiter = &state.throttle; |
| 139 | 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 | 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 | 288 | Ok(view! { |
| 282 | 289 | head(title: t(lang, Key::TwoFactorCheck)) |
| 283 | 290 | <div class="sheet fit"> |
| @@ -299,7 +306,7 @@ async fn two_factor_form(lang: Lang, precsrf: &str, error: Option<String>) -> Re | ||
| 299 | 306 | /// The second-factor step. Needs a live pending-login cookie; otherwise back to `/login`. |
| 300 | 307 | #[page("/login/2fa")] |
| 301 | 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 | 310 | if pending_login(cx, &state.key).is_none() { |
| 304 | 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 | 322 | if !check_pre_csrf(cx, &form.precsrf) { |
| 316 | 323 | return Err(forbidden().into()); |
| 317 | 324 | } |
| 318 | - let state = app_context::<AppState>(cx); | |
| 325 | + let state = context::<AppState>(cx); | |
| 319 | 326 | let lang = i18n::lang(cx, None); |
| 320 | 327 | let Some(pending) = pending_login(cx, &state.key) else { |
| 321 | 328 | return Err(see_other("/login").into()); |
| @@ -398,7 +405,7 @@ async fn logout_submit(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> | ||
| 398 | 405 | if !check_csrf(&session, &form.csrf) { |
| 399 | 406 | return Err(forbidden().into()); |
| 400 | 407 | } |
| 401 | - let state = app_context::<AppState>(cx); | |
| 408 | + let state = context::<AppState>(cx); | |
| 402 | 409 | logout(cx, &session).await?; |
| 403 | 410 | audit::record( |
| 404 | 411 | &state.store, |
crates/forge-web/src/pages/media.rsmodified+2 -2
| @@ -10,7 +10,7 @@ use http_body::Frame; | ||
| 10 | 10 | use http_body_util::StreamBody; |
| 11 | 11 | use serde::Deserialize; |
| 12 | 12 | use tokio_util::io::ReaderStream; |
| 13 | -use topcoat::context::{Cx, app_context}; | |
| 13 | +use topcoat::context::{Cx, context}; | |
| 14 | 14 | use topcoat::router::request::method; |
| 15 | 15 | use topcoat::router::response::Response; |
| 16 | 16 | use topcoat::router::{ |
| @@ -58,7 +58,7 @@ pub(crate) fn media_file(cx: &Cx, _body: Body) -> RouteFuture<'_> { | ||
| 58 | 58 | |
| 59 | 59 | /// Serves one LFS object. Every failure is turned into a response here, so the route never errors. |
| 60 | 60 | async fn serve(cx: &Cx) -> Response { |
| 61 | - let state = app_context::<AppState>(cx).clone(); | |
| 61 | + let state = context::<AppState>(cx).clone(); | |
| 62 | 62 | let owner = path_param_segment(cx, "owner").to_owned(); |
| 63 | 63 | let name = path_param_segment(cx, "repo").to_owned(); |
| 64 | 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 | 17 | use serde::Deserialize; |
| 18 | 18 | use tokio::sync::watch; |
| 19 | 19 | use topcoat::Result; |
| 20 | -use topcoat::context::{Cx, app_context}; | |
| 20 | +use topcoat::context::{Cx, context}; | |
| 21 | 21 | use topcoat::router::content::Form; |
| 22 | 22 | use topcoat::router::content::sse::Event; |
| 23 | 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 | 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 | 82 | match state.store.pull_by_number(&ctx.repo.id, number).await? { |
| 83 | 83 | Some(pr) => Ok(pr), |
| 84 | 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 | 88 | #[route(POST "/{owner}/{repo}/pulls/{number}/merge-queue")] |
| 89 | 89 | async fn enqueue_post(cx: &Cx, Form(form): Form<QueueForm>) -> Result<Response> { |
| 90 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 91 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 90 | + let number = parse_number(number(cx))?; | |
| 91 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 92 | 92 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 93 | 93 | if ctx.repo.archived |
| 94 | 94 | || authorize( |
| @@ -102,7 +102,7 @@ async fn enqueue_post(cx: &Cx, Form(form): Form<QueueForm>) -> Result<Response> | ||
| 102 | 102 | { |
| 103 | 103 | return Err(forbidden().into()); |
| 104 | 104 | } |
| 105 | - let state = app_context::<AppState>(cx); | |
| 105 | + let state = context::<AppState>(cx); | |
| 106 | 106 | let pr = load_pull(cx, &ctx, number).await?; |
| 107 | 107 | let href = pull_href(&ctx, number); |
| 108 | 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 | 127 | #[route(POST "/{owner}/{repo}/pulls/{number}/merge-queue/remove")] |
| 128 | 128 | async fn remove_post(cx: &Cx, Form(form): Form<QueueForm>) -> Result<Response> { |
| 129 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 130 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 129 | + let number = parse_number(number(cx))?; | |
| 130 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 131 | 131 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 132 | 132 | if ctx.repo.archived |
| 133 | 133 | || authorize( |
| @@ -141,7 +141,7 @@ async fn remove_post(cx: &Cx, Form(form): Form<QueueForm>) -> Result<Response> { | ||
| 141 | 141 | { |
| 142 | 142 | return Err(forbidden().into()); |
| 143 | 143 | } |
| 144 | - let state = app_context::<AppState>(cx); | |
| 144 | + let state = context::<AppState>(cx); | |
| 145 | 145 | let pr = load_pull(cx, &ctx, number).await?; |
| 146 | 146 | let href = pull_href(&ctx, number); |
| 147 | 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 | 154 | /// The queue page: waiting entries, or the history with `?show=history`. |
| 155 | 155 | #[page("/{owner}/{repo}/merge-queue")] |
| 156 | 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 | 158 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u)); |
| 159 | 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 | 161 | let frame = crate::pages::issue_meta::RepoFrame::new(&ctx, state, "pulls").await?; |
| 162 | 162 | let entries = state.store.queue_overview(&ctx.repo.id).await?; |
| 163 | 163 | let rows = queue_rows(state, &ctx, lang, entries, history).await?; |
| @@ -332,8 +332,8 @@ fn reason_label(lang: Lang, reason: &str) -> String { | ||
| 332 | 332 | /// after that point is sent. |
| 333 | 333 | #[route(GET "/{owner}/{repo}/merge-queue/events")] |
| 334 | 334 | async fn queue_events(cx: &Cx) -> Result<Response> { |
| 335 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 336 | - let state = app_context::<AppState>(cx); | |
| 335 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 336 | + let state = context::<AppState>(cx); | |
| 337 | 337 | let wake = state.ci_live.subscribe_queue(&ctx.repo.id); |
| 338 | 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 | 348 | #[component] |
| 349 | 349 | async fn queue_body( |
| 350 | + cx: &Cx, | |
| 350 | 351 | lang: Lang, |
| 351 | 352 | head: crate::pages::repo_ctx::RepoHead, |
| 352 | 353 | waiting_href: String, |
| @@ -359,12 +360,9 @@ async fn queue_body( | ||
| 359 | 360 | csrf: String, |
| 360 | 361 | ) -> Result<impl View> { |
| 361 | 362 | let remove_label = g::t(lang, K::RemoveFromQueue); |
| 362 | - let remove_note = crate::pages::passkeys::s( | |
| 363 | - lang, | |
| 364 | - "Remove it from the queue?", | |
| 365 | - "Sıradan çıkarılsın mı?", | |
| 366 | - ) | |
| 367 | - .to_owned(); | |
| 363 | + let remove_note = | |
| 364 | + crate::pages::passkeys::s(lang, "Remove it from the queue?", "Sıradan çıkarılsın mı?") | |
| 365 | + .to_owned(); | |
| 368 | 366 | Ok(view! { |
| 369 | 367 | repo_head(head: head, title: Some(g::t(lang, K::MergeQueueTitle).to_owned())) |
| 370 | 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 | 8 | use jiff::tz::TimeZone; |
| 9 | 9 | use serde::Deserialize; |
| 10 | 10 | use topcoat::Result; |
| 11 | -use topcoat::context::{Cx, app_context}; | |
| 11 | +use topcoat::context::{Cx, context}; | |
| 12 | 12 | use topcoat::router::content::Form; |
| 13 | 13 | use topcoat::router::error::{forbidden, not_found, see_other}; |
| 14 | 14 | use topcoat::router::{page, path_param, query_params}; |
| @@ -100,7 +100,7 @@ fn due_on_field(raw: &str) -> Option<&str> { | ||
| 100 | 100 | |
| 101 | 101 | /// The Open and Closed filter as the sheet's tools row: the shown state in bold, the other a link. |
| 102 | 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 | 104 | let open_href = format!("{}?state=open", milestones_href(&title)); |
| 105 | 105 | let closed_href = format!("{}?state=closed", milestones_href(&title)); |
| 106 | 106 | Ok(view! { |
| @@ -120,6 +120,7 @@ async fn state_tabs(lang: Lang, title: String, closed: bool) -> Result<impl View | ||
| 120 | 120 | /// and the triage controls. |
| 121 | 121 | #[component] |
| 122 | 122 | async fn milestone_row( |
| 123 | + cx: &Cx, | |
| 123 | 124 | lang: Lang, |
| 124 | 125 | row: MilestoneRow, |
| 125 | 126 | csrf: String, |
| @@ -166,8 +167,8 @@ async fn milestone_row( | ||
| 166 | 167 | /// Gets the milestone list for one state (open by default). |
| 167 | 168 | #[page("/{owner}/{repo}/milestones")] |
| 168 | 169 | async fn milestones_page(cx: &Cx) -> Result<impl View> { |
| 169 | - let owner = path_param::<Owner>(cx); | |
| 170 | - let name = path_param::<Repo>(cx); | |
| 170 | + let owner = owner(cx); | |
| 171 | + let name = repo(cx); | |
| 171 | 172 | let ctx = load_repo(cx, owner, name).await?; |
| 172 | 173 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u)); |
| 173 | 174 | let query = query_params::<MilestoneQuery>(cx)?; |
| @@ -177,11 +178,11 @@ async fn milestones_page(cx: &Cx) -> Result<impl View> { | ||
| 177 | 178 | } else { |
| 178 | 179 | IssueState::Open |
| 179 | 180 | }; |
| 180 | - let milestones = app_context::<AppState>(cx) | |
| 181 | + let milestones = context::<AppState>(cx) | |
| 181 | 182 | .store |
| 182 | 183 | .list_milestones(&ctx.repo.id, Some(state)) |
| 183 | 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 | 186 | let today = today_in(ctx.viewer_tz()); |
| 186 | 187 | let title = frame.title.clone(); |
| 187 | 188 | let all: Vec<MilestoneRow> = milestones |
| @@ -236,6 +237,7 @@ async fn milestones_page(cx: &Cx) -> Result<impl View> { | ||
| 236 | 237 | /// The header, state tabs, milestone rows and the create form. |
| 237 | 238 | #[component] |
| 238 | 239 | async fn milestones_body( |
| 240 | + cx: &Cx, | |
| 239 | 241 | lang: Lang, |
| 240 | 242 | frame: RepoFrame, |
| 241 | 243 | rows: Vec<MilestoneRow>, |
| @@ -310,13 +312,13 @@ async fn milestones_body( | ||
| 310 | 312 | /// Creates a milestone with an optional due date. |
| 311 | 313 | #[page(POST "/{owner}/{repo}/milestones")] |
| 312 | 314 | async fn milestone_create(cx: &Cx, Form(form): Form<MilestoneForm>) -> Result<impl View> { |
| 313 | - let owner = path_param::<Owner>(cx); | |
| 314 | - let name = path_param::<Repo>(cx); | |
| 315 | + let owner = owner(cx); | |
| 316 | + let name = repo(cx); | |
| 315 | 317 | let ctx = load_repo(cx, owner, name).await?; |
| 316 | 318 | triage_guard(cx, &ctx, &form.csrf).await?; |
| 317 | 319 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u)); |
| 318 | 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 | 322 | .store |
| 321 | 323 | .create_milestone( |
| 322 | 324 | &ctx.repo.id, |
| @@ -327,9 +329,7 @@ async fn milestone_create(cx: &Cx, Form(form): Form<MilestoneForm>) -> Result<im | ||
| 327 | 329 | .await; |
| 328 | 330 | match result { |
| 329 | 331 | Ok(_) => { |
| 330 | - app_context::<AppState>(cx) | |
| 331 | - .live | |
| 332 | - .bump_repo_issues(&ctx.repo.id); | |
| 332 | + context::<AppState>(cx).live.bump_repo_issues(&ctx.repo.id); | |
| 333 | 333 | Err(see_other(back).into()) |
| 334 | 334 | } |
| 335 | 335 | Err(e) => { |
| @@ -345,23 +345,23 @@ async fn milestone_create(cx: &Cx, Form(form): Form<MilestoneForm>) -> Result<im | ||
| 345 | 345 | /// The edit page: title, description, due date and state. Triage holders only. |
| 346 | 346 | #[page("/{owner}/{repo}/milestones/{milestone_id}/edit")] |
| 347 | 347 | async fn milestone_edit_page(cx: &Cx) -> Result<impl View> { |
| 348 | - let owner = path_param::<Owner>(cx); | |
| 349 | - let name = path_param::<Repo>(cx); | |
| 350 | - let id = path_param::<MilestoneId>(cx); | |
| 348 | + let owner = owner(cx); | |
| 349 | + let name = repo(cx); | |
| 350 | + let id = milestone_id(cx); | |
| 351 | 351 | let ctx = load_repo(cx, owner, name).await?; |
| 352 | 352 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u)); |
| 353 | 353 | require_user(cx).await?; |
| 354 | 354 | if !can_triage(&ctx) { |
| 355 | 355 | return Err(forbidden().into()); |
| 356 | 356 | } |
| 357 | - let Some(milestone) = app_context::<AppState>(cx) | |
| 357 | + let Some(milestone) = context::<AppState>(cx) | |
| 358 | 358 | .store |
| 359 | 359 | .milestone_by_id(&ctx.repo.id, id) |
| 360 | 360 | .await? |
| 361 | 361 | else { |
| 362 | 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 | 365 | let page_title = g::milestone_edit_title(lang, &frame.title); |
| 366 | 366 | let action = format!("{}/{}/edit", milestones_href(&frame.title), milestone.id); |
| 367 | 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 | 376 | /// The edit form body. |
| 377 | 377 | #[component] |
| 378 | 378 | async fn milestone_edit_body( |
| 379 | + cx: &Cx, | |
| 379 | 380 | lang: Lang, |
| 380 | 381 | frame: RepoFrame, |
| 381 | 382 | action: String, |
| @@ -425,9 +426,9 @@ async fn milestone_edit_body( | ||
| 425 | 426 | /// Saves the edit form. A state of `closed` closes the milestone; anything else reopens it. |
| 426 | 427 | #[page(POST "/{owner}/{repo}/milestones/{milestone_id}/edit")] |
| 427 | 428 | async fn milestone_edit_save(cx: &Cx, Form(form): Form<MilestoneForm>) -> Result<impl View> { |
| 428 | - let owner = path_param::<Owner>(cx); | |
| 429 | - let name = path_param::<Repo>(cx); | |
| 430 | - let id = path_param::<MilestoneId>(cx); | |
| 429 | + let owner = owner(cx); | |
| 430 | + let name = repo(cx); | |
| 431 | + let id = milestone_id(cx); | |
| 431 | 432 | let ctx = load_repo(cx, owner, name).await?; |
| 432 | 433 | triage_guard(cx, &ctx, &form.csrf).await?; |
| 433 | 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 | 438 | } else { |
| 438 | 439 | IssueState::Open |
| 439 | 440 | }; |
| 440 | - let result = app_context::<AppState>(cx) | |
| 441 | + let result = context::<AppState>(cx) | |
| 441 | 442 | .store |
| 442 | 443 | .update_milestone( |
| 443 | 444 | &ctx.repo.id, |
| @@ -450,9 +451,7 @@ async fn milestone_edit_save(cx: &Cx, Form(form): Form<MilestoneForm>) -> Result | ||
| 450 | 451 | .await; |
| 451 | 452 | match result { |
| 452 | 453 | Ok(()) => { |
| 453 | - app_context::<AppState>(cx) | |
| 454 | - .live | |
| 455 | - .bump_repo_issues(&ctx.repo.id); | |
| 454 | + context::<AppState>(cx).live.bump_repo_issues(&ctx.repo.id); | |
| 456 | 455 | Err(see_other(back).into()) |
| 457 | 456 | } |
| 458 | 457 | Err(e) => { |
| @@ -468,22 +467,20 @@ async fn milestone_edit_save(cx: &Cx, Form(form): Form<MilestoneForm>) -> Result | ||
| 468 | 467 | /// Deletes a milestone. Its issues stay open or closed; they just lose the milestone. |
| 469 | 468 | #[page(POST "/{owner}/{repo}/milestones/{milestone_id}/delete")] |
| 470 | 469 | async fn milestone_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<impl View> { |
| 471 | - let owner = path_param::<Owner>(cx); | |
| 472 | - let name = path_param::<Repo>(cx); | |
| 473 | - let id = path_param::<MilestoneId>(cx); | |
| 470 | + let owner = owner(cx); | |
| 471 | + let name = repo(cx); | |
| 472 | + let id = milestone_id(cx); | |
| 474 | 473 | let ctx = load_repo(cx, owner, name).await?; |
| 475 | 474 | triage_guard(cx, &ctx, &form.csrf).await?; |
| 476 | 475 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(u, _)| u)); |
| 477 | 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 | 478 | .store |
| 480 | 479 | .delete_milestone(&ctx.repo.id, id) |
| 481 | 480 | .await; |
| 482 | 481 | match result { |
| 483 | 482 | Ok(()) => { |
| 484 | - app_context::<AppState>(cx) | |
| 485 | - .live | |
| 486 | - .bump_repo_issues(&ctx.repo.id); | |
| 483 | + context::<AppState>(cx).live.bump_repo_issues(&ctx.repo.id); | |
| 487 | 484 | Err(see_other(back).into()) |
| 488 | 485 | } |
| 489 | 486 | Err(e) => { |
crates/forge-web/src/pages/needs_you.rsmodified+4 -4
| @@ -9,7 +9,7 @@ use forge_core::User; | ||
| 9 | 9 | use forge_core::authz::{Action, authorize}; |
| 10 | 10 | use forge_core::store::needs::Verdict; |
| 11 | 11 | use topcoat::Result; |
| 12 | -use topcoat::context::{Cx, app_context}; | |
| 12 | +use topcoat::context::{Cx, context}; | |
| 13 | 13 | use topcoat::router::response::Response; |
| 14 | 14 | use topcoat::router::{Body, StatusCode, page, query_params, route}; |
| 15 | 15 | use topcoat::view::{View, component, view}; |
| @@ -344,7 +344,7 @@ async fn load_full( | ||
| 344 | 344 | |
| 345 | 345 | /// One section of the page: its head, its rows as a compact list, its full-list link and its pager. |
| 346 | 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 | 348 | let NeedSection { |
| 349 | 349 | heading, |
| 350 | 350 | more, |
| @@ -386,7 +386,7 @@ pub(crate) async fn need_section(lang: Lang, section: NeedSection) -> Result<imp | ||
| 386 | 386 | #[page("/needs-you")] |
| 387 | 387 | async fn needs_you(cx: &Cx) -> Result<impl View> { |
| 388 | 388 | let viewer = require_user(cx).await?; |
| 389 | - let state = app_context::<AppState>(cx); | |
| 389 | + let state = context::<AppState>(cx); | |
| 390 | 390 | let user = &viewer.0; |
| 391 | 391 | let lang = i18n::lang(cx, Some(user)); |
| 392 | 392 | let query = query_params::<NeedsQuery>(cx)?; |
| @@ -444,7 +444,7 @@ async fn needs_you_events(cx: &Cx) -> Result<Response> { | ||
| 444 | 444 | *res.status_mut() = StatusCode::UNAUTHORIZED; |
| 445 | 445 | return Ok(res); |
| 446 | 446 | }; |
| 447 | - let state = app_context::<AppState>(cx); | |
| 447 | + let state = context::<AppState>(cx); | |
| 448 | 448 | stream_wakes( |
| 449 | 449 | cx, |
| 450 | 450 | &state.live, |
crates/forge-web/src/pages/new_repo.rsmodified+7 -6
| @@ -7,7 +7,7 @@ use forge_core::{AuditAction, User, Visibility}; | ||
| 7 | 7 | use forge_git::repo::{init_bare, repo_path}; |
| 8 | 8 | use serde::Deserialize; |
| 9 | 9 | use topcoat::Result; |
| 10 | -use topcoat::context::{Cx, app_context}; | |
| 10 | +use topcoat::context::{Cx, context}; | |
| 11 | 11 | use topcoat::router::content::Form; |
| 12 | 12 | use topcoat::router::error::see_other; |
| 13 | 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 | 209 | #[component] |
| 210 | 210 | async fn new_repo_form( |
| 211 | + cx: &Cx, | |
| 211 | 212 | lang: Lang, |
| 212 | 213 | username: String, |
| 213 | 214 | csrf: &str, |
| @@ -329,7 +330,7 @@ async fn new_repo_page(cx: &Cx) -> Result<impl View> { | ||
| 329 | 330 | let viewer = require_user(cx).await?; |
| 330 | 331 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 331 | 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 | 334 | let mut draft = Draft::fresh(); |
| 334 | 335 | if let Some(wanted) = wanted.as_deref() |
| 335 | 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 | 338 | draft.owner = owner.clone(); |
| 338 | 339 | } |
| 339 | 340 | let csrf = viewer.1.csrf_token.clone(); |
| 340 | - Ok(view! { cx => | |
| 341 | + Ok(view! { | |
| 341 | 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 | 351 | match outcome { |
| 351 | 352 | Ok(location) => Err(see_other(location).into()), |
| 352 | 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 | 355 | let csrf = viewer.1.csrf_token.clone(); |
| 355 | 356 | let draft = Draft::from_form(&form); |
| 356 | - Ok(view! { cx => | |
| 357 | + Ok(view! { | |
| 357 | 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 | 390 | owner: &User, |
| 390 | 391 | form: &NewRepoForm, |
| 391 | 392 | ) -> Result<std::result::Result<String, String>> { |
| 392 | - let state = app_context::<AppState>(cx); | |
| 393 | + let state = context::<AppState>(cx); | |
| 393 | 394 | let lang = i18n::lang(cx, Some(owner)); |
| 394 | 395 | let name = match validate_name(&form.name) { |
| 395 | 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 | 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 | 50 | let (title, hint, back) = texts(lang); |
| 51 | 51 | Ok(view! { |
| 52 | 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 | 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 | 105 | let (title, hint, back) = forbidden_texts(lang); |
| 106 | 106 | Ok(view! { |
| 107 | 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 | 15 | use futures_util::{Stream, StreamExt, future, stream}; |
| 16 | 16 | use serde::Deserialize; |
| 17 | 17 | use topcoat::Result; |
| 18 | -use topcoat::context::{Cx, app_context}; | |
| 18 | +use topcoat::context::{Cx, context}; | |
| 19 | 19 | use topcoat::router::content::Form; |
| 20 | 20 | use topcoat::router::content::sse::Event; |
| 21 | 21 | use topcoat::router::error::{SeeOther, bad_request, not_found, see_other}; |
| @@ -320,7 +320,7 @@ async fn entry_visible( | ||
| 320 | 320 | #[page("/notifications")] |
| 321 | 321 | async fn inbox(cx: &Cx) -> Result<impl View> { |
| 322 | 322 | let viewer = require_user(cx).await?; |
| 323 | - let state = app_context::<AppState>(cx); | |
| 323 | + let state = context::<AppState>(cx); | |
| 324 | 324 | let query = query_params::<InboxQuery>(cx)?; |
| 325 | 325 | let all = query.all.as_deref() == Some("1"); |
| 326 | 326 | let before = query.before.clone().filter(|s| !s.is_empty()); |
| @@ -545,7 +545,7 @@ async fn inbox_events(cx: &Cx) -> Result<Response> { | ||
| 545 | 545 | return Ok(res); |
| 546 | 546 | }; |
| 547 | 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 | 549 | let topic = Topic::Inbox(user.id.clone()); |
| 550 | 550 | stream_changes(cx, &state.live.clone(), &[topic], move || { |
| 551 | 551 | let state = state.clone(); |
| @@ -560,8 +560,8 @@ async fn inbox_events(cx: &Cx) -> Result<Response> { | ||
| 560 | 560 | #[route(GET "/notifications/{note}/open")] |
| 561 | 561 | async fn open_notification(cx: &Cx) -> Result<SeeOther> { |
| 562 | 562 | let (user, _) = require_user(cx).await?; |
| 563 | - let state = app_context::<AppState>(cx); | |
| 564 | - let id = path_param::<Note>(cx); | |
| 563 | + let state = context::<AppState>(cx); | |
| 564 | + let id = note(cx); | |
| 565 | 565 | let Some(target) = state.store.notification_target(&user.id, id).await? else { |
| 566 | 566 | return Err(not_found().into()); |
| 567 | 567 | }; |
| @@ -585,8 +585,8 @@ async fn open_notification(cx: &Cx) -> Result<SeeOther> { | ||
| 585 | 585 | #[route(GET "/notifications/discussions/{discussion_id}/open")] |
| 586 | 586 | async fn open_discussion_notification(cx: &Cx) -> Result<SeeOther> { |
| 587 | 587 | let (user, _) = require_user(cx).await?; |
| 588 | - let state = app_context::<AppState>(cx); | |
| 589 | - let id = path_param::<DiscussionId>(cx); | |
| 588 | + let state = context::<AppState>(cx); | |
| 589 | + let id = discussion_id(cx); | |
| 590 | 590 | let Some(note) = state.store.discussion_notification(&user.id, id).await? else { |
| 591 | 591 | return Err(not_found().into()); |
| 592 | 592 | }; |
| @@ -611,8 +611,8 @@ async fn open_discussion_notification(cx: &Cx) -> Result<SeeOther> { | ||
| 611 | 611 | #[route(POST "/notifications/discussions/{discussion_id}/read")] |
| 612 | 612 | async fn read_discussion_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { |
| 613 | 613 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 614 | - let state = app_context::<AppState>(cx); | |
| 615 | - let id = path_param::<DiscussionId>(cx); | |
| 614 | + let state = context::<AppState>(cx); | |
| 615 | + let id = discussion_id(cx); | |
| 616 | 616 | state |
| 617 | 617 | .store |
| 618 | 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 | 626 | #[route(GET "/notifications/advisories/{advisory_repo_id}/open")] |
| 627 | 627 | async fn open_advisory_notification(cx: &Cx) -> Result<SeeOther> { |
| 628 | 628 | let (user, _) = require_user(cx).await?; |
| 629 | - let state = app_context::<AppState>(cx); | |
| 630 | - let repo_id = path_param::<AdvisoryRepoId>(cx); | |
| 629 | + let state = context::<AppState>(cx); | |
| 630 | + let repo_id = advisory_repo_id(cx); | |
| 631 | 631 | let Some(notice) = state.store.advisory_notification(&user.id, repo_id).await? else { |
| 632 | 632 | return Err(not_found().into()); |
| 633 | 633 | }; |
| @@ -651,8 +651,8 @@ async fn open_advisory_notification(cx: &Cx) -> Result<SeeOther> { | ||
| 651 | 651 | #[route(POST "/notifications/advisories/{advisory_repo_id}/read")] |
| 652 | 652 | async fn read_advisory_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { |
| 653 | 653 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 654 | - let state = app_context::<AppState>(cx); | |
| 655 | - let repo_id = path_param::<AdvisoryRepoId>(cx); | |
| 654 | + let state = context::<AppState>(cx); | |
| 655 | + let repo_id = advisory_repo_id(cx); | |
| 656 | 656 | state |
| 657 | 657 | .store |
| 658 | 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 | 666 | #[route(GET "/notifications/admin/{admin_note}/open")] |
| 667 | 667 | async fn open_admin_notification(cx: &Cx) -> Result<SeeOther> { |
| 668 | 668 | let (user, _) = require_user(cx).await?; |
| 669 | - let state = app_context::<AppState>(cx); | |
| 670 | - let id = path_param::<AdminNote>(cx); | |
| 669 | + let state = context::<AppState>(cx); | |
| 670 | + let id = admin_note(cx); | |
| 671 | 671 | let owned = state |
| 672 | 672 | .store |
| 673 | 673 | .list_admin_notices(&user.id, false, None, 200) |
| @@ -686,8 +686,8 @@ async fn open_admin_notification(cx: &Cx) -> Result<SeeOther> { | ||
| 686 | 686 | #[route(POST "/notifications/admin/{admin_note}/read")] |
| 687 | 687 | async fn read_admin_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { |
| 688 | 688 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 689 | - let state = app_context::<AppState>(cx); | |
| 690 | - let id = path_param::<AdminNote>(cx); | |
| 689 | + let state = context::<AppState>(cx); | |
| 690 | + let id = admin_note(cx); | |
| 691 | 691 | state.store.mark_admin_notice_read(&user.id, id).await?; |
| 692 | 692 | publish_unread(state, &user.id).await; |
| 693 | 693 | Ok(see_other(back(cx))) |
| @@ -697,8 +697,8 @@ async fn read_admin_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result< | ||
| 697 | 697 | #[route(POST "/notifications/{note}/read")] |
| 698 | 698 | async fn read_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { |
| 699 | 699 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 700 | - let state = app_context::<AppState>(cx); | |
| 701 | - let id = path_param::<Note>(cx); | |
| 700 | + let state = context::<AppState>(cx); | |
| 701 | + let id = note(cx); | |
| 702 | 702 | state.store.mark_read(&user.id, id).await?; |
| 703 | 703 | publish_unread(state, &user.id).await; |
| 704 | 704 | Ok(see_other(back(cx))) |
| @@ -708,7 +708,7 @@ async fn read_notification(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOth | ||
| 708 | 708 | #[route(POST "/notifications/mark_all_read")] |
| 709 | 709 | async fn mark_all_read(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { |
| 710 | 710 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 711 | - let state = app_context::<AppState>(cx); | |
| 711 | + let state = context::<AppState>(cx); | |
| 712 | 712 | let query = query_params::<RepoQuery>(cx)?; |
| 713 | 713 | let repo_id = query.repo.as_deref().filter(|s| !s.is_empty()); |
| 714 | 714 | if repo_id == Some(ADMIN_GROUP) { |
| @@ -765,7 +765,7 @@ async fn notification_stream(cx: &Cx) -> Result<Response> { | ||
| 765 | 765 | *res.status_mut() = StatusCode::UNAUTHORIZED; |
| 766 | 766 | return Ok(res); |
| 767 | 767 | }; |
| 768 | - let state = app_context::<AppState>(cx); | |
| 768 | + let state = context::<AppState>(cx); | |
| 769 | 769 | let events = unread_changes(state, &user.id).await?; |
| 770 | 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 | 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 | 787 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 788 | - let state = app_context::<AppState>(cx); | |
| 789 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 788 | + let state = context::<AppState>(cx); | |
| 789 | + let number = parse_number(number(cx))?; | |
| 790 | 790 | let issue = if pull { |
| 791 | 791 | state |
| 792 | 792 | .store |
| @@ -841,7 +841,7 @@ async fn set_subscription(cx: &Cx, pull: bool, form: &SubscriptionForm) -> Resul | ||
| 841 | 841 | /// Sets the viewer's watch level on a repo. The viewer must be able to read the repo. |
| 842 | 842 | #[route(POST "/{owner}/{repo}/watch")] |
| 843 | 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 | 845 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 846 | 846 | let level = match form.level.as_str() { |
| 847 | 847 | "participating" => WatchLevel::Participating, |
| @@ -849,7 +849,7 @@ async fn set_watch(cx: &Cx, Form(form): Form<WatchForm>) -> Result<SeeOther> { | ||
| 849 | 849 | "ignoring" => WatchLevel::Ignoring, |
| 850 | 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 | 853 | state.store.set_watch(&user.id, &ctx.repo.id, level).await?; |
| 854 | 854 | state.live.bump_repo(&ctx.repo.owner_id, &ctx.repo.id); |
| 855 | 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 | 973 | current: key == current, |
| 974 | 974 | }; |
| 975 | 975 | vec![ |
| 976 | - item("unread", g::t(lang, K::Unread), unread_count.to_string(), "/notifications"), | |
| 977 | - item("all", g::t(lang, K::AllTab), String::new(), "/notifications?all=1"), | |
| 976 | + item( | |
| 977 | + "unread", | |
| 978 | + g::t(lang, K::Unread), | |
| 979 | + unread_count.to_string(), | |
| 980 | + "/notifications", | |
| 981 | + ), | |
| 982 | + item( | |
| 983 | + "all", | |
| 984 | + g::t(lang, K::AllTab), | |
| 985 | + String::new(), | |
| 986 | + "/notifications?all=1", | |
| 987 | + ), | |
| 978 | 988 | item( |
| 979 | 989 | "needs", |
| 980 | 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 | 1003 | /// The inbox rail as Needs you and Review requests show it, beside their sheet. |
| 994 | 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 | 1011 | let items = inbox_items(lang, current, unread_count); |
| 997 | 1012 | Ok(view! { |
| 998 | 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 | 1018 | /// sheet holding the transfers, the repo groups and the older-rows link. |
| 1004 | 1019 | #[component] |
| 1005 | 1020 | async fn inbox_list( |
| 1021 | + cx: &Cx, | |
| 1006 | 1022 | lang: Lang, |
| 1007 | 1023 | all: bool, |
| 1008 | 1024 | unread_count: u64, |
| @@ -1076,6 +1092,7 @@ async fn inbox_list( | ||
| 1076 | 1092 | /// The Subscribe or Unsubscribe pill of an issue or pull request, in its head. |
| 1077 | 1093 | #[component] |
| 1078 | 1094 | pub(crate) async fn notify_pill( |
| 1095 | + cx: &Cx, | |
| 1079 | 1096 | lang: Lang, |
| 1080 | 1097 | action: String, |
| 1081 | 1098 | csrf: String, |
| @@ -1100,6 +1117,7 @@ pub(crate) async fn notify_pill( | ||
| 1100 | 1117 | /// without JavaScript; nav.js submits them in place and closes the menu. |
| 1101 | 1118 | #[component] |
| 1102 | 1119 | pub(crate) async fn watch_form( |
| 1120 | + cx: &Cx, | |
| 1103 | 1121 | lang: Lang, |
| 1104 | 1122 | action: String, |
| 1105 | 1123 | csrf: String, |
crates/forge-web/src/pages/org_ctx.rsmodified+4 -3
| @@ -9,7 +9,7 @@ use forge_core::store::orgs::OrgMemberRole; | ||
| 9 | 9 | use forge_core::store::repo_listing::RepoScope; |
| 10 | 10 | use forge_core::{Role, Session, User}; |
| 11 | 11 | use topcoat::Result; |
| 12 | -use topcoat::context::{Cx, app_context}; | |
| 12 | +use topcoat::context::{Cx, context}; | |
| 13 | 13 | use topcoat::router::error::{forbidden, not_found}; |
| 14 | 14 | use topcoat::router::request::uri; |
| 15 | 15 | use topcoat::view::{View, component, view}; |
| @@ -102,7 +102,7 @@ impl OrgCtx { | ||
| 102 | 102 | /// names and people (anything that is not an org) are 404. |
| 103 | 103 | pub async fn load_org(cx: &Cx, name: &str) -> Result<OrgCtx> { |
| 104 | 104 | let viewer = require_user(cx).await?; |
| 105 | - let state = app_context::<AppState>(cx); | |
| 105 | + let state = context::<AppState>(cx); | |
| 106 | 106 | let Some(org) = state.store.user_by_username(name).await? else { |
| 107 | 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 | 201 | /// Teams are always listed; an owner also gets Settings. `current` marks the page's own tab. |
| 202 | 202 | #[component] |
| 203 | 203 | pub async fn org_tabs( |
| 204 | + cx: &Cx, | |
| 204 | 205 | lang: Lang, |
| 205 | 206 | name: String, |
| 206 | 207 | current: String, |
| @@ -251,7 +252,7 @@ pub async fn org_tabs( | ||
| 251 | 252 | |
| 252 | 253 | /// The notice after a write: an error alert, or a status line. |
| 253 | 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 | 256 | Ok(view! { |
| 256 | 257 | if let Some((text, is_error)) = notice { |
| 257 | 258 | if is_error { |
crates/forge-web/src/pages/org_live.rsmodified+11 -11
| @@ -15,7 +15,7 @@ use forge_core::User; | ||
| 15 | 15 | use forge_core::store::Store; |
| 16 | 16 | use forge_core::store::orgs::OrgMemberRole; |
| 17 | 17 | use topcoat::Result; |
| 18 | -use topcoat::context::{Cx, app_context}; | |
| 18 | +use topcoat::context::{Cx, context}; | |
| 19 | 19 | use topcoat::router::request::{method, uri}; |
| 20 | 20 | use topcoat::router::response::Response; |
| 21 | 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 | 130 | /// The members page's change stream. Members only, as the page. |
| 131 | 131 | #[route(GET "/org/{org}/members/events")] |
| 132 | 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 | 134 | require_member(&ctx)?; |
| 135 | - let state = app_context::<AppState>(cx); | |
| 135 | + let state = context::<AppState>(cx); | |
| 136 | 136 | let org_id = ctx.org.id.clone(); |
| 137 | 137 | let store = state.store.clone(); |
| 138 | 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 | 146 | /// The teams list's change stream. Members only, as the page. |
| 147 | 147 | #[route(GET "/org/{org}/teams/events")] |
| 148 | 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 | 150 | require_member(&ctx)?; |
| 151 | - let state = app_context::<AppState>(cx); | |
| 151 | + let state = context::<AppState>(cx); | |
| 152 | 152 | let org_id = ctx.org.id.clone(); |
| 153 | 153 | let store = state.store.clone(); |
| 154 | 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 | 163 | /// It also follows each repo the team links, for a rename or a visibility change. |
| 164 | 164 | #[route(GET "/org/{org}/teams/{team}/events")] |
| 165 | 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 | 167 | require_member(&ctx)?; |
| 168 | - let state = app_context::<AppState>(cx); | |
| 169 | - let team = team_of(state, &ctx, path_param::<Team>(cx)).await?; | |
| 168 | + let state = context::<AppState>(cx); | |
| 169 | + let team = team_of(state, &ctx, team(cx)).await?; | |
| 170 | 170 | let linked = state.store.team_repos(&team.id).await?; |
| 171 | 171 | let mut topics = vec![Topic::Org(ctx.org.id.clone())]; |
| 172 | 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 | 187 | /// The settings page's change stream. Owners only, as the page. |
| 188 | 188 | #[route(GET "/org/{org}/settings/events")] |
| 189 | 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 | 191 | require_owner(&ctx)?; |
| 192 | - let state = app_context::<AppState>(cx); | |
| 192 | + let state = context::<AppState>(cx); | |
| 193 | 193 | let org_id = ctx.org.id.clone(); |
| 194 | 194 | let store = state.store.clone(); |
| 195 | 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 | 222 | let Some(name) = written_org(cx) else { |
| 223 | 223 | return next.run(cx, body).await; |
| 224 | 224 | }; |
| 225 | - let state = app_context::<AppState>(cx); | |
| 225 | + let state = context::<AppState>(cx); | |
| 226 | 226 | let org_id = match state.store.user_by_username(&name).await { |
| 227 | 227 | Ok(Some(org)) if org.is_org() => Some(org.id), |
| 228 | 228 | Ok(_) => None, |
crates/forge-web/src/pages/org_members.rsmodified+20 -11
| @@ -9,7 +9,7 @@ use forge_core::AuditAction; | ||
| 9 | 9 | use forge_core::store::orgs::OrgMemberRole; |
| 10 | 10 | use serde::Deserialize; |
| 11 | 11 | use topcoat::Result; |
| 12 | -use topcoat::context::{Cx, app_context}; | |
| 12 | +use topcoat::context::{Cx, context}; | |
| 13 | 13 | use topcoat::router::content::Form; |
| 14 | 14 | use topcoat::router::error::{SeeOther, see_other}; |
| 15 | 15 | use topcoat::router::{page, path_param, route}; |
| @@ -61,6 +61,7 @@ struct RemoveForm { | ||
| 61 | 61 | /// else sees the plain list. |
| 62 | 62 | #[component] |
| 63 | 63 | async fn members_body( |
| 64 | + cx: &Cx, | |
| 64 | 65 | name: String, |
| 65 | 66 | description: String, |
| 66 | 67 | base: String, |
| @@ -115,10 +116,10 @@ async fn members_body( | ||
| 115 | 116 | /// Gets the members page. Non-members get 404. |
| 116 | 117 | #[page("/org/{org}/members")] |
| 117 | 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 | 120 | require_member(&ctx)?; |
| 120 | 121 | let lang = i18n::lang(cx, Some(&ctx.viewer.0)); |
| 121 | - let state = app_context::<AppState>(cx); | |
| 122 | + let state = context::<AppState>(cx); | |
| 122 | 123 | let members = state.store.org_members(&ctx.org.id).await?; |
| 123 | 124 | let rows: Vec<PersonRow> = members |
| 124 | 125 | .into_iter() |
| @@ -132,7 +133,15 @@ async fn org_members_page(cx: &Cx) -> Result<impl View> { | ||
| 132 | 133 | label: display_name(lang, &user.username), |
| 133 | 134 | username: user.username, |
| 134 | 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 | 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 | 155 | let csrf = ctx.viewer.1.csrf_token.clone(); |
| 147 | 156 | let live = ctx.href("/members/events"); |
| 148 | 157 | let (repo_count, package_count) = org_tab_counts(state, &ctx.org, &ctx.viewer.0).await?; |
| 149 | - Ok(view! { cx => | |
| 158 | + Ok(view! { | |
| 150 | 159 | shell(title: title.as_str(), viewer: Some(&ctx.viewer), |
| 151 | 160 | members_body(name: name, description: description, base: base, owner: owner, |
| 152 | 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 | 166 | /// Adds a person as a member or owner. Owners only. |
| 158 | 167 | #[route(POST "/org/{org}/members/add")] |
| 159 | 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 | 170 | require_form_csrf(&ctx, &form.csrf)?; |
| 162 | 171 | require_owner(&ctx)?; |
| 163 | - let state = app_context::<AppState>(cx); | |
| 172 | + let state = context::<AppState>(cx); | |
| 164 | 173 | let back = ctx.href("/members"); |
| 165 | 174 | |
| 166 | 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 | 217 | /// Changes a member's org role. Owners only. Demoting the last owner is refused. |
| 209 | 218 | #[route(POST "/org/{org}/members/role")] |
| 210 | 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 | 221 | require_form_csrf(&ctx, &form.csrf)?; |
| 213 | 222 | require_owner(&ctx)?; |
| 214 | - let state = app_context::<AppState>(cx); | |
| 223 | + let state = context::<AppState>(cx); | |
| 215 | 224 | let back = ctx.href("/members"); |
| 216 | 225 | |
| 217 | 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 | 266 | /// leaving member is sent to the public org page, since the members page is no longer theirs. |
| 258 | 267 | #[route(POST "/org/{org}/members/remove")] |
| 259 | 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 | 270 | require_form_csrf(&ctx, &form.csrf)?; |
| 262 | 271 | require_member(&ctx)?; |
| 263 | - let state = app_context::<AppState>(cx); | |
| 272 | + let state = context::<AppState>(cx); | |
| 264 | 273 | let user_id = form.user_id.trim().to_owned(); |
| 265 | 274 | let self_removal = user_id == ctx.viewer.0.id; |
| 266 | 275 | if !self_removal { |
crates/forge-web/src/pages/org_new.rsmodified+6 -5
| @@ -6,7 +6,7 @@ use forge_core::config::OrgCreation; | ||
| 6 | 6 | use forge_core::{AuditAction, User}; |
| 7 | 7 | use serde::Deserialize; |
| 8 | 8 | use topcoat::Result; |
| 9 | -use topcoat::context::{Cx, app_context}; | |
| 9 | +use topcoat::context::{Cx, context}; | |
| 10 | 10 | use topcoat::router::content::Form; |
| 11 | 11 | use topcoat::router::error::{forbidden, see_other}; |
| 12 | 12 | use topcoat::router::page; |
| @@ -43,6 +43,7 @@ pub(crate) fn may_create_org(state: &AppState, user: &User) -> bool { | ||
| 43 | 43 | |
| 44 | 44 | #[component] |
| 45 | 45 | async fn new_org_form( |
| 46 | + cx: &Cx, | |
| 46 | 47 | csrf: String, |
| 47 | 48 | name: String, |
| 48 | 49 | description: String, |
| @@ -76,13 +77,13 @@ async fn new_org_form( | ||
| 76 | 77 | #[page("/org/new")] |
| 77 | 78 | async fn new_org_page(cx: &Cx) -> Result<impl View> { |
| 78 | 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 | 81 | return Err(forbidden().into()); |
| 81 | 82 | } |
| 82 | 83 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 83 | 84 | let title = g::t(lang, K::NewOrganization); |
| 84 | 85 | let csrf = viewer.1.csrf_token.clone(); |
| 85 | - Ok(view! { cx => | |
| 86 | + Ok(view! { | |
| 86 | 87 | shell(title: title, viewer: Some(&viewer), |
| 87 | 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 | 92 | #[page(POST "/org/new")] |
| 92 | 93 | async fn new_org_submit(cx: &Cx, Form(form): Form<NewOrgForm>) -> Result<impl View> { |
| 93 | 94 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 94 | - let state = app_context::<AppState>(cx); | |
| 95 | + let state = context::<AppState>(cx); | |
| 95 | 96 | if !may_create_org(state, &viewer.0) { |
| 96 | 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 | 104 | let csrf = viewer.1.csrf_token.clone(); |
| 104 | 105 | let name = form.name.clone(); |
| 105 | 106 | let description = form.description.clone(); |
| 106 | - Ok(view! { cx => | |
| 107 | + Ok(view! { | |
| 107 | 108 | shell(title: title, viewer: Some(&viewer), |
| 108 | 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 | 10 | use forge_core::store::orgs::{DefaultRepoRole, OrgSettings}; |
| 11 | 11 | use serde::Deserialize; |
| 12 | 12 | use topcoat::Result; |
| 13 | -use topcoat::context::{Cx, app_context}; | |
| 13 | +use topcoat::context::{Cx, context}; | |
| 14 | 14 | use topcoat::router::content::Form; |
| 15 | 15 | use topcoat::router::content::multipart::Multipart; |
| 16 | 16 | use topcoat::router::error::{SeeOther, see_other}; |
| @@ -67,6 +67,7 @@ struct DeleteForm { | ||
| 67 | 67 | |
| 68 | 68 | #[component] |
| 69 | 69 | async fn settings_body( |
| 70 | + cx: &Cx, | |
| 70 | 71 | name: String, |
| 71 | 72 | display_name: String, |
| 72 | 73 | description: String, |
| @@ -169,10 +170,10 @@ async fn settings_body( | ||
| 169 | 170 | /// Gets the settings page. Owners only. |
| 170 | 171 | #[page("/org/{org}/settings")] |
| 171 | 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 | 174 | require_owner(&ctx)?; |
| 174 | 175 | let lang = i18n::lang(cx, Some(&ctx.viewer.0)); |
| 175 | - let state = app_context::<AppState>(cx); | |
| 176 | + let state = context::<AppState>(cx); | |
| 176 | 177 | let settings = state.store.org_settings(&ctx.org.id).await?; |
| 177 | 178 | let default_role = settings.default_repo_role.as_str().to_owned(); |
| 178 | 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 | 189 | let csrf = ctx.viewer.1.csrf_token.clone(); |
| 189 | 190 | let live = ctx.href("/settings/events"); |
| 190 | 191 | let (repo_count, package_count) = org_tab_counts(state, &ctx.org, &ctx.viewer.0).await?; |
| 191 | - Ok(view! { cx => | |
| 192 | + Ok(view! { | |
| 192 | 193 | shell(title: title.as_str(), viewer: Some(&ctx.viewer), |
| 193 | 194 | settings_body(name: name, display_name: display_name, description: description, |
| 194 | 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 | 202 | /// store refuses redirects with a notice before anything is written. |
| 202 | 203 | #[route(POST "/org/{org}/settings")] |
| 203 | 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 | 206 | require_form_csrf(&ctx, &form.csrf)?; |
| 206 | 207 | require_owner(&ctx)?; |
| 207 | - let state = app_context::<AppState>(cx); | |
| 208 | + let state = context::<AppState>(cx); | |
| 208 | 209 | let back = ctx.href("/settings"); |
| 209 | 210 | |
| 210 | 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 | 264 | /// Uploads the org's avatar. Owners only. The multipart fields are read as the person's upload |
| 264 | 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 | 267 | async fn org_avatar_upload(cx: &Cx, mut multipart: Multipart) -> Result<SeeOther> { |
| 267 | 268 | let mut csrf = String::new(); |
| 268 | 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 | 279 | require_form_csrf(&ctx, &csrf)?; |
| 279 | 280 | require_owner(&ctx)?; |
| 280 | - let state = app_context::<AppState>(cx); | |
| 281 | + let state = context::<AppState>(cx); | |
| 281 | 282 | let lang = i18n::lang(cx, Some(&ctx.viewer.0)); |
| 282 | 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 | 309 | /// Removes the org's avatar. Owners only. |
| 309 | 310 | #[route(POST "/org/{org}/settings/avatar/delete")] |
| 310 | 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 | 313 | require_form_csrf(&ctx, &form.csrf)?; |
| 313 | 314 | require_owner(&ctx)?; |
| 314 | - let state = app_context::<AppState>(cx); | |
| 315 | + let state = context::<AppState>(cx); | |
| 315 | 316 | let back = ctx.href("/settings"); |
| 316 | 317 | |
| 317 | 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 | 336 | /// repositories; then the settings page says so. |
| 336 | 337 | #[route(POST "/org/{org}/settings/delete")] |
| 337 | 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 | 340 | require_form_csrf(&ctx, &form.csrf)?; |
| 340 | 341 | require_owner(&ctx)?; |
| 341 | - let state = app_context::<AppState>(cx); | |
| 342 | + let state = context::<AppState>(cx); | |
| 342 | 343 | let back = ctx.href("/settings"); |
| 343 | 344 | |
| 344 | 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 | 9 | use forge_core::{AuditAction, Role}; |
| 10 | 10 | use serde::Deserialize; |
| 11 | 11 | use topcoat::Result; |
| 12 | -use topcoat::context::{Cx, app_context}; | |
| 12 | +use topcoat::context::{Cx, context}; | |
| 13 | 13 | use topcoat::router::content::Form; |
| 14 | 14 | use topcoat::router::error::{SeeOther, not_found, see_other}; |
| 15 | 15 | use topcoat::router::{page, path_param, route}; |
| @@ -183,6 +183,7 @@ pub(crate) async fn visible_team_repos( | ||
| 183 | 183 | |
| 184 | 184 | #[component] |
| 185 | 185 | async fn teams_body( |
| 186 | + cx: &Cx, | |
| 186 | 187 | name: String, |
| 187 | 188 | description: String, |
| 188 | 189 | base: String, |
| @@ -258,10 +259,10 @@ async fn teams_body( | ||
| 258 | 259 | /// Gets the teams list. Members only. |
| 259 | 260 | #[page("/org/{org}/teams")] |
| 260 | 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 | 263 | require_member(&ctx)?; |
| 263 | 264 | let lang = i18n::lang(cx, Some(&ctx.viewer.0)); |
| 264 | - let state = app_context::<AppState>(cx); | |
| 265 | + let state = context::<AppState>(cx); | |
| 265 | 266 | let teams = state.store.teams_for_org(&ctx.org.id).await?; |
| 266 | 267 | let rows: Vec<TeamRow> = teams |
| 267 | 268 | .into_iter() |
| @@ -282,7 +283,7 @@ async fn org_teams_page(cx: &Cx) -> Result<impl View> { | ||
| 282 | 283 | let csrf = ctx.viewer.1.csrf_token.clone(); |
| 283 | 284 | let live = ctx.href("/teams/events"); |
| 284 | 285 | let (repo_count, package_count) = org_tab_counts(state, &ctx.org, &ctx.viewer.0).await?; |
| 285 | - Ok(view! { cx => | |
| 286 | + Ok(view! { | |
| 286 | 287 | shell(title: title.as_str(), viewer: Some(&ctx.viewer), |
| 287 | 288 | teams_body(name: name, description: description, base: base, owner: owner, |
| 288 | 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 | 294 | #[component] |
| 294 | 295 | async fn team_body( |
| 296 | + cx: &Cx, | |
| 295 | 297 | data: TeamPage, |
| 296 | 298 | notice: Option<(&'static str, bool)>, |
| 297 | 299 | lang: Lang, |
| @@ -443,11 +445,11 @@ async fn team_body( | ||
| 443 | 445 | /// Gets one team's page. Members only; a team of another org is 404. |
| 444 | 446 | #[page("/org/{org}/teams/{team}")] |
| 445 | 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 | 449 | require_member(&ctx)?; |
| 448 | 450 | let lang = i18n::lang(cx, Some(&ctx.viewer.0)); |
| 449 | - let state = app_context::<AppState>(cx); | |
| 450 | - let team = team_of(state, &ctx, path_param::<Team>(cx)).await?; | |
| 451 | + let state = context::<AppState>(cx); | |
| 452 | + let team = team_of(state, &ctx, team(cx)).await?; | |
| 451 | 453 | let members: Vec<TeamMemberRow> = state |
| 452 | 454 | .store |
| 453 | 455 | .team_members(&team.id) |
| @@ -492,7 +494,7 @@ async fn org_team_page(cx: &Cx) -> Result<impl View> { | ||
| 492 | 494 | choices, |
| 493 | 495 | }; |
| 494 | 496 | let notice = take_notice(cx, lang); |
| 495 | - Ok(view! { cx => | |
| 497 | + Ok(view! { | |
| 496 | 498 | shell(title: title.as_str(), viewer: Some(&ctx.viewer), |
| 497 | 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 | 503 | /// Creates a team. Owners only. |
| 502 | 504 | #[route(POST "/org/{org}/teams/new")] |
| 503 | 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 | 507 | require_form_csrf(&ctx, &form.csrf)?; |
| 506 | 508 | require_owner(&ctx)?; |
| 507 | - let state = app_context::<AppState>(cx); | |
| 509 | + let state = context::<AppState>(cx); | |
| 508 | 510 | let back = ctx.href("/teams"); |
| 509 | 511 | |
| 510 | 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 | 554 | /// Renames a team and changes its description, role and coverage. Owners only. |
| 553 | 555 | #[route(POST "/org/{org}/teams/{team}/update")] |
| 554 | 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 | 558 | require_form_csrf(&ctx, &form.csrf)?; |
| 557 | 559 | require_owner(&ctx)?; |
| 558 | - let state = app_context::<AppState>(cx); | |
| 559 | - let team = team_of(state, &ctx, path_param::<Team>(cx)).await?; | |
| 560 | + let state = context::<AppState>(cx); | |
| 561 | + let team = team_of(state, &ctx, team(cx)).await?; | |
| 560 | 562 | let back = ctx.href(&format!("/teams/{}", team.id)); |
| 561 | 563 | |
| 562 | 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 | 605 | /// Deletes a team. Owners only. |
| 604 | 606 | #[route(POST "/org/{org}/teams/{team}/delete")] |
| 605 | 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 | 609 | require_form_csrf(&ctx, &form.csrf)?; |
| 608 | 610 | require_owner(&ctx)?; |
| 609 | - let state = app_context::<AppState>(cx); | |
| 610 | - let team = team_of(state, &ctx, path_param::<Team>(cx)).await?; | |
| 611 | + let state = context::<AppState>(cx); | |
| 612 | + let team = team_of(state, &ctx, team(cx)).await?; | |
| 611 | 613 | let name = team.name.clone(); |
| 612 | 614 | state.store.delete_team(&team.id).await?; |
| 613 | 615 | audit::record( |
| @@ -629,11 +631,11 @@ async fn org_team_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther | ||
| 629 | 631 | /// Adds an organization member to a team. Owners only. |
| 630 | 632 | #[route(POST "/org/{org}/teams/{team}/members/add")] |
| 631 | 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 | 635 | require_form_csrf(&ctx, &form.csrf)?; |
| 634 | 636 | require_owner(&ctx)?; |
| 635 | - let state = app_context::<AppState>(cx); | |
| 636 | - let team = team_of(state, &ctx, path_param::<Team>(cx)).await?; | |
| 637 | + let state = context::<AppState>(cx); | |
| 638 | + let team = team_of(state, &ctx, team(cx)).await?; | |
| 637 | 639 | let back = ctx.href(&format!("/teams/{}", team.id)); |
| 638 | 640 | |
| 639 | 641 | let username = form.username.trim(); |
| @@ -675,11 +677,11 @@ async fn org_team_member_add(cx: &Cx, Form(form): Form<TeamMemberForm>) -> Resul | ||
| 675 | 677 | /// Removes a person from a team. Owners only. |
| 676 | 678 | #[route(POST "/org/{org}/teams/{team}/members/remove")] |
| 677 | 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 | 681 | require_form_csrf(&ctx, &form.csrf)?; |
| 680 | 682 | require_owner(&ctx)?; |
| 681 | - let state = app_context::<AppState>(cx); | |
| 682 | - let team = team_of(state, &ctx, path_param::<Team>(cx)).await?; | |
| 683 | + let state = context::<AppState>(cx); | |
| 684 | + let team = team_of(state, &ctx, team(cx)).await?; | |
| 683 | 685 | let back = ctx.href(&format!("/teams/{}", team.id)); |
| 684 | 686 | |
| 685 | 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 | 707 | /// Links one of the org's repos to a team. Owners only. |
| 706 | 708 | #[route(POST "/org/{org}/teams/{team}/repos/add")] |
| 707 | 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 | 711 | require_form_csrf(&ctx, &form.csrf)?; |
| 710 | 712 | require_owner(&ctx)?; |
| 711 | - let state = app_context::<AppState>(cx); | |
| 712 | - let team = team_of(state, &ctx, path_param::<Team>(cx)).await?; | |
| 713 | + let state = context::<AppState>(cx); | |
| 714 | + let team = team_of(state, &ctx, team(cx)).await?; | |
| 713 | 715 | let back = ctx.href(&format!("/teams/{}", team.id)); |
| 714 | 716 | |
| 715 | 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 | 744 | /// Unlinks a repo from a team. Owners only. |
| 743 | 745 | #[route(POST "/org/{org}/teams/{team}/repos/remove")] |
| 744 | 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 | 748 | require_form_csrf(&ctx, &form.csrf)?; |
| 747 | 749 | require_owner(&ctx)?; |
| 748 | - let state = app_context::<AppState>(cx); | |
| 749 | - let team = team_of(state, &ctx, path_param::<Team>(cx)).await?; | |
| 750 | + let state = context::<AppState>(cx); | |
| 751 | + let team = team_of(state, &ctx, team(cx)).await?; | |
| 750 | 752 | let back = ctx.href(&format!("/teams/{}", team.id)); |
| 751 | 753 | |
| 752 | 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 | 9 | use serde::Deserialize; |
| 10 | 10 | use tokio::sync::watch; |
| 11 | 11 | use topcoat::Result; |
| 12 | -use topcoat::context::{Cx, app_context}; | |
| 12 | +use topcoat::context::{Cx, context}; | |
| 13 | 13 | use topcoat::router::content::Form; |
| 14 | 14 | use topcoat::router::content::sse::Event; |
| 15 | 15 | use topcoat::router::error::{SeeOther, forbidden, not_found, see_other}; |
| @@ -98,10 +98,10 @@ struct PackageQuery { | ||
| 98 | 98 | /// The package page: the head with the install snippet, then one tab of README or versions. |
| 99 | 99 | #[page("/{owner}/-/packages/{*pkg}")] |
| 100 | 100 | async fn package_page(cx: &Cx) -> Result<impl View> { |
| 101 | - let owner_name = path_param::<Owner>(cx); | |
| 102 | - let pkg_name = path_param::<Pkg>(cx).collect::<Vec<_>>().join("/"); | |
| 101 | + let owner_name = owner(cx); | |
| 102 | + let pkg_name = pkg(cx).collect::<Vec<_>>().join("/"); | |
| 103 | 103 | let pkg_name = pkg_name.as_str(); |
| 104 | - let state = app_context::<AppState>(cx); | |
| 104 | + let state = context::<AppState>(cx); | |
| 105 | 105 | let viewer = current_user(cx).await?; |
| 106 | 106 | let query = query_params::<PackageQuery>(cx)?; |
| 107 | 107 | let actor = viewer.as_ref().map(|(u, _)| u); |
| @@ -202,7 +202,7 @@ async fn package_page(cx: &Cx) -> Result<impl View> { | ||
| 202 | 202 | version_rows, |
| 203 | 203 | lang, |
| 204 | 204 | }; |
| 205 | - Ok(view! { cx => | |
| 205 | + Ok(view! { | |
| 206 | 206 | shell(title: title.as_str(), viewer: viewer.as_ref(), |
| 207 | 207 | if let Some(page) = oci { |
| 208 | 208 | oci_package_view(page: page) |
| @@ -228,8 +228,8 @@ struct TagDeleteForm { | ||
| 228 | 228 | #[route(POST "/{owner}/-/packages/tags/delete")] |
| 229 | 229 | async fn tag_delete(cx: &Cx, Form(form): Form<TagDeleteForm>) -> Result<SeeOther> { |
| 230 | 230 | let (viewer, _) = require_csrf(cx, &form.csrf).await?; |
| 231 | - let owner_name = path_param::<Owner>(cx); | |
| 232 | - let state = app_context::<AppState>(cx); | |
| 231 | + let owner_name = owner(cx); | |
| 232 | + let state = context::<AppState>(cx); | |
| 233 | 233 | let Some(owner) = state.store.user_by_username(owner_name).await? else { |
| 234 | 234 | return Err(not_found().into()); |
| 235 | 235 | }; |
| @@ -272,7 +272,7 @@ struct PackagePage { | ||
| 272 | 272 | |
| 273 | 273 | /// The package page body. |
| 274 | 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 | 276 | let lang = page.lang; |
| 277 | 277 | let PackagePage { |
| 278 | 278 | owner_name, |
| @@ -393,8 +393,8 @@ async fn package_view(page: PackagePage) -> Result<impl View> { | ||
| 393 | 393 | /// on connect, since the page was just rendered. |
| 394 | 394 | #[route(GET "/{owner}/-/packages/events")] |
| 395 | 395 | async fn packages_events(cx: &Cx) -> Result<Response> { |
| 396 | - let owner_name = path_param::<Owner>(cx); | |
| 397 | - let state = app_context::<AppState>(cx); | |
| 396 | + let owner_name = owner(cx); | |
| 397 | + let state = context::<AppState>(cx); | |
| 398 | 398 | let Some(owner) = state.store.user_by_username(owner_name).await? else { |
| 399 | 399 | return Err(not_found().into()); |
| 400 | 400 | }; |
| @@ -452,7 +452,7 @@ pub async fn repo_package_links( | ||
| 452 | 452 | |
| 453 | 453 | /// The Packages card of a repo's sidebar: the packages linked to this repo. |
| 454 | 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 | 456 | let heading = pk::t(lang, K::TabPackages); |
| 457 | 457 | Ok(view! { |
| 458 | 458 | <section class="sec repo-packages"> |
crates/forge-web/src/pages/packages_oci.rsmodified+2 -1
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | use forge_core::User; |
| 6 | 6 | use forge_core::packages::{OciTag, Package}; |
| 7 | 7 | use topcoat::Result; |
| 8 | +use topcoat::context::Cx; | |
| 8 | 9 | use topcoat::view::{View, component, view}; |
| 9 | 10 | |
| 10 | 11 | use crate::i18n::Lang; |
| @@ -72,7 +73,7 @@ fn short_digest(digest: &str) -> String { | ||
| 72 | 73 | |
| 73 | 74 | /// The container package page body. |
| 74 | 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 | 77 | let lang = page.lang; |
| 77 | 78 | let OciPage { |
| 78 | 79 | owner_name, |
crates/forge-web/src/pages/palette.rsmodified+2 -2
| @@ -21,7 +21,7 @@ use forge_core::store::orgs::OrgMemberRole; | ||
| 21 | 21 | use http::header::{CACHE_CONTROL, CONTENT_TYPE, X_CONTENT_TYPE_OPTIONS}; |
| 22 | 22 | use serde_json::{Value, json}; |
| 23 | 23 | use topcoat::Result; |
| 24 | -use topcoat::context::{Cx, app_context}; | |
| 24 | +use topcoat::context::{Cx, context}; | |
| 25 | 25 | use topcoat::router::response::Response; |
| 26 | 26 | use topcoat::router::{Body, HeaderValue, StatusCode, route}; |
| 27 | 27 | |
| @@ -379,7 +379,7 @@ async fn palette(cx: &Cx) -> Result<Response> { | ||
| 379 | 379 | *res.status_mut() = StatusCode::UNAUTHORIZED; |
| 380 | 380 | return Ok(res); |
| 381 | 381 | }; |
| 382 | - let state = app_context::<AppState>(cx); | |
| 382 | + let state = context::<AppState>(cx); | |
| 383 | 383 | let lang = i18n::lang(cx, Some(&user)); |
| 384 | 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 | 19 | use serde::Deserialize; |
| 20 | 20 | use serde_json::json; |
| 21 | 21 | use topcoat::Result; |
| 22 | -use topcoat::context::{Cx, app_context}; | |
| 22 | +use topcoat::context::{Cx, context}; | |
| 23 | 23 | use topcoat::router::content::Form; |
| 24 | 24 | use topcoat::router::error::{SeeOther, forbidden, not_found, see_other}; |
| 25 | 25 | use topcoat::router::response::Response; |
| @@ -250,7 +250,7 @@ struct LoginFinishForm { | ||
| 250 | 250 | #[route(POST "/settings/security/passkeys/register/begin")] |
| 251 | 251 | async fn register_begin(cx: &Cx, Form(form): Form<BeginForm>) -> Result<Response> { |
| 252 | 252 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 253 | - let state = app_context::<AppState>(cx); | |
| 253 | + let state = context::<AppState>(cx); | |
| 254 | 254 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 255 | 255 | let user = &viewer.0; |
| 256 | 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 | 317 | #[route(POST "/settings/security/passkeys/register/finish")] |
| 318 | 318 | async fn register_finish(cx: &Cx, Form(form): Form<FinishForm>) -> Result<Response> { |
| 319 | 319 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 320 | - let state = app_context::<AppState>(cx); | |
| 320 | + let state = context::<AppState>(cx); | |
| 321 | 321 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 322 | 322 | let user = &viewer.0; |
| 323 | 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 | 392 | #[route(POST "/settings/security/passkeys/{passkey_id}/rename")] |
| 393 | 393 | async fn rename(cx: &Cx, Form(form): Form<RenameForm>) -> Result<SeeOther> { |
| 394 | 394 | let (user, _session) = require_csrf(cx, &form.csrf).await?; |
| 395 | - let state = app_context::<AppState>(cx); | |
| 395 | + let state = context::<AppState>(cx); | |
| 396 | 396 | let id = path_param_segment(cx, "passkey_id").to_owned(); |
| 397 | 397 | let Ok(name) = clean_name(&form.name) else { |
| 398 | 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 | 415 | #[route(POST "/settings/security/passkeys/{passkey_id}/delete")] |
| 416 | 416 | async fn delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { |
| 417 | 417 | let (user, _session) = require_csrf(cx, &form.csrf).await?; |
| 418 | - let state = app_context::<AppState>(cx); | |
| 418 | + let state = context::<AppState>(cx); | |
| 419 | 419 | let id = path_param_segment(cx, "passkey_id").to_owned(); |
| 420 | 420 | // Only the owner's own list is searched, so another account's id looks like a missing one. |
| 421 | 421 | let Some(row) = state |
| @@ -462,7 +462,7 @@ async fn login_begin(cx: &Cx, Form(form): Form<LoginBeginForm>) -> Result<Respon | ||
| 462 | 462 | if !check_pre_csrf(cx, &form.precsrf) { |
| 463 | 463 | return Err(forbidden().into()); |
| 464 | 464 | } |
| 465 | - let state = app_context::<AppState>(cx); | |
| 465 | + let state = context::<AppState>(cx); | |
| 466 | 466 | let lang = i18n::lang(cx, None); |
| 467 | 467 | let ip_key = throttle::ip_key("passkey-ip", client_ip(cx)); |
| 468 | 468 | if let Some(retry) = state |
| @@ -502,7 +502,7 @@ async fn login_finish(cx: &Cx, Form(form): Form<LoginFinishForm>) -> Result<Resp | ||
| 502 | 502 | if !check_pre_csrf(cx, &form.precsrf) { |
| 503 | 503 | return Err(forbidden().into()); |
| 504 | 504 | } |
| 505 | - let state = app_context::<AppState>(cx); | |
| 505 | + let state = context::<AppState>(cx); | |
| 506 | 506 | let lang = i18n::lang(cx, None); |
| 507 | 507 | let now = Instant::now(); |
| 508 | 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 | 650 | /// The Passkeys topic of the security page: the list, rename and delete, and the add form that |
| 651 | 651 | /// `nav.js` drives. The add form stays hidden until the browser proves it supports passkeys. |
| 652 | 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 | 659 | let PasskeyPanel { items, problem } = panel; |
| 655 | 660 | let empty = items.is_empty(); |
| 656 | 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 | 726 | /// The passkey button and its error line for the login page. Hidden until the browser proves it |
| 722 | 727 | /// supports passkeys. |
| 723 | 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 | 730 | Ok(view! { |
| 726 | 731 | <div class="passkey-login" data-passkey-login="" hidden=(true)> |
| 727 | 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 | 598 | let page = send(&fx.router, "GET", &detail, session_cookie(ADMIN_TOKEN), &[]).await; |
| 599 | 599 | assert_eq!(page.status, 200); |
| 600 | 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 | 606 | let uri = format!("{detail}/remove-passkeys"); |
| 604 | 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 | 14 | use forge_core::tz::local_time_now; |
| 15 | 15 | use forge_core::{Repo, User, Visibility}; |
| 16 | 16 | use topcoat::Result; |
| 17 | -use topcoat::context::{Cx, app_context}; | |
| 17 | +use topcoat::context::{Cx, context}; | |
| 18 | 18 | use topcoat::router::error::not_found; |
| 19 | 19 | use topcoat::router::response::Response; |
| 20 | 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 | 99 | #[page("/{username}")] |
| 100 | 100 | async fn profile_page(cx: &Cx) -> Result<impl View> { |
| 101 | - let name = path_param::<Username>(cx); | |
| 102 | - let state = app_context::<AppState>(cx); | |
| 101 | + let name = username(cx); | |
| 102 | + let state = context::<AppState>(cx); | |
| 103 | 103 | let viewer = current_user(cx).await?; |
| 104 | 104 | let query = query_params::<ProfileQuery>(cx)?; |
| 105 | 105 | |
| @@ -234,7 +234,13 @@ async fn profile_page(cx: &Cx) -> Result<impl View> { | ||
| 234 | 234 | let snippet_pages = snippet_total.div_ceil(PER_PAGE).max(1); |
| 235 | 235 | let snippet_page = page.min(snippet_pages); |
| 236 | 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 | 245 | let snippets: Vec<ListRow> = snippets |
| 240 | 246 | .into_iter() |
| @@ -370,7 +376,7 @@ async fn profile_page(cx: &Cx) -> Result<impl View> { | ||
| 370 | 376 | // A repo deleted just before this redirect here shows its one-line notice once. |
| 371 | 377 | let notice = take_notice(cx); |
| 372 | 378 | let title = user.username.clone(); |
| 373 | - Ok(view! { cx => | |
| 379 | + Ok(view! { | |
| 374 | 380 | shell(title: title.as_str(), viewer: viewer.as_ref(), |
| 375 | 381 | notice_banner_for(lang: lang, title: notice) |
| 376 | 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 | 396 | /// comes from the session, so what it sends is what that viewer may read. An unknown name is 404. |
| 391 | 397 | #[route(GET "/users/{username}/events")] |
| 392 | 398 | async fn profile_events(cx: &Cx) -> Result<Response> { |
| 393 | - let name = path_param::<Username>(cx); | |
| 394 | - let state = app_context::<AppState>(cx).clone(); | |
| 399 | + let name = username(cx); | |
| 400 | + let state = context::<AppState>(cx).clone(); | |
| 395 | 401 | let Some(user) = state.store.user_by_username(name).await? else { |
| 396 | 402 | return Err(not_found().into()); |
| 397 | 403 | }; |
| @@ -601,6 +607,7 @@ async fn readable( | ||
| 601 | 607 | |
| 602 | 608 | #[component] |
| 603 | 609 | async fn profile_card( |
| 610 | + cx: &Cx, | |
| 604 | 611 | user: User, |
| 605 | 612 | avatar: Option<String>, |
| 606 | 613 | about_html: String, |
| @@ -875,10 +882,15 @@ async fn profile_card( | ||
| 875 | 882 | /// The viewer's own profile tabs on a page that makes something of theirs (a repository, a |
| 876 | 883 | /// snippet, an organization): the same tabs and counts as their profile, with `current` marked. |
| 877 | 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 | 891 | let items = crate::views::profile_items(lang, &username, false, true, false); |
| 880 | 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 | 894 | && let Some(user) = state.store.user_by_username(&username).await? |
| 883 | 895 | { |
| 884 | 896 | let actor = Some(&user); |
| @@ -913,6 +925,7 @@ pub async fn own_profile_tabs(lang: Lang, username: String, current: String) -> | ||
| 913 | 925 | /// organization's member pages all render it. |
| 914 | 926 | #[component] |
| 915 | 927 | pub async fn profile_tabs( |
| 928 | + cx: &Cx, | |
| 916 | 929 | username: String, |
| 917 | 930 | items: Vec<NavItem>, |
| 918 | 931 | current: String, |
crates/forge-web/src/pages/profile_pins.rsmodified+6 -5
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | use forge_core::store::profile_pins::MAX_PROFILE_PINS; |
| 6 | 6 | use forge_core::{Repo, Store, User}; |
| 7 | 7 | use topcoat::Result; |
| 8 | -use topcoat::context::{Cx, app_context}; | |
| 8 | +use topcoat::context::{Cx, context}; | |
| 9 | 9 | use topcoat::router::content::RawForm; |
| 10 | 10 | use topcoat::router::error::{SeeOther, see_other}; |
| 11 | 11 | use topcoat::router::{path_param, route}; |
| @@ -60,6 +60,7 @@ fn selection(raw: Vec<String>) -> Vec<String> { | ||
| 60 | 60 | /// the result after the redirect. |
| 61 | 61 | #[component] |
| 62 | 62 | pub(crate) async fn pins_menu( |
| 63 | + cx: &Cx, | |
| 63 | 64 | lang: Lang, |
| 64 | 65 | action: String, |
| 65 | 66 | csrf: String, |
| @@ -117,13 +118,13 @@ async fn pins_save(cx: &Cx, RawForm(raw): RawForm) -> Result<SeeOther> { | ||
| 117 | 118 | let chosen = selection(form_all(&pairs, "repo")); |
| 118 | 119 | let back = format!("/{}", viewer.0.username); |
| 119 | 120 | let owner = viewer.0.clone(); |
| 120 | - save_pins(app_context::<AppState>(cx), owner, chosen, back).await | |
| 121 | + save_pins(context::<AppState>(cx), owner, chosen, back).await | |
| 121 | 122 | } |
| 122 | 123 | |
| 123 | 124 | /// Pins are picked on the profile; an old link lands there. Owners only, as the form was. |
| 124 | 125 | #[route(GET "/org/{org}/settings/pins")] |
| 125 | 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 | 128 | require_owner(&ctx)?; |
| 128 | 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 | 132 | /// Saves an organization's pins, then back to the org profile. Owners only. |
| 132 | 133 | #[route(POST "/org/{org}/settings/pins")] |
| 133 | 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 | 136 | let pairs = form_pairs(&raw[..]); |
| 136 | 137 | require_form_csrf(&ctx, &form_field(&pairs, "csrf"))?; |
| 137 | 138 | require_owner(&ctx)?; |
| 138 | 139 | let chosen = selection(form_all(&pairs, "repo")); |
| 139 | 140 | let back = format!("/{}", ctx.org.username); |
| 140 | - save_pins(app_context::<AppState>(cx), ctx.org, chosen, back).await | |
| 141 | + save_pins(context::<AppState>(cx), ctx.org, chosen, back).await | |
| 141 | 142 | } |
| 142 | 143 | |
| 143 | 144 | #[cfg(test)] |
crates/forge-web/src/pages/pull_branch.rsmodified+5 -4
| @@ -17,7 +17,7 @@ use forge_git::repo::repo_path; | ||
| 17 | 17 | use serde::Deserialize; |
| 18 | 18 | use serde_json::json; |
| 19 | 19 | use topcoat::Result; |
| 20 | -use topcoat::context::{Cx, app_context}; | |
| 20 | +use topcoat::context::{Cx, context}; | |
| 21 | 21 | use topcoat::router::content::Form; |
| 22 | 22 | use topcoat::router::error::{forbidden, not_found, see_other}; |
| 23 | 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 | 83 | async fn branch_post(cx: &Cx, csrf: &str, op: Op) -> Result<Response> { |
| 84 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 85 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 84 | + let number = parse_number(number(cx))?; | |
| 85 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 86 | 86 | let (user, _) = require_csrf(cx, csrf).await?; |
| 87 | - let state = app_context::<AppState>(cx); | |
| 87 | + let state = context::<AppState>(cx); | |
| 88 | 88 | let Some(pr) = state.store.pull_by_number(&ctx.repo.id, number).await? else { |
| 89 | 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 | 374 | /// when the viewer may act, the delete or restore tool. |
| 375 | 375 | #[component] |
| 376 | 376 | pub(crate) async fn branch_box( |
| 377 | + cx: &Cx, | |
| 377 | 378 | lang: Lang, |
| 378 | 379 | action: Option<BranchAction>, |
| 379 | 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 | 13 | use forge_git::pulls::{blob_at, range_diff_files_ws}; |
| 14 | 14 | use serde::Deserialize; |
| 15 | 15 | use topcoat::Result; |
| 16 | -use topcoat::context::{Cx, app_context}; | |
| 16 | +use topcoat::context::{Cx, context}; | |
| 17 | 17 | use topcoat::router::content::Form; |
| 18 | 18 | use topcoat::router::error::{SeeOther, not_found, see_other}; |
| 19 | 19 | use topcoat::router::request::uri; |
| @@ -26,9 +26,7 @@ use crate::i18n::pulls as review_strings; | ||
| 26 | 26 | use crate::i18n::pulls::{self as g, K}; |
| 27 | 27 | use crate::i18n::{self, Lang}; |
| 28 | 28 | use crate::pages::edit_history::thread_edit_counts; |
| 29 | -use crate::pages::issue_parts::{ | |
| 30 | - check_write, csrf_of, may_converse, parse_number, triage, viewer, | |
| 31 | -}; | |
| 29 | +use crate::pages::issue_parts::{check_write, csrf_of, may_converse, parse_number, triage, viewer}; | |
| 32 | 30 | use crate::pages::passkeys; |
| 33 | 31 | use crate::pages::pull_reviews::{error_text_in, pull_diff, suggest_states}; |
| 34 | 32 | use crate::pages::pull_view::{commits_of, frame_in, is_merged, pull_header}; |
| @@ -206,6 +204,7 @@ struct RailFile { | ||
| 206 | 204 | /// toggle, and a changed file says so. |
| 207 | 205 | #[component] |
| 208 | 206 | async fn files_rail( |
| 207 | + cx: &Cx, | |
| 209 | 208 | lang: Lang, |
| 210 | 209 | rows: Vec<RailFile>, |
| 211 | 210 | done_text: String, |
| @@ -253,6 +252,7 @@ async fn files_rail( | ||
| 253 | 252 | /// The diff pane's top row: Unified or Split, and whitespace. Its links are the toolbar's own. |
| 254 | 253 | #[component] |
| 255 | 254 | async fn diff_top( |
| 255 | + cx: &Cx, | |
| 256 | 256 | lang: Lang, |
| 257 | 257 | unified: String, |
| 258 | 258 | split: String, |
| @@ -286,11 +286,11 @@ struct ViewedForm { | ||
| 286 | 286 | /// unreadable repo answers with the same not-found. |
| 287 | 287 | #[route(POST "/{owner}/{repo}/pulls/{number}/viewed")] |
| 288 | 288 | async fn viewed_post(cx: &Cx, Form(form): Form<ViewedForm>) -> Result<SeeOther> { |
| 289 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 290 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 289 | + let number = parse_number(number(cx))?; | |
| 290 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 291 | 291 | let (user, session) = require_user(cx).await?; |
| 292 | 292 | check_write(&ctx, &session, &form.csrf)?; |
| 293 | - let state = app_context::<AppState>(cx); | |
| 293 | + let state = context::<AppState>(cx); | |
| 294 | 294 | let pr = match state.store.pull_by_number(&ctx.repo.id, number).await? { |
| 295 | 295 | Some(pr) => pr, |
| 296 | 296 | None => return Err(not_found().into()), |
| @@ -334,6 +334,7 @@ async fn viewed_post(cx: &Cx, Form(form): Form<ViewedForm>) -> Result<SeeOther> | ||
| 334 | 334 | /// Request changes in the pull's head submit the same form. |
| 335 | 335 | #[component] |
| 336 | 336 | async fn review_bar( |
| 337 | + cx: &Cx, | |
| 337 | 338 | lang: Lang, |
| 338 | 339 | pr_href: String, |
| 339 | 340 | csrf: String, |
| @@ -413,9 +414,9 @@ fn file_param(cx: &Cx) -> Option<usize> { | ||
| 413 | 414 | |
| 414 | 415 | #[page("/{owner}/{repo}/pulls/{number}/files")] |
| 415 | 416 | async fn pull_files(cx: &Cx) -> Result<impl View> { |
| 416 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 417 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 418 | - let state = app_context::<AppState>(cx); | |
| 417 | + let number = parse_number(number(cx))?; | |
| 418 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 419 | + let state = context::<AppState>(cx); | |
| 419 | 420 | let pr = match state.store.pull_by_number(&ctx.repo.id, number).await? { |
| 420 | 421 | Some(pr) => pr, |
| 421 | 422 | None => return Err(not_found().into()), |
| @@ -568,7 +569,10 @@ async fn pull_files(cx: &Cx) -> Result<impl View> { | ||
| 568 | 569 | .as_ref() |
| 569 | 570 | .map(|c| format!("{}/viewed", c.pr_href)) |
| 570 | 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 | 577 | let done = rows |
| 574 | 578 | .iter() |
| @@ -653,9 +657,7 @@ async fn pull_files(cx: &Cx) -> Result<impl View> { | ||
| 653 | 657 | } |
| 654 | 658 | .to_owned(), |
| 655 | 659 | tick, |
| 656 | - href: row | |
| 657 | - .index | |
| 658 | - .map(|i| format!("?file={i}#file-{}", i + 1)), | |
| 660 | + href: row.index.map(|i| format!("?file={i}#file-{}", i + 1)), | |
| 659 | 661 | path: row.path, |
| 660 | 662 | label: row.label, |
| 661 | 663 | state: row.state, |
crates/forge-web/src/pages/pull_flow.rsmodified+11 -11
| @@ -13,7 +13,7 @@ | ||
| 13 | 13 | use forge_core::{Action, IssueState, MergeStyle, PullRequest, authorize}; |
| 14 | 14 | use serde::Deserialize; |
| 15 | 15 | use topcoat::Result; |
| 16 | -use topcoat::context::{Cx, app_context}; | |
| 16 | +use topcoat::context::{Cx, context}; | |
| 17 | 17 | use topcoat::router::content::Form; |
| 18 | 18 | use topcoat::router::error::{bad_request, forbidden, not_found, see_other}; |
| 19 | 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 | 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 | 58 | match state.store.pull_by_number(&ctx.repo.id, number).await? { |
| 59 | 59 | Some(pr) => Ok(pr), |
| 60 | 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 | 74 | async fn set_draft(cx: &Cx, csrf: &str, draft: bool) -> Result<Response> { |
| 75 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 76 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 75 | + let number = parse_number(number(cx))?; | |
| 76 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 77 | 77 | let (user, _) = require_csrf(cx, csrf).await?; |
| 78 | - let state = app_context::<AppState>(cx); | |
| 78 | + let state = context::<AppState>(cx); | |
| 79 | 79 | let pr = load(cx, &ctx, number).await?; |
| 80 | 80 | if ctx.repo.archived || !(can_write(&ctx, &user) || user.id == pr.issue.author_id) { |
| 81 | 81 | return Err(forbidden().into()); |
| @@ -118,13 +118,13 @@ async fn set_draft(cx: &Cx, csrf: &str, draft: bool) -> Result<Response> { | ||
| 118 | 118 | |
| 119 | 119 | #[route(POST "/{owner}/{repo}/pulls/{number}/auto-merge")] |
| 120 | 120 | async fn auto_merge_enable(cx: &Cx, Form(form): Form<FlowForm>) -> Result<Response> { |
| 121 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 122 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 121 | + let number = parse_number(number(cx))?; | |
| 122 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 123 | 123 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 124 | 124 | if ctx.repo.archived || !can_write(&ctx, &user) { |
| 125 | 125 | return Err(forbidden().into()); |
| 126 | 126 | } |
| 127 | - let state = app_context::<AppState>(cx); | |
| 127 | + let state = context::<AppState>(cx); | |
| 128 | 128 | let pr = load(cx, &ctx, number).await?; |
| 129 | 129 | let style = form |
| 130 | 130 | .style |
| @@ -149,13 +149,13 @@ async fn auto_merge_enable(cx: &Cx, Form(form): Form<FlowForm>) -> Result<Respon | ||
| 149 | 149 | |
| 150 | 150 | #[route(POST "/{owner}/{repo}/pulls/{number}/auto-merge/disable")] |
| 151 | 151 | async fn auto_merge_disable(cx: &Cx, Form(form): Form<FlowForm>) -> Result<Response> { |
| 152 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 153 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 152 | + let number = parse_number(number(cx))?; | |
| 153 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 154 | 154 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 155 | 155 | if ctx.repo.archived || !can_write(&ctx, &user) { |
| 156 | 156 | return Err(forbidden().into()); |
| 157 | 157 | } |
| 158 | - let state = app_context::<AppState>(cx); | |
| 158 | + let state = context::<AppState>(cx); | |
| 159 | 159 | let pr = load(cx, &ctx, number).await?; |
| 160 | 160 | state |
| 161 | 161 | .store |
crates/forge-web/src/pages/pull_live.rsmodified+7 -7
| @@ -18,7 +18,7 @@ use forge_core::PullRequest; | ||
| 18 | 18 | use forge_core::reactions::ReactionTarget; |
| 19 | 19 | use forge_core::store::Store; |
| 20 | 20 | use topcoat::Result; |
| 21 | -use topcoat::context::{Cx, app_context}; | |
| 21 | +use topcoat::context::{Cx, context}; | |
| 22 | 22 | use topcoat::router::request::{method, uri}; |
| 23 | 23 | use topcoat::router::response::Response; |
| 24 | 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 | 202 | /// The pull list's change stream. Auth is the repo read check of the list page. |
| 203 | 203 | #[route(GET "/{owner}/{repo}/pulls/events")] |
| 204 | 204 | async fn pulls_events(cx: &Cx) -> Result<Response> { |
| 205 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 206 | - let state = app_context::<AppState>(cx); | |
| 205 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 206 | + let state = context::<AppState>(cx); | |
| 207 | 207 | let topic = Topic::PullList(ctx.repo.id.clone()); |
| 208 | 208 | let store = state.store.clone(); |
| 209 | 209 | let repo_id = ctx.repo.id.clone(); |
| @@ -220,9 +220,9 @@ async fn pulls_events(cx: &Cx) -> Result<Response> { | ||
| 220 | 220 | /// One pull request's change stream. Auth is the page's: the repo read check, then the pull. |
| 221 | 221 | #[route(GET "/{owner}/{repo}/pulls/{number}/events")] |
| 222 | 222 | async fn pull_events(cx: &Cx) -> Result<Response> { |
| 223 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 224 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 225 | - let state = app_context::<AppState>(cx); | |
| 223 | + let number = parse_number(number(cx))?; | |
| 224 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 225 | + let state = context::<AppState>(cx); | |
| 226 | 226 | let Some(pr) = state.store.pull_by_number(&ctx.repo.id, number).await? else { |
| 227 | 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 | 284 | let target = written(cx); |
| 285 | 285 | let result = next.run(cx, body).await; |
| 286 | 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 | 289 | 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 | 20 | use forge_git::pulls::{FileEdit, Signature, commit_file_edit, range_diff_files}; |
| 21 | 21 | use serde::Deserialize; |
| 22 | 22 | use topcoat::Result; |
| 23 | -use topcoat::context::{Cx, app_context}; | |
| 23 | +use topcoat::context::{Cx, context}; | |
| 24 | 24 | use topcoat::router::content::Form; |
| 25 | 25 | use topcoat::router::error::{SeeOther, forbidden, not_found, see_other}; |
| 26 | 26 | use topcoat::router::request::uri; |
| @@ -341,11 +341,11 @@ fn signature_of(state: &AppState, user: &User) -> Signature { | ||
| 341 | 341 | /// request must name the head the form was rendered for, and the line must be on that diff. |
| 342 | 342 | #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments")] |
| 343 | 343 | async fn review_comment_post(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> { |
| 344 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 345 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 344 | + let number = parse_number(number(cx))?; | |
| 345 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 346 | 346 | let (user, session) = require_user(cx).await?; |
| 347 | 347 | check_write(&ctx, &session, &form.csrf)?; |
| 348 | - let state = app_context::<AppState>(cx); | |
| 348 | + let state = context::<AppState>(cx); | |
| 349 | 349 | let pr = pull_for(state, &ctx, number).await?; |
| 350 | 350 | if !may_converse(&ctx, &pr.issue) { |
| 351 | 351 | return Err(forbidden().into()); |
| @@ -411,16 +411,16 @@ async fn review_comment_post(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<Se | ||
| 411 | 411 | /// Replies in the thread of a root comment. Replies post at once, even on a closed pull request. |
| 412 | 412 | #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/reply")] |
| 413 | 413 | async fn review_comment_reply(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> { |
| 414 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 415 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 414 | + let number = parse_number(number(cx))?; | |
| 415 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 416 | 416 | let (user, session) = require_user(cx).await?; |
| 417 | 417 | check_write(&ctx, &session, &form.csrf)?; |
| 418 | - let state = app_context::<AppState>(cx); | |
| 418 | + let state = context::<AppState>(cx); | |
| 419 | 419 | let pr = pull_for(state, &ctx, number).await?; |
| 420 | 420 | if !may_converse(&ctx, &pr.issue) { |
| 421 | 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 | 424 | let root = root_of(&parent); |
| 425 | 425 | let tab = tab_url(&ctx, number, &form.ret); |
| 426 | 426 | let anchor = format!("#rc-{root}"); |
| @@ -441,13 +441,13 @@ async fn review_comment_reply(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<S | ||
| 441 | 441 | /// The edit form for a comment. Only its author may open it. |
| 442 | 442 | #[page("/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/edit")] |
| 443 | 443 | async fn review_comment_edit_form(cx: &Cx) -> Result<impl View> { |
| 444 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 445 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 444 | + let number = parse_number(number(cx))?; | |
| 445 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 446 | 446 | let (user, _) = require_user(cx).await?; |
| 447 | 447 | let lang = i18n::lang(cx, Some(&user)); |
| 448 | - let state = app_context::<AppState>(cx); | |
| 448 | + let state = context::<AppState>(cx); | |
| 449 | 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 | 451 | if comment.author_id != user.id { |
| 452 | 452 | return Err(forbidden().into()); |
| 453 | 453 | } |
| @@ -464,7 +464,7 @@ async fn edit_page( | ||
| 464 | 464 | error: Option<&'static str>, |
| 465 | 465 | lang: Lang, |
| 466 | 466 | ) -> Result<impl View> { |
| 467 | - let state = app_context::<AppState>(cx); | |
| 467 | + let state = context::<AppState>(cx); | |
| 468 | 468 | let owner = ctx.repo.owner_name.clone(); |
| 469 | 469 | let name = ctx.repo.name.clone(); |
| 470 | 470 | let csrf = csrf_of(&ctx); |
| @@ -481,7 +481,7 @@ async fn edit_page( | ||
| 481 | 481 | let save_label = g::t(lang, K::SaveComment); |
| 482 | 482 | let cancel_label = g::t(lang, K::CancelButton); |
| 483 | 483 | let header = ctx.head(state, "pulls").await?; |
| 484 | - Ok(view! { cx => | |
| 484 | + Ok(view! { | |
| 485 | 485 | shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(), |
| 486 | 486 | repo_head(head: header, title: Some(heading.to_owned())) |
| 487 | 487 | <div class="sheet fit"> |
| @@ -507,13 +507,13 @@ async fn edit_page( | ||
| 507 | 507 | /// Saves an edited comment. Only its author; the store records the previous body. |
| 508 | 508 | #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/edit")] |
| 509 | 509 | async fn review_comment_edit_save(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> { |
| 510 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 511 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 510 | + let number = parse_number(number(cx))?; | |
| 511 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 512 | 512 | let (user, session) = require_user(cx).await?; |
| 513 | 513 | check_write(&ctx, &session, &form.csrf)?; |
| 514 | - let state = app_context::<AppState>(cx); | |
| 514 | + let state = context::<AppState>(cx); | |
| 515 | 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 | 517 | if comment.author_id != user.id { |
| 518 | 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 | 543 | /// Deletes a comment. Its author or Triage. Deleting a root deletes its replies. |
| 544 | 544 | #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/delete")] |
| 545 | 545 | async fn review_comment_delete(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> { |
| 546 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 547 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 546 | + let number = parse_number(number(cx))?; | |
| 547 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 548 | 548 | let (user, session) = require_user(cx).await?; |
| 549 | 549 | check_write(&ctx, &session, &form.csrf)?; |
| 550 | - let state = app_context::<AppState>(cx); | |
| 550 | + let state = context::<AppState>(cx); | |
| 551 | 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 | 553 | if !may_change(&ctx, &comment.author_id) { |
| 554 | 554 | return Err(forbidden().into()); |
| 555 | 555 | } |
| @@ -565,13 +565,13 @@ async fn review_comment_delete(cx: &Cx, Form(form): Form<ReviewForm>) -> Result< | ||
| 565 | 565 | /// Resolves or unresolves a thread (`resolved=1|0`). The PR author or Write. |
| 566 | 566 | #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/resolve")] |
| 567 | 567 | async fn review_comment_resolve(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> { |
| 568 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 569 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 568 | + let number = parse_number(number(cx))?; | |
| 569 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 570 | 570 | let (user, session) = require_user(cx).await?; |
| 571 | 571 | check_write(&ctx, &session, &form.csrf)?; |
| 572 | - let state = app_context::<AppState>(cx); | |
| 572 | + let state = context::<AppState>(cx); | |
| 573 | 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 | 575 | let is_pr_author = pr.issue.author_id == user.id; |
| 576 | 576 | if !is_pr_author |
| 577 | 577 | && authorize( |
| @@ -607,13 +607,13 @@ async fn review_comment_resolve(cx: &Cx, Form(form): Form<ReviewForm>) -> Result | ||
| 607 | 607 | /// suggestion was written against. |
| 608 | 608 | #[route(POST "/{owner}/{repo}/pulls/{number}/review_comments/{comment_id}/apply")] |
| 609 | 609 | async fn review_comment_apply(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> { |
| 610 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 611 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 610 | + let number = parse_number(number(cx))?; | |
| 611 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 612 | 612 | let (user, session) = require_user(cx).await?; |
| 613 | 613 | check_write(&ctx, &session, &form.csrf)?; |
| 614 | - let state = app_context::<AppState>(cx); | |
| 614 | + let state = context::<AppState>(cx); | |
| 615 | 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 | 617 | let files = tab_url(&ctx, number, &form.ret); |
| 618 | 618 | let anchor = format!("#rc-{}", comment.id); |
| 619 | 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 | 697 | /// cannot approve or request changes on their own pull request. Closed pull requests refuse it. |
| 698 | 698 | #[route(POST "/{owner}/{repo}/pulls/{number}/reviews")] |
| 699 | 699 | async fn review_submit(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> { |
| 700 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 701 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 700 | + let number = parse_number(number(cx))?; | |
| 701 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 702 | 702 | let (user, session) = require_user(cx).await?; |
| 703 | 703 | check_write(&ctx, &session, &form.csrf)?; |
| 704 | - let state = app_context::<AppState>(cx); | |
| 704 | + let state = context::<AppState>(cx); | |
| 705 | 705 | let pr = pull_for(state, &ctx, number).await?; |
| 706 | 706 | if !may_converse(&ctx, &pr.issue) { |
| 707 | 707 | return Err(forbidden().into()); |
| @@ -772,11 +772,11 @@ async fn review_text( | ||
| 772 | 772 | /// Discards the viewer's pending review and its draft comments. |
| 773 | 773 | #[route(POST "/{owner}/{repo}/pulls/{number}/reviews/discard")] |
| 774 | 774 | async fn review_discard(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> { |
| 775 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 776 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 775 | + let number = parse_number(number(cx))?; | |
| 776 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 777 | 777 | let (user, session) = require_user(cx).await?; |
| 778 | 778 | check_write(&ctx, &session, &form.csrf)?; |
| 779 | - let state = app_context::<AppState>(cx); | |
| 779 | + let state = context::<AppState>(cx); | |
| 780 | 780 | let pr = pull_for(state, &ctx, number).await?; |
| 781 | 781 | state |
| 782 | 782 | .store |
| @@ -788,8 +788,8 @@ async fn review_discard(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOthe | ||
| 788 | 788 | /// Dismisses an approval or a change request with a reason. Write only. |
| 789 | 789 | #[route(POST "/{owner}/{repo}/pulls/{number}/reviews/{review_id}/dismiss")] |
| 790 | 790 | async fn review_dismiss(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOther> { |
| 791 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 792 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 791 | + let number = parse_number(number(cx))?; | |
| 792 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 793 | 793 | let (user, session) = require_user(cx).await?; |
| 794 | 794 | check_write(&ctx, &session, &form.csrf)?; |
| 795 | 795 | if authorize( |
| @@ -803,9 +803,9 @@ async fn review_dismiss(cx: &Cx, Form(form): Form<ReviewForm>) -> Result<SeeOthe | ||
| 803 | 803 | { |
| 804 | 804 | return Err(forbidden().into()); |
| 805 | 805 | } |
| 806 | - let state = app_context::<AppState>(cx); | |
| 806 | + let state = context::<AppState>(cx); | |
| 807 | 807 | let pr = pull_for(state, &ctx, number).await?; |
| 808 | - let wanted = path_param::<ReviewId>(cx); | |
| 808 | + let wanted = review_id(cx); | |
| 809 | 809 | let Some(review) = state |
| 810 | 810 | .store |
| 811 | 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 | 12 | use forge_git::history::CommitDiff; |
| 13 | 13 | use forge_git::pulls::{is_ancestor, range_diff_files, range_log}; |
| 14 | 14 | use topcoat::Result; |
| 15 | -use topcoat::context::{Cx, app_context}; | |
| 15 | +use topcoat::context::{Cx, context}; | |
| 16 | 16 | use topcoat::router::content::Form; |
| 17 | 17 | use topcoat::router::error::{not_found, see_other}; |
| 18 | 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 | 70 | /// The repo and pull request for a request whose path names `{owner}/{repo}/pulls/{number}`. |
| 71 | 71 | async fn load_pull(cx: &Cx) -> Result<(RepoCtx, PullRequest)> { |
| 72 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 73 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 74 | - let pr = pull_for(app_context::<AppState>(cx), &ctx, number).await?; | |
| 72 | + let number = parse_number(number(cx))?; | |
| 73 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 74 | + let pr = pull_for(context::<AppState>(cx), &ctx, number).await?; | |
| 75 | 75 | Ok((ctx, pr)) |
| 76 | 76 | } |
| 77 | 77 | |
| @@ -192,6 +192,7 @@ pub(crate) async fn frame_in( | ||
| 192 | 192 | /// then the pull request's tabs. `active` names the tab that is open. |
| 193 | 193 | #[component] |
| 194 | 194 | pub(crate) async fn pull_header( |
| 195 | + cx: &Cx, | |
| 195 | 196 | frame: Frame, |
| 196 | 197 | active: String, |
| 197 | 198 | #[default] child: Child<'_>, |
| @@ -317,6 +318,7 @@ struct FlowView { | ||
| 317 | 318 | /// `ok`, `bad` or `muted` and picks the box colors. |
| 318 | 319 | #[component] |
| 319 | 320 | async fn merge_box( |
| 321 | + cx: &Cx, | |
| 320 | 322 | headline: String, |
| 321 | 323 | tone: String, |
| 322 | 324 | conflicts: Vec<String>, |
| @@ -458,6 +460,7 @@ async fn merge_box( | ||
| 458 | 460 | /// The note that replaces the merge box once the pull request is merged. |
| 459 | 461 | #[component] |
| 460 | 462 | async fn merged_notice( |
| 463 | + cx: &Cx, | |
| 461 | 464 | who: String, |
| 462 | 465 | when: When, |
| 463 | 466 | commit: String, |
| @@ -500,6 +503,7 @@ struct DismissRow { | ||
| 500 | 503 | /// holders. Either summary line may be absent. |
| 501 | 504 | #[component] |
| 502 | 505 | async fn review_box( |
| 506 | + cx: &Cx, | |
| 503 | 507 | approved: Option<String>, |
| 504 | 508 | approved_before: Option<String>, |
| 505 | 509 | changes: Option<String>, |
| @@ -571,7 +575,7 @@ async fn head_checks( | ||
| 571 | 575 | } |
| 572 | 576 | |
| 573 | 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 | 579 | let empty = rows.is_empty(); |
| 576 | 580 | let no_commits = g::t(lang, K::NoCommits); |
| 577 | 581 | let committed = g::t(lang, K::Committed); |
| @@ -612,7 +616,7 @@ async fn pull_conversation( | ||
| 612 | 616 | error: Option<String>, |
| 613 | 617 | merge_error: Option<String>, |
| 614 | 618 | ) -> Result<impl View> { |
| 615 | - let state = app_context::<AppState>(cx); | |
| 619 | + let state = context::<AppState>(cx); | |
| 616 | 620 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user)); |
| 617 | 621 | let commit_count = commits_of(state, &ctx, &pr).await?.len(); |
| 618 | 622 | let file_count = diff_of(state, &ctx, &pr).await?.files.len(); |
| @@ -899,7 +903,7 @@ async fn pull_conversation( | ||
| 899 | 903 | let labels_href = repo_href(&owner, &name, "labels.css", ""); |
| 900 | 904 | // The conversation follows the pull request's event stream: a change re-renders it. |
| 901 | 905 | let live = format!("{href}/events"); |
| 902 | - Ok(view! { cx => | |
| 906 | + Ok(view! { | |
| 903 | 907 | shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(), extra_stylesheet: Some(labels_href.as_str()), |
| 904 | 908 | pull_header(frame: frame.clone(), active: "conversation".to_owned(), |
| 905 | 909 | item_head_tools(lang: lang, close: close, notify: notify) |
| @@ -1005,7 +1009,7 @@ async fn pull_show(cx: &Cx) -> Result<impl View> { | ||
| 1005 | 1009 | #[page("/{owner}/{repo}/pulls/{number}/commits")] |
| 1006 | 1010 | async fn pull_commits(cx: &Cx) -> Result<impl View> { |
| 1007 | 1011 | let (ctx, pr) = load_pull(cx).await?; |
| 1008 | - let state = app_context::<AppState>(cx); | |
| 1012 | + let state = context::<AppState>(cx); | |
| 1009 | 1013 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user)); |
| 1010 | 1014 | let commits = commits_of(state, &ctx, &pr).await?; |
| 1011 | 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 | 1046 | /// routes. A merged pull request's state cannot change, and a refused comment re-renders the |
| 1043 | 1047 | /// Conversation with its text. |
| 1044 | 1048 | async fn pull_post(cx: &Cx, form: CommentForm) -> Result<impl View> { |
| 1045 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 1046 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 1049 | + let number = parse_number(number(cx))?; | |
| 1050 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 1047 | 1051 | let (user, session) = require_user(cx).await?; |
| 1048 | 1052 | check_write(&ctx, &session, &form.csrf)?; |
| 1049 | - let state = app_context::<AppState>(cx); | |
| 1053 | + let state = context::<AppState>(cx); | |
| 1050 | 1054 | let pr = pull_for(state, &ctx, number).await?; |
| 1051 | 1055 | let lang = i18n::lang(cx, Some(&user)); |
| 1052 | 1056 | |
| @@ -1301,10 +1305,7 @@ mod tests { | ||
| 1301 | 1305 | assert_eq!(status, 200, "clean"); |
| 1302 | 1306 | assert!(body.contains("Add feature"), "clean: {body}"); |
| 1303 | 1307 | assert!(body.contains("issue-badge-open\">Open<"), "clean: {body}"); |
| 1304 | - assert!( | |
| 1305 | - body.contains("Ready to merge"), | |
| 1306 | - "clean: {body}" | |
| 1307 | - ); | |
| 1308 | + assert!(body.contains("Ready to merge"), "clean: {body}"); | |
| 1308 | 1309 | assert!( |
| 1309 | 1310 | body.contains(&format!("action=\"{uri}/merge\"")), |
| 1310 | 1311 | "clean: {body}" |
| @@ -1320,10 +1321,7 @@ mod tests { | ||
| 1320 | 1321 | // A reader sees the clean status but no merge form. |
| 1321 | 1322 | let (status, _, body) = send(&fx.router, "GET", &uri, Some("bob-token"), None).await; |
| 1322 | 1323 | assert_eq!(status, 200, "reader"); |
| 1323 | - assert!( | |
| 1324 | - body.contains("Ready to merge"), | |
| 1325 | - "reader: {body}" | |
| 1326 | - ); | |
| 1324 | + assert!(body.contains("Ready to merge"), "reader: {body}"); | |
| 1327 | 1325 | assert!(!body.contains("name=\"style\""), "reader: {body}"); |
| 1328 | 1326 | assert!(!body.contains("Merge pull request"), "reader: {body}"); |
| 1329 | 1327 | |
| @@ -1723,7 +1721,10 @@ mod tests { | ||
| 1723 | 1721 | assert!(body.contains("Please rename this"), "approval: {body}"); |
| 1724 | 1722 | assert!(body.contains("feat.txt:1"), "approval: {body}"); |
| 1725 | 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 | 1728 | assert!(body.contains("Approved by bob"), "approval: {body}"); |
| 1728 | 1729 | |
| 1729 | 1730 | fx.store |
crates/forge-web/src/pages/pulls_list.rsmodified+16 -10
| @@ -8,7 +8,7 @@ use std::collections::HashMap; | ||
| 8 | 8 | use forge_core::tz::format_in_tz; |
| 9 | 9 | use forge_core::{IssueListItem, IssueState}; |
| 10 | 10 | use topcoat::Result; |
| 11 | -use topcoat::context::{Cx, app_context}; | |
| 11 | +use topcoat::context::{Cx, context}; | |
| 12 | 12 | use topcoat::router::{page, path_param, query_params}; |
| 13 | 13 | use topcoat::view::{View, view}; |
| 14 | 14 | |
| @@ -16,13 +16,12 @@ use crate::i18n::merge_queue as mq; | ||
| 16 | 16 | use crate::i18n::pulls::{self as g, K}; |
| 17 | 17 | use crate::i18n::{self, Lang}; |
| 18 | 18 | use crate::pages::issues_list::{ |
| 19 | - AssigneeView, LabelView, ListQuery, MilestoneView, Selection, SortOption, list_href, | |
| 20 | - stamp_unix, | |
| 19 | + AssigneeView, LabelView, ListQuery, MilestoneView, Selection, SortOption, list_href, stamp_unix, | |
| 21 | 20 | }; |
| 21 | +use crate::pages::passkeys::s; | |
| 22 | 22 | use crate::pages::repo::repo_head; |
| 23 | 23 | use crate::pages::repo_ctx::load_repo; |
| 24 | 24 | use crate::state::AppState; |
| 25 | -use crate::pages::passkeys::s; | |
| 26 | 25 | use crate::views::parts::{RailItem, SubPart, rail}; |
| 27 | 26 | use crate::views::{ |
| 28 | 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 | 63 | if open { |
| 65 | 64 | (g::t(lang, K::PrStateOpenLabel), g::t(lang, K::StateOpen)) |
| 66 | 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 | 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 | 156 | #[page("/{owner}/{repo}/pulls")] |
| 152 | 157 | async fn pulls_list_page(cx: &Cx) -> Result<impl View> { |
| 153 | - let owner = path_param::<Owner>(cx); | |
| 154 | - let name = path_param::<Repo>(cx); | |
| 158 | + let owner = owner(cx); | |
| 159 | + let name = repo(cx); | |
| 155 | 160 | let query = query_params::<ListQuery>(cx)?; |
| 156 | 161 | let ctx = load_repo(cx, owner, name).await?; |
| 157 | - let state = app_context::<AppState>(cx); | |
| 162 | + let state = context::<AppState>(cx); | |
| 158 | 163 | let mut sel = Selection::parse(query); |
| 159 | 164 | sel.resolve_me(ctx.viewer.as_ref().map(|(user, _)| user.username.as_str())); |
| 160 | 165 | let search_value = sel.search_text(); |
| @@ -411,7 +416,8 @@ mod tests { | ||
| 411 | 416 | } |
| 412 | 417 | |
| 413 | 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 | 423 | const HEAD_OID: &str = "1111111111111111111111111111111111111111"; |
crates/forge-web/src/pages/pulls_merge.rsmodified+4 -4
| @@ -25,7 +25,7 @@ use http::HeaderValue; | ||
| 25 | 25 | use http::header::CONTENT_TYPE; |
| 26 | 26 | use serde::Deserialize; |
| 27 | 27 | use topcoat::Result; |
| 28 | -use topcoat::context::{Cx, app_context}; | |
| 28 | +use topcoat::context::{Cx, context}; | |
| 29 | 29 | use topcoat::router::content::Form; |
| 30 | 30 | use topcoat::router::error::{bad_request, forbidden, not_found, see_other}; |
| 31 | 31 | use topcoat::router::response::Response; |
| @@ -110,8 +110,8 @@ pub enum MergeOutcome { | ||
| 110 | 110 | |
| 111 | 111 | #[route(POST "/{owner}/{repo}/pulls/{number}/merge")] |
| 112 | 112 | async fn merge_post(cx: &Cx, Form(form): Form<MergeForm>) -> Result<Response> { |
| 113 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 114 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 113 | + let number = parse_number(number(cx))?; | |
| 114 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 115 | 115 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 116 | 116 | if ctx.repo.archived |
| 117 | 117 | || authorize( |
| @@ -125,7 +125,7 @@ async fn merge_post(cx: &Cx, Form(form): Form<MergeForm>) -> Result<Response> { | ||
| 125 | 125 | { |
| 126 | 126 | return Err(forbidden().into()); |
| 127 | 127 | } |
| 128 | - let state = app_context::<AppState>(cx); | |
| 128 | + let state = context::<AppState>(cx); | |
| 129 | 129 | let Some(pr) = state.store.pull_by_number(&ctx.repo.id, number).await? else { |
| 130 | 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 | 17 | use serde_json::json; |
| 18 | 18 | use tokio::sync::broadcast::error::RecvError; |
| 19 | 19 | use topcoat::Result; |
| 20 | -use topcoat::context::{Cx, app_context}; | |
| 20 | +use topcoat::context::{Cx, context}; | |
| 21 | 21 | use topcoat::router::content::Form; |
| 22 | 22 | use topcoat::router::content::sse::Event; |
| 23 | 23 | use topcoat::router::error::{SeeOther, see_other}; |
| @@ -117,7 +117,7 @@ fn no_content() -> Response { | ||
| 117 | 117 | #[route(GET "/push/vapid-key")] |
| 118 | 118 | async fn vapid_key(cx: &Cx) -> Result<Response> { |
| 119 | 119 | require_user(cx).await?; |
| 120 | - let state = app_context::<AppState>(cx); | |
| 120 | + let state = context::<AppState>(cx); | |
| 121 | 121 | let keys = web_push::vapid_keys(state).await?; |
| 122 | 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 | 126 | #[route(POST "/push/subscribe")] |
| 127 | 127 | async fn subscribe(cx: &Cx, Form(form): Form<SubscribeForm>) -> Result<Response> { |
| 128 | 128 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 129 | - let state = app_context::<AppState>(cx); | |
| 129 | + let state = context::<AppState>(cx); | |
| 130 | 130 | let policy = crate::mirrors::policy(state); |
| 131 | 131 | if let Err(e) = |
| 132 | 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 | 156 | #[route(POST "/push/unsubscribe")] |
| 157 | 157 | async fn unsubscribe(cx: &Cx, Form(form): Form<EndpointForm>) -> Result<Response> { |
| 158 | 158 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 159 | - let state = app_context::<AppState>(cx); | |
| 159 | + let state = context::<AppState>(cx); | |
| 160 | 160 | if state |
| 161 | 161 | .store |
| 162 | 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 | 171 | #[route(POST "/settings/notifications/push/remove")] |
| 172 | 172 | async fn remove_device(cx: &Cx, Form(form): Form<DeviceForm>) -> Result<SeeOther> { |
| 173 | 173 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 174 | - let state = app_context::<AppState>(cx); | |
| 174 | + let state = context::<AppState>(cx); | |
| 175 | 175 | if state |
| 176 | 176 | .store |
| 177 | 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 | 187 | #[route(POST "/settings/notifications/push/test")] |
| 188 | 188 | async fn send_test(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { |
| 189 | 189 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 190 | - let state = app_context::<AppState>(cx); | |
| 190 | + let state = context::<AppState>(cx); | |
| 191 | 191 | let devices = state.store.push_subscriptions(&user.id).await?.len(); |
| 192 | 192 | if devices > 0 { |
| 193 | 193 | web_push::queue(state, &user.id, Alert::Test); |
| @@ -204,7 +204,7 @@ async fn push_events(cx: &Cx) -> Result<Response> { | ||
| 204 | 204 | *res.status_mut() = StatusCode::UNAUTHORIZED; |
| 205 | 205 | return Ok(res); |
| 206 | 206 | }; |
| 207 | - let state = app_context::<AppState>(cx); | |
| 207 | + let state = context::<AppState>(cx); | |
| 208 | 208 | let rx = state.push_live.subscribe(); |
| 209 | 209 | let changes = stream::unfold((rx, user.id), |(mut rx, user_id)| async move { |
| 210 | 210 | loop { |
| @@ -263,31 +263,31 @@ fn static_headers(content_type: &'static str, cache: &'static str) -> HeaderMap | ||
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 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 | 267 | let headers = static_headers("text/javascript; charset=utf-8", "no-cache"); |
| 268 | 268 | Ok((StatusCode::OK, headers, SW_JS)) |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 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 | 273 | let headers = static_headers("application/manifest+json", "public, max-age=3600"); |
| 274 | 274 | Ok((StatusCode::OK, headers, MANIFEST)) |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 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 | 279 | let headers = static_headers("image/png", "public, max-age=604800"); |
| 280 | 280 | Ok((StatusCode::OK, headers, ICON_192)) |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 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 | 285 | let headers = static_headers("image/png", "public, max-age=604800"); |
| 286 | 286 | Ok((StatusCode::OK, headers, ICON_512)) |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 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 | 291 | let headers = static_headers("image/png", "public, max-age=604800"); |
| 292 | 292 | Ok((StatusCode::OK, headers, APPLE_TOUCH_ICON)) |
| 293 | 293 | } |
crates/forge-web/src/pages/reactions.rsmodified+4 -4
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | use forge_core::{Reaction, ReactionTarget}; |
| 8 | 8 | use serde::Deserialize; |
| 9 | 9 | use topcoat::Result; |
| 10 | -use topcoat::context::{Cx, app_context}; | |
| 10 | +use topcoat::context::{Cx, context}; | |
| 11 | 11 | use topcoat::router::content::Form; |
| 12 | 12 | use topcoat::router::error::{SeeOther, bad_request, forbidden, not_found, see_other}; |
| 13 | 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 | 49 | async fn react(cx: &Cx, kind: ItemKind, form: ReactionForm) -> Result<SeeOther> { |
| 50 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 51 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 50 | + let number = parse_number(number(cx))?; | |
| 51 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 52 | 52 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 53 | 53 | if ctx.repo.archived { |
| 54 | 54 | return Err(forbidden().into()); |
| 55 | 55 | } |
| 56 | - let state = app_context::<AppState>(cx); | |
| 56 | + let state = context::<AppState>(cx); | |
| 57 | 57 | let item = item_for(state, &ctx, kind, number).await?; |
| 58 | 58 | if !may_converse(&ctx, &item) { |
| 59 | 59 | return Err(forbidden().into()); |
crates/forge-web/src/pages/ref_live.rsmodified+4 -4
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | //! the commits they show, and a soft re-read is cheap. |
| 10 | 10 | |
| 11 | 11 | use topcoat::Result; |
| 12 | -use topcoat::context::{Cx, app_context}; | |
| 12 | +use topcoat::context::{Cx, context}; | |
| 13 | 13 | use topcoat::router::response::Response; |
| 14 | 14 | use topcoat::router::{path_param, route}; |
| 15 | 15 | |
| @@ -38,10 +38,10 @@ pub fn topics(repo: &forge_core::Repo) -> [Topic; 3] { | ||
| 38 | 38 | /// who cannot read the repo gets the same 404 as the page. |
| 39 | 39 | #[route(GET "/{owner}/{repo}/refs/events")] |
| 40 | 40 | async fn ref_events(cx: &Cx) -> Result<Response> { |
| 41 | - let owner = path_param::<Owner>(cx); | |
| 42 | - let name = path_param::<Repo>(cx); | |
| 41 | + let owner = owner(cx); | |
| 42 | + let name = repo(cx); | |
| 43 | 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 | 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 | 8 | use forge_core::Repo as RepoRow; |
| 9 | 9 | use forge_git::browse::{self, CommitInfo, RefInfo, RefKind}; |
| 10 | 10 | use topcoat::Result; |
| 11 | -use topcoat::context::{Cx, app_context}; | |
| 11 | +use topcoat::context::{Cx, context}; | |
| 12 | 12 | use topcoat::router::{page, path_param}; |
| 13 | 13 | use topcoat::view::{View, component, view}; |
| 14 | 14 | |
| @@ -105,7 +105,7 @@ pub(crate) async fn ref_rows( | ||
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 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 | 109 | let empty = rows.is_empty(); |
| 110 | 110 | Ok(view! { |
| 111 | 111 | if empty { |
| @@ -142,8 +142,8 @@ struct RefsPage { | ||
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | async fn refs_data(cx: &Cx, kind: RefKind) -> Result<RefsPage> { |
| 145 | - let owner = path_param::<Owner>(cx); | |
| 146 | - let name = path_param::<Repo>(cx); | |
| 145 | + let owner = owner(cx); | |
| 146 | + let name = repo(cx); | |
| 147 | 147 | let ctx = load_repo(cx, owner, name).await?; |
| 148 | 148 | let now = now_unix(); |
| 149 | 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 | 174 | ctx.repo.name, |
| 175 | 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 | 178 | header.live = ref_live::live_url(&ctx.repo.owner_name, &ctx.repo.name); |
| 179 | 179 | Ok(view! { |
| 180 | 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 | 9 | use forge_core::{AuditAction, Registration, User}; |
| 10 | 10 | use serde::Deserialize; |
| 11 | 11 | use topcoat::Result; |
| 12 | -use topcoat::context::{Cx, app_context}; | |
| 12 | +use topcoat::context::{Cx, context}; | |
| 13 | 13 | use topcoat::router::content::Form; |
| 14 | 14 | use topcoat::router::error::{SeeOther, forbidden, not_found, see_other}; |
| 15 | 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 | 121 | #[component] |
| 122 | 122 | async fn register_form( |
| 123 | + cx: &Cx, | |
| 123 | 124 | lang: Lang, |
| 124 | 125 | gate: Gate, |
| 125 | 126 | invite: &str, |
| @@ -179,7 +180,7 @@ async fn register_form( | ||
| 179 | 180 | |
| 180 | 181 | #[page("/register")] |
| 181 | 182 | async fn register_page(cx: &Cx) -> Result<impl View> { |
| 182 | - let state = app_context::<AppState>(cx); | |
| 183 | + let state = context::<AppState>(cx); | |
| 183 | 184 | if state.live().registration == Registration::Closed { |
| 184 | 185 | return Err(not_found().into()); |
| 185 | 186 | } |
| @@ -260,7 +261,7 @@ async fn create_account( | ||
| 260 | 261 | |
| 261 | 262 | #[page(POST "/register")] |
| 262 | 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 | 265 | if state.live().registration == Registration::Closed { |
| 265 | 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 | 345 | #[component] |
| 345 | 346 | async fn verify_body( |
| 347 | + cx: &Cx, | |
| 346 | 348 | lang: Lang, |
| 347 | 349 | token: &str, |
| 348 | 350 | precsrf: &str, |
| @@ -382,7 +384,7 @@ async fn verify_submit(cx: &Cx, Form(form): Form<VerifyForm>) -> Result<impl Vie | ||
| 382 | 384 | if !check_pre_csrf(cx, &form.precsrf) { |
| 383 | 385 | return Err(forbidden().into()); |
| 384 | 386 | } |
| 385 | - let state = app_context::<AppState>(cx); | |
| 387 | + let state = context::<AppState>(cx); | |
| 386 | 388 | let lang = i18n::lang(cx, None); |
| 387 | 389 | let token = path_param_segment(cx, "token").to_owned(); |
| 388 | 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 | 417 | #[route(POST "/settings/security/email/resend")] |
| 416 | 418 | async fn verify_resend(cx: &Cx, Form(form): Form<ResendForm>) -> Result<SeeOther> { |
| 417 | 419 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 418 | - let state = app_context::<AppState>(cx); | |
| 420 | + let state = context::<AppState>(cx); | |
| 419 | 421 | if !mail_can_send(state).await { |
| 420 | 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 | 20 | use http_body_util::StreamBody; |
| 21 | 21 | use serde::Deserialize; |
| 22 | 22 | use topcoat::Result; |
| 23 | -use topcoat::context::{Cx, app_context}; | |
| 23 | +use topcoat::context::{Cx, context}; | |
| 24 | 24 | use topcoat::router::content::Form; |
| 25 | 25 | use topcoat::router::error::{SeeOther, forbidden, not_found, see_other}; |
| 26 | 26 | use topcoat::router::request::headers; |
| @@ -344,6 +344,7 @@ fn check_title_body(lang: Lang, title: &str, body: &str) -> std::result::Result< | ||
| 344 | 344 | /// Release-form list of branches and the form itself, shared by the new and edit pages. |
| 345 | 345 | #[component] |
| 346 | 346 | async fn release_form( |
| 347 | + cx: &Cx, | |
| 347 | 348 | action: String, |
| 348 | 349 | csrf: String, |
| 349 | 350 | lang: Lang, |
| @@ -413,6 +414,7 @@ async fn release_form( | ||
| 413 | 414 | /// The assets table on the edit page. `delete_actions` holds one form action per asset. |
| 414 | 415 | #[component] |
| 415 | 416 | async fn asset_rows( |
| 417 | + cx: &Cx, | |
| 416 | 418 | assets: Vec<AssetLink>, |
| 417 | 419 | delete_actions: Vec<String>, |
| 418 | 420 | upload_action: String, |
| @@ -464,6 +466,7 @@ async fn asset_rows( | ||
| 464 | 466 | /// The list page body. |
| 465 | 467 | #[component] |
| 466 | 468 | async fn list_body( |
| 469 | + cx: &Cx, | |
| 467 | 470 | head: crate::pages::repo_ctx::RepoHead, |
| 468 | 471 | lang: Lang, |
| 469 | 472 | notice: Option<(&'static str, bool)>, |
| @@ -537,12 +540,12 @@ async fn list_body( | ||
| 537 | 540 | /// Lists the repo's releases, newest first. Drafts appear only for writers. |
| 538 | 541 | #[page("/{owner}/{repo}/releases")] |
| 539 | 542 | async fn releases_list_page(cx: &Cx) -> Result<impl View> { |
| 540 | - let owner = path_param::<Owner>(cx); | |
| 541 | - let name = path_param::<Repo>(cx); | |
| 543 | + let owner = owner(cx); | |
| 544 | + let name = repo(cx); | |
| 542 | 545 | let query = query_params::<ReleasesQuery>(cx)?; |
| 543 | 546 | let ctx = load_repo(cx, owner, name).await?; |
| 544 | 547 | let lang = i18n::lang(cx, viewer_user(&ctx)); |
| 545 | - let state = app_context::<AppState>(cx); | |
| 548 | + let state = context::<AppState>(cx); | |
| 546 | 549 | let writer = can_write(&ctx); |
| 547 | 550 | let latest_id = state |
| 548 | 551 | .store |
| @@ -605,6 +608,7 @@ async fn new_form_data(state: &AppState, ctx: &RepoCtx) -> Result<(RepoHead, Vec | ||
| 605 | 608 | /// The new-release form body, below the repo header. |
| 606 | 609 | #[component] |
| 607 | 610 | async fn new_form_body( |
| 611 | + cx: &Cx, | |
| 608 | 612 | head: RepoHead, |
| 609 | 613 | lang: Lang, |
| 610 | 614 | action: String, |
| @@ -626,12 +630,12 @@ async fn new_form_body( | ||
| 626 | 630 | /// The new-release form. |
| 627 | 631 | #[page("/{owner}/{repo}/releases/new")] |
| 628 | 632 | async fn release_new_page(cx: &Cx) -> Result<impl View> { |
| 629 | - let owner = path_param::<Owner>(cx); | |
| 630 | - let name = path_param::<Repo>(cx); | |
| 633 | + let owner = owner(cx); | |
| 634 | + let name = repo(cx); | |
| 631 | 635 | let ctx = load_repo(cx, owner, name).await?; |
| 632 | 636 | require_write(&ctx)?; |
| 633 | 637 | let lang = i18n::lang(cx, viewer_user(&ctx)); |
| 634 | - let state = app_context::<AppState>(cx); | |
| 638 | + let state = context::<AppState>(cx); | |
| 635 | 639 | let csrf = match crate::auth::current_user(cx).await? { |
| 636 | 640 | Some((_, session)) => session.csrf_token.clone(), |
| 637 | 641 | None => String::new(), |
| @@ -653,13 +657,13 @@ async fn release_new_page(cx: &Cx) -> Result<impl View> { | ||
| 653 | 657 | /// Creates a release. The tag is created at the target branch's head when it does not exist. |
| 654 | 658 | #[page(POST "/{owner}/{repo}/releases/new")] |
| 655 | 659 | async fn release_create(cx: &Cx, Form(form): Form<CreateForm>) -> Result<impl View> { |
| 656 | - let owner = path_param::<Owner>(cx); | |
| 657 | - let name = path_param::<Repo>(cx); | |
| 660 | + let owner = owner(cx); | |
| 661 | + let name = repo(cx); | |
| 658 | 662 | let ctx = load_repo(cx, owner, name).await?; |
| 659 | 663 | let (user, session) = require_csrf(cx, &form.csrf).await?; |
| 660 | 664 | require_write(&ctx)?; |
| 661 | 665 | let lang = i18n::lang(cx, viewer_user(&ctx)); |
| 662 | - let state = app_context::<AppState>(cx); | |
| 666 | + let state = context::<AppState>(cx); | |
| 663 | 667 | let draft = FormDraft { |
| 664 | 668 | tag: form.tag.trim().to_owned(), |
| 665 | 669 | target: form.target.trim().to_owned(), |
| @@ -733,12 +737,12 @@ async fn create_checked( | ||
| 733 | 737 | /// The public view of one release: notes, assets and the source archive links. |
| 734 | 738 | #[page("/{owner}/{repo}/releases/tag/{tag}")] |
| 735 | 739 | async fn release_tag_page(cx: &Cx) -> Result<impl View> { |
| 736 | - let owner = path_param::<Owner>(cx); | |
| 737 | - let name = path_param::<Repo>(cx); | |
| 738 | - let tag_param = path_param::<Tag>(cx).to_owned(); | |
| 740 | + let owner = owner(cx); | |
| 741 | + let name = repo(cx); | |
| 742 | + let tag_param = tag(cx).to_owned(); | |
| 739 | 743 | let ctx = load_repo(cx, owner, name).await?; |
| 740 | 744 | let lang = i18n::lang(cx, viewer_user(&ctx)); |
| 741 | - let state = app_context::<AppState>(cx); | |
| 745 | + let state = context::<AppState>(cx); | |
| 742 | 746 | let writer = can_write(&ctx); |
| 743 | 747 | let Some(release) = state.store.release_by_tag(&ctx.repo.id, &tag_param).await? else { |
| 744 | 748 | return Err(not_found().into()); |
| @@ -864,6 +868,7 @@ async fn release_tag_page(cx: &Cx) -> Result<impl View> { | ||
| 864 | 868 | /// which shows the typed values again. |
| 865 | 869 | #[component] |
| 866 | 870 | async fn edit_body( |
| 871 | + cx: &Cx, | |
| 867 | 872 | head: RepoHead, |
| 868 | 873 | lang: Lang, |
| 869 | 874 | notice: Option<(&'static str, bool)>, |
| @@ -976,13 +981,13 @@ async fn edit_parts( | ||
| 976 | 981 | /// The edit page: the release fields, its assets, and the upload form. |
| 977 | 982 | #[page("/{owner}/{repo}/releases/{release_id}/edit")] |
| 978 | 983 | async fn release_edit_page(cx: &Cx) -> Result<impl View> { |
| 979 | - let owner = path_param::<Owner>(cx); | |
| 980 | - let name = path_param::<Repo>(cx); | |
| 981 | - let id = path_param::<ReleaseId>(cx).to_owned(); | |
| 984 | + let owner = owner(cx); | |
| 985 | + let name = repo(cx); | |
| 986 | + let id = release_id(cx).to_owned(); | |
| 982 | 987 | let ctx = load_repo(cx, owner, name).await?; |
| 983 | 988 | require_write(&ctx)?; |
| 984 | 989 | let lang = i18n::lang(cx, viewer_user(&ctx)); |
| 985 | - let state = app_context::<AppState>(cx); | |
| 990 | + let state = context::<AppState>(cx); | |
| 986 | 991 | let Some(release) = state.store.release(&id).await? else { |
| 987 | 992 | return Err(not_found().into()); |
| 988 | 993 | }; |
| @@ -1016,14 +1021,14 @@ async fn release_edit_page(cx: &Cx) -> Result<impl View> { | ||
| 1016 | 1021 | /// unchanged tag keeps the tag. A refused save shows its message and keeps the typed values. |
| 1017 | 1022 | #[page(POST "/{owner}/{repo}/releases/{release_id}/edit")] |
| 1018 | 1023 | async fn release_update(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View> { |
| 1019 | - let owner = path_param::<Owner>(cx); | |
| 1020 | - let name = path_param::<Repo>(cx); | |
| 1021 | - let id = path_param::<ReleaseId>(cx).to_owned(); | |
| 1024 | + let owner = owner(cx); | |
| 1025 | + let name = repo(cx); | |
| 1026 | + let id = release_id(cx).to_owned(); | |
| 1022 | 1027 | let ctx = load_repo(cx, owner, name).await?; |
| 1023 | 1028 | let (user, session) = require_csrf(cx, &form.csrf).await?; |
| 1024 | 1029 | require_write(&ctx)?; |
| 1025 | 1030 | let lang = i18n::lang(cx, viewer_user(&ctx)); |
| 1026 | - let state = app_context::<AppState>(cx); | |
| 1031 | + let state = context::<AppState>(cx); | |
| 1027 | 1032 | let Some(before) = state.store.release(&id).await? else { |
| 1028 | 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 | 1077 | /// Deletes a release and its assets, then their blobs. The git tag is kept. Requires the confirm box. |
| 1073 | 1078 | #[route(POST "/{owner}/{repo}/releases/{release_id}/delete")] |
| 1074 | 1079 | async fn release_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<Response> { |
| 1075 | - let owner = path_param::<Owner>(cx); | |
| 1076 | - let name = path_param::<Repo>(cx); | |
| 1077 | - let id = path_param::<ReleaseId>(cx).to_owned(); | |
| 1080 | + let owner = owner(cx); | |
| 1081 | + let name = repo(cx); | |
| 1082 | + let id = release_id(cx).to_owned(); | |
| 1078 | 1083 | let ctx = load_repo(cx, owner, name).await?; |
| 1079 | 1084 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 1080 | 1085 | require_write(&ctx)?; |
| @@ -1083,7 +1088,7 @@ async fn release_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<Response> | ||
| 1083 | 1088 | let href = release_edit_href(&title, &id); |
| 1084 | 1089 | return Err(notice_redirect(&href, "confirm").into()); |
| 1085 | 1090 | } |
| 1086 | - let state = app_context::<AppState>(cx); | |
| 1091 | + let state = context::<AppState>(cx); | |
| 1087 | 1092 | let Some(release) = state.store.release(&id).await? else { |
| 1088 | 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 | 1102 | /// Deletes one asset row and its blob. |
| 1098 | 1103 | #[route(POST "/{owner}/{repo}/releases/{release_id}/assets/{asset_id}/delete")] |
| 1099 | 1104 | async fn asset_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<Response> { |
| 1100 | - let owner = path_param::<Owner>(cx); | |
| 1101 | - let name = path_param::<Repo>(cx); | |
| 1102 | - let release_id = path_param::<ReleaseId>(cx).to_owned(); | |
| 1103 | - let asset = path_param::<AssetId>(cx).to_owned(); | |
| 1105 | + let owner = owner(cx); | |
| 1106 | + let name = repo(cx); | |
| 1107 | + let release_id = release_id(cx).to_owned(); | |
| 1108 | + let asset = asset_id(cx).to_owned(); | |
| 1104 | 1109 | let ctx = load_repo(cx, owner, name).await?; |
| 1105 | 1110 | require_csrf(cx, &form.csrf).await?; |
| 1106 | 1111 | require_write(&ctx)?; |
| 1107 | - let state = app_context::<AppState>(cx); | |
| 1112 | + let state = context::<AppState>(cx); | |
| 1108 | 1113 | let Some(release) = state.store.release(&release_id).await? else { |
| 1109 | 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 | 1128 | /// `assets/<id>` only when it is complete and the row is stored. |
| 1124 | 1129 | #[route(POST "/{owner}/{repo}/releases/{release_id}/assets")] |
| 1125 | 1130 | async fn asset_upload(cx: &Cx, body: Body) -> Result<Response> { |
| 1126 | - let owner = path_param::<Owner>(cx); | |
| 1127 | - let name = path_param::<Repo>(cx); | |
| 1128 | - let id = path_param::<ReleaseId>(cx).to_owned(); | |
| 1131 | + let owner = owner(cx); | |
| 1132 | + let name = repo(cx); | |
| 1133 | + let id = release_id(cx).to_owned(); | |
| 1129 | 1134 | let ctx = load_repo(cx, owner, name).await?; |
| 1130 | - let state = app_context::<AppState>(cx); | |
| 1135 | + let state = context::<AppState>(cx); | |
| 1131 | 1136 | let href = release_edit_href(&title_of(&ctx), &id); |
| 1132 | 1137 | let max_bytes = state |
| 1133 | 1138 | .config |
| @@ -1255,11 +1260,11 @@ async fn store_upload( | ||
| 1255 | 1260 | /// people who can write; anyone else gets a 404. |
| 1256 | 1261 | #[route(GET "/{owner}/{repo}/releases/download/{tag}/{name}")] |
| 1257 | 1262 | async fn asset_download(cx: &Cx) -> Result<Response> { |
| 1258 | - let owner = path_param::<Owner>(cx); | |
| 1259 | - let repo_name = path_param::<Repo>(cx); | |
| 1260 | - let tag_param = path_param::<Tag>(cx).to_owned(); | |
| 1261 | - let file_name = path_param::<Name>(cx).to_owned(); | |
| 1262 | - let state = app_context::<AppState>(cx); | |
| 1263 | + let owner = owner(cx); | |
| 1264 | + let repo_name = repo(cx); | |
| 1265 | + let tag_param = tag(cx).to_owned(); | |
| 1266 | + let file_name = name(cx).to_owned(); | |
| 1267 | + let state = context::<AppState>(cx); | |
| 1263 | 1268 | // A caller that sends credentials (a Gitea or Forgejo server migrating this repo) is judged by |
| 1264 | 1269 | // its token, with the same rules as the API. Everyone else goes through the session. |
| 1265 | 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 | 12 | use forge_core::store::Store; |
| 13 | 13 | use topcoat::Result; |
| 14 | -use topcoat::context::{Cx, app_context}; | |
| 14 | +use topcoat::context::{Cx, context}; | |
| 15 | 15 | use topcoat::router::error::not_found; |
| 16 | 16 | use topcoat::router::response::Response; |
| 17 | 17 | use topcoat::router::{path_param, route}; |
| @@ -85,8 +85,8 @@ pub(crate) async fn release_fingerprint( | ||
| 85 | 85 | /// The release list's change stream. |
| 86 | 86 | #[route(GET "/{owner}/{repo}/releases/events")] |
| 87 | 87 | async fn releases_events(cx: &Cx) -> Result<Response> { |
| 88 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 89 | - let state = app_context::<AppState>(cx); | |
| 88 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 89 | + let state = context::<AppState>(cx); | |
| 90 | 90 | let writer = can_write(&ctx); |
| 91 | 91 | let topic = Topic::RepoReleases(ctx.repo.id.clone()); |
| 92 | 92 | let store = state.store.clone(); |
| @@ -102,9 +102,9 @@ async fn releases_events(cx: &Cx) -> Result<Response> { | ||
| 102 | 102 | /// One release page's change stream. A release the viewer cannot open gets the page's 404. |
| 103 | 103 | #[route(GET "/{owner}/{repo}/releases/tag/{tag}/events")] |
| 104 | 104 | async fn release_events(cx: &Cx) -> Result<Response> { |
| 105 | - let tag = path_param::<Tag>(cx).to_owned(); | |
| 106 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 107 | - let state = app_context::<AppState>(cx); | |
| 105 | + let tag = tag(cx).to_owned(); | |
| 106 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 107 | + let state = context::<AppState>(cx); | |
| 108 | 108 | let writer = can_write(&ctx); |
| 109 | 109 | let visible = match state.store.release_by_tag(&ctx.repo.id, &tag).await? { |
| 110 | 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 | 12 | use forge_git::browse; |
| 13 | 13 | use forge_git::repo::repo_path; |
| 14 | 14 | use topcoat::Result; |
| 15 | -use topcoat::context::{Cx, app_context}; | |
| 15 | +use topcoat::context::{Cx, context}; | |
| 16 | 16 | use topcoat::router::error::not_found; |
| 17 | 17 | use topcoat::router::{page, path_param, route}; |
| 18 | 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 | 84 | /// `RepoCtx::head`; every repo page passes one. |
| 85 | 85 | #[component] |
| 86 | 86 | pub async fn repo_head( |
| 87 | + cx: &Cx, | |
| 87 | 88 | head: RepoHead, |
| 88 | 89 | #[default] title: Option<String>, |
| 89 | 90 | #[default] sub: Vec<SubPart>, |
| @@ -228,6 +229,7 @@ pub async fn repo_head( | ||
| 228 | 229 | /// the branch has a commit, links to its archive (`downloads`: the zip and tar.gz hrefs). |
| 229 | 230 | #[component] |
| 230 | 231 | async fn clone_popover( |
| 232 | + cx: &Cx, | |
| 231 | 233 | https: String, |
| 232 | 234 | ssh: String, |
| 233 | 235 | downloads: Option<(String, String)>, |
| @@ -258,6 +260,7 @@ async fn clone_popover( | ||
| 258 | 260 | /// or push instructions when there are none. |
| 259 | 261 | #[component] |
| 260 | 262 | async fn branches_card( |
| 263 | + cx: &Cx, | |
| 261 | 264 | branches: Vec<String>, |
| 262 | 265 | push_https: String, |
| 263 | 266 | push_ssh: String, |
| @@ -408,7 +411,12 @@ async fn recent_push_banners( | ||
| 408 | 411 | |
| 409 | 412 | /// The "had recent pushes" banners above the code tab. |
| 410 | 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 | 420 | Ok(view! { |
| 413 | 421 | <section class="recent-pushes" aria-label=(g::t(lang, K::RecentPushes))> |
| 414 | 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 | 435 | #[page("/{owner}/{repo}")] |
| 428 | 436 | async fn repo_page(cx: &Cx) -> Result<impl View> { |
| 429 | - let owner = path_param::<Owner>(cx); | |
| 430 | - let name = path_param::<Repo>(cx); | |
| 437 | + let owner = owner(cx); | |
| 438 | + let name = repo(cx); | |
| 431 | 439 | let ctx = load_repo(cx, owner, name).await?; |
| 432 | - let state = app_context::<AppState>(cx); | |
| 440 | + let state = context::<AppState>(cx); | |
| 433 | 441 | let lang = ctx.lang; |
| 434 | 442 | let repo = &ctx.repo; |
| 435 | 443 | let branch = repo.default_branch.clone(); |
| @@ -530,7 +538,7 @@ async fn repo_page(cx: &Cx) -> Result<impl View> { | ||
| 530 | 538 | |
| 531 | 539 | /// Other methods on a repo path get a plain 404, not a 405 that would reveal the route shape. |
| 532 | 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 | 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 | 14 | use forge_core::{AuditAction, Role, User}; |
| 15 | 15 | use serde::Deserialize; |
| 16 | 16 | use topcoat::Result; |
| 17 | -use topcoat::context::{Cx, app_context}; | |
| 17 | +use topcoat::context::{Cx, context}; | |
| 18 | 18 | use topcoat::cookie::{Cookie, Cookies, SameSite, cookies}; |
| 19 | 19 | use topcoat::router::content::Form; |
| 20 | 20 | use topcoat::router::error::{SeeOther, forbidden, see_other}; |
| @@ -159,6 +159,7 @@ impl FrameData { | ||
| 159 | 159 | /// The page body: repo header with Settings active, the notice, then the collaborators topic. |
| 160 | 160 | #[component] |
| 161 | 161 | async fn collaborators_body( |
| 162 | + cx: &Cx, | |
| 162 | 163 | lang: Lang, |
| 163 | 164 | frame: FrameData, |
| 164 | 165 | rows: Vec<PersonRow>, |
| @@ -230,15 +231,15 @@ async fn collaborators_body( | ||
| 230 | 231 | /// and signed-in viewers who may not manage the repo get 403. |
| 231 | 232 | #[page("/{owner}/{repo}/settings/collaborators")] |
| 232 | 233 | async fn collaborators_page(cx: &Cx) -> Result<impl View> { |
| 233 | - let owner = path_param::<Owner>(cx); | |
| 234 | - let name = path_param::<Repo>(cx); | |
| 234 | + let owner = owner(cx); | |
| 235 | + let name = repo(cx); | |
| 235 | 236 | let ctx = load_repo(cx, owner, name).await?; |
| 236 | 237 | let (user, session) = require_user(cx).await?; |
| 237 | 238 | if !ctx.can_admin() { |
| 238 | 239 | return Err(forbidden().into()); |
| 239 | 240 | } |
| 240 | 241 | let lang = i18n::lang(cx, Some(&user)); |
| 241 | - let state = app_context::<AppState>(cx); | |
| 242 | + let state = context::<AppState>(cx); | |
| 242 | 243 | let collaborators = state.store.list_collaborators(&ctx.repo.id).await?; |
| 243 | 244 | let viewer_id = user.id.clone(); |
| 244 | 245 | let rows = collaborators |
| @@ -275,15 +276,15 @@ async fn collaborators_page(cx: &Cx) -> Result<impl View> { | ||
| 275 | 276 | /// Adds a collaborator or updates an existing one's role. Admin grants need the owner or an instance admin. |
| 276 | 277 | #[route(POST "/{owner}/{repo}/settings/collaborators/add")] |
| 277 | 278 | async fn collaborators_add(cx: &Cx, Form(form): Form<AddForm>) -> Result<SeeOther> { |
| 278 | - let owner = path_param::<Owner>(cx); | |
| 279 | - let name = path_param::<Repo>(cx); | |
| 279 | + let owner = owner(cx); | |
| 280 | + let name = repo(cx); | |
| 280 | 281 | let ctx = load_repo(cx, owner, name).await?; |
| 281 | 282 | let (actor, _) = require_csrf(cx, &form.csrf).await?; |
| 282 | 283 | if !ctx.can_admin() { |
| 283 | 284 | return Err(forbidden().into()); |
| 284 | 285 | } |
| 285 | 286 | let title = title_of(&ctx); |
| 286 | - let state = app_context::<AppState>(cx); | |
| 287 | + let state = context::<AppState>(cx); | |
| 287 | 288 | |
| 288 | 289 | let Ok(role) = form.role.trim().parse::<Role>() else { |
| 289 | 290 | set_notice(cx, "invalid_role"); |
| @@ -361,15 +362,15 @@ async fn collaborators_add(cx: &Cx, Form(form): Form<AddForm>) -> Result<SeeOthe | ||
| 361 | 362 | /// Changes an existing collaborator's role. Only existing collaborators can be changed here. |
| 362 | 363 | #[route(POST "/{owner}/{repo}/settings/collaborators/role")] |
| 363 | 364 | async fn collaborators_role(cx: &Cx, Form(form): Form<RoleForm>) -> Result<SeeOther> { |
| 364 | - let owner = path_param::<Owner>(cx); | |
| 365 | - let name = path_param::<Repo>(cx); | |
| 365 | + let owner = owner(cx); | |
| 366 | + let name = repo(cx); | |
| 366 | 367 | let ctx = load_repo(cx, owner, name).await?; |
| 367 | 368 | let (actor, _) = require_csrf(cx, &form.csrf).await?; |
| 368 | 369 | if !ctx.can_admin() { |
| 369 | 370 | return Err(forbidden().into()); |
| 370 | 371 | } |
| 371 | 372 | let title = title_of(&ctx); |
| 372 | - let state = app_context::<AppState>(cx); | |
| 373 | + let state = context::<AppState>(cx); | |
| 373 | 374 | |
| 374 | 375 | let Ok(role) = form.role.trim().parse::<Role>() else { |
| 375 | 376 | set_notice(cx, "invalid_role"); |
| @@ -422,15 +423,15 @@ async fn collaborators_role(cx: &Cx, Form(form): Form<RoleForm>) -> Result<SeeOt | ||
| 422 | 423 | /// yourself is allowed and redirects to the repo home page. |
| 423 | 424 | #[route(POST "/{owner}/{repo}/settings/collaborators/remove")] |
| 424 | 425 | async fn collaborators_remove(cx: &Cx, Form(form): Form<RemoveForm>) -> Result<SeeOther> { |
| 425 | - let owner = path_param::<Owner>(cx); | |
| 426 | - let name = path_param::<Repo>(cx); | |
| 426 | + let owner = owner(cx); | |
| 427 | + let name = repo(cx); | |
| 427 | 428 | let ctx = load_repo(cx, owner, name).await?; |
| 428 | 429 | let (actor, _) = require_csrf(cx, &form.csrf).await?; |
| 429 | 430 | if !ctx.can_admin() { |
| 430 | 431 | return Err(forbidden().into()); |
| 431 | 432 | } |
| 432 | 433 | let title = title_of(&ctx); |
| 433 | - let state = app_context::<AppState>(cx); | |
| 434 | + let state = context::<AppState>(cx); | |
| 434 | 435 | let target_id = form.user_id.trim(); |
| 435 | 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 | 8 | use forge_core::authz::{Action, authorize}; |
| 9 | 9 | use forge_core::{Repo, Role, Session, Store, User, Visibility, WatchLevel}; |
| 10 | 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 | 15 | use topcoat::Result; |
| 13 | -use topcoat::context::{Cx, app_context}; | |
| 16 | +use topcoat::context::{Cx, context}; | |
| 14 | 17 | use topcoat::router::error::not_found; |
| 15 | 18 | use topcoat::router::request::uri; |
| 16 | 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 | 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 | 313 | let viewer = current_user(cx).await?; |
| 311 | 314 | |
| 312 | 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 | 16 | use time::OffsetDateTime; |
| 17 | 17 | use time::format_description::well_known::Rfc3339; |
| 18 | 18 | use topcoat::Result; |
| 19 | -use topcoat::context::{Cx, app_context}; | |
| 19 | +use topcoat::context::{Cx, context}; | |
| 20 | 20 | use topcoat::router::content::Form; |
| 21 | 21 | use topcoat::router::error::{SeeOther, forbidden, not_found, see_other}; |
| 22 | 22 | use topcoat::router::request::uri; |
| @@ -391,6 +391,7 @@ async fn rows_of(state: &AppState, ctx: &RepoCtx, frame: &Frame) -> Result<Vec<M | ||
| 391 | 391 | /// mirror's redacted URL on its own page. |
| 392 | 392 | #[component] |
| 393 | 393 | async fn frame_top( |
| 394 | + cx: &Cx, | |
| 394 | 395 | head: RepoHead, |
| 395 | 396 | title: String, |
| 396 | 397 | heading: String, |
| @@ -421,6 +422,7 @@ async fn frame_top( | ||
| 421 | 422 | /// `direction` is sent as a hidden field by the add-pull form only (empty for the others). |
| 422 | 423 | #[component] |
| 423 | 424 | async fn mirror_form( |
| 425 | + cx: &Cx, | |
| 424 | 426 | action: String, |
| 425 | 427 | csrf: String, |
| 426 | 428 | prefix: &'static str, |
| @@ -494,6 +496,7 @@ async fn mirror_form( | ||
| 494 | 496 | /// Archived repos show no add rows. |
| 495 | 497 | #[component] |
| 496 | 498 | async fn mirrors_list_body( |
| 499 | + cx: &Cx, | |
| 497 | 500 | head: RepoHead, |
| 498 | 501 | title: String, |
| 499 | 502 | notice: Option<(&'static str, bool)>, |
| @@ -575,14 +578,14 @@ async fn mirrors_list_body( | ||
| 575 | 578 | /// Lists the repo's mirrors. Admins only: anyone else gets 404. |
| 576 | 579 | #[page("/{owner}/{repo}/settings/mirrors")] |
| 577 | 580 | async fn mirrors_list_page(cx: &Cx) -> Result<impl View> { |
| 578 | - let owner = path_param::<Owner>(cx); | |
| 579 | - let name = path_param::<Repo>(cx); | |
| 581 | + let owner = owner(cx); | |
| 582 | + let name = repo(cx); | |
| 580 | 583 | let ctx = load_repo(cx, owner, name).await?; |
| 581 | 584 | let (_, session) = require_user(cx).await?; |
| 582 | 585 | if !ctx.can_admin() { |
| 583 | 586 | return Err(not_found().into()); |
| 584 | 587 | } |
| 585 | - let state = app_context::<AppState>(cx); | |
| 588 | + let state = context::<AppState>(cx); | |
| 586 | 589 | let lang = lang_of(cx, &ctx); |
| 587 | 590 | let frame = Frame::new(&ctx, state, lang).await?; |
| 588 | 591 | let rows = rows_of(state, &ctx, &frame).await?; |
| @@ -690,8 +693,8 @@ async fn add_pull_mirror( | ||
| 690 | 693 | /// before anything is stored. |
| 691 | 694 | #[page(POST "/{owner}/{repo}/settings/mirrors")] |
| 692 | 695 | async fn mirror_create(cx: &Cx, Form(form): Form<PushForm>) -> Result<impl View> { |
| 693 | - let owner = path_param::<Owner>(cx); | |
| 694 | - let name = path_param::<Repo>(cx); | |
| 696 | + let owner = owner(cx); | |
| 697 | + let name = repo(cx); | |
| 695 | 698 | let ctx = load_repo(cx, owner, name).await?; |
| 696 | 699 | let (user, session) = require_csrf(cx, &form.csrf).await?; |
| 697 | 700 | if !ctx.can_admin() { |
| @@ -700,7 +703,7 @@ async fn mirror_create(cx: &Cx, Form(form): Form<PushForm>) -> Result<impl View> | ||
| 700 | 703 | if ctx.repo.archived { |
| 701 | 704 | return Err(forbidden().into()); |
| 702 | 705 | } |
| 703 | - let state = app_context::<AppState>(cx); | |
| 706 | + let state = context::<AppState>(cx); | |
| 704 | 707 | let lang = lang_of(cx, &ctx); |
| 705 | 708 | let pull = form.direction == "pull"; |
| 706 | 709 | let stored = if pull { |
| @@ -768,6 +771,7 @@ async fn repo_mirror(state: &AppState, ctx: &RepoCtx, id: &str) -> Result<Mirror | ||
| 768 | 771 | /// The edit page body: the form, the sync and delete controls. |
| 769 | 772 | #[component] |
| 770 | 773 | async fn mirror_body( |
| 774 | + cx: &Cx, | |
| 771 | 775 | head: RepoHead, |
| 772 | 776 | title: String, |
| 773 | 777 | notice: Option<(&'static str, bool)>, |
| @@ -844,15 +848,15 @@ impl EditDraft { | ||
| 844 | 848 | /// The edit page for one mirror. |
| 845 | 849 | #[page("/{owner}/{repo}/settings/mirrors/{mirror_id}")] |
| 846 | 850 | async fn mirror_page(cx: &Cx) -> Result<impl View> { |
| 847 | - let owner = path_param::<Owner>(cx); | |
| 848 | - let name = path_param::<Repo>(cx); | |
| 849 | - let id = path_param::<MirrorId>(cx); | |
| 851 | + let owner = owner(cx); | |
| 852 | + let name = repo(cx); | |
| 853 | + let id = mirror_id(cx); | |
| 850 | 854 | let ctx = load_repo(cx, owner, name).await?; |
| 851 | 855 | let (_, session) = require_user(cx).await?; |
| 852 | 856 | if !ctx.can_admin() { |
| 853 | 857 | return Err(not_found().into()); |
| 854 | 858 | } |
| 855 | - let state = app_context::<AppState>(cx); | |
| 859 | + let state = context::<AppState>(cx); | |
| 856 | 860 | let mirror = repo_mirror(state, &ctx, id).await?; |
| 857 | 861 | let lang = lang_of(cx, &ctx); |
| 858 | 862 | let frame = Frame::new(&ctx, state, lang).await?; |
| @@ -872,9 +876,9 @@ async fn mirror_page(cx: &Cx) -> Result<impl View> { | ||
| 872 | 876 | /// the clear box removes it. A refused form shows the error on the edit page. |
| 873 | 877 | #[page(POST "/{owner}/{repo}/settings/mirrors/{mirror_id}")] |
| 874 | 878 | async fn mirror_update(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View> { |
| 875 | - let owner = path_param::<Owner>(cx); | |
| 876 | - let name = path_param::<Repo>(cx); | |
| 877 | - let id = path_param::<MirrorId>(cx); | |
| 879 | + let owner = owner(cx); | |
| 880 | + let name = repo(cx); | |
| 881 | + let id = mirror_id(cx); | |
| 878 | 882 | let ctx = load_repo(cx, owner, name).await?; |
| 879 | 883 | let (user, session) = require_csrf(cx, &form.csrf).await?; |
| 880 | 884 | if !ctx.can_admin() { |
| @@ -883,7 +887,7 @@ async fn mirror_update(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View> | ||
| 883 | 887 | if ctx.repo.archived { |
| 884 | 888 | return Err(forbidden().into()); |
| 885 | 889 | } |
| 886 | - let state = app_context::<AppState>(cx); | |
| 890 | + let state = context::<AppState>(cx); | |
| 887 | 891 | let mirror = repo_mirror(state, &ctx, id).await?; |
| 888 | 892 | let url = if form.url.trim().is_empty() { |
| 889 | 893 | mirror.url.clone() |
| @@ -966,9 +970,9 @@ async fn mirror_update(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View> | ||
| 966 | 970 | /// Queues a sync now: the mirror is due at the current time and the worker is woken. |
| 967 | 971 | #[route(POST "/{owner}/{repo}/settings/mirrors/{mirror_id}/sync")] |
| 968 | 972 | async fn mirror_sync(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { |
| 969 | - let owner = path_param::<Owner>(cx); | |
| 970 | - let name = path_param::<Repo>(cx); | |
| 971 | - let id = path_param::<MirrorId>(cx); | |
| 973 | + let owner = owner(cx); | |
| 974 | + let name = repo(cx); | |
| 975 | + let id = mirror_id(cx); | |
| 972 | 976 | let ctx = load_repo(cx, owner, name).await?; |
| 973 | 977 | require_csrf(cx, &form.csrf).await?; |
| 974 | 978 | if !ctx.can_admin() { |
| @@ -977,7 +981,7 @@ async fn mirror_sync(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { | ||
| 977 | 981 | if ctx.repo.archived { |
| 978 | 982 | return Err(forbidden().into()); |
| 979 | 983 | } |
| 980 | - let state = app_context::<AppState>(cx); | |
| 984 | + let state = context::<AppState>(cx); | |
| 981 | 985 | let mirror = repo_mirror(state, &ctx, id).await?; |
| 982 | 986 | state |
| 983 | 987 | .store |
| @@ -990,9 +994,9 @@ async fn mirror_sync(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { | ||
| 990 | 994 | /// Deletes a mirror. The box must be ticked. Deleting the pull mirror makes the repo a normal one. |
| 991 | 995 | #[route(POST "/{owner}/{repo}/settings/mirrors/{mirror_id}/delete")] |
| 992 | 996 | async fn mirror_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther> { |
| 993 | - let owner = path_param::<Owner>(cx); | |
| 994 | - let name = path_param::<Repo>(cx); | |
| 995 | - let id = path_param::<MirrorId>(cx); | |
| 997 | + let owner = owner(cx); | |
| 998 | + let name = repo(cx); | |
| 999 | + let id = mirror_id(cx); | |
| 996 | 1000 | let ctx = load_repo(cx, owner, name).await?; |
| 997 | 1001 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 998 | 1002 | if !ctx.can_admin() { |
| @@ -1001,7 +1005,7 @@ async fn mirror_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther | ||
| 1001 | 1005 | if ctx.repo.archived { |
| 1002 | 1006 | return Err(forbidden().into()); |
| 1003 | 1007 | } |
| 1004 | - let state = app_context::<AppState>(cx); | |
| 1008 | + let state = context::<AppState>(cx); | |
| 1005 | 1009 | let mirror = repo_mirror(state, &ctx, id).await?; |
| 1006 | 1010 | let title = title_of(&ctx); |
| 1007 | 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 | 10 | use forge_core::{AuditAction, Error as CoreError}; |
| 11 | 11 | use serde::Deserialize; |
| 12 | 12 | use topcoat::Result; |
| 13 | -use topcoat::context::{Cx, app_context}; | |
| 13 | +use topcoat::context::{Cx, context}; | |
| 14 | 14 | use topcoat::router::content::Form; |
| 15 | 15 | use topcoat::router::error::{SeeOther, forbidden, see_other}; |
| 16 | 16 | use topcoat::router::{page, path_param, route}; |
| @@ -51,6 +51,7 @@ struct TransferForm { | ||
| 51 | 51 | /// form opens with it and keeps the typed `name`. |
| 52 | 52 | #[component] |
| 53 | 53 | pub(crate) async fn rename_section( |
| 54 | + cx: &Cx, | |
| 54 | 55 | lang: Lang, |
| 55 | 56 | title: String, |
| 56 | 57 | csrf: String, |
| @@ -84,17 +85,19 @@ pub(crate) async fn rename_section( | ||
| 84 | 85 | /// The rename form moved into the danger zone; the old address goes there. |
| 85 | 86 | #[route(GET "/{owner}/{repo}/settings/rename")] |
| 86 | 87 | async fn rename_get(cx: &Cx) -> Result<SeeOther> { |
| 87 | - let owner = path_param::<Owner>(cx); | |
| 88 | - let name = path_param::<Repo>(cx); | |
| 89 | - Ok(see_other(format!("/{owner}/{name}/settings?section=danger"))) | |
| 88 | + let owner = owner(cx); | |
| 89 | + let name = repo(cx); | |
| 90 | + Ok(see_other(format!( | |
| 91 | + "/{owner}/{name}/settings?section=danger" | |
| 92 | + ))) | |
| 90 | 93 | } |
| 91 | 94 | |
| 92 | 95 | /// Renames the repo. The store validates the name with `validate_name`; an invalid name or a name |
| 93 | 96 | /// taken by another repo of the owner re-renders the danger zone with the message. |
| 94 | 97 | #[page(POST "/{owner}/{repo}/settings/rename")] |
| 95 | 98 | async fn rename_post(cx: &Cx, Form(form): Form<RenameForm>) -> Result<impl View> { |
| 96 | - let owner = path_param::<Owner>(cx); | |
| 97 | - let name = path_param::<Repo>(cx); | |
| 99 | + let owner = owner(cx); | |
| 100 | + let name = repo(cx); | |
| 98 | 101 | let ctx = load_repo(cx, owner, name).await?; |
| 99 | 102 | let (user, session) = require_csrf(cx, &form.csrf).await?; |
| 100 | 103 | if !ctx.can_admin() { |
| @@ -107,7 +110,7 @@ async fn rename_post(cx: &Cx, Form(form): Form<RenameForm>) -> Result<impl View> | ||
| 107 | 110 | .chars() |
| 108 | 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 | 114 | state |
| 112 | 115 | .store |
| 113 | 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 | 130 | "repository renamed" |
| 128 | 131 | ); |
| 129 | 132 | audit::record( |
| 130 | - &app_context::<AppState>(cx).store, | |
| 133 | + &context::<AppState>(cx).store, | |
| 131 | 134 | Some(cx), |
| 132 | 135 | Actor::User(&user), |
| 133 | 136 | AuditAction::RepoRenamed, |
| @@ -170,8 +173,8 @@ async fn rename_post(cx: &Cx, Form(form): Form<RenameForm>) -> Result<impl View> | ||
| 170 | 173 | /// `owner/name` confirmation. The store removes the new owner's collaborator row. |
| 171 | 174 | #[page(POST "/{owner}/{repo}/settings/transfer")] |
| 172 | 175 | async fn transfer_post(cx: &Cx, Form(form): Form<TransferForm>) -> Result<impl View> { |
| 173 | - let owner = path_param::<Owner>(cx); | |
| 174 | - let name = path_param::<Repo>(cx); | |
| 176 | + let owner = owner(cx); | |
| 177 | + let name = repo(cx); | |
| 175 | 178 | let ctx = load_repo(cx, owner, name).await?; |
| 176 | 179 | let (user, session) = require_csrf(cx, &form.csrf).await?; |
| 177 | 180 | if !ctx.can_delete() { |
| @@ -180,7 +183,7 @@ async fn transfer_post(cx: &Cx, Form(form): Form<TransferForm>) -> Result<impl V | ||
| 180 | 183 | let lang = i18n::lang(cx, Some(&user)); |
| 181 | 184 | let title = format!("{}/{}", ctx.repo.owner_name, ctx.repo.name); |
| 182 | 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 | 188 | let error: Option<String> = 'attempt: { |
| 186 | 189 | if form.confirm.trim() != title { |
| @@ -226,10 +229,7 @@ async fn transfer_post(cx: &Cx, Form(form): Form<TransferForm>) -> Result<impl V | ||
| 226 | 229 | serde_json::json!({ "to": new_owner.username }), |
| 227 | 230 | ) |
| 228 | 231 | .await; |
| 229 | - return Err(see_other(format!( | |
| 230 | - "/{title}/settings?section=danger" | |
| 231 | - )) | |
| 232 | - .into()); | |
| 232 | + return Err(see_other(format!("/{title}/settings?section=danger")).into()); | |
| 233 | 233 | } |
| 234 | 234 | Err(CoreError::Conflict(message)) => break 'attempt Some(message), |
| 235 | 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 | 12 | use forge_core::Repo as RepoRow; |
| 13 | 13 | use forge_git::browse; |
| 14 | 14 | use topcoat::Result; |
| 15 | -use topcoat::context::{Cx, app_context}; | |
| 15 | +use topcoat::context::{Cx, context}; | |
| 16 | 16 | use topcoat::router::error::not_found; |
| 17 | 17 | use topcoat::router::{page, path_param}; |
| 18 | 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 | 163 | /// The listing rows. Names link to their entry at the commit; directories get the folder icon. |
| 164 | 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 | 166 | Ok(view! { |
| 167 | 167 | for row in rows.into_iter() { |
| 168 | 168 | <div class="tree-entry"> |
| @@ -187,14 +187,14 @@ async fn scrub_table(rows: Vec<ScrubRow>, lang: Lang) -> Result<impl View> { | ||
| 187 | 187 | |
| 188 | 188 | #[page("/{owner}/{repo}/scrub/{oid}")] |
| 189 | 189 | async fn scrub_page(cx: &Cx) -> Result<impl View> { |
| 190 | - let owner = path_param::<Owner>(cx); | |
| 191 | - let name = path_param::<Repo>(cx); | |
| 192 | - let oid = path_param::<Oid>(cx); | |
| 190 | + let owner = owner(cx); | |
| 191 | + let name = repo(cx); | |
| 192 | + let oid = oid(cx); | |
| 193 | 193 | let ctx = load_repo(cx, owner, name).await?; |
| 194 | 194 | if !is_full_oid(&oid) { |
| 195 | 195 | return Err(not_found().into()); |
| 196 | 196 | } |
| 197 | - let state = app_context::<AppState>(cx); | |
| 197 | + let state = context::<AppState>(cx); | |
| 198 | 198 | let Some(parts) = scrub_parts(state, &ctx, &oid).await? else { |
| 199 | 199 | return Err(not_found().into()); |
| 200 | 200 | }; |
crates/forge-web/src/pages/repo_secrets.rsmodified+12 -10
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | use forge_core::AuditAction; |
| 8 | 8 | use serde::Deserialize; |
| 9 | 9 | use topcoat::Result; |
| 10 | -use topcoat::context::{Cx, app_context}; | |
| 10 | +use topcoat::context::{Cx, context}; | |
| 11 | 11 | use topcoat::router::content::Form; |
| 12 | 12 | use topcoat::router::error::{SeeOther, forbidden, not_found, see_other}; |
| 13 | 13 | use topcoat::router::request::uri; |
| @@ -151,6 +151,7 @@ impl SecretsData { | ||
| 151 | 151 | /// Header, the rail and the one-line notice. |
| 152 | 152 | #[component] |
| 153 | 153 | async fn frame_top( |
| 154 | + cx: &Cx, | |
| 154 | 155 | lang: Lang, |
| 155 | 156 | head: RepoHead, |
| 156 | 157 | title: String, |
| @@ -182,6 +183,7 @@ async fn frame_top( | ||
| 182 | 183 | /// value is never passed back, so the textarea is always empty. |
| 183 | 184 | #[component] |
| 184 | 185 | async fn secrets_body( |
| 186 | + cx: &Cx, | |
| 185 | 187 | lang: Lang, |
| 186 | 188 | head: RepoHead, |
| 187 | 189 | title: String, |
| @@ -252,15 +254,15 @@ async fn secrets_body( | ||
| 252 | 254 | /// Lists the repo's CI secret names. Admins only: anyone else gets 404. |
| 253 | 255 | #[page("/{owner}/{repo}/settings/secrets")] |
| 254 | 256 | async fn secrets_list_page(cx: &Cx) -> Result<impl View> { |
| 255 | - let owner = path_param::<Owner>(cx); | |
| 256 | - let name = path_param::<Repo>(cx); | |
| 257 | + let owner = owner(cx); | |
| 258 | + let name = repo(cx); | |
| 257 | 259 | let ctx = load_repo(cx, owner, name).await?; |
| 258 | 260 | let (user, session) = require_user(cx).await?; |
| 259 | 261 | if !ctx.can_admin() { |
| 260 | 262 | return Err(not_found().into()); |
| 261 | 263 | } |
| 262 | 264 | let lang = i18n::lang(cx, Some(&user)); |
| 263 | - let state = app_context::<AppState>(cx); | |
| 265 | + let state = context::<AppState>(cx); | |
| 264 | 266 | let data = SecretsData::load(state, &ctx, lang).await?; |
| 265 | 267 | let csrf = session.csrf_token.clone(); |
| 266 | 268 | let notice = notice_from_query(cx); |
| @@ -276,8 +278,8 @@ async fn secrets_list_page(cx: &Cx) -> Result<impl View> { | ||
| 276 | 278 | /// is dropped, not sent back. |
| 277 | 279 | #[page(POST "/{owner}/{repo}/settings/secrets")] |
| 278 | 280 | async fn secret_set(cx: &Cx, Form(form): Form<SetForm>) -> Result<impl View> { |
| 279 | - let owner = path_param::<Owner>(cx); | |
| 280 | - let name = path_param::<Repo>(cx); | |
| 281 | + let owner = owner(cx); | |
| 282 | + let name = repo(cx); | |
| 281 | 283 | let ctx = load_repo(cx, owner, name).await?; |
| 282 | 284 | let (user, session) = require_csrf(cx, &form.csrf).await?; |
| 283 | 285 | if !ctx.can_admin() { |
| @@ -287,7 +289,7 @@ async fn secret_set(cx: &Cx, Form(form): Form<SetForm>) -> Result<impl View> { | ||
| 287 | 289 | return Err(forbidden().into()); |
| 288 | 290 | } |
| 289 | 291 | let lang = i18n::lang(cx, Some(&user)); |
| 290 | - let state = app_context::<AppState>(cx); | |
| 292 | + let state = context::<AppState>(cx); | |
| 291 | 293 | let secret_name = form.name.trim().to_owned(); |
| 292 | 294 | if let Err(message) = check_secret(lang, &secret_name, &form.value) { |
| 293 | 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 | 325 | /// Deletes a secret by name. A name that is not stored is refused with a notice. |
| 324 | 326 | #[route(POST "/{owner}/{repo}/settings/secrets/delete")] |
| 325 | 327 | async fn secret_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther> { |
| 326 | - let owner = path_param::<Owner>(cx); | |
| 327 | - let name = path_param::<Repo>(cx); | |
| 328 | + let owner = owner(cx); | |
| 329 | + let name = repo(cx); | |
| 328 | 330 | let ctx = load_repo(cx, owner, name).await?; |
| 329 | 331 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 330 | 332 | if !ctx.can_admin() { |
| @@ -333,7 +335,7 @@ async fn secret_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther | ||
| 333 | 335 | if ctx.repo.archived { |
| 334 | 336 | return Err(forbidden().into()); |
| 335 | 337 | } |
| 336 | - let state = app_context::<AppState>(cx); | |
| 338 | + let state = context::<AppState>(cx); | |
| 337 | 339 | let title = title_of(&ctx); |
| 338 | 340 | let secret_name = form.name.trim().to_owned(); |
| 339 | 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 | 9 | use serde::Deserialize; |
| 10 | 10 | use serde_json::json; |
| 11 | 11 | use topcoat::Result; |
| 12 | -use topcoat::context::{Cx, app_context}; | |
| 12 | +use topcoat::context::{Cx, context}; | |
| 13 | 13 | use topcoat::router::content::Form; |
| 14 | 14 | use topcoat::router::error::{SeeOther, forbidden, not_found, see_other}; |
| 15 | 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 | 113 | #[component] |
| 114 | 114 | async fn security_body( |
| 115 | + cx: &Cx, | |
| 115 | 116 | lang: Lang, |
| 116 | 117 | head: RepoHead, |
| 117 | 118 | enabled: bool, |
| @@ -156,15 +157,15 @@ async fn security_body( | ||
| 156 | 157 | /// The security page. Write on the repo or 404. |
| 157 | 158 | #[page("/{owner}/{repo}/security")] |
| 158 | 159 | async fn security_page(cx: &Cx) -> Result<impl View> { |
| 159 | - let owner = path_param::<Owner>(cx); | |
| 160 | - let name = path_param::<Repo>(cx); | |
| 160 | + let owner = owner(cx); | |
| 161 | + let name = repo(cx); | |
| 161 | 162 | let ctx = load_repo(cx, owner, name).await?; |
| 162 | 163 | let (user, session) = require_user(cx).await?; |
| 163 | 164 | if !can_write(&ctx) { |
| 164 | 165 | return Err(not_found().into()); |
| 165 | 166 | } |
| 166 | 167 | let lang = i18n::lang(cx, Some(&user)); |
| 167 | - let state = app_context::<AppState>(cx); | |
| 168 | + let state = context::<AppState>(cx); | |
| 168 | 169 | let title = title_of(&ctx); |
| 169 | 170 | let mut head = ctx.head(state, "security").await?; |
| 170 | 171 | head.live = security_live_url(&ctx.repo.owner_name, &ctx.repo.name); |
| @@ -195,8 +196,8 @@ async fn change_alert( | ||
| 195 | 196 | to: AlertState, |
| 196 | 197 | action: AuditAction, |
| 197 | 198 | ) -> Result<SeeOther> { |
| 198 | - let owner = path_param::<Owner>(cx); | |
| 199 | - let name = path_param::<Repo>(cx); | |
| 199 | + let owner = owner(cx); | |
| 200 | + let name = repo(cx); | |
| 200 | 201 | let ctx = load_repo(cx, owner, name).await?; |
| 201 | 202 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 202 | 203 | if !can_write(&ctx) { |
| @@ -205,7 +206,7 @@ async fn change_alert( | ||
| 205 | 206 | if ctx.repo.archived { |
| 206 | 207 | return Err(forbidden().into()); |
| 207 | 208 | } |
| 208 | - let state = app_context::<AppState>(cx); | |
| 209 | + let state = context::<AppState>(cx); | |
| 209 | 210 | let key = AlertKey { |
| 210 | 211 | advisory_id: form.advisory.clone(), |
| 211 | 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 | 23 | use serde::Deserialize; |
| 24 | 24 | use topcoat::Result; |
| 25 | -use topcoat::context::{Cx, app_context}; | |
| 25 | +use topcoat::context::{Cx, context}; | |
| 26 | 26 | use topcoat::cookie::{Cookie, Cookies, SameSite, cookies}; |
| 27 | 27 | use topcoat::router::content::Form; |
| 28 | 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 | 262 | /// The one-line notice on the profile page after a delete. |
| 263 | 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 | 265 | Ok(view! { |
| 266 | 266 | if let Some(title) = title { |
| 267 | 267 | <p class="state" role="status"> |
| @@ -296,6 +296,7 @@ impl DangerForms { | ||
| 296 | 296 | /// The Visibility topic: the current value as a line, and the other side behind a confirm. |
| 297 | 297 | #[component] |
| 298 | 298 | async fn visibility_section( |
| 299 | + cx: &Cx, | |
| 299 | 300 | lang: Lang, |
| 300 | 301 | title: String, |
| 301 | 302 | csrf: String, |
| @@ -334,6 +335,7 @@ async fn visibility_section( | ||
| 334 | 335 | /// The Archive topic: what archiving does, and the one action for the repo's state. |
| 335 | 336 | #[component] |
| 336 | 337 | async fn archive_section( |
| 338 | + cx: &Cx, | |
| 337 | 339 | lang: Lang, |
| 338 | 340 | title: String, |
| 339 | 341 | csrf: String, |
| @@ -363,6 +365,7 @@ async fn archive_section( | ||
| 363 | 365 | /// action is a small pill that opens its form or confirm in place. |
| 364 | 366 | #[component] |
| 365 | 367 | async fn danger_section( |
| 368 | + cx: &Cx, | |
| 366 | 369 | lang: Lang, |
| 367 | 370 | title: String, |
| 368 | 371 | csrf: String, |
| @@ -396,6 +399,7 @@ async fn danger_section( | ||
| 396 | 399 | /// The Delete topic: what deleting does, and the confirmation form, which opens in place. |
| 397 | 400 | #[component] |
| 398 | 401 | async fn delete_section( |
| 402 | + cx: &Cx, | |
| 399 | 403 | lang: Lang, |
| 400 | 404 | csrf: String, |
| 401 | 405 | title: String, |
| @@ -437,6 +441,7 @@ async fn delete_section( | ||
| 437 | 441 | /// page is for a repo admin, so the Danger zone is always listed. |
| 438 | 442 | #[component] |
| 439 | 443 | pub async fn settings_frame( |
| 444 | + cx: &Cx, | |
| 440 | 445 | lang: Lang, |
| 441 | 446 | title: String, |
| 442 | 447 | current: &'static str, |
| @@ -449,13 +454,41 @@ pub async fn settings_frame( | ||
| 449 | 454 | current: on, |
| 450 | 455 | }; |
| 451 | 456 | let items = vec![ |
| 452 | - item(g::t(lang, K::General), format!("/{title}/settings"), current == "general"), | |
| 453 | - item(g::t(lang, K::Collaborators), format!("/{title}/settings/collaborators"), current == "collaborators"), | |
| 454 | - item(g::t(lang, K::BranchProtection), format!("/{title}/settings?section=branches"), current == "branches"), | |
| 455 | - item(g::t(lang, K::Webhooks), format!("/{title}/settings/hooks"), current == "webhooks"), | |
| 456 | - item(g::t(lang, K::Mirrors), format!("/{title}/settings/mirrors"), current == "mirrors"), | |
| 457 | - item(g::t(lang, K::Secrets), format!("/{title}/settings/secrets"), current == "secrets"), | |
| 458 | - item(g::t(lang, K::DangerZone), format!("/{title}/settings?section=danger"), current == "danger"), | |
| 457 | + item( | |
| 458 | + g::t(lang, K::General), | |
| 459 | + format!("/{title}/settings"), | |
| 460 | + current == "general", | |
| 461 | + ), | |
| 462 | + item( | |
| 463 | + g::t(lang, K::Collaborators), | |
| 464 | + format!("/{title}/settings/collaborators"), | |
| 465 | + current == "collaborators", | |
| 466 | + ), | |
| 467 | + item( | |
| 468 | + g::t(lang, K::BranchProtection), | |
| 469 | + format!("/{title}/settings?section=branches"), | |
| 470 | + current == "branches", | |
| 471 | + ), | |
| 472 | + item( | |
| 473 | + g::t(lang, K::Webhooks), | |
| 474 | + format!("/{title}/settings/hooks"), | |
| 475 | + current == "webhooks", | |
| 476 | + ), | |
| 477 | + item( | |
| 478 | + g::t(lang, K::Mirrors), | |
| 479 | + format!("/{title}/settings/mirrors"), | |
| 480 | + current == "mirrors", | |
| 481 | + ), | |
| 482 | + item( | |
| 483 | + g::t(lang, K::Secrets), | |
| 484 | + format!("/{title}/settings/secrets"), | |
| 485 | + current == "secrets", | |
| 486 | + ), | |
| 487 | + item( | |
| 488 | + g::t(lang, K::DangerZone), | |
| 489 | + format!("/{title}/settings?section=danger"), | |
| 490 | + current == "danger", | |
| 491 | + ), | |
| 459 | 492 | ]; |
| 460 | 493 | Ok(view! { |
| 461 | 494 | <div class="work"> |
| @@ -467,12 +500,12 @@ pub async fn settings_frame( | ||
| 467 | 500 | }) |
| 468 | 501 | } |
| 469 | 502 | |
| 470 | - | |
| 471 | 503 | /// The General section: description and default branch in one form, under no heading (the page's |
| 472 | 504 | /// head names it), then the Features topic with one switch per feature. Each form carries its own |
| 473 | 505 | /// CSRF token. An empty repo shows "No branches yet" and no selector. |
| 474 | 506 | #[component] |
| 475 | 507 | async fn general_section( |
| 508 | + cx: &Cx, | |
| 476 | 509 | lang: Lang, |
| 477 | 510 | title: String, |
| 478 | 511 | csrf: String, |
| @@ -617,6 +650,7 @@ struct RuleCard { | ||
| 617 | 650 | /// opens with the draft when no rule takes it. The rows share one `name`, so opening one closes the rest. |
| 618 | 651 | #[component] |
| 619 | 652 | async fn branch_rule_cards( |
| 653 | + cx: &Cx, | |
| 620 | 654 | lang: Lang, |
| 621 | 655 | cards: Vec<RuleCard>, |
| 622 | 656 | builtin_row: bool, |
| @@ -673,6 +707,7 @@ async fn branch_rule_cards( | ||
| 673 | 707 | /// an existing rule's Remove action is a confirm_act beside them, on the same row. |
| 674 | 708 | #[component] |
| 675 | 709 | async fn branch_rule_form( |
| 710 | + cx: &Cx, | |
| 676 | 711 | lang: Lang, |
| 677 | 712 | csrf: String, |
| 678 | 713 | save_action: String, |
| @@ -700,7 +735,11 @@ async fn branch_rule_form( | ||
| 700 | 735 | || require_up_to_date |
| 701 | 736 | || require_merge_queue |
| 702 | 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 | 743 | // Field ids are per rule, so two open rule forms never share an id. |
| 705 | 744 | let prefix = match &rule_id { |
| 706 | 745 | Some(id) => format!("rule-{id}"), |
| @@ -896,7 +935,7 @@ pub(crate) async fn render_settings( | ||
| 896 | 935 | lang: Lang, |
| 897 | 936 | shown: Shown, |
| 898 | 937 | ) -> Result<impl View> { |
| 899 | - let state = app_context::<AppState>(cx); | |
| 938 | + let state = context::<AppState>(cx); | |
| 900 | 939 | let Shown { |
| 901 | 940 | section, |
| 902 | 941 | notice, |
| @@ -915,14 +954,11 @@ pub(crate) async fn render_settings( | ||
| 915 | 954 | danger, |
| 916 | 955 | transfer, |
| 917 | 956 | wiki_on: state.store.wiki_enabled(&ctx.repo.id).await?, |
| 918 | - contexts: state | |
| 919 | - .store | |
| 920 | - .recent_status_contexts(&ctx.repo.id, 20) | |
| 921 | - .await?, | |
| 957 | + contexts: state.store.recent_status_contexts(&ctx.repo.id, 20).await?, | |
| 922 | 958 | }; |
| 923 | 959 | let frame = SettingsFrame::new(&ctx, state, lang).await?; |
| 924 | 960 | let branches = load_branch_names(&ctx).await?; |
| 925 | - Ok(view! { cx => | |
| 961 | + Ok(view! { | |
| 926 | 962 | shell(title: frame.page_title.as_str(), viewer: ctx.viewer.as_ref(), |
| 927 | 963 | settings_body(lang: lang, head: frame.head, default_branch: frame.default_branch, archived: frame.archived, |
| 928 | 964 | branches: branches, title: frame.title, csrf: csrf, |
| @@ -934,6 +970,7 @@ pub(crate) async fn render_settings( | ||
| 934 | 970 | /// general, branches or danger) in the sheet. |
| 935 | 971 | #[component] |
| 936 | 972 | async fn settings_body( |
| 973 | + cx: &Cx, | |
| 937 | 974 | lang: Lang, |
| 938 | 975 | head: RepoHead, |
| 939 | 976 | default_branch: String, |
| @@ -1057,8 +1094,8 @@ impl SettingsFrame { | ||
| 1057 | 1094 | /// visible repos go to login, and signed-in viewers who may not manage the repo get 403. |
| 1058 | 1095 | #[page("/{owner}/{repo}/settings")] |
| 1059 | 1096 | async fn settings_page(cx: &Cx) -> Result<impl View> { |
| 1060 | - let owner = path_param::<Owner>(cx); | |
| 1061 | - let name = path_param::<Repo>(cx); | |
| 1097 | + let owner = owner(cx); | |
| 1098 | + let name = repo(cx); | |
| 1062 | 1099 | let ctx = load_repo(cx, owner, name).await?; |
| 1063 | 1100 | let (user, session) = require_user(cx).await?; |
| 1064 | 1101 | if !ctx.can_admin() { |
| @@ -1080,15 +1117,15 @@ async fn settings_page(cx: &Cx) -> Result<impl View> { | ||
| 1080 | 1117 | /// and the database changes only when that succeeds. A failed database write puts HEAD back. |
| 1081 | 1118 | #[route(POST "/{owner}/{repo}/settings/general")] |
| 1082 | 1119 | async fn settings_general_save(cx: &Cx, Form(form): Form<GeneralForm>) -> Result<SeeOther> { |
| 1083 | - let owner = path_param::<Owner>(cx); | |
| 1084 | - let name = path_param::<Repo>(cx); | |
| 1120 | + let owner = owner(cx); | |
| 1121 | + let name = repo(cx); | |
| 1085 | 1122 | let ctx = load_repo(cx, owner, name).await?; |
| 1086 | 1123 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 1087 | 1124 | if !ctx.can_admin() { |
| 1088 | 1125 | return Err(forbidden().into()); |
| 1089 | 1126 | } |
| 1090 | 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 | 1130 | let description = clean_description(&form.description); |
| 1094 | 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 | 1186 | /// changes nothing. |
| 1150 | 1187 | #[route(POST "/{owner}/{repo}/settings/visibility")] |
| 1151 | 1188 | async fn settings_visibility_save(cx: &Cx, Form(form): Form<VisibilityForm>) -> Result<SeeOther> { |
| 1152 | - let owner = path_param::<Owner>(cx); | |
| 1153 | - let name = path_param::<Repo>(cx); | |
| 1189 | + let owner = owner(cx); | |
| 1190 | + let name = repo(cx); | |
| 1154 | 1191 | let ctx = load_repo(cx, owner, name).await?; |
| 1155 | 1192 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 1156 | 1193 | if !ctx.can_admin() { |
| @@ -1166,7 +1203,7 @@ async fn settings_visibility_save(cx: &Cx, Form(form): Form<VisibilityForm>) -> | ||
| 1166 | 1203 | set_settings_notice(cx, "understand"); |
| 1167 | 1204 | return Ok(back_to_section(&title, "danger")); |
| 1168 | 1205 | } |
| 1169 | - let state = app_context::<AppState>(cx); | |
| 1206 | + let state = context::<AppState>(cx); | |
| 1170 | 1207 | state |
| 1171 | 1208 | .store |
| 1172 | 1209 | .set_repo_visibility(&ctx.repo.id, target) |
| @@ -1201,8 +1238,8 @@ async fn settings_visibility_save(cx: &Cx, Form(form): Form<VisibilityForm>) -> | ||
| 1201 | 1238 | /// the archived flag does not block Admin. |
| 1202 | 1239 | #[route(POST "/{owner}/{repo}/settings/archive")] |
| 1203 | 1240 | async fn settings_archive_save(cx: &Cx, Form(form): Form<ArchiveForm>) -> Result<SeeOther> { |
| 1204 | - let owner = path_param::<Owner>(cx); | |
| 1205 | - let name = path_param::<Repo>(cx); | |
| 1241 | + let owner = owner(cx); | |
| 1242 | + let name = repo(cx); | |
| 1206 | 1243 | let ctx = load_repo(cx, owner, name).await?; |
| 1207 | 1244 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 1208 | 1245 | if !ctx.can_admin() { |
| @@ -1217,7 +1254,7 @@ async fn settings_archive_save(cx: &Cx, Form(form): Form<ArchiveForm>) -> Result | ||
| 1217 | 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 | 1258 | state |
| 1222 | 1259 | .store |
| 1223 | 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 | 1295 | /// A wrong confirmation re-renders the page with an error and changes nothing. |
| 1259 | 1296 | #[page(POST "/{owner}/{repo}/settings/delete")] |
| 1260 | 1297 | async fn settings_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<impl View> { |
| 1261 | - let owner = path_param::<Owner>(cx); | |
| 1262 | - let name = path_param::<Repo>(cx); | |
| 1298 | + let owner = owner(cx); | |
| 1299 | + let name = repo(cx); | |
| 1263 | 1300 | let ctx = load_repo(cx, owner, name).await?; |
| 1264 | 1301 | let (user, session) = require_csrf(cx, &form.csrf).await?; |
| 1265 | 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 | 1313 | if error.is_none() { |
| 1277 | - let state = app_context::<AppState>(cx); | |
| 1314 | + let state = context::<AppState>(cx); | |
| 1278 | 1315 | let repo: &RepoRow = &ctx.repo; |
| 1279 | 1316 | let data_dir = &state.config.data_dir; |
| 1280 | 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 | 1415 | /// `Action::Admin` first. An invalid pattern re-renders the page with the error next to the form. |
| 1379 | 1416 | #[page(POST "/{owner}/{repo}/settings/branches")] |
| 1380 | 1417 | async fn settings_branch_save(cx: &Cx, Form(form): Form<BranchForm>) -> Result<impl View> { |
| 1381 | - let owner = path_param::<Owner>(cx); | |
| 1382 | - let name = path_param::<Repo>(cx); | |
| 1418 | + let owner = owner(cx); | |
| 1419 | + let name = repo(cx); | |
| 1383 | 1420 | let ctx = load_repo(cx, owner, name).await?; |
| 1384 | 1421 | let (user, session) = require_csrf(cx, &form.csrf).await?; |
| 1385 | 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 | 1429 | let is_new = form.existing.is_none(); |
| 1393 | 1430 | let taken = is_new |
| 1394 | - && app_context::<AppState>(cx) | |
| 1431 | + && context::<AppState>(cx) | |
| 1395 | 1432 | .store |
| 1396 | 1433 | .list_branch_rules(&ctx.repo.id) |
| 1397 | 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 | 1474 | state |
| 1438 | 1475 | .store |
| 1439 | 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 | 1495 | /// Removes a branch rule by id, scoped to this repo. Same checks as the save form. |
| 1459 | 1496 | #[route(POST "/{owner}/{repo}/settings/branches/delete")] |
| 1460 | 1497 | async fn settings_branch_delete(cx: &Cx, Form(form): Form<BranchDeleteForm>) -> Result<SeeOther> { |
| 1461 | - let owner = path_param::<Owner>(cx); | |
| 1462 | - let name = path_param::<Repo>(cx); | |
| 1498 | + let owner = owner(cx); | |
| 1499 | + let name = repo(cx); | |
| 1463 | 1500 | let ctx = load_repo(cx, owner, name).await?; |
| 1464 | 1501 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 1465 | 1502 | if !ctx.can_admin() { |
| 1466 | 1503 | return Err(forbidden().into()); |
| 1467 | 1504 | } |
| 1468 | - let state = app_context::<AppState>(cx); | |
| 1505 | + let state = context::<AppState>(cx); | |
| 1469 | 1506 | state |
| 1470 | 1507 | .store |
| 1471 | 1508 | .delete_branch_rule(&ctx.repo.id, &form.rule_id) |
| @@ -1568,7 +1605,11 @@ mod tests { | ||
| 1568 | 1605 | let (status, _) = post_rule( |
| 1569 | 1606 | &app, |
| 1570 | 1607 | &cookie, |
| 1571 | - &[("pattern", "main"), ("existing", "1"), ("required_approvals", "")], | |
| 1608 | + &[ | |
| 1609 | + ("pattern", "main"), | |
| 1610 | + ("existing", "1"), | |
| 1611 | + ("required_approvals", ""), | |
| 1612 | + ], | |
| 1572 | 1613 | ) |
| 1573 | 1614 | .await; |
| 1574 | 1615 | assert_eq!(status, 303); |
| @@ -1583,7 +1624,8 @@ mod tests { | ||
| 1583 | 1624 | &app, |
| 1584 | 1625 | &cookie, |
| 1585 | 1626 | &[ |
| 1586 | - ("pattern", "main"), ("existing", "1"), | |
| 1627 | + ("pattern", "main"), | |
| 1628 | + ("existing", "1"), | |
| 1587 | 1629 | ("required_approvals", "21"), |
| 1588 | 1630 | ("restrict_push", "on"), |
| 1589 | 1631 | ], |
| @@ -1602,7 +1644,11 @@ mod tests { | ||
| 1602 | 1644 | let (status, body) = post_rule( |
| 1603 | 1645 | &app, |
| 1604 | 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 | 1653 | .await; |
| 1608 | 1654 | assert_eq!(status, 200); |
crates/forge-web/src/pages/repo_settings_live.rsmodified+7 -7
| @@ -15,7 +15,7 @@ | ||
| 15 | 15 | //! security and transfer streams for the signed-in viewers their pages admit. |
| 16 | 16 | |
| 17 | 17 | use topcoat::Result; |
| 18 | -use topcoat::context::{Cx, app_context}; | |
| 18 | +use topcoat::context::{Cx, context}; | |
| 19 | 19 | use topcoat::router::error::forbidden; |
| 20 | 20 | use topcoat::router::request::{method, uri}; |
| 21 | 21 | use topcoat::router::response::Response; |
| @@ -56,11 +56,11 @@ pub fn bump_settings(hub: &LiveHub, repo_id: &str) { | ||
| 56 | 56 | /// as the settings page is. |
| 57 | 57 | #[route(GET "/{owner}/{repo}/settings/live")] |
| 58 | 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 | 60 | if !ctx.can_admin() { |
| 61 | 61 | return Err(forbidden().into()); |
| 62 | 62 | } |
| 63 | - let state = app_context::<AppState>(cx); | |
| 63 | + let state = context::<AppState>(cx); | |
| 64 | 64 | let topics = [ |
| 65 | 65 | Topic::RepoSettings(ctx.repo.id.clone()), |
| 66 | 66 | Topic::RepoRefs(ctx.repo.id.clone()), |
| @@ -72,9 +72,9 @@ async fn settings_live(cx: &Cx) -> Result<Response> { | ||
| 72 | 72 | /// read the repo. |
| 73 | 73 | #[route(GET "/{owner}/{repo}/security/live")] |
| 74 | 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 | 76 | require_user(cx).await?; |
| 77 | - let state = app_context::<AppState>(cx); | |
| 77 | + let state = context::<AppState>(cx); | |
| 78 | 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 | 115 | async fn bump_after_write(cx: &Cx, body: Body, next: Next<'_>) -> Result<Response> { |
| 116 | 116 | let repo_id = match written(cx) { |
| 117 | 117 | Some((owner, name)) => { |
| 118 | - let state = app_context::<AppState>(cx); | |
| 118 | + let state = context::<AppState>(cx); | |
| 119 | 119 | match state.store.repo_by_owner_and_name(&owner, &name).await { |
| 120 | 120 | Ok(repo) => repo.map(|repo| repo.id), |
| 121 | 121 | Err(e) => { |
| @@ -128,7 +128,7 @@ async fn bump_after_write(cx: &Cx, body: Body, next: Next<'_>) -> Result<Respons | ||
| 128 | 128 | }; |
| 129 | 129 | let result = next.run(cx, body).await; |
| 130 | 130 | if let Some(repo_id) = repo_id { |
| 131 | - let state = app_context::<AppState>(cx); | |
| 131 | + let state = context::<AppState>(cx); | |
| 132 | 132 | bump_settings(&state.live, &repo_id); |
| 133 | 133 | // The repo header shows settings too (the mirror line, the archived notice, the tabs); its |
| 134 | 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 | 256 | parts.push(SubPart::text(lang_name(lang, share))); |
| 257 | 257 | } |
| 258 | 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 | 263 | if facts.size > 0 { |
| 262 | 264 | parts.push(SubPart::text(human_size(lang, facts.size))); |
| @@ -329,4 +331,3 @@ fn lang_name(lang: Lang, share: &LangShare) -> String { | ||
| 329 | 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 | 12 | use forge_core::{AuditAction, Error as CoreError}; |
| 13 | 13 | use serde::Deserialize; |
| 14 | 14 | use topcoat::Result; |
| 15 | -use topcoat::context::{Cx, app_context}; | |
| 15 | +use topcoat::context::{Cx, context}; | |
| 16 | 16 | use topcoat::router::content::Form; |
| 17 | 17 | use topcoat::router::error::{SeeOther, forbidden, see_other}; |
| 18 | 18 | use topcoat::router::{path_param, route}; |
| @@ -94,6 +94,7 @@ pub(crate) async fn transfer_status( | ||
| 94 | 94 | /// with an error opens with it. |
| 95 | 95 | #[component] |
| 96 | 96 | pub(crate) async fn transfer_section( |
| 97 | + cx: &Cx, | |
| 97 | 98 | lang: Lang, |
| 98 | 99 | title: String, |
| 99 | 100 | csrf: String, |
| @@ -146,9 +147,11 @@ pub(crate) async fn transfer_section( | ||
| 146 | 147 | /// The transfer page moved into the danger zone; the old address goes there. |
| 147 | 148 | #[route(GET "/{owner}/{repo}/transfer")] |
| 148 | 149 | async fn transfer_get(cx: &Cx) -> Result<SeeOther> { |
| 149 | - let owner = path_param::<Owner>(cx); | |
| 150 | - let repo = path_param::<Repo>(cx); | |
| 151 | - Ok(see_other(format!("/{owner}/{repo}/settings?section=danger"))) | |
| 150 | + let owner = owner(cx); | |
| 151 | + let repo = repo(cx); | |
| 152 | + Ok(see_other(format!( | |
| 153 | + "/{owner}/{repo}/settings?section=danger" | |
| 154 | + ))) | |
| 152 | 155 | } |
| 153 | 156 | |
| 154 | 157 | /// The open transfer `repo_id`, or `NotFound`. |
| @@ -163,9 +166,9 @@ async fn open_transfer(state: &AppState, repo_id: &str) -> Result<PendingTransfe | ||
| 163 | 166 | /// Accepts the transfer as the target and moves the repo. Then goes to the repo at its new owner. |
| 164 | 167 | #[route(POST "/-/transfers/{transfer}/accept")] |
| 165 | 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 | 170 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 168 | - let state = app_context::<AppState>(cx); | |
| 171 | + let state = context::<AppState>(cx); | |
| 169 | 172 | let pending = open_transfer(state, &repo_id).await?; |
| 170 | 173 | let from_owner = state |
| 171 | 174 | .store |
| @@ -201,9 +204,9 @@ async fn accept_post(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther> | ||
| 201 | 204 | /// Declines the transfer as one of its target's owners. The repo stays where it is. |
| 202 | 205 | #[route(POST "/-/transfers/{transfer}/decline")] |
| 203 | 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 | 208 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 206 | - let state = app_context::<AppState>(cx); | |
| 209 | + let state = context::<AppState>(cx); | |
| 207 | 210 | let pending = open_transfer(state, &repo_id).await?; |
| 208 | 211 | state.store.decline_transfer(&repo_id, &user.id).await?; |
| 209 | 212 | bump_settings(&state.live, &repo_id); |
| @@ -226,9 +229,9 @@ async fn decline_post(cx: &Cx, Form(form): Form<ActionForm>) -> Result<SeeOther> | ||
| 226 | 229 | /// Cancels the transfer. The initiator may, and so may anyone who may delete the repo. |
| 227 | 230 | #[route(POST "/-/transfers/{transfer}/cancel")] |
| 228 | 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 | 233 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 231 | - let state = app_context::<AppState>(cx); | |
| 234 | + let state = context::<AppState>(cx); | |
| 232 | 235 | let pending = open_transfer(state, &repo_id).await?; |
| 233 | 236 | let repo = state |
| 234 | 237 | .store |
| @@ -276,6 +279,7 @@ struct InboxRow { | ||
| 276 | 279 | /// private repo. |
| 277 | 280 | #[component] |
| 278 | 281 | pub(crate) async fn transfer_list_for( |
| 282 | + cx: &Cx, | |
| 279 | 283 | lang: Lang, |
| 280 | 284 | transfers: Vec<PendingTransfer>, |
| 281 | 285 | csrf: String, |
crates/forge-web/src/pages/repo_webhooks.rsmodified+37 -31
| @@ -13,7 +13,7 @@ use serde_json::Value; | ||
| 13 | 13 | use time::OffsetDateTime; |
| 14 | 14 | use time::format_description::well_known::Rfc3339; |
| 15 | 15 | use topcoat::Result; |
| 16 | -use topcoat::context::{Cx, app_context}; | |
| 16 | +use topcoat::context::{Cx, context}; | |
| 17 | 17 | use topcoat::router::content::Form; |
| 18 | 18 | use topcoat::router::error::{SeeOther, forbidden, not_found, see_other}; |
| 19 | 19 | use topcoat::router::request::uri; |
| @@ -490,6 +490,7 @@ impl Frame { | ||
| 490 | 490 | /// list's name, or the hook's URL); `action` is the head's main action as (href, label), if any. |
| 491 | 491 | #[component] |
| 492 | 492 | async fn frame_top( |
| 493 | + cx: &Cx, | |
| 493 | 494 | head: RepoHead, |
| 494 | 495 | title: String, |
| 495 | 496 | heading: String, |
| @@ -524,6 +525,7 @@ async fn frame_top( | ||
| 524 | 525 | /// The add or edit form. `secret_hint` says what the secret field does for this form. |
| 525 | 526 | #[component] |
| 526 | 527 | async fn hook_form( |
| 528 | + cx: &Cx, | |
| 527 | 529 | action: String, |
| 528 | 530 | csrf: String, |
| 529 | 531 | url: String, |
| @@ -584,6 +586,7 @@ async fn hook_form( | ||
| 584 | 586 | |
| 585 | 587 | #[component] |
| 586 | 588 | async fn hooks_list_body( |
| 589 | + cx: &Cx, | |
| 587 | 590 | head: RepoHead, |
| 588 | 591 | title: String, |
| 589 | 592 | notice: Option<(&'static str, bool)>, |
| @@ -628,6 +631,7 @@ async fn hooks_list_body( | ||
| 628 | 631 | |
| 629 | 632 | #[component] |
| 630 | 633 | async fn delivery_list( |
| 634 | + cx: &Cx, | |
| 631 | 635 | deliveries: Vec<DeliveryRow>, |
| 632 | 636 | csrf: String, |
| 633 | 637 | archived: bool, |
| @@ -671,6 +675,7 @@ async fn delivery_list( | ||
| 671 | 675 | |
| 672 | 676 | #[component] |
| 673 | 677 | async fn hook_body( |
| 678 | + cx: &Cx, | |
| 674 | 679 | head: RepoHead, |
| 675 | 680 | title: String, |
| 676 | 681 | notice: Option<(&'static str, bool)>, |
| @@ -731,14 +736,14 @@ async fn hook_body( | ||
| 731 | 736 | /// Lists the repo's hooks. Admins only: a hidden repo is 404, any other viewer is 403. |
| 732 | 737 | #[page("/{owner}/{repo}/settings/hooks")] |
| 733 | 738 | async fn hooks_list_page(cx: &Cx) -> Result<impl View> { |
| 734 | - let owner = path_param::<Owner>(cx); | |
| 735 | - let name = path_param::<Repo>(cx); | |
| 739 | + let owner = owner(cx); | |
| 740 | + let name = repo(cx); | |
| 736 | 741 | let ctx = load_repo(cx, owner, name).await?; |
| 737 | 742 | require_user(cx).await?; |
| 738 | 743 | if !ctx.can_admin() { |
| 739 | 744 | return Err(forbidden().into()); |
| 740 | 745 | } |
| 741 | - let state = app_context::<AppState>(cx); | |
| 746 | + let state = context::<AppState>(cx); | |
| 742 | 747 | let hooks = state.store.list_webhooks(&ctx.repo.id).await?; |
| 743 | 748 | let lang = lang_of(cx, &ctx); |
| 744 | 749 | let frame = Frame::new(&ctx, state, lang).await?; |
| @@ -771,14 +776,14 @@ async fn hooks_list_page(cx: &Cx) -> Result<impl View> { | ||
| 771 | 776 | /// The add form. |
| 772 | 777 | #[page("/{owner}/{repo}/settings/hooks/new")] |
| 773 | 778 | async fn hook_new_page(cx: &Cx) -> Result<impl View> { |
| 774 | - let owner = path_param::<Owner>(cx); | |
| 775 | - let name = path_param::<Repo>(cx); | |
| 779 | + let owner = owner(cx); | |
| 780 | + let name = repo(cx); | |
| 776 | 781 | let ctx = load_repo(cx, owner, name).await?; |
| 777 | 782 | let (_, session) = require_user(cx).await?; |
| 778 | 783 | if !ctx.can_admin() { |
| 779 | 784 | return Err(forbidden().into()); |
| 780 | 785 | } |
| 781 | - let state = app_context::<AppState>(cx); | |
| 786 | + let state = context::<AppState>(cx); | |
| 782 | 787 | let lang = lang_of(cx, &ctx); |
| 783 | 788 | let frame = Frame::new(&ctx, state, lang).await?; |
| 784 | 789 | let csrf = session.csrf_token.clone(); |
| @@ -793,6 +798,7 @@ async fn hook_new_page(cx: &Cx) -> Result<impl View> { | ||
| 793 | 798 | |
| 794 | 799 | #[component] |
| 795 | 800 | async fn hook_new_body( |
| 801 | + cx: &Cx, | |
| 796 | 802 | head: RepoHead, |
| 797 | 803 | title: String, |
| 798 | 804 | archived: bool, |
| @@ -820,14 +826,14 @@ async fn hook_new_body( | ||
| 820 | 826 | /// Creates a hook. The secret is sealed before it is stored. A ping is queued on success. |
| 821 | 827 | #[page(POST "/{owner}/{repo}/settings/hooks/new")] |
| 822 | 828 | async fn hook_create(cx: &Cx, Form(form): Form<HookForm>) -> Result<impl View> { |
| 823 | - let owner = path_param::<Owner>(cx); | |
| 824 | - let name = path_param::<Repo>(cx); | |
| 829 | + let owner = owner(cx); | |
| 830 | + let name = repo(cx); | |
| 825 | 831 | let ctx = load_repo(cx, owner, name).await?; |
| 826 | 832 | let (user, session) = require_csrf(cx, &form.csrf).await?; |
| 827 | 833 | if !ctx.can_admin() || ctx.repo.archived { |
| 828 | 834 | return Err(forbidden().into()); |
| 829 | 835 | } |
| 830 | - let state = app_context::<AppState>(cx); | |
| 836 | + let state = context::<AppState>(cx); | |
| 831 | 837 | let url = form.url.trim().to_owned(); |
| 832 | 838 | let events = form.events(); |
| 833 | 839 | let lang = lang_of(cx, &ctx); |
| @@ -970,15 +976,15 @@ async fn hook_page_data( | ||
| 970 | 976 | /// The hook page: its form, a test button, the last deliveries and the delete form. |
| 971 | 977 | #[page("/{owner}/{repo}/settings/hooks/{hook_id}")] |
| 972 | 978 | async fn hook_page(cx: &Cx) -> Result<impl View> { |
| 973 | - let owner = path_param::<Owner>(cx); | |
| 974 | - let name = path_param::<Repo>(cx); | |
| 975 | - let id = path_param::<HookId>(cx); | |
| 979 | + let owner = owner(cx); | |
| 980 | + let name = repo(cx); | |
| 981 | + let id = hook_id(cx); | |
| 976 | 982 | let ctx = load_repo(cx, owner, name).await?; |
| 977 | 983 | let (_, session) = require_user(cx).await?; |
| 978 | 984 | if !ctx.can_admin() { |
| 979 | 985 | return Err(forbidden().into()); |
| 980 | 986 | } |
| 981 | - let state = app_context::<AppState>(cx); | |
| 987 | + let state = context::<AppState>(cx); | |
| 982 | 988 | let hook = repo_hook(state, &ctx, id).await?; |
| 983 | 989 | let draft = HookDraft::of_hook(&hook); |
| 984 | 990 | let csrf = session.csrf_token.clone(); |
| @@ -998,15 +1004,15 @@ async fn hook_page(cx: &Cx) -> Result<impl View> { | ||
| 998 | 1004 | /// page with the submitted values. |
| 999 | 1005 | #[page(POST "/{owner}/{repo}/settings/hooks/{hook_id}")] |
| 1000 | 1006 | async fn hook_update(cx: &Cx, Form(form): Form<HookForm>) -> Result<impl View> { |
| 1001 | - let owner = path_param::<Owner>(cx); | |
| 1002 | - let name = path_param::<Repo>(cx); | |
| 1003 | - let id = path_param::<HookId>(cx); | |
| 1007 | + let owner = owner(cx); | |
| 1008 | + let name = repo(cx); | |
| 1009 | + let id = hook_id(cx); | |
| 1004 | 1010 | let ctx = load_repo(cx, owner, name).await?; |
| 1005 | 1011 | let (user, session) = require_csrf(cx, &form.csrf).await?; |
| 1006 | 1012 | if !ctx.can_admin() || ctx.repo.archived { |
| 1007 | 1013 | return Err(forbidden().into()); |
| 1008 | 1014 | } |
| 1009 | - let state = app_context::<AppState>(cx); | |
| 1015 | + let state = context::<AppState>(cx); | |
| 1010 | 1016 | let hook = repo_hook(state, &ctx, id).await?; |
| 1011 | 1017 | let url = form.url.trim().to_owned(); |
| 1012 | 1018 | let events = form.events(); |
| @@ -1064,15 +1070,15 @@ async fn hook_update(cx: &Cx, Form(form): Form<HookForm>) -> Result<impl View> { | ||
| 1064 | 1070 | /// Sends a ping to the hook now. |
| 1065 | 1071 | #[route(POST "/{owner}/{repo}/settings/hooks/{hook_id}/test")] |
| 1066 | 1072 | async fn hook_test(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { |
| 1067 | - let owner = path_param::<Owner>(cx); | |
| 1068 | - let name = path_param::<Repo>(cx); | |
| 1069 | - let id = path_param::<HookId>(cx); | |
| 1073 | + let owner = owner(cx); | |
| 1074 | + let name = repo(cx); | |
| 1075 | + let id = hook_id(cx); | |
| 1070 | 1076 | let ctx = load_repo(cx, owner, name).await?; |
| 1071 | 1077 | require_csrf(cx, &form.csrf).await?; |
| 1072 | 1078 | if !ctx.can_admin() || ctx.repo.archived { |
| 1073 | 1079 | return Err(forbidden().into()); |
| 1074 | 1080 | } |
| 1075 | - let state = app_context::<AppState>(cx); | |
| 1081 | + let state = context::<AppState>(cx); | |
| 1076 | 1082 | let hook = repo_hook(state, &ctx, id).await?; |
| 1077 | 1083 | emit_ping(state, &hook).await?; |
| 1078 | 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 | 1087 | /// Queues a new delivery with the same payload as an earlier one, then wakes the worker. |
| 1082 | 1088 | #[route(POST "/{owner}/{repo}/settings/hooks/{hook_id}/deliveries/{delivery_id}/redeliver")] |
| 1083 | 1089 | async fn hook_redeliver(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { |
| 1084 | - let owner = path_param::<Owner>(cx); | |
| 1085 | - let name = path_param::<Repo>(cx); | |
| 1086 | - let id = path_param::<HookId>(cx); | |
| 1087 | - let delivery = path_param::<DeliveryId>(cx); | |
| 1090 | + let owner = owner(cx); | |
| 1091 | + let name = repo(cx); | |
| 1092 | + let id = hook_id(cx); | |
| 1093 | + let delivery = delivery_id(cx); | |
| 1088 | 1094 | let ctx = load_repo(cx, owner, name).await?; |
| 1089 | 1095 | require_csrf(cx, &form.csrf).await?; |
| 1090 | 1096 | if !ctx.can_admin() || ctx.repo.archived { |
| 1091 | 1097 | return Err(forbidden().into()); |
| 1092 | 1098 | } |
| 1093 | - let state = app_context::<AppState>(cx); | |
| 1099 | + let state = context::<AppState>(cx); | |
| 1094 | 1100 | let hook = repo_hook(state, &ctx, id).await?; |
| 1095 | 1101 | match state.store.delivery(delivery).await? { |
| 1096 | 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 | 1110 | /// Deletes a hook and its deliveries. The box must be ticked. |
| 1105 | 1111 | #[route(POST "/{owner}/{repo}/settings/hooks/{hook_id}/delete")] |
| 1106 | 1112 | async fn hook_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther> { |
| 1107 | - let owner = path_param::<Owner>(cx); | |
| 1108 | - let name = path_param::<Repo>(cx); | |
| 1109 | - let id = path_param::<HookId>(cx); | |
| 1113 | + let owner = owner(cx); | |
| 1114 | + let name = repo(cx); | |
| 1115 | + let id = hook_id(cx); | |
| 1110 | 1116 | let ctx = load_repo(cx, owner, name).await?; |
| 1111 | 1117 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 1112 | 1118 | if !ctx.can_admin() || ctx.repo.archived { |
| 1113 | 1119 | return Err(forbidden().into()); |
| 1114 | 1120 | } |
| 1115 | - let state = app_context::<AppState>(cx); | |
| 1121 | + let state = context::<AppState>(cx); | |
| 1116 | 1122 | let hook = repo_hook(state, &ctx, id).await?; |
| 1117 | 1123 | let title = title_of(&ctx); |
| 1118 | 1124 | if form.confirm.is_none() { |
crates/forge-web/src/pages/review_requests.rsmodified+11 -7
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | use forge_core::authz::{Action, authorize}; |
| 8 | 8 | use serde::Deserialize; |
| 9 | 9 | use topcoat::Result; |
| 10 | -use topcoat::context::{Cx, app_context}; | |
| 10 | +use topcoat::context::{Cx, context}; | |
| 11 | 11 | use topcoat::router::content::Form; |
| 12 | 12 | use topcoat::router::error::{SeeOther, forbidden, not_found, see_other}; |
| 13 | 13 | use topcoat::router::request::uri; |
| @@ -76,7 +76,7 @@ async fn review_requests_events(cx: &Cx) -> Result<Response> { | ||
| 76 | 76 | *res.status_mut() = StatusCode::UNAUTHORIZED; |
| 77 | 77 | return Ok(res); |
| 78 | 78 | }; |
| 79 | - let state = app_context::<AppState>(cx); | |
| 79 | + let state = context::<AppState>(cx); | |
| 80 | 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 | 88 | #[route(POST "/{owner}/{repo}/pulls/{number}/reviewers")] |
| 89 | 89 | async fn reviewers_save(cx: &Cx, Form(form): Form<ReviewerForm>) -> Result<SeeOther> { |
| 90 | - let number = parse_number(path_param::<Number>(cx))?; | |
| 91 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 90 | + let number = parse_number(number(cx))?; | |
| 91 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 92 | 92 | let (user, session) = require_user(cx).await?; |
| 93 | 93 | check_write(&ctx, &session, &form.csrf)?; |
| 94 | - let state = app_context::<AppState>(cx); | |
| 94 | + let state = context::<AppState>(cx); | |
| 95 | 95 | let Some(pr) = state.store.pull_by_number(&ctx.repo.id, number).await? else { |
| 96 | 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 | 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 | 209 | let ReviewersView { |
| 206 | 210 | action, |
| 207 | 211 | csrf, |
| @@ -251,7 +255,7 @@ pub(crate) async fn reviewers_box(lang: Lang, reviewers: ReviewersView) -> Resul | ||
| 251 | 255 | #[page("/review-requests")] |
| 252 | 256 | async fn review_requests(cx: &Cx) -> Result<impl View> { |
| 253 | 257 | let viewer = require_user(cx).await?; |
| 254 | - let state = app_context::<AppState>(cx); | |
| 258 | + let state = context::<AppState>(cx); | |
| 255 | 259 | let user = &viewer.0; |
| 256 | 260 | let lang = i18n::lang(cx, Some(user)); |
| 257 | 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 | 11 | use forge_core::{Error as CoreError, Session, Store, User}; |
| 12 | 12 | use serde::{Deserialize, Deserializer}; |
| 13 | 13 | use topcoat::Result; |
| 14 | -use topcoat::context::{Cx, app_context}; | |
| 14 | +use topcoat::context::{Cx, context}; | |
| 15 | 15 | use topcoat::router::content::Form; |
| 16 | 16 | use topcoat::router::error::{SeeOther, see_other}; |
| 17 | 17 | use topcoat::router::{page, route}; |
| @@ -289,7 +289,7 @@ fn colour_group(lang: Lang, dark: bool, base: &str, accent_id: &str) -> ColourGr | ||
| 289 | 289 | /// vividness slider and a hex box. The Custom radio carries `hue-H-vV`, and nav.js keeps it, the |
| 290 | 290 | /// sliders and the hex box in step while the row is used. |
| 291 | 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 | 293 | let ColourRow { |
| 294 | 294 | dark, |
| 295 | 295 | base, |
| @@ -358,7 +358,7 @@ async fn colour_row(row: ColourRow) -> Result<impl View> { | ||
| 358 | 358 | |
| 359 | 359 | /// One theme's panel: a Background row and an Accent row. |
| 360 | 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 | 362 | let ColourGroup { |
| 363 | 363 | dark, |
| 364 | 364 | background, |
| @@ -408,7 +408,7 @@ async fn colour_panel(group: ColourGroup) -> Result<impl View> { | ||
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 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 | 412 | let AppearancePage { |
| 413 | 413 | lang, |
| 414 | 414 | csrf, |
| @@ -591,7 +591,7 @@ fn pref_choice( | ||
| 591 | 591 | async fn appearance_page(cx: &Cx) -> Result<impl View> { |
| 592 | 592 | let viewer = require_user(cx).await?; |
| 593 | 593 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 594 | - let prefs = app_context::<AppState>(cx) | |
| 594 | + let prefs = context::<AppState>(cx) | |
| 595 | 595 | .store |
| 596 | 596 | .user_prefs(&viewer.0.id) |
| 597 | 597 | .await?; |
| @@ -609,7 +609,7 @@ async fn appearance_page(cx: &Cx) -> Result<impl View> { | ||
| 609 | 609 | async fn appearance_save(cx: &Cx, Form(form): Form<AppearanceForm>) -> Result<SeeOther> { |
| 610 | 610 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 611 | 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 | 613 | let user = &viewer.0; |
| 614 | 614 | |
| 615 | 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 | 16 | use serde::Deserialize; |
| 17 | 17 | use tokio_util::io::ReaderStream; |
| 18 | 18 | use topcoat::Result; |
| 19 | -use topcoat::context::{Cx, app_context}; | |
| 19 | +use topcoat::context::{Cx, context}; | |
| 20 | 20 | use topcoat::router::content::Form; |
| 21 | 21 | use topcoat::router::error::{SeeOther, not_found, see_other}; |
| 22 | 22 | use topcoat::router::response::Response; |
| @@ -79,7 +79,12 @@ fn data_rail_items(lang: Lang, delete: bool) -> Vec<RailItem> { | ||
| 79 | 79 | |
| 80 | 80 | /// The archives sheet: the request's state, and each archive with its download and delete. |
| 81 | 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 | 88 | let building = exports.iter().any(|e| e.state == ExportState::Building); |
| 84 | 89 | let live = building.then(|| { |
| 85 | 90 | format!( |
| @@ -139,6 +144,7 @@ async fn export_sheet(lang: Lang, csrf: &str, exports: Vec<DataExport>) -> Resul | ||
| 139 | 144 | /// username, in one reveal. Repositories still owned by the user block it, and are listed. |
| 140 | 145 | #[component] |
| 141 | 146 | async fn delete_sheet( |
| 147 | + cx: &Cx, | |
| 142 | 148 | lang: Lang, |
| 143 | 149 | csrf: &str, |
| 144 | 150 | two_factor_on: bool, |
| @@ -196,6 +202,7 @@ async fn delete_sheet( | ||
| 196 | 202 | /// The Data page body: the head of the topic, then the rail beside its sheet. |
| 197 | 203 | #[component] |
| 198 | 204 | async fn data_body( |
| 205 | + cx: &Cx, | |
| 199 | 206 | lang: Lang, |
| 200 | 207 | csrf: &str, |
| 201 | 208 | delete: bool, |
| @@ -239,7 +246,7 @@ async fn page_view( | ||
| 239 | 246 | delete_error: Option<String>, |
| 240 | 247 | throttled: Option<Duration>, |
| 241 | 248 | ) -> Result<impl View> { |
| 242 | - let state = app_context::<AppState>(cx); | |
| 249 | + let state = context::<AppState>(cx); | |
| 243 | 250 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 244 | 251 | let user_id = viewer.0.id.clone(); |
| 245 | 252 | let exports = state.store.list_exports(&user_id).await?; |
| @@ -260,9 +267,9 @@ async fn page_view( | ||
| 260 | 267 | None => StatusCode::OK, |
| 261 | 268 | }; |
| 262 | 269 | let csrf = viewer.1.csrf_token.clone(); |
| 263 | - // `view!` expects the `__cx` binding that `#[page]` and `#[component]` provide. This plain | |
| 270 | + // `view!` expects the `cx` binding that `#[page]` and `#[component]` provide. This plain | |
| 264 | 271 | // helper has to bind it itself. |
| 265 | - let __cx = cx; | |
| 272 | + let cx = cx; | |
| 266 | 273 | Ok(view! { |
| 267 | 274 | (status) |
| 268 | 275 | (headers) |
| @@ -286,16 +293,23 @@ pub(crate) async fn respond_delete( | ||
| 286 | 293 | #[page("/settings/export")] |
| 287 | 294 | async fn export_page(cx: &Cx) -> Result<impl View> { |
| 288 | 295 | let viewer = require_user(cx).await?; |
| 289 | - let state = app_context::<AppState>(cx); | |
| 296 | + let state = context::<AppState>(cx); | |
| 290 | 297 | exporter::sweep_expired(state).await; |
| 291 | 298 | let query = query_params::<TopicQuery>(cx)?; |
| 292 | - page_view(cx, viewer, query.part.as_deref() == Some("delete"), None, None).await | |
| 299 | + page_view( | |
| 300 | + cx, | |
| 301 | + viewer, | |
| 302 | + query.part.as_deref() == Some("delete"), | |
| 303 | + None, | |
| 304 | + None, | |
| 305 | + ) | |
| 306 | + .await | |
| 293 | 307 | } |
| 294 | 308 | |
| 295 | 309 | #[route(POST "/settings/export")] |
| 296 | 310 | async fn export_request(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { |
| 297 | 311 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 298 | - let state = app_context::<AppState>(cx); | |
| 312 | + let state = context::<AppState>(cx); | |
| 299 | 313 | exporter::start(state, &viewer.0).await?; |
| 300 | 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 | 318 | #[route(POST "/settings/export/{export_id}/delete")] |
| 305 | 319 | async fn export_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { |
| 306 | 320 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 307 | - let id = path_param::<ExportId>(cx).to_owned(); | |
| 308 | - let state = app_context::<AppState>(cx); | |
| 321 | + let id = export_id(cx).to_owned(); | |
| 322 | + let state = context::<AppState>(cx); | |
| 309 | 323 | let export = match state.store.data_export(&id).await? { |
| 310 | 324 | Some(e) if e.user_id == viewer.0.id && e.state != ExportState::Building => e, |
| 311 | 325 | _ => return Err(not_found().into()), |
| @@ -320,7 +334,7 @@ async fn export_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> | ||
| 320 | 334 | async fn export_events(cx: &Cx) -> Result<Response> { |
| 321 | 335 | let viewer = require_user(cx).await?; |
| 322 | 336 | let query = query_params::<SeenQuery>(cx)?; |
| 323 | - let state = app_context::<AppState>(cx); | |
| 337 | + let state = context::<AppState>(cx); | |
| 324 | 338 | let user_id = viewer.0.id.clone(); |
| 325 | 339 | let wake = exporter::subscribe(&user_id); |
| 326 | 340 | let store = state.store.clone(); |
| @@ -354,8 +368,8 @@ async fn export_events(cx: &Cx) -> Result<Response> { | ||
| 354 | 368 | #[route(GET "/settings/export/{export_id}/download")] |
| 355 | 369 | async fn export_download(cx: &Cx) -> Result<Response> { |
| 356 | 370 | let viewer = require_user(cx).await?; |
| 357 | - let id = path_param::<ExportId>(cx).to_owned(); | |
| 358 | - let state = app_context::<AppState>(cx); | |
| 371 | + let id = export_id(cx).to_owned(); | |
| 372 | + let state = context::<AppState>(cx); | |
| 359 | 373 | exporter::sweep_expired(state).await; |
| 360 | 374 | let export = match state.store.data_export(&id).await? { |
| 361 | 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 | 5 | use forge_core::store::signatures::GpgKey; |
| 6 | 6 | use serde::Deserialize; |
| 7 | 7 | use topcoat::Result; |
| 8 | -use topcoat::context::{Cx, app_context}; | |
| 8 | +use topcoat::context::{Cx, context}; | |
| 9 | 9 | use topcoat::router::content::Form; |
| 10 | 10 | use topcoat::router::error::{SeeOther, not_found, see_other}; |
| 11 | 11 | use topcoat::router::{page, query_params, route}; |
| @@ -39,6 +39,7 @@ struct DeleteKeyForm { | ||
| 39 | 39 | |
| 40 | 40 | #[component] |
| 41 | 41 | pub(crate) async fn gpg_section( |
| 42 | + cx: &Cx, | |
| 42 | 43 | lang: Lang, |
| 43 | 44 | csrf: &str, |
| 44 | 45 | keys: Vec<GpgKey>, |
| @@ -87,7 +88,7 @@ pub(crate) async fn gpg_section( | ||
| 87 | 88 | async fn gpg_page(cx: &Cx) -> Result<impl View> { |
| 88 | 89 | let viewer = require_user(cx).await?; |
| 89 | 90 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 90 | - let state = app_context::<AppState>(cx); | |
| 91 | + let state = context::<AppState>(cx); | |
| 91 | 92 | let draft = KeysDraft { |
| 92 | 93 | add: query_params::<AddQuery>(cx)?.add.is_some(), |
| 93 | 94 | ..KeysDraft::default() |
| @@ -101,7 +102,7 @@ async fn gpg_page(cx: &Cx) -> Result<impl View> { | ||
| 101 | 102 | async fn gpg_add(cx: &Cx, Form(form): Form<AddKeyForm>) -> Result<impl View> { |
| 102 | 103 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 103 | 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 | 107 | let message: String = match signatures::import_gpg_key(state, &form.armored).await { |
| 107 | 108 | Err(message) => message, |
| @@ -149,7 +150,7 @@ async fn gpg_add(cx: &Cx, Form(form): Form<AddKeyForm>) -> Result<impl View> { | ||
| 149 | 150 | #[route(POST "/settings/gpg/delete")] |
| 150 | 151 | async fn gpg_delete(cx: &Cx, Form(form): Form<DeleteKeyForm>) -> Result<SeeOther> { |
| 151 | 152 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 152 | - let state = app_context::<AppState>(cx); | |
| 153 | + let state = context::<AppState>(cx); | |
| 153 | 154 | // `delete_gpg_key` only matches the viewer's own keys, so anything else is a 404. |
| 154 | 155 | let Some(key) = state.store.delete_gpg_key(&user.id, &form.id).await? else { |
| 155 | 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 | 6 | use serde::Deserialize; |
| 7 | 7 | use sha2::{Digest, Sha256}; |
| 8 | 8 | use topcoat::Result; |
| 9 | -use topcoat::context::{Cx, app_context}; | |
| 9 | +use topcoat::context::{Cx, context}; | |
| 10 | 10 | use topcoat::router::content::Form; |
| 11 | 11 | use topcoat::router::error::{SeeOther, see_other}; |
| 12 | 12 | use topcoat::router::{page, query_params, route}; |
| @@ -195,6 +195,7 @@ pub(crate) struct AddQuery { | ||
| 195 | 195 | /// The keys page for the viewer, one kind at a time, with what a form sent back. |
| 196 | 196 | #[component] |
| 197 | 197 | pub(crate) async fn keys_page_view( |
| 198 | + cx: &Cx, | |
| 198 | 199 | lang: Lang, |
| 199 | 200 | state: &AppState, |
| 200 | 201 | viewer: &(User, Session), |
| @@ -255,6 +256,7 @@ fn pk_title(lang: Lang) -> &'static str { | ||
| 255 | 256 | |
| 256 | 257 | #[component] |
| 257 | 258 | async fn ssh_section( |
| 259 | + cx: &Cx, | |
| 258 | 260 | lang: Lang, |
| 259 | 261 | csrf: &str, |
| 260 | 262 | keys: Vec<SshKey>, |
| @@ -303,7 +305,7 @@ async fn ssh_section( | ||
| 303 | 305 | async fn keys_page(cx: &Cx) -> Result<impl View> { |
| 304 | 306 | let viewer = require_user(cx).await?; |
| 305 | 307 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 306 | - let state = app_context::<AppState>(cx); | |
| 308 | + let state = context::<AppState>(cx); | |
| 307 | 309 | let draft = KeysDraft { |
| 308 | 310 | add: query_params::<AddQuery>(cx)?.add.is_some(), |
| 309 | 311 | ..KeysDraft::default() |
| @@ -317,7 +319,7 @@ async fn keys_page(cx: &Cx) -> Result<impl View> { | ||
| 317 | 319 | async fn keys_add(cx: &Cx, Form(form): Form<AddKeyForm>) -> Result<impl View> { |
| 318 | 320 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 319 | 321 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 320 | - let state = app_context::<AppState>(cx); | |
| 322 | + let state = context::<AppState>(cx); | |
| 321 | 323 | let store = &state.store; |
| 322 | 324 | |
| 323 | 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 | 377 | #[route(POST "/settings/keys/delete")] |
| 376 | 378 | async fn keys_delete(cx: &Cx, Form(form): Form<DeleteKeyForm>) -> Result<SeeOther> { |
| 377 | 379 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 378 | - let state = app_context::<AppState>(cx); | |
| 380 | + let state = context::<AppState>(cx); | |
| 379 | 381 | if state.store.delete_ssh_key(&user.id, &form.id).await? { |
| 380 | 382 | audit::record( |
| 381 | 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 | 27 | use futures_util::stream::{self, BoxStream, StreamExt}; |
| 28 | 28 | use tokio::sync::watch; |
| 29 | 29 | use topcoat::Result; |
| 30 | -use topcoat::context::{Cx, app_context, try_app_context}; | |
| 30 | +use topcoat::context::{Cx, context, try_context}; | |
| 31 | 31 | use topcoat::router::content::sse::Event; |
| 32 | 32 | use topcoat::router::request::{method, uri}; |
| 33 | 33 | use topcoat::router::response::Response; |
| @@ -52,7 +52,7 @@ async fn settings_events(cx: &Cx) -> Result<Response> { | ||
| 52 | 52 | *res.status_mut() = StatusCode::UNAUTHORIZED; |
| 53 | 53 | return Ok(res); |
| 54 | 54 | }; |
| 55 | - let hub: &LiveHub = &app_context::<AppState>(cx).live; | |
| 55 | + let hub: &LiveHub = &context::<AppState>(cx).live; | |
| 56 | 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 | 166 | /// means the server is back. |
| 167 | 167 | pub async fn alive_response(cx: &Cx) -> Result<Response> { |
| 168 | 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 | 170 | return events_response(cx, stream::pending::<Result<Event>>()); |
| 171 | 171 | }; |
| 172 | 172 | let viewer = current_user(cx) |
| @@ -305,7 +305,7 @@ async fn bump_after_settings_write(cx: &Cx, body: Body, next: Next<'_>) -> Resul | ||
| 305 | 305 | .map(|(user, _)| user.id); |
| 306 | 306 | let result = next.run(cx, body).await; |
| 307 | 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 | 310 | 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 | 8 | use forge_core::{Session, Store, User}; |
| 9 | 9 | use serde::Deserialize; |
| 10 | 10 | use topcoat::Result; |
| 11 | -use topcoat::context::{Cx, app_context}; | |
| 11 | +use topcoat::context::{Cx, context}; | |
| 12 | 12 | use topcoat::router::content::Form; |
| 13 | 13 | use topcoat::router::error::{SeeOther, see_other}; |
| 14 | 14 | use topcoat::router::{page, query_params, route}; |
| @@ -56,7 +56,7 @@ struct NotificationsPage { | ||
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 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 | 60 | let NotificationsPage { |
| 61 | 61 | lang, |
| 62 | 62 | csrf, |
| @@ -166,7 +166,7 @@ async fn page_for( | ||
| 166 | 166 | #[page("/settings/notifications")] |
| 167 | 167 | async fn notifications_page(cx: &Cx) -> Result<impl View> { |
| 168 | 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 | 170 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 171 | 171 | let query = query_params::<NotificationsQuery>(cx)?; |
| 172 | 172 | let notice = if query.saved.as_deref() == Some("1") { |
| @@ -191,7 +191,7 @@ async fn notifications_page(cx: &Cx) -> Result<impl View> { | ||
| 191 | 191 | #[route(POST "/settings/notifications")] |
| 192 | 192 | async fn notifications_save(cx: &Cx, Form(form): Form<NotificationsForm>) -> Result<SeeOther> { |
| 193 | 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 | 195 | store |
| 196 | 196 | .set_email_notifications(&viewer.0.id, form.email_notifications.is_some()) |
| 197 | 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 | 12 | use serde::Deserialize; |
| 13 | 13 | use tokio::sync::Semaphore; |
| 14 | 14 | use topcoat::Result; |
| 15 | -use topcoat::context::{Cx, app_context}; | |
| 15 | +use topcoat::context::{Cx, context}; | |
| 16 | 16 | use topcoat::router::content::Form; |
| 17 | 17 | use topcoat::router::content::multipart::Multipart; |
| 18 | 18 | use topcoat::router::error::{SeeOther, see_other}; |
| @@ -33,16 +33,8 @@ pub const MAX_ABOUT_CHARS: usize = 2000; | ||
| 33 | 33 | /// Multipart framing overhead allowed on top of the image itself. |
| 34 | 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. | |
| 37 | -pub fn avatar_body_limit() -> BodyLimit { | |
| 38 | - BodyLimit::max(MAX_UPLOAD_BYTES + MULTIPART_OVERHEAD).at("/settings/profile/avatar") | |
| 39 | -} | |
| 40 | - | |
| 41 | -/// Body limit for the org avatar upload route. A `{org}` segment in a layer path matches any | |
| 42 | -/// org name, as it does in the route path itself. | |
| 43 | -pub fn org_avatar_body_limit() -> BodyLimit { | |
| 44 | - BodyLimit::max(MAX_UPLOAD_BYTES + MULTIPART_OVERHEAD).at("/org/{org}/settings/avatar") | |
| 45 | -} | |
| 36 | +/// Body limit for the avatar upload routes. The default 2 MiB is too small for a 5 MiB image. | |
| 37 | +pub const AVATAR_BODY_LIMIT: usize = MAX_UPLOAD_BYTES + MULTIPART_OVERHEAD; | |
| 46 | 38 | |
| 47 | 39 | #[query_params(error = bad_request)] |
| 48 | 40 | struct ProfileQuery { |
| @@ -127,7 +119,7 @@ struct ProfilePage { | ||
| 127 | 119 | } |
| 128 | 120 | |
| 129 | 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 | 123 | let ProfilePage { |
| 132 | 124 | lang, |
| 133 | 125 | csrf, |
| @@ -352,7 +344,7 @@ async fn profile_page(cx: &Cx) -> Result<impl View> { | ||
| 352 | 344 | async fn profile_save(cx: &Cx, Form(form): Form<ProfileForm>) -> Result<impl View> { |
| 353 | 345 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 354 | 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 | 348 | let about = form.about.replace("\r\n", "\n"); |
| 357 | 349 | |
| 358 | 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 | 406 | // The public profile shows the name, the username and the about text: its viewers follow the |
| 415 | 407 | // user's topic too. |
| 416 | - app_context::<AppState>(cx) | |
| 408 | + context::<AppState>(cx) | |
| 417 | 409 | .live |
| 418 | 410 | .bump(&Topic::User(viewer.0.id.clone())); |
| 419 | 411 | Err(see_other("/settings/profile?saved=1").into()) |
| 420 | 412 | } |
| 421 | 413 | |
| 422 | 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 | 416 | async fn avatar_upload(cx: &Cx, mut multipart: Multipart) -> Result<impl View> { |
| 425 | 417 | let mut csrf = String::new(); |
| 426 | 418 | let mut image = None; |
| @@ -434,11 +426,11 @@ async fn avatar_upload(cx: &Cx, mut multipart: Multipart) -> Result<impl View> { | ||
| 434 | 426 | } |
| 435 | 427 | let viewer = require_csrf(cx, &csrf).await?; |
| 436 | 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 | 431 | let message = match store_avatar(store, &viewer.0.id, image, lang).await { |
| 440 | 432 | Ok(()) => { |
| 441 | - app_context::<AppState>(cx) | |
| 433 | + context::<AppState>(cx) | |
| 442 | 434 | .live |
| 443 | 435 | .bump(&Topic::User(viewer.0.id.clone())); |
| 444 | 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 | 453 | #[route(POST "/settings/profile/avatar/delete")] |
| 462 | 454 | async fn avatar_remove(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { |
| 463 | 455 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 464 | - let state = app_context::<AppState>(cx); | |
| 456 | + let state = context::<AppState>(cx); | |
| 465 | 457 | state.store.delete_avatar(&viewer.0.id).await?; |
| 466 | 458 | state.live.bump(&Topic::User(viewer.0.id.clone())); |
| 467 | 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 | 11 | use http::header::{HeaderValue, RETRY_AFTER}; |
| 12 | 12 | use serde::Deserialize; |
| 13 | 13 | use topcoat::Result; |
| 14 | -use topcoat::context::{Cx, app_context}; | |
| 14 | +use topcoat::context::{Cx, context}; | |
| 15 | 15 | use topcoat::router::content::Form; |
| 16 | 16 | use topcoat::router::error::{SeeOther, see_other}; |
| 17 | 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 | 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 | 278 | let SecurityPage { |
| 279 | 279 | lang, |
| 280 | 280 | email, |
| @@ -656,10 +656,10 @@ async fn build_page( | ||
| 656 | 656 | |
| 657 | 657 | /// Renders the page. A throttled check answers 429 with `Retry-After`. |
| 658 | 658 | async fn respond(cx: &Cx, viewer: (User, Session), shown: Shown) -> Result<impl View> { |
| 659 | - let state = app_context::<AppState>(cx); | |
| 660 | - // `view!` expects the `__cx` binding that `#[page]` and `#[component]` provide. This plain | |
| 659 | + let state = context::<AppState>(cx); | |
| 660 | + // `view!` expects the `cx` binding that `#[page]` and `#[component]` provide. This plain | |
| 661 | 661 | // helper has to bind it itself. |
| 662 | - let __cx = cx; | |
| 662 | + let cx = cx; | |
| 663 | 663 | let mut headers = HeaderMap::new(); |
| 664 | 664 | let status = match shown.throttled { |
| 665 | 665 | Some(retry) => { |
| @@ -779,7 +779,7 @@ async fn security_page(cx: &Cx) -> Result<impl View> { | ||
| 779 | 779 | async fn password_change(cx: &Cx, Form(form): Form<PasswordForm>) -> Result<impl View> { |
| 780 | 780 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 781 | 781 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 782 | - let state = app_context::<AppState>(cx); | |
| 782 | + let state = context::<AppState>(cx); | |
| 783 | 783 | let mut shown = Shown::default(); |
| 784 | 784 | if let Err(refused) = require_password(lang, state, &viewer.0, &form.current_password).await? { |
| 785 | 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 | 822 | async fn email_change(cx: &Cx, Form(form): Form<EmailForm>) -> Result<impl View> { |
| 823 | 823 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 824 | 824 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 825 | - let state = app_context::<AppState>(cx); | |
| 825 | + let state = context::<AppState>(cx); | |
| 826 | 826 | let email = form.email.trim().to_owned(); |
| 827 | 827 | let mut shown = Shown { |
| 828 | 828 | email_draft: Some(email.clone()), |
| @@ -865,7 +865,7 @@ async fn email_change(cx: &Cx, Form(form): Form<EmailForm>) -> Result<impl View> | ||
| 865 | 865 | #[route(POST "/settings/security/2fa/enable")] |
| 866 | 866 | async fn two_factor_enable(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { |
| 867 | 867 | let (user, _session) = require_csrf(cx, &form.csrf).await?; |
| 868 | - let state = app_context::<AppState>(cx); | |
| 868 | + let state = context::<AppState>(cx); | |
| 869 | 869 | if !two_factor_enabled(&state.store, &user.id).await? { |
| 870 | 870 | // A new enrollment replaces any unconfirmed secret. |
| 871 | 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 | 878 | async fn two_factor_confirm(cx: &Cx, Form(form): Form<EnrollForm>) -> Result<impl View> { |
| 879 | 879 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 880 | 880 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 881 | - let state = app_context::<AppState>(cx); | |
| 881 | + let state = context::<AppState>(cx); | |
| 882 | 882 | let user_id = viewer.0.id.clone(); |
| 883 | 883 | let Some(totp_state) = state.store.totp_state(&user_id).await? else { |
| 884 | 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 | 938 | async fn two_factor_disable(cx: &Cx, Form(form): Form<DisableForm>) -> Result<impl View> { |
| 939 | 939 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 940 | 940 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 941 | - let state = app_context::<AppState>(cx); | |
| 941 | + let state = context::<AppState>(cx); | |
| 942 | 942 | let user_id = viewer.0.id.clone(); |
| 943 | 943 | if !two_factor_enabled(&state.store, &user_id).await? { |
| 944 | 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 | 981 | async fn account_delete(cx: &Cx, Form(form): Form<DeleteAccountForm>) -> Result<impl View> { |
| 982 | 982 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 983 | 983 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 984 | - let state = app_context::<AppState>(cx); | |
| 984 | + let state = context::<AppState>(cx); | |
| 985 | 985 | let user_id = viewer.0.id.clone(); |
| 986 | 986 | if form.confirm_username != viewer.0.username { |
| 987 | 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 | 1036 | async fn two_factor_recovery(cx: &Cx, Form(form): Form<CodeForm>) -> Result<impl View> { |
| 1037 | 1037 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 1038 | 1038 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 1039 | - let state = app_context::<AppState>(cx); | |
| 1039 | + let state = context::<AppState>(cx); | |
| 1040 | 1040 | let user_id = viewer.0.id.clone(); |
| 1041 | 1041 | if !two_factor_enabled(&state.store, &user_id).await? { |
| 1042 | 1042 | return Err(see_other("/settings/security").into()); |
| @@ -1089,7 +1089,7 @@ mod tests { | ||
| 1089 | 1089 | use forge_core::token::hash_token; |
| 1090 | 1090 | use forge_core::{Config, Registration, Store, User, secret, totp}; |
| 1091 | 1091 | use forge_git::GitEnv; |
| 1092 | - use topcoat::cookie::RouterBuilderCookieExt; | |
| 1092 | + use topcoat::cookie::CookieLayer; | |
| 1093 | 1093 | use topcoat::router::request::Request; |
| 1094 | 1094 | use topcoat::router::{Body, Router, RouterBuilderDiscoverExt, to_bytes}; |
| 1095 | 1095 | |
| @@ -1184,8 +1184,8 @@ mod tests { | ||
| 1184 | 1184 | .unwrap(); |
| 1185 | 1185 | let router = Router::builder() |
| 1186 | 1186 | .discover() |
| 1187 | - .cookies() | |
| 1188 | - .app_context(state.clone()) | |
| 1187 | + .layer(CookieLayer::new()) | |
| 1188 | + .with(state.clone()) | |
| 1189 | 1189 | .build(); |
| 1190 | 1190 | Fixture { |
| 1191 | 1191 | router, |
crates/forge-web/src/pages/settings_sessions.rsmodified+4 -4
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | use forge_core::{AuditAction, Session}; |
| 6 | 6 | use serde::Deserialize; |
| 7 | 7 | use topcoat::Result; |
| 8 | -use topcoat::context::{Cx, app_context}; | |
| 8 | +use topcoat::context::{Cx, context}; | |
| 9 | 9 | use topcoat::router::content::Form; |
| 10 | 10 | use topcoat::router::error::{SeeOther, see_other}; |
| 11 | 11 | use topcoat::router::route; |
| @@ -55,7 +55,7 @@ async fn sessions_revoke(cx: &Cx, Form(form): Form<RevokeForm>) -> Result<SeeOth | ||
| 55 | 55 | let (user, current) = require_csrf(cx, &form.csrf).await?; |
| 56 | 56 | if form.id == current.id { |
| 57 | 57 | audit::record( |
| 58 | - &app_context::<AppState>(cx).store, | |
| 58 | + &context::<AppState>(cx).store, | |
| 59 | 59 | Some(cx), |
| 60 | 60 | Actor::User(&user), |
| 61 | 61 | AuditAction::SessionRevoked, |
| @@ -70,7 +70,7 @@ async fn sessions_revoke(cx: &Cx, Form(form): Form<RevokeForm>) -> Result<SeeOth | ||
| 70 | 70 | logout(cx, ¤t).await?; |
| 71 | 71 | return Ok(see_other("/")); |
| 72 | 72 | } |
| 73 | - let store = &app_context::<AppState>(cx).store; | |
| 73 | + let store = &context::<AppState>(cx).store; | |
| 74 | 74 | // Only revoke sessions that belong to the signed-in user. |
| 75 | 75 | let owned = store.list_sessions(&user.id).await?; |
| 76 | 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 | 95 | #[route(POST "/settings/sessions/revoke-others")] |
| 96 | 96 | async fn sessions_revoke_others(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther> { |
| 97 | 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 | 99 | let mut revoked = 0_u64; |
| 100 | 100 | for session in store.list_sessions(&user.id).await? { |
| 101 | 101 | if session.id != current.id { |
crates/forge-web/src/pages/settings_tokens.rsmodified+5 -4
| @@ -9,7 +9,7 @@ use http::HeaderValue; | ||
| 9 | 9 | use http::header::CACHE_CONTROL; |
| 10 | 10 | use serde::Deserialize; |
| 11 | 11 | use topcoat::Result; |
| 12 | -use topcoat::context::{Cx, app_context}; | |
| 12 | +use topcoat::context::{Cx, context}; | |
| 13 | 13 | use topcoat::router::content::Form; |
| 14 | 14 | use topcoat::router::error::{SeeOther, see_other}; |
| 15 | 15 | use topcoat::router::response::response_headers; |
| @@ -66,6 +66,7 @@ fn expiry_days(choice: &str) -> Option<u64> { | ||
| 66 | 66 | |
| 67 | 67 | #[component] |
| 68 | 68 | pub(crate) async fn tokens_section( |
| 69 | + cx: &Cx, | |
| 69 | 70 | lang: Lang, |
| 70 | 71 | csrf: &str, |
| 71 | 72 | tokens: Vec<AccessToken>, |
| @@ -133,7 +134,7 @@ pub(crate) async fn tokens_section( | ||
| 133 | 134 | async fn tokens_page(cx: &Cx) -> Result<impl View> { |
| 134 | 135 | let viewer = require_user(cx).await?; |
| 135 | 136 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 136 | - let state = app_context::<AppState>(cx); | |
| 137 | + let state = context::<AppState>(cx); | |
| 137 | 138 | let draft = KeysDraft { |
| 138 | 139 | add: query_params::<AddQuery>(cx)?.add.is_some(), |
| 139 | 140 | ..KeysDraft::default() |
| @@ -147,7 +148,7 @@ async fn tokens_page(cx: &Cx) -> Result<impl View> { | ||
| 147 | 148 | async fn tokens_create(cx: &Cx, Form(form): Form<CreateTokenForm>) -> Result<impl View> { |
| 148 | 149 | let viewer = require_csrf(cx, &form.csrf).await?; |
| 149 | 150 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 150 | - let state = app_context::<AppState>(cx); | |
| 151 | + let state = context::<AppState>(cx); | |
| 151 | 152 | let store = &state.store; |
| 152 | 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 | 212 | #[route(POST "/settings/tokens/delete")] |
| 212 | 213 | async fn tokens_delete(cx: &Cx, Form(form): Form<DeleteTokenForm>) -> Result<SeeOther> { |
| 213 | 214 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 214 | - let state = app_context::<AppState>(cx); | |
| 215 | + let state = context::<AppState>(cx); | |
| 215 | 216 | if state.store.delete_token(&user.id, &form.id).await? { |
| 216 | 217 | audit::record( |
| 217 | 218 | &state.store, |
crates/forge-web/src/pages/setup.rsmodified+4 -3
| @@ -4,7 +4,7 @@ use forge_core::AuditAction; | ||
| 4 | 4 | use forge_core::names::validate_username; |
| 5 | 5 | use serde::Deserialize; |
| 6 | 6 | use topcoat::Result; |
| 7 | -use topcoat::context::{Cx, app_context}; | |
| 7 | +use topcoat::context::{Cx, context}; | |
| 8 | 8 | use topcoat::router::content::Form; |
| 9 | 9 | use topcoat::router::error::{forbidden, not_found, see_other}; |
| 10 | 10 | use topcoat::router::page; |
| @@ -36,6 +36,7 @@ struct SetupForm { | ||
| 36 | 36 | |
| 37 | 37 | #[component] |
| 38 | 38 | async fn setup_form( |
| 39 | + cx: &Cx, | |
| 39 | 40 | lang: Lang, |
| 40 | 41 | username: &str, |
| 41 | 42 | email: &str, |
| @@ -75,7 +76,7 @@ async fn setup_form( | ||
| 75 | 76 | |
| 76 | 77 | #[page("/setup")] |
| 77 | 78 | async fn setup_page(cx: &Cx) -> Result<impl View> { |
| 78 | - let state = app_context::<AppState>(cx); | |
| 79 | + let state = context::<AppState>(cx); | |
| 79 | 80 | if state.store.user_count().await? != 0 { |
| 80 | 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 | 93 | if !check_pre_csrf(cx, &form.precsrf) { |
| 93 | 94 | return Err(forbidden().into()); |
| 94 | 95 | } |
| 95 | - let state = app_context::<AppState>(cx); | |
| 96 | + let state = context::<AppState>(cx); | |
| 96 | 97 | if state.store.user_count().await? != 0 { |
| 97 | 98 | return Err(not_found().into()); |
| 98 | 99 | } |
crates/forge-web/src/pages/shell_events.rsmodified+2 -2
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | use futures_util::StreamExt; |
| 13 | 13 | use futures_util::stream::{self, BoxStream}; |
| 14 | 14 | use topcoat::Result; |
| 15 | -use topcoat::context::{Cx, try_app_context}; | |
| 15 | +use topcoat::context::{Cx, try_context}; | |
| 16 | 16 | use topcoat::router::content::sse::Event; |
| 17 | 17 | use topcoat::router::response::Response; |
| 18 | 18 | use topcoat::router::route; |
| @@ -29,7 +29,7 @@ use crate::state::AppState; | ||
| 29 | 29 | #[route(GET "/-/shell/events")] |
| 30 | 30 | async fn shell_events(cx: &Cx) -> Result<Response> { |
| 31 | 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 | 33 | return events_response(cx, stream::pending::<Result<Event>>()); |
| 34 | 34 | }; |
| 35 | 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 | 7 | use forge_core::store::snippets::{Snippet, SnippetVisibility}; |
| 8 | 8 | use serde::Deserialize; |
| 9 | 9 | use sha2::{Digest, Sha256}; |
| 10 | -use topcoat::context::{Cx, app_context}; | |
| 10 | +use topcoat::context::{Cx, context}; | |
| 11 | 11 | use topcoat::router::request::{headers, method}; |
| 12 | 12 | use topcoat::router::response::Response; |
| 13 | 13 | use topcoat::router::{ |
| @@ -66,7 +66,7 @@ fn content_type(file_name: &str) -> &'static str { | ||
| 66 | 66 | |
| 67 | 67 | /// Serves one file. Every failure is turned into a response here, so the route never errors. |
| 68 | 68 | async fn serve(cx: &Cx) -> Response { |
| 69 | - let state = app_context::<AppState>(cx).clone(); | |
| 69 | + let state = context::<AppState>(cx).clone(); | |
| 70 | 70 | let id = path_param_segment(cx, "id").to_owned(); |
| 71 | 71 | let segments: Vec<&str> = path_param_segments(cx, "rest").collect(); |
| 72 | 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 | 13 | use forge_core::{AuditAction, Session, User}; |
| 14 | 14 | use topcoat::Result; |
| 15 | -use topcoat::context::{Cx, app_context}; | |
| 15 | +use topcoat::context::{Cx, context}; | |
| 16 | 16 | use topcoat::router::content::Form; |
| 17 | 17 | use topcoat::router::error::{SeeOther, not_found, see_other}; |
| 18 | 18 | use topcoat::router::{page, path_param, route}; |
| @@ -257,7 +257,7 @@ pub(crate) async fn readable( | ||
| 257 | 257 | viewer_id: Option<&str>, |
| 258 | 258 | snippet_id: &str, |
| 259 | 259 | ) -> Result<Snippet> { |
| 260 | - let store = &app_context::<AppState>(cx).store; | |
| 260 | + let store = &context::<AppState>(cx).store; | |
| 261 | 261 | match store.get_snippet(snippet_id).await? { |
| 262 | 262 | Some(snippet) if snippet.is_visible_to(viewer_id) => Ok(snippet), |
| 263 | 263 | _ => Err(not_found().into()), |
| @@ -266,7 +266,7 @@ pub(crate) async fn readable( | ||
| 266 | 266 | |
| 267 | 267 | /// The snippet if the user owns it, else 404. Edits and deletes go through this check. |
| 268 | 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 | 270 | match store.get_snippet(snippet_id).await? { |
| 271 | 271 | Some(snippet) if snippet.owner_id == user.id => Ok(snippet), |
| 272 | 272 | _ => Err(not_found().into()), |
| @@ -275,7 +275,7 @@ async fn owned(cx: &Cx, user: &User, snippet_id: &str) -> Result<Snippet> { | ||
| 275 | 275 | |
| 276 | 276 | /// The snippet rows, one linked line each: title, owner, visibility, file count and update time. |
| 277 | 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 | 279 | Ok(view! { |
| 280 | 280 | <div class="snippet-list"> |
| 281 | 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 | 291 | #[component] |
| 292 | 292 | async fn snippet_list_body( |
| 293 | + cx: &Cx, | |
| 293 | 294 | lang: Lang, |
| 294 | 295 | rows: Vec<ListRow>, |
| 295 | 296 | signed_in: bool, |
| @@ -317,6 +318,7 @@ async fn snippet_list_body( | ||
| 317 | 318 | /// The panel's remove button is shown only when there is more than one file. |
| 318 | 319 | #[component] |
| 319 | 320 | async fn snippet_files( |
| 321 | + cx: &Cx, | |
| 320 | 322 | lang: Lang, |
| 321 | 323 | slots: Vec<Slot>, |
| 322 | 324 | active: usize, |
| @@ -389,6 +391,7 @@ async fn snippet_files( | ||
| 389 | 391 | /// and the remove buttons submit the same form with `formnovalidate` and never save. |
| 390 | 392 | #[component] |
| 391 | 393 | async fn snippet_form( |
| 394 | + cx: &Cx, | |
| 392 | 395 | lang: Lang, |
| 393 | 396 | csrf: &str, |
| 394 | 397 | action: &str, |
| @@ -452,6 +455,7 @@ async fn snippet_form( | ||
| 452 | 455 | |
| 453 | 456 | #[component] |
| 454 | 457 | async fn snippet_body( |
| 458 | + cx: &Cx, | |
| 455 | 459 | lang: Lang, |
| 456 | 460 | snippet_id: &str, |
| 457 | 461 | title: &str, |
| @@ -508,6 +512,7 @@ async fn snippet_body( | ||
| 508 | 512 | |
| 509 | 513 | #[component] |
| 510 | 514 | async fn revisions_body( |
| 515 | + cx: &Cx, | |
| 511 | 516 | lang: Lang, |
| 512 | 517 | snippet_id: &str, |
| 513 | 518 | title: &str, |
| @@ -541,6 +546,7 @@ async fn revisions_body( | ||
| 541 | 546 | |
| 542 | 547 | #[component] |
| 543 | 548 | async fn snippet_form_page( |
| 549 | + cx: &Cx, | |
| 544 | 550 | lang: Lang, |
| 545 | 551 | viewer: &(User, Session), |
| 546 | 552 | heading: &str, |
| @@ -573,7 +579,7 @@ async fn snippets_list(cx: &Cx) -> Result<impl View> { | ||
| 573 | 579 | let viewer = current_user(cx).await?; |
| 574 | 580 | let lang = i18n::lang(cx, viewer.as_ref().map(|(user, _)| user)); |
| 575 | 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 | 583 | .store |
| 578 | 584 | .list_snippets(viewer_id.as_deref()) |
| 579 | 585 | .await?; |
| @@ -605,7 +611,7 @@ async fn snippet_create(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> R | ||
| 605 | 611 | let mut error = None; |
| 606 | 612 | let step = apply_slot_step(&mut draft, &form); |
| 607 | 613 | if step.is_none() { |
| 608 | - let store = &app_context::<AppState>(cx).store; | |
| 614 | + let store = &context::<AppState>(cx).store; | |
| 609 | 615 | let files = draft.saved_files(); |
| 610 | 616 | let saved = match SnippetVisibility::parse(&draft.visibility) { |
| 611 | 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 | 647 | serde_json::Value::Null, |
| 642 | 648 | ) |
| 643 | 649 | .await; |
| 644 | - bump_snippet(app_context::<AppState>(cx), &snippet.id); | |
| 650 | + bump_snippet(context::<AppState>(cx), &snippet.id); | |
| 645 | 651 | return Err(see_other(format!("/snippets/{}", snippet.id)).into()); |
| 646 | 652 | } |
| 647 | 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 | 664 | #[page("/snippets/{id}")] |
| 659 | 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 | 667 | let viewer = current_user(cx).await?; |
| 662 | 668 | let lang = i18n::lang(cx, viewer.as_ref().map(|(user, _)| user)); |
| 663 | 669 | let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone()); |
| 664 | 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 | 672 | let files: Vec<FileView> = snippet |
| 667 | 673 | .files |
| 668 | 674 | .iter() |
| @@ -685,7 +691,7 @@ async fn snippet_view(cx: &Cx) -> Result<impl View> { | ||
| 685 | 691 | |
| 686 | 692 | #[page("/snippets/{id}/edit")] |
| 687 | 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 | 695 | let viewer = require_user(cx).await?; |
| 690 | 696 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 691 | 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 | 706 | #[page(POST "/snippets/{id}/edit")] |
| 701 | 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 | 709 | let (user, _) = require_csrf(cx, form.get("csrf").map_or("", String::as_str)).await?; |
| 704 | 710 | let lang = i18n::lang(cx, Some(&user)); |
| 705 | 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 | 713 | let mut error = None; |
| 708 | 714 | let step = apply_slot_step(&mut draft, &form); |
| 709 | 715 | if step.is_none() { |
| 710 | - let store = &app_context::<AppState>(cx).store; | |
| 716 | + let store = &context::<AppState>(cx).store; | |
| 711 | 717 | let files = draft.saved_files(); |
| 712 | 718 | let saved = match SnippetVisibility::parse(&draft.visibility) { |
| 713 | 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 | 750 | serde_json::Value::Null, |
| 745 | 751 | ) |
| 746 | 752 | .await; |
| 747 | - bump_snippet(app_context::<AppState>(cx), &snippet.id); | |
| 753 | + bump_snippet(context::<AppState>(cx), &snippet.id); | |
| 748 | 754 | return Err(see_other(format!("/snippets/{}", snippet.id)).into()); |
| 749 | 755 | } |
| 750 | 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 | 768 | #[page("/snippets/{id}/revisions")] |
| 763 | 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 | 771 | let viewer = current_user(cx).await?; |
| 766 | 772 | let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone()); |
| 767 | 773 | let snippet = readable(cx, viewer_id.as_deref(), &snippet_id).await?; |
| 768 | 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 | 776 | let revisions: Vec<SnippetRevision> = store.list_snippet_revisions(&snippet.id).await?; |
| 771 | 777 | // Stored oldest first; the page shows the newest first with its number. |
| 772 | 778 | let rows: Vec<RevisionView> = revisions |
| @@ -796,10 +802,10 @@ async fn snippet_revisions(cx: &Cx) -> Result<impl View> { | ||
| 796 | 802 | |
| 797 | 803 | #[route(POST "/snippets/{id}/delete")] |
| 798 | 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 | 806 | let (user, _) = require_csrf(cx, form.get("csrf").map_or("", String::as_str)).await?; |
| 801 | 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 | 809 | if store.delete_snippet(&user.id, &snippet.id).await? { |
| 804 | 810 | audit::record( |
| 805 | 811 | store, |
| @@ -814,7 +820,7 @@ async fn snippet_delete(cx: &Cx, Form(form): Form<HashMap<String, String>>) -> R | ||
| 814 | 820 | serde_json::Value::Null, |
| 815 | 821 | ) |
| 816 | 822 | .await; |
| 817 | - bump_snippet(app_context::<AppState>(cx), &snippet.id); | |
| 823 | + bump_snippet(context::<AppState>(cx), &snippet.id); | |
| 818 | 824 | } |
| 819 | 825 | Ok(see_other("/snippets")) |
| 820 | 826 | } |
crates/forge-web/src/pages/snippets_live.rsmodified+4 -4
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | use forge_core::store::Store; |
| 13 | 13 | use forge_core::store::snippets::{Snippet, SnippetSummary}; |
| 14 | 14 | use topcoat::Result; |
| 15 | -use topcoat::context::{Cx, app_context}; | |
| 15 | +use topcoat::context::{Cx, context}; | |
| 16 | 16 | use topcoat::router::response::Response; |
| 17 | 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 | 87 | async fn snippets_events(cx: &Cx) -> Result<Response> { |
| 88 | 88 | let viewer = current_user(cx).await?; |
| 89 | 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 | 91 | let store = state.store.clone(); |
| 92 | 92 | stream_changes(cx, &state.live, &[Topic::Snippets], move || { |
| 93 | 93 | let store = store.clone(); |
| @@ -101,11 +101,11 @@ async fn snippets_events(cx: &Cx) -> Result<Response> { | ||
| 101 | 101 | /// must be readable by the viewer. |
| 102 | 102 | #[route(GET "/snippets/{id}/events")] |
| 103 | 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 | 105 | let viewer = current_user(cx).await?; |
| 106 | 106 | let viewer_id = viewer.as_ref().map(|(user, _)| user.id.clone()); |
| 107 | 107 | readable(cx, viewer_id.as_deref(), &snippet_id).await?; |
| 108 | - let state = app_context::<AppState>(cx); | |
| 108 | + let state = context::<AppState>(cx); | |
| 109 | 109 | let store = state.store.clone(); |
| 110 | 110 | stream_changes( |
| 111 | 111 | cx, |
crates/forge-web/src/pages/star.rsmodified+4 -4
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | use http::header::{HOST, REFERER}; |
| 7 | 7 | use serde::Deserialize; |
| 8 | 8 | use topcoat::Result; |
| 9 | -use topcoat::context::{Cx, app_context}; | |
| 9 | +use topcoat::context::{Cx, context}; | |
| 10 | 10 | use topcoat::router::content::Form; |
| 11 | 11 | use topcoat::router::error::{SeeOther, see_other}; |
| 12 | 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 | 39 | async fn set_starred(cx: &Cx, csrf: &str, starred: bool) -> Result<SeeOther> { |
| 40 | - let owner = path_param::<Owner>(cx); | |
| 41 | - let name = path_param::<Repo>(cx); | |
| 40 | + let owner = owner(cx); | |
| 41 | + let name = repo(cx); | |
| 42 | 42 | let ctx = load_repo(cx, owner, name).await?; |
| 43 | 43 | let (user, _) = require_csrf(cx, csrf).await?; |
| 44 | - let state = app_context::<AppState>(cx); | |
| 44 | + let state = context::<AppState>(cx); | |
| 45 | 45 | if starred { |
| 46 | 46 | state.store.star(&user.id, &ctx.repo.id).await?; |
| 47 | 47 | } else { |
crates/forge-web/src/pages/theme_cookie.rsmodified+2 -2
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | |
| 6 | 6 | use serde::Deserialize; |
| 7 | 7 | use topcoat::Result; |
| 8 | -use topcoat::context::{Cx, app_context}; | |
| 8 | +use topcoat::context::{Cx, context}; | |
| 9 | 9 | use topcoat::router::content::Form; |
| 10 | 10 | use topcoat::router::error::{SeeOther, see_other}; |
| 11 | 11 | use topcoat::router::route; |
| @@ -54,7 +54,7 @@ async fn set_theme(cx: &Cx, Form(form): Form<ThemeForm>) -> Result<SeeOther> { | ||
| 54 | 54 | if !THEMES.contains(&form.theme.as_str()) { |
| 55 | 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 | 58 | store |
| 59 | 59 | .set_ui_prefs(&viewer.0.id, &form.theme, &viewer.0.language) |
| 60 | 60 | .await?; |
crates/forge-web/src/pages/tree.rsmodified+16 -10
| @@ -10,7 +10,7 @@ use forge_core::tz::format_in_tz; | ||
| 10 | 10 | use forge_git::browse::{self, BlobData, CommitInfo, EntryKind, RefInfo, TreeEntry}; |
| 11 | 11 | use forge_git::history; |
| 12 | 12 | use topcoat::Result; |
| 13 | -use topcoat::context::{Cx, app_context}; | |
| 13 | +use topcoat::context::{Cx, context}; | |
| 14 | 14 | use topcoat::router::error::not_found; |
| 15 | 15 | use topcoat::router::{page, path_param}; |
| 16 | 16 | use topcoat::view::{Unescaped, View, component, view}; |
| @@ -24,9 +24,7 @@ use crate::pages::passkeys::s; | ||
| 24 | 24 | use crate::pages::refs::{load_refs, ref_links}; |
| 25 | 25 | use crate::pages::repo::repo_head; |
| 26 | 26 | use crate::pages::repo_ctx::load_repo; |
| 27 | -use crate::pages::repo_side::{ | |
| 28 | - code_sub, commit_strip, run_pips, run_rows, tree_facts, | |
| 29 | -}; | |
| 27 | +use crate::pages::repo_side::{code_sub, commit_strip, run_pips, run_rows, tree_facts}; | |
| 30 | 28 | use crate::raw::raw_url; |
| 31 | 29 | use crate::render::emoji::emojify; |
| 32 | 30 | use crate::render::markdown::{LinkContext, render_markdown}; |
| @@ -351,6 +349,7 @@ pub async fn load_readme( | ||
| 351 | 349 | /// Submodules have no page, so their row shows the short sha. A long folder scrolls here alone. |
| 352 | 350 | #[component] |
| 353 | 351 | pub async fn tree_table( |
| 352 | + cx: &Cx, | |
| 354 | 353 | rows: Vec<EntryRow>, |
| 355 | 354 | lang: Lang, |
| 356 | 355 | #[default] current: Option<String>, |
| @@ -381,6 +380,7 @@ pub async fn tree_table( | ||
| 381 | 380 | /// The sheet beside a folder: its README, with Source, History and Raw as tools, or `none`. |
| 382 | 381 | #[component] |
| 383 | 382 | pub async fn readme_sheet( |
| 383 | + cx: &Cx, | |
| 384 | 384 | lang: Lang, |
| 385 | 385 | owner: String, |
| 386 | 386 | repo: String, |
| @@ -404,7 +404,13 @@ pub async fn readme_sheet( | ||
| 404 | 404 | ) |
| 405 | 405 | }); |
| 406 | 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 | 414 | Ok(view! { |
| 409 | 415 | <div class="sheet"> |
| 410 | 416 | <div class="sheet-tools"> |
| @@ -427,7 +433,7 @@ pub async fn readme_sheet( | ||
| 427 | 433 | /// README body. Markdown HTML is embedded only from `render_markdown`; plain text is escaped. The |
| 428 | 434 | /// file name is for screen readers: the pane head shows it. |
| 429 | 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 | 437 | Ok(view! { |
| 432 | 438 | <section class="readme"> |
| 433 | 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 | 449 | #[page("/{owner}/{repo}/tree/{*rest}")] |
| 444 | 450 | async fn tree_page(cx: &Cx) -> Result<impl View> { |
| 445 | - let owner = path_param::<Owner>(cx); | |
| 446 | - let name = path_param::<Repo>(cx); | |
| 447 | - let rest = path_param::<Rest>(cx).collect::<Vec<_>>().join("/"); | |
| 451 | + let owner = owner(cx); | |
| 452 | + let name = repo(cx); | |
| 453 | + let rest = rest(cx).collect::<Vec<_>>().join("/"); | |
| 448 | 454 | let ctx = load_repo(cx, owner, name).await?; |
| 449 | - let state = app_context::<AppState>(cx); | |
| 455 | + let state = context::<AppState>(cx); | |
| 450 | 456 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user)); |
| 451 | 457 | let repo = &ctx.repo; |
| 452 | 458 |
crates/forge-web/src/pages/user_prefs.rsmodified+2 -2
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | use http::StatusCode; |
| 6 | 6 | use serde::Deserialize; |
| 7 | 7 | use topcoat::Result; |
| 8 | -use topcoat::context::{Cx, app_context}; | |
| 8 | +use topcoat::context::{Cx, context}; | |
| 9 | 9 | use topcoat::router::content::Form; |
| 10 | 10 | use topcoat::router::error::bad_request; |
| 11 | 11 | use topcoat::router::response::Response; |
| @@ -43,7 +43,7 @@ pub fn clean_pref(key: &str, value: &str) -> std::result::Result<Option<String>, | ||
| 43 | 43 | #[route(POST "/-/prefs")] |
| 44 | 44 | async fn set_pref(cx: &Cx, Form(form): Form<PrefForm>) -> Result<Response> { |
| 45 | 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 | 47 | match clean_pref(&form.key, &form.value) { |
| 48 | 48 | Err(message) => return Err(bad_request(message).into()), |
| 49 | 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 | 13 | use forge_git::wiki::{self, MAX_PAGE_BYTES, PageEdit, PageRevision, valid_page_name}; |
| 14 | 14 | use serde::Deserialize; |
| 15 | 15 | use topcoat::Result; |
| 16 | -use topcoat::context::{Cx, app_context}; | |
| 16 | +use topcoat::context::{Cx, context}; | |
| 17 | 17 | use topcoat::router::content::Form; |
| 18 | 18 | use topcoat::router::error::{SeeOther, forbidden, not_found, see_other}; |
| 19 | 19 | use topcoat::router::{page, path_param, route}; |
| @@ -179,6 +179,7 @@ fn wiki_links( | ||
| 179 | 179 | /// The page list beside a wiki page: every page, the one on screen marked. |
| 180 | 180 | #[component] |
| 181 | 181 | async fn wiki_rail( |
| 182 | + cx: &Cx, | |
| 182 | 183 | lang: Lang, |
| 183 | 184 | owner: String, |
| 184 | 185 | repo: String, |
| @@ -203,6 +204,7 @@ async fn wiki_rail( | ||
| 203 | 204 | /// the screen follows. |
| 204 | 205 | #[component] |
| 205 | 206 | async fn wiki_sheet( |
| 207 | + cx: &Cx, | |
| 206 | 208 | #[default] title: Option<String>, |
| 207 | 209 | links: Vec<(String, String)>, |
| 208 | 210 | #[default] live: Option<String>, |
| @@ -251,7 +253,7 @@ fn page_links( | ||
| 251 | 253 | } |
| 252 | 254 | |
| 253 | 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 | 257 | Ok(view! { |
| 256 | 258 | <section class="sec wiki-page"> |
| 257 | 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 | 264 | #[component] |
| 263 | 265 | async fn wiki_empty_body( |
| 266 | + cx: &Cx, | |
| 264 | 267 | lang: Lang, |
| 265 | 268 | owner: String, |
| 266 | 269 | repo: String, |
| @@ -278,6 +281,7 @@ async fn wiki_empty_body( | ||
| 278 | 281 | |
| 279 | 282 | #[component] |
| 280 | 283 | async fn wiki_list_body( |
| 284 | + cx: &Cx, | |
| 281 | 285 | lang: Lang, |
| 282 | 286 | owner: String, |
| 283 | 287 | repo: String, |
| @@ -304,7 +308,7 @@ async fn wiki_list_body( | ||
| 304 | 308 | } |
| 305 | 309 | |
| 306 | 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 | 312 | Ok(view! { |
| 309 | 313 | if rows.is_empty() { |
| 310 | 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 | 326 | #[component] |
| 323 | 327 | async fn wiki_edit_body( |
| 328 | + cx: &Cx, | |
| 324 | 329 | lang: Lang, |
| 325 | 330 | action: String, |
| 326 | 331 | csrf: String, |
| @@ -370,10 +375,10 @@ async fn load_page(dir: PathBuf, name: String) -> Result<(Option<String>, Option | ||
| 370 | 375 | |
| 371 | 376 | #[page("/{owner}/{repo}/wiki")] |
| 372 | 377 | async fn wiki_home(cx: &Cx) -> Result<impl View> { |
| 373 | - let owner = path_param::<Owner>(cx); | |
| 374 | - let name = path_param::<Repo>(cx); | |
| 378 | + let owner = owner(cx); | |
| 379 | + let name = repo(cx); | |
| 375 | 380 | let ctx = load_repo(cx, owner, name).await?; |
| 376 | - let state = app_context::<AppState>(cx); | |
| 381 | + let state = context::<AppState>(cx); | |
| 377 | 382 | ensure_enabled(state, &ctx).await?; |
| 378 | 383 | let dir = wiki_dir(state, &ctx)?; |
| 379 | 384 | let names = page_names(dir.clone()).await?; |
| @@ -401,7 +406,7 @@ async fn wiki_home(cx: &Cx) -> Result<impl View> { | ||
| 401 | 406 | }; |
| 402 | 407 | let links = wiki_links(lang, &owner_name, &repo_name, can_write, extra); |
| 403 | 408 | let header = ctx.head(state, "wiki").await?; |
| 404 | - Ok(view! { cx => | |
| 409 | + Ok(view! { | |
| 405 | 410 | shell(title: title.as_str(), viewer: ctx.viewer.as_ref(), |
| 406 | 411 | repo_head(head: header, title: head_title) |
| 407 | 412 | <div class="work"> |
| @@ -421,10 +426,10 @@ async fn wiki_home(cx: &Cx) -> Result<impl View> { | ||
| 421 | 426 | |
| 422 | 427 | #[page("/{owner}/{repo}/wiki/-/pages")] |
| 423 | 428 | async fn wiki_pages(cx: &Cx) -> Result<impl View> { |
| 424 | - let owner = path_param::<Owner>(cx); | |
| 425 | - let name = path_param::<Repo>(cx); | |
| 429 | + let owner = owner(cx); | |
| 430 | + let name = repo(cx); | |
| 426 | 431 | let ctx = load_repo(cx, owner, name).await?; |
| 427 | - let state = app_context::<AppState>(cx); | |
| 432 | + let state = context::<AppState>(cx); | |
| 428 | 433 | ensure_enabled(state, &ctx).await?; |
| 429 | 434 | let lang = i18n::lang(cx, ctx.viewer.as_ref().map(|(user, _)| user)); |
| 430 | 435 | let dir = wiki_dir(state, &ctx)?; |
| @@ -440,7 +445,7 @@ async fn wiki_pages(cx: &Cx) -> Result<impl View> { | ||
| 440 | 445 | ); |
| 441 | 446 | let links = wiki_links(lang, &owner_name, &repo_name, can_write, Vec::new()); |
| 442 | 447 | let header = ctx.head(state, "wiki").await?; |
| 443 | - Ok(view! { cx => | |
| 448 | + Ok(view! { | |
| 444 | 449 | shell(title: title.as_str(), viewer: ctx.viewer.as_ref(), |
| 445 | 450 | repo_head(head: header, title: Some(g::t(lang, K::AllPages).to_owned())) |
| 446 | 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 | 458 | #[page("/{owner}/{repo}/wiki/{wiki_page}")] |
| 454 | 459 | async fn wiki_page_view(cx: &Cx) -> Result<impl View> { |
| 455 | - let owner = path_param::<Owner>(cx); | |
| 456 | - let repo_param = path_param::<Repo>(cx); | |
| 457 | - let page_name = path_param::<WikiPage>(cx).to_owned(); | |
| 460 | + let owner = owner(cx); | |
| 461 | + let repo_param = repo(cx); | |
| 462 | + let page_name = wiki_page(cx).to_owned(); | |
| 458 | 463 | let ctx = load_repo(cx, owner, repo_param).await?; |
| 459 | - let state = app_context::<AppState>(cx); | |
| 464 | + let state = context::<AppState>(cx); | |
| 460 | 465 | ensure_enabled(state, &ctx).await?; |
| 461 | 466 | if !valid_page_name(&page_name) { |
| 462 | 467 | return Err(not_found().into()); |
| @@ -486,7 +491,7 @@ async fn wiki_page_view(cx: &Cx) -> Result<impl View> { | ||
| 486 | 491 | page_links(lang, &owner_name, &repo_name, &page_name, can_write), |
| 487 | 492 | ); |
| 488 | 493 | let header = ctx.head(state, "wiki").await?; |
| 489 | - Ok(view! { cx => | |
| 494 | + Ok(view! { | |
| 490 | 495 | shell(title: title.as_str(), viewer: ctx.viewer.as_ref(), |
| 491 | 496 | repo_head(head: header, title: Some(page_name.replace('-', " "))) |
| 492 | 497 | <div class="work"> |
| @@ -501,11 +506,11 @@ async fn wiki_page_view(cx: &Cx) -> Result<impl View> { | ||
| 501 | 506 | |
| 502 | 507 | #[page("/{owner}/{repo}/wiki/{wiki_page}/history")] |
| 503 | 508 | async fn wiki_page_history(cx: &Cx) -> Result<impl View> { |
| 504 | - let owner = path_param::<Owner>(cx); | |
| 505 | - let repo_param = path_param::<Repo>(cx); | |
| 506 | - let page_name = path_param::<WikiPage>(cx).to_owned(); | |
| 509 | + let owner = owner(cx); | |
| 510 | + let repo_param = repo(cx); | |
| 511 | + let page_name = wiki_page(cx).to_owned(); | |
| 507 | 512 | let ctx = load_repo(cx, owner, repo_param).await?; |
| 508 | - let state = app_context::<AppState>(cx); | |
| 513 | + let state = context::<AppState>(cx); | |
| 509 | 514 | ensure_enabled(state, &ctx).await?; |
| 510 | 515 | if !valid_page_name(&page_name) { |
| 511 | 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 | 543 | let header = ctx.head(state, "wiki").await?; |
| 539 | - Ok(view! { cx => | |
| 544 | + Ok(view! { | |
| 540 | 545 | shell(title: title.as_str(), viewer: ctx.viewer.as_ref(), |
| 541 | 546 | repo_head(head: header, title: Some(format!("{} \u{b7} {}", page_name.replace('-', " "), g::t(lang, K::History)))) |
| 542 | 547 | <div class="work"> |
| @@ -558,7 +563,7 @@ async fn edit_screen( | ||
| 558 | 563 | content: String, |
| 559 | 564 | error: Option<String>, |
| 560 | 565 | ) -> Result<impl View> { |
| 561 | - let state = app_context::<AppState>(cx); | |
| 566 | + let state = context::<AppState>(cx); | |
| 562 | 567 | let (user, session) = require_user(cx).await?; |
| 563 | 568 | let lang = i18n::lang(cx, Some(&user)); |
| 564 | 569 | let dir = wiki_dir(state, &ctx)?; |
| @@ -599,7 +604,7 @@ async fn edit_screen( | ||
| 599 | 604 | )] |
| 600 | 605 | }; |
| 601 | 606 | let links = wiki_links(lang, &owner_name, &repo_name, !is_new, back_links); |
| 602 | - Ok(view! { cx => | |
| 607 | + Ok(view! { | |
| 603 | 608 | shell(title: title.as_str(), viewer: ctx.viewer.as_ref(), |
| 604 | 609 | repo_head(head: header, title: Some(head_title)) |
| 605 | 610 | <div class="work"> |
| @@ -614,10 +619,10 @@ async fn edit_screen( | ||
| 614 | 619 | |
| 615 | 620 | #[page("/{owner}/{repo}/wiki/-/new")] |
| 616 | 621 | async fn wiki_new_page(cx: &Cx) -> Result<impl View> { |
| 617 | - let owner = path_param::<Owner>(cx); | |
| 618 | - let repo_param = path_param::<Repo>(cx); | |
| 622 | + let owner = owner(cx); | |
| 623 | + let repo_param = repo(cx); | |
| 619 | 624 | let ctx = load_repo(cx, owner, repo_param).await?; |
| 620 | - let state = app_context::<AppState>(cx); | |
| 625 | + let state = context::<AppState>(cx); | |
| 621 | 626 | ensure_enabled(state, &ctx).await?; |
| 622 | 627 | if !ctx.can_write() { |
| 623 | 628 | return Err(forbidden().into()); |
| @@ -627,11 +632,11 @@ async fn wiki_new_page(cx: &Cx) -> Result<impl View> { | ||
| 627 | 632 | |
| 628 | 633 | #[page("/{owner}/{repo}/wiki/{wiki_page}/edit")] |
| 629 | 634 | async fn wiki_edit_page(cx: &Cx) -> Result<impl View> { |
| 630 | - let owner = path_param::<Owner>(cx); | |
| 631 | - let repo_param = path_param::<Repo>(cx); | |
| 632 | - let page_name = path_param::<WikiPage>(cx).to_owned(); | |
| 635 | + let owner = owner(cx); | |
| 636 | + let repo_param = repo(cx); | |
| 637 | + let page_name = wiki_page(cx).to_owned(); | |
| 633 | 638 | let ctx = load_repo(cx, owner, repo_param).await?; |
| 634 | - let state = app_context::<AppState>(cx); | |
| 639 | + let state = context::<AppState>(cx); | |
| 635 | 640 | ensure_enabled(state, &ctx).await?; |
| 636 | 641 | if !ctx.can_write() { |
| 637 | 642 | return Err(forbidden().into()); |
| @@ -646,10 +651,10 @@ async fn wiki_edit_page(cx: &Cx) -> Result<impl View> { | ||
| 646 | 651 | |
| 647 | 652 | #[page(POST "/{owner}/{repo}/wiki/-/new")] |
| 648 | 653 | async fn wiki_new_post(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View> { |
| 649 | - let owner = path_param::<Owner>(cx); | |
| 650 | - let repo_param = path_param::<Repo>(cx); | |
| 654 | + let owner = owner(cx); | |
| 655 | + let repo_param = repo(cx); | |
| 651 | 656 | let ctx = load_repo(cx, owner, repo_param).await?; |
| 652 | - let state = app_context::<AppState>(cx); | |
| 657 | + let state = context::<AppState>(cx); | |
| 653 | 658 | ensure_enabled(state, &ctx).await?; |
| 654 | 659 | if !ctx.can_write() { |
| 655 | 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 | 686 | #[page(POST "/{owner}/{repo}/wiki/{wiki_page}/edit")] |
| 682 | 687 | async fn wiki_edit_post(cx: &Cx, Form(form): Form<EditForm>) -> Result<impl View> { |
| 683 | - let owner = path_param::<Owner>(cx); | |
| 684 | - let repo_param = path_param::<Repo>(cx); | |
| 685 | - let page_name = path_param::<WikiPage>(cx).to_owned(); | |
| 688 | + let owner = owner(cx); | |
| 689 | + let repo_param = repo(cx); | |
| 690 | + let page_name = wiki_page(cx).to_owned(); | |
| 686 | 691 | let ctx = load_repo(cx, owner, repo_param).await?; |
| 687 | - let state = app_context::<AppState>(cx); | |
| 692 | + let state = context::<AppState>(cx); | |
| 688 | 693 | ensure_enabled(state, &ctx).await?; |
| 689 | 694 | if !ctx.can_write() { |
| 690 | 695 | return Err(forbidden().into()); |
| @@ -709,7 +714,7 @@ enum SaveOutcome { | ||
| 709 | 714 | /// Writes the page as a commit guarded by the form's `base`. A conflicting or invalid save is |
| 710 | 715 | /// refused with a message, and the caller shows the edit screen again with the typed text. |
| 711 | 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 | 718 | let (user, _) = require_user(cx).await?; |
| 714 | 719 | let lang = i18n::lang(cx, Some(&user)); |
| 715 | 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 | 770 | /// change (`data-autosubmit`), then its hint. `enabled` is the current state. |
| 766 | 771 | #[component] |
| 767 | 772 | pub(crate) async fn wiki_switch( |
| 773 | + cx: &Cx, | |
| 768 | 774 | action: String, |
| 769 | 775 | csrf: String, |
| 770 | 776 | enabled: bool, |
| @@ -783,8 +789,8 @@ pub(crate) async fn wiki_switch( | ||
| 783 | 789 | /// The wiki switch moved to the General settings page; the old address goes there. |
| 784 | 790 | #[route(GET "/{owner}/{repo}/settings/wiki")] |
| 785 | 791 | async fn wiki_settings_page(cx: &Cx) -> Result<SeeOther> { |
| 786 | - let owner = path_param::<Owner>(cx); | |
| 787 | - let repo_param = path_param::<Repo>(cx); | |
| 792 | + let owner = owner(cx); | |
| 793 | + let repo_param = repo(cx); | |
| 788 | 794 | Ok(see_other(repo_href(owner, repo_param, "settings", ""))) |
| 789 | 795 | } |
| 790 | 796 | |
| @@ -798,14 +804,14 @@ struct WikiSettingsForm { | ||
| 798 | 804 | |
| 799 | 805 | #[route(POST "/{owner}/{repo}/settings/wiki")] |
| 800 | 806 | async fn wiki_settings_post(cx: &Cx, Form(form): Form<WikiSettingsForm>) -> Result<SeeOther> { |
| 801 | - let owner = path_param::<Owner>(cx); | |
| 802 | - let repo_param = path_param::<Repo>(cx); | |
| 807 | + let owner = owner(cx); | |
| 808 | + let repo_param = repo(cx); | |
| 803 | 809 | let ctx = load_repo(cx, owner, repo_param).await?; |
| 804 | 810 | let (user, _) = require_csrf(cx, &form.csrf).await?; |
| 805 | 811 | if !ctx.can_admin() { |
| 806 | 812 | return Err(forbidden().into()); |
| 807 | 813 | } |
| 808 | - let state = app_context::<AppState>(cx); | |
| 814 | + let state = context::<AppState>(cx); | |
| 809 | 815 | let enable = form.enabled.is_some(); |
| 810 | 816 | let before = state.store.wiki_enabled(&ctx.repo.id).await?; |
| 811 | 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 | 15 | use forge_git::GitEnv; |
| 16 | 16 | use forge_git::wiki::{self, valid_page_name}; |
| 17 | 17 | use topcoat::Result; |
| 18 | -use topcoat::context::{Cx, app_context}; | |
| 18 | +use topcoat::context::{Cx, context}; | |
| 19 | 19 | use topcoat::router::error::not_found; |
| 20 | 20 | use topcoat::router::response::Response; |
| 21 | 21 | use topcoat::router::{path_param, route}; |
| @@ -66,8 +66,8 @@ async fn page_fingerprint(git: &GitEnv, dir: &Path, name: &str) -> Result<String | ||
| 66 | 66 | /// wiki's on switch. |
| 67 | 67 | #[route(GET "/{owner}/{repo}/wiki/-/events")] |
| 68 | 68 | async fn wiki_events(cx: &Cx) -> Result<Response> { |
| 69 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 70 | - let state = app_context::<AppState>(cx); | |
| 69 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 70 | + let state = context::<AppState>(cx); | |
| 71 | 71 | ensure_enabled(state, &ctx).await?; |
| 72 | 72 | let dir = wiki_dir(state, &ctx)?; |
| 73 | 73 | let topic = Topic::Wiki(ctx.repo.id.clone()); |
| @@ -80,9 +80,9 @@ async fn wiki_events(cx: &Cx) -> Result<Response> { | ||
| 80 | 80 | /// The change stream of one wiki page, its page view and its history. |
| 81 | 81 | #[route(GET "/{owner}/{repo}/wiki/{wiki_page}/events")] |
| 82 | 82 | async fn wiki_page_events(cx: &Cx) -> Result<Response> { |
| 83 | - let page_name = path_param::<WikiPage>(cx).to_owned(); | |
| 84 | - let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | |
| 85 | - let state = app_context::<AppState>(cx); | |
| 83 | + let page_name = wiki_page(cx).to_owned(); | |
| 84 | + let ctx = load_repo(cx, owner(cx), repo(cx)).await?; | |
| 85 | + let state = context::<AppState>(cx); | |
| 86 | 86 | ensure_enabled(state, &ctx).await?; |
| 87 | 87 | if !valid_page_name(&page_name) { |
| 88 | 88 | return Err(not_found().into()); |
crates/forge-web/src/raw.rsmodified+4 -4
| @@ -17,7 +17,7 @@ use serde::Deserialize; | ||
| 17 | 17 | use tokio::io::AsyncReadExt; |
| 18 | 18 | use tokio::process::Child; |
| 19 | 19 | use tokio_util::io::ReaderStream; |
| 20 | -use topcoat::context::{Cx, app_context}; | |
| 20 | +use topcoat::context::{Cx, context}; | |
| 21 | 21 | use topcoat::router::request::{headers, method}; |
| 22 | 22 | use topcoat::router::response::Response; |
| 23 | 23 | use topcoat::router::{ |
| @@ -113,8 +113,8 @@ pub fn router(state: AppState) -> Router { | ||
| 113 | 113 | )) |
| 114 | 114 | .route(RouteFn::new(Method::GET, "/healthz", healthz)) |
| 115 | 115 | // Responses must match the bytes behind the ETag and Content-Length. |
| 116 | - .compression(Compression::off()) | |
| 117 | - .app_context(state) | |
| 116 | + .with(Compression::disable()) | |
| 117 | + .with(state) | |
| 118 | 118 | .build() |
| 119 | 119 | } |
| 120 | 120 | |
| @@ -137,7 +137,7 @@ fn raw_file(cx: &Cx, _body: topcoat::router::Body) -> RouteFuture<'_> { | ||
| 137 | 137 | |
| 138 | 138 | /// Serves one file. Every failure is turned into a response here, so the route never errors. |
| 139 | 139 | async fn serve(cx: &Cx) -> Response { |
| 140 | - let state = app_context::<AppState>(cx).clone(); | |
| 140 | + let state = context::<AppState>(cx).clone(); | |
| 141 | 141 | let owner = path_param_segment(cx, "owner").to_owned(); |
| 142 | 142 | let name = path_param_segment(cx, "repo").to_owned(); |
| 143 | 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 | 13 | use forge_core::{Config, Registration, Store}; |
| 14 | 14 | use forge_git::GitEnv; |
| 15 | 15 | use tokio::sync::Notify; |
| 16 | -use topcoat::cookie::RouterBuilderCookieExt; | |
| 16 | +use topcoat::cookie::CookieLayer; | |
| 17 | 17 | use topcoat::router::tower::TowerLayer; |
| 18 | 18 | use topcoat::router::{Compression, Router, RouterBuilderDiscoverExt}; |
| 19 | 19 | |
| 20 | 20 | use crate::pages::repo_ctx::RepoMovedLayer; |
| 21 | -use crate::pages::settings_profile::{avatar_body_limit, org_avatar_body_limit}; | |
| 22 | 21 | use crate::state::AppState; |
| 23 | 22 | use crate::throttle::Throttle; |
| 24 | 23 | |
| @@ -105,18 +104,16 @@ pub async fn test_state(dir: &Path) -> AppState { | ||
| 105 | 104 | pub fn app_router(state: AppState) -> Router { |
| 106 | 105 | Router::builder() |
| 107 | 106 | .discover() |
| 108 | - .app_context(state) | |
| 107 | + .with(state) | |
| 109 | 108 | .layer(crate::pages::settings_live::AccountWriteLayer) |
| 110 | - .cookies() | |
| 111 | - .layer(avatar_body_limit()) | |
| 112 | - .layer(org_avatar_body_limit()) | |
| 109 | + .layer(CookieLayer::new()) | |
| 113 | 110 | .layer(RepoMovedLayer) |
| 114 | 111 | .layer(crate::pages::repo_settings_live::RepoSettingsWriteLayer) |
| 115 | 112 | .layer(crate::pages::pull_live::PullWriteLayer) |
| 116 | 113 | .layer(crate::pages::discussion_live::DiscussionWriteLayer) |
| 117 | 114 | .layer(crate::pages::org_live::OrgWriteLayer) |
| 118 | 115 | .layer(TowerLayer::new(crate::compression::ResponseCompression)) |
| 119 | - .compression(Compression::off()) | |
| 116 | + .with(Compression::disable()) | |
| 120 | 117 | .build() |
| 121 | 118 | } |
| 122 | 119 |
crates/forge-web/src/views/commit_line.rsmodified+2 -1
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | //! subject as written, like GitHub. The full subject is the `title` attribute. |
| 4 | 4 | |
| 5 | 5 | use topcoat::Result; |
| 6 | +use topcoat::context::Cx; | |
| 6 | 7 | use topcoat::view::{View, component, view}; |
| 7 | 8 | |
| 8 | 9 | use crate::render::emoji::emojify; |
| @@ -10,7 +11,7 @@ use crate::render::emoji::emojify; | ||
| 10 | 11 | /// One subject on one line as it was written, header included, truncated by CSS. The full subject |
| 11 | 12 | /// is the `title` attribute. |
| 12 | 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 | 15 | let text = emojify(&subject).into_owned(); |
| 15 | 16 | Ok(view! { |
| 16 | 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 | 5 | use forge_core::store::commit_status::{CommitStatus, StatusState, combine}; |
| 6 | 6 | use topcoat::Result; |
| 7 | +use topcoat::context::Cx; | |
| 7 | 8 | use topcoat::view::{View, component, view}; |
| 8 | 9 | |
| 9 | 10 | use crate::i18n::Lang; |
| @@ -88,6 +89,7 @@ pub fn css(state: StatusState) -> &'static str { | ||
| 88 | 89 | /// no statuses. |
| 89 | 90 | #[component] |
| 90 | 91 | pub async fn commit_status( |
| 92 | + cx: &Cx, | |
| 91 | 93 | summary: StatusSummary, |
| 92 | 94 | #[default] lang: StatusLang, |
| 93 | 95 | ) -> Result<impl View> { |
| @@ -118,6 +120,7 @@ pub async fn commit_status( | ||
| 118 | 120 | /// the contexts beneath it. |
| 119 | 121 | #[component] |
| 120 | 122 | pub async fn checks_summary( |
| 123 | + cx: &Cx, | |
| 121 | 124 | summary: StatusSummary, |
| 122 | 125 | #[default] lang: StatusLang, |
| 123 | 126 | ) -> Result<impl View> { |
| @@ -167,7 +170,7 @@ fn description_text(lang: Lang, text: &str) -> &str { | ||
| 167 | 170 | |
| 168 | 171 | /// The contexts of one commit: icon, context name, description and a details link. |
| 169 | 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 | 174 | Ok(view! { |
| 172 | 175 | <ul class="status-list"> |
| 173 | 176 | for item in items.iter() { |
crates/forge-web/src/views/diff.rsmodified+20 -8
| @@ -13,7 +13,7 @@ use std::collections::HashMap; | ||
| 13 | 13 | use forge_core::{Side, Thread}; |
| 14 | 14 | use forge_git::history::{CommitDiff, DiffLimits, DiffStatus, FileDiff, LineKind}; |
| 15 | 15 | use topcoat::Result; |
| 16 | -use topcoat::context::{Cx, app_context}; | |
| 16 | +use topcoat::context::{Cx, context}; | |
| 17 | 17 | use topcoat::cookie::{Cookie, Cookies, SameSite, cookies, time}; |
| 18 | 18 | use topcoat::router::request::uri; |
| 19 | 19 | use topcoat::view::{View, component, view}; |
| @@ -111,7 +111,7 @@ impl DiffOpts { | ||
| 111 | 111 | } |
| 112 | 112 | let split = match current_user(cx).await? { |
| 113 | 113 | Some((user, _)) => { |
| 114 | - let state = app_context::<AppState>(cx); | |
| 114 | + let state = context::<AppState>(cx); | |
| 115 | 115 | let stored = state.store.user_prefs(&user.id).await?.remove(DIFF_VIEW); |
| 116 | 116 | match view_param.as_deref() { |
| 117 | 117 | Some(v @ ("split" | "unified")) => { |
| @@ -511,6 +511,7 @@ struct NavItem { | ||
| 511 | 511 | #[allow(clippy::too_many_arguments)] |
| 512 | 512 | #[component] |
| 513 | 513 | pub async fn diff_section( |
| 514 | + cx: &Cx, | |
| 514 | 515 | diff: &CommitDiff, |
| 515 | 516 | owner: &str, |
| 516 | 517 | repo: &str, |
| @@ -529,7 +530,12 @@ pub async fn diff_section( | ||
| 529 | 530 | .files |
| 530 | 531 | .iter() |
| 531 | 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 | 539 | .filter(|(i, _)| opts.only.is_none_or(|only| only == *i)) |
| 534 | 540 | .map(|(_, file)| file) |
| 535 | 541 | .collect(); |
| @@ -605,7 +611,7 @@ pub async fn diff_section( | ||
| 605 | 611 | |
| 606 | 612 | /// Unified or split, ignore whitespace, and the patch and diff downloads. |
| 607 | 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 | 615 | let unified_on = if bar.split { "false" } else { "true" }; |
| 610 | 616 | let split_on = if bar.split { "true" } else { "false" }; |
| 611 | 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 | 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 | 639 | let add_label = format!("+{}", file.additions); |
| 628 | 640 | let del_label = format!("-{}", file.deletions); |
| 629 | 641 | let rows = file.rows; |
| @@ -683,7 +695,7 @@ async fn diff_file(file: FileView, lang: Lang, split: bool, anchored: bool) -> R | ||
| 683 | 695 | /// One split row as a `<tbody>`: the two sides, then, when either has threads or an open form, a |
| 684 | 696 | /// full-width row holding them. A hunk header spans the table. |
| 685 | 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 | 699 | let SplitRow { |
| 688 | 700 | hunk, |
| 689 | 701 | left, |
| @@ -752,7 +764,7 @@ async fn diff_split_line(row: SplitRow, lang: Lang, anchored: bool) -> Result<im | ||
| 752 | 764 | /// One diff line as a `<tbody>`: the line itself, then, when it has threads or an open form, a |
| 753 | 765 | /// full-width row holding them. |
| 754 | 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 | 768 | let DiffRow { |
| 757 | 769 | class, |
| 758 | 770 | old, |
| @@ -803,7 +815,7 @@ async fn diff_line(row: DiffRow, lang: Lang) -> Result<impl View> { | ||
| 803 | 815 | /// The inline comment form under a line. "Add single comment" posts one comment; the review |
| 804 | 816 | /// button starts a review, or adds to the pending one. |
| 805 | 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 | 819 | let InlineForm { |
| 808 | 820 | action, |
| 809 | 821 | cancel_href, |
crates/forge-web/src/views/find.rsmodified+2 -0
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | //! word as typed. |
| 6 | 6 | |
| 7 | 7 | use topcoat::Result; |
| 8 | +use topcoat::context::Cx; | |
| 8 | 9 | use topcoat::view::{View, component, view}; |
| 9 | 10 | |
| 10 | 11 | use crate::i18n::Lang; |
| @@ -160,6 +161,7 @@ fn distance(a: &[char], b: &[char]) -> usize { | ||
| 160 | 161 | /// searches as you type; an option applies the moment it is ticked. |
| 161 | 162 | #[component] |
| 162 | 163 | pub async fn finder_field( |
| 164 | + cx: &Cx, | |
| 163 | 165 | lang: Lang, |
| 164 | 166 | finder: Finder, |
| 165 | 167 | placeholder: &str, |
crates/forge-web/src/views/heatmap.rsmodified+2 -0
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | //! that day's contributions under the calendar, and clicking the selected day again clears it. |
| 9 | 9 | |
| 10 | 10 | use std::collections::HashMap; |
| 11 | +use topcoat::context::Cx; | |
| 11 | 12 | |
| 12 | 13 | use forge_core::store::contributions::{ContributionItem, ContributionKind}; |
| 13 | 14 | use forge_core::time::stamp_to_unix; |
| @@ -346,6 +347,7 @@ fn day_entries(lang: Lang, items: &[ContributionItem], now: i64) -> Vec<DayEntry | ||
| 346 | 347 | /// is the stream URL the card re-renders on; it is set on a person's overview only. |
| 347 | 348 | #[component] |
| 348 | 349 | pub async fn contribution_calendar( |
| 350 | + cx: &Cx, | |
| 349 | 351 | calendar: Calendar, |
| 350 | 352 | selected: Option<DayDetail>, |
| 351 | 353 | lang: Lang, |
crates/forge-web/src/views/mod.rsmodified+26 -19
| @@ -23,7 +23,7 @@ use http::header::{ | ||
| 23 | 23 | use http::{HeaderValue, Uri}; |
| 24 | 24 | use sha2::{Digest, Sha256}; |
| 25 | 25 | use topcoat::Result; |
| 26 | -use topcoat::context::{Cx, try_app_context}; | |
| 26 | +use topcoat::context::{Cx, try_context}; | |
| 27 | 27 | use topcoat::router::request::uri; |
| 28 | 28 | use topcoat::router::response::{Response, response_headers}; |
| 29 | 29 | use topcoat::router::{Body, Next, layer}; |
| @@ -495,7 +495,7 @@ struct ProfileCorner { | ||
| 495 | 495 | /// waits. Its menu holds the name, notifications with their count, the settings and admin links and |
| 496 | 496 | /// log out. |
| 497 | 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 | 499 | let profile_href = user_href(&corner.username); |
| 500 | 500 | let profile_label = mi::t(lang, MK::YourProfile); |
| 501 | 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 | 542 | /// more stylesheet link to the head (such as a repo's generated label colors). |
| 543 | 543 | #[component] |
| 544 | 544 | pub async fn shell( |
| 545 | + cx: &Cx, | |
| 545 | 546 | title: &str, |
| 546 | 547 | viewer: Option<&(User, Session)>, |
| 547 | 548 | #[default] extra_stylesheet: Option<&str>, |
| @@ -552,7 +553,7 @@ pub async fn shell( | ||
| 552 | 553 | // The unread count, the profile corner's inbox counts, their CI runs and the items waiting on |
| 553 | 554 | // them. Signed-in only. |
| 554 | 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 | 557 | Some(state) => ( |
| 557 | 558 | state.store.unread_count(&user.id).await?, |
| 558 | 559 | state.store.inbox_kind_counts(&user.id).await?, |
| @@ -567,26 +568,26 @@ pub async fn shell( | ||
| 567 | 568 | // stored preference saved. Anonymous visitors get the cookie. Either way the browser comes |
| 568 | 569 | // back to the page it was on. |
| 569 | 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 lang = i18n::lang(__cx, viewer.map(|(user, _)| user)); | |
| 571 | + let back = uri(cx).path_and_query().map(|p| p.as_str().to_owned()); | |
| 572 | + let lang = i18n::lang(cx, viewer.map(|(user, _)| user)); | |
| 572 | 573 | // A signed-in viewer's account preferences, read once for the banner, the tree width and the |
| 573 | 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 | 576 | (Some((user, _)), Some(state)) => Some(state.store.user_prefs(&user.id).await?), |
| 576 | 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 | 580 | let sound_attr = crate::pages::settings_appearance::sound_attr(prefs.as_ref()); |
| 580 | 581 | let banner_back = back.clone().unwrap_or_else(|| "/".to_owned()); |
| 581 | 582 | let dismiss_label = crate::i18n::accounts::t(lang, crate::i18n::accounts::A::Dismiss); |
| 582 | 583 | // The admin area and the user settings swap the global links for their own list. Signed-in only. |
| 583 | 584 | let section = if signed_in { |
| 584 | - section_for(lang, uri(__cx).path()) | |
| 585 | + section_for(lang, uri(cx).path()) | |
| 585 | 586 | } else { |
| 586 | 587 | None |
| 587 | 588 | }; |
| 588 | - let width = page_width(uri(__cx).path()); | |
| 589 | - let theme_attr = crate::theme::data_theme(__cx, viewer.map(|(user, _)| user)); | |
| 589 | + let width = page_width(uri(cx).path()); | |
| 590 | + let theme_attr = crate::theme::data_theme(cx, viewer.map(|(user, _)| user)); | |
| 590 | 591 | // The relative-time wording and the server's clock, for nav.js to keep `<time data-rel>` labels current. |
| 591 | 592 | let rel_words_attr = rel_words(lang); |
| 592 | 593 | let rel_now_attr = now_unix().to_string(); |
| @@ -627,7 +628,7 @@ pub async fn shell( | ||
| 627 | 628 | }; |
| 628 | 629 | // The stored preference, "auto" included, drives the button: its icon, its label and the |
| 629 | 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 | 632 | let next_theme = crate::theme::next_preference(theme_pref); |
| 632 | 633 | let theme_state = match theme_pref { |
| 633 | 634 | "light" => mi::t(lang, MK::Light), |
| @@ -649,7 +650,7 @@ pub async fn shell( | ||
| 649 | 650 | let explore_label = t(lang, Key::Explore); |
| 650 | 651 | let home_label = o::t(lang, OK::Home); |
| 651 | 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 | 654 | // A page with no place of its own in the path, such as settings, names its section and itself. |
| 654 | 655 | // A page below one of the section's tabs (an account under Users) names that tab too. |
| 655 | 656 | if segments.is_empty() { |
| @@ -658,7 +659,7 @@ pub async fn shell( | ||
| 658 | 659 | if section.title != title { |
| 659 | 660 | segments.push((section.title.clone(), first)); |
| 660 | 661 | } |
| 661 | - let path = uri(__cx).path(); | |
| 662 | + let path = uri(cx).path(); | |
| 662 | 663 | if let Some(item) = section.items.iter().find(|item| { |
| 663 | 664 | path.strip_prefix(item.href.as_str()) |
| 664 | 665 | .is_some_and(|below| below.starts_with('/')) |
| @@ -1072,6 +1073,7 @@ pub fn section_for(lang: Lang, path: &str) -> Option<Section> { | ||
| 1072 | 1073 | /// One row of text tabs, with `aria-current="page"` on the current one. |
| 1073 | 1074 | #[component] |
| 1074 | 1075 | async fn section_tabs( |
| 1076 | + cx: &Cx, | |
| 1075 | 1077 | key: &'static str, |
| 1076 | 1078 | label: &str, |
| 1077 | 1079 | items: Vec<NavItem>, |
| @@ -1132,7 +1134,7 @@ pub fn user_href(username: &str) -> String { | ||
| 1132 | 1134 | /// the text to display (it differs from `login` only for the ghost account). Both are escaped |
| 1133 | 1135 | /// like any other interpolation. |
| 1134 | 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 | 1138 | let href = user_href(login); |
| 1137 | 1139 | Ok(view! { |
| 1138 | 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 | 1144 | /// Hidden CSRF input for a POST form. |
| 1143 | 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 | 1147 | Ok(view! { |
| 1146 | 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 | 1152 | /// Inline error box. |
| 1151 | 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 | 1155 | Ok(view! { |
| 1154 | 1156 | <p class="alert" role="alert">(message)</p> |
| 1155 | 1157 | }) |
| @@ -1160,6 +1162,7 @@ pub async fn alert(message: &str) -> Result<impl View> { | ||
| 1160 | 1162 | /// reads the same way. |
| 1161 | 1163 | #[component] |
| 1162 | 1164 | pub async fn empty_state( |
| 1165 | + cx: &Cx, | |
| 1163 | 1166 | title: &str, |
| 1164 | 1167 | #[default] hint: Option<&str>, |
| 1165 | 1168 | #[default] child: Child<'_>, |
| @@ -1194,7 +1197,7 @@ pub async fn security_headers(cx: &Cx, body: Body, next: Next<'_>) -> Result<Res | ||
| 1194 | 1197 | headers.append(X_CONTENT_TYPE_OPTIONS, HeaderValue::from_static("nosniff")); |
| 1195 | 1198 | headers.append(REFERRER_POLICY, HeaderValue::from_static("same-origin")); |
| 1196 | 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 | 1201 | Some(state) => APP_CSP |
| 1199 | 1202 | .get_or_init(|| csp_header(&state.config.user_content_base_url)) |
| 1200 | 1203 | .clone(), |
| @@ -1327,7 +1330,7 @@ pub fn rel_words(lang: Lang) -> String { | ||
| 1327 | 1330 | /// A live relative time for an RFC 3339 stamp: a `<time data-rel>` that nav.js re-words as the |
| 1328 | 1331 | /// clock moves. A stamp that does not parse renders empty. |
| 1329 | 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 | 1334 | let label = forge_core::time::stamp_to_unix(stamp) |
| 1332 | 1335 | .map_or_else(String::new, |unix| relative_time(lang, unix, now_unix())); |
| 1333 | 1336 | Ok(view! { |
| @@ -1337,7 +1340,7 @@ pub async fn rel_time(lang: Lang, stamp: &str) -> Result<impl View> { | ||
| 1337 | 1340 | |
| 1338 | 1341 | /// A live relative time, or "never" when there is no stamp. |
| 1339 | 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 | 1344 | Ok(view! { |
| 1342 | 1345 | if let Some(stamp) = stamp { |
| 1343 | 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 | 1354 | /// stamp is left out. |
| 1352 | 1355 | #[component] |
| 1353 | 1356 | pub async fn added_status( |
| 1357 | + cx: &Cx, | |
| 1354 | 1358 | lang: Lang, |
| 1355 | 1359 | added: Option<&str>, |
| 1356 | 1360 | used: Option<&str>, |
| @@ -1423,6 +1427,7 @@ fn tab_more_class(on: bool) -> &'static str { | ||
| 1423 | 1427 | /// counts shown on their tabs; a zero count (or `None`) shows the tab without one. |
| 1424 | 1428 | #[component] |
| 1425 | 1429 | pub async fn repo_tabs( |
| 1430 | + cx: &Cx, | |
| 1426 | 1431 | owner: String, |
| 1427 | 1432 | repo: String, |
| 1428 | 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 | 1550 | /// is left out. |
| 1546 | 1551 | #[component] |
| 1547 | 1552 | async fn ref_group( |
| 1553 | + cx: &Cx, | |
| 1548 | 1554 | lang: Lang, |
| 1549 | 1555 | kind: &'static str, |
| 1550 | 1556 | heading: &'static str, |
| @@ -1593,6 +1599,7 @@ async fn ref_group( | ||
| 1593 | 1599 | /// still lists the first entries of each section. |
| 1594 | 1600 | #[component] |
| 1595 | 1601 | pub async fn ref_selector( |
| 1602 | + cx: &Cx, | |
| 1596 | 1603 | lang: Lang, |
| 1597 | 1604 | label: &'static str, |
| 1598 | 1605 | current: String, |
crates/forge-web/src/views/parts.rsmodified+11 -2
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | //! `docs/ui-language.md`. |
| 3 | 3 | |
| 4 | 4 | use topcoat::Result; |
| 5 | +use topcoat::context::Cx; | |
| 5 | 6 | use topcoat::view::{Child, View, ViewExt, component, view}; |
| 6 | 7 | |
| 7 | 8 | use crate::i18n::Lang; |
| @@ -10,7 +11,9 @@ use crate::pages::passkeys::s; | ||
| 10 | 11 | /// The width class of a strip segment holding `part` of `total`: `fr1` to `fr40`, since a page may |
| 11 | 12 | /// not set inline styles. A segment with nothing in it still shows. |
| 12 | 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 | 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 | 21 | /// starts it open, as a form sent back with an error must. |
| 19 | 22 | #[component] |
| 20 | 23 | pub async fn reveal( |
| 24 | + cx: &Cx, | |
| 21 | 25 | label: &str, |
| 22 | 26 | #[default] id: Option<&str>, |
| 23 | 27 | #[default] open: bool, |
| @@ -35,6 +39,7 @@ pub async fn reveal( | ||
| 35 | 39 | /// `fields` are the form's hidden fields besides the CSRF token, `note` says what will be lost. |
| 36 | 40 | #[component] |
| 37 | 41 | pub async fn confirm_act( |
| 42 | + cx: &Cx, | |
| 38 | 43 | lang: Lang, |
| 39 | 44 | label: &str, |
| 40 | 45 | action: &str, |
| @@ -65,6 +70,7 @@ pub async fn confirm_act( | ||
| 65 | 70 | /// One text link that posts at once, for actions that lose nothing. |
| 66 | 71 | #[component] |
| 67 | 72 | pub async fn post_act( |
| 73 | + cx: &Cx, | |
| 68 | 74 | label: &str, |
| 69 | 75 | action: &str, |
| 70 | 76 | csrf: &str, |
| @@ -132,7 +138,7 @@ pub struct PeopleList { | ||
| 132 | 138 | |
| 133 | 139 | /// The people list and its add form. The caller puts it in a sheet. |
| 134 | 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 | 142 | let PeopleList { |
| 137 | 143 | lang, |
| 138 | 144 | title, |
| @@ -287,6 +293,7 @@ impl SubPart { | ||
| 287 | 293 | /// The line under a head's title. `pips` are recent runs, oldest first, as (href, title, class). |
| 288 | 294 | #[component] |
| 289 | 295 | pub async fn head_sub( |
| 296 | + cx: &Cx, | |
| 290 | 297 | parts: Vec<SubPart>, |
| 291 | 298 | #[default] pips: Vec<(String, String, &'static str)>, |
| 292 | 299 | ) -> Result<impl View> { |
| @@ -323,6 +330,7 @@ pub async fn head_sub( | ||
| 323 | 330 | /// beside it (`child`), then the sub line. Every page starts with one. Section tabs follow it. |
| 324 | 331 | #[component] |
| 325 | 332 | pub async fn head( |
| 333 | + cx: &Cx, | |
| 326 | 334 | title: &str, |
| 327 | 335 | #[default] sub: Vec<SubPart>, |
| 328 | 336 | #[default] live: Option<&str>, |
| @@ -354,6 +362,7 @@ pub struct RailItem { | ||
| 354 | 362 | /// for a filter. |
| 355 | 363 | #[component] |
| 356 | 364 | pub async fn rail( |
| 365 | + cx: &Cx, | |
| 357 | 366 | label: &str, |
| 358 | 367 | items: Vec<RailItem>, |
| 359 | 368 | #[default] heading: Option<&str>, |
crates/forge-web/src/views/repo_list.rsmodified+6 -3
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | use forge_core::Visibility; |
| 5 | 5 | use forge_core::store::ListedRepo; |
| 6 | 6 | use topcoat::Result; |
| 7 | +use topcoat::context::Cx; | |
| 7 | 8 | use topcoat::view::{View, component, view}; |
| 8 | 9 | |
| 9 | 10 | use crate::i18n::orgs::{self as g, K}; |
| @@ -14,7 +15,8 @@ use crate::views::repo_href; | ||
| 14 | 15 | /// The fact a row leads with when the repo is private ("Private · "); public says nothing, it is |
| 15 | 16 | /// the usual case. |
| 16 | 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 | 22 | /// One listed repo, formatted for display. |
| @@ -45,7 +47,7 @@ impl RepoRow { | ||
| 45 | 47 | |
| 46 | 48 | /// The repo rows: name, a one-line description, then Private (when it is), stars and the last update. |
| 47 | 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 | 51 | let (before, after) = g::updated_parts(lang); |
| 50 | 52 | Ok(view! { |
| 51 | 53 | <ul class="repo-list"> |
| @@ -79,7 +81,7 @@ pub struct SortLink { | ||
| 79 | 81 | |
| 80 | 82 | /// The "Sort by" chips. |
| 81 | 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 | 85 | Ok(view! { |
| 84 | 86 | <nav class="sort" aria-label=(g::t(lang, K::SortNav))> |
| 85 | 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 | 139 | /// page. |
| 138 | 140 | #[component] |
| 139 | 141 | pub async fn pager( |
| 142 | + cx: &Cx, | |
| 140 | 143 | page: u64, |
| 141 | 144 | pages: u64, |
| 142 | 145 | links: Vec<PageLink>, |
crates/forge-web/src/views/review_thread.rsmodified+7 -2
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | |
| 6 | 6 | use std::collections::HashMap; |
| 7 | 7 | use std::sync::Arc; |
| 8 | +use topcoat::context::Cx; | |
| 8 | 9 | |
| 9 | 10 | use forge_core::suggestions::{Part, hunk_line, split_body}; |
| 10 | 11 | use forge_core::{ReviewComment, Thread}; |
| @@ -167,6 +168,7 @@ fn comment_row( | ||
| 167 | 168 | /// `conversation` and tells the POST routes which tab to redirect to. |
| 168 | 169 | #[component] |
| 169 | 170 | pub async fn review_thread( |
| 171 | + cx: &Cx, | |
| 170 | 172 | thread: Thread, |
| 171 | 173 | ctx: ThreadCtx, |
| 172 | 174 | show_hunk: bool, |
| @@ -181,6 +183,7 @@ pub async fn review_thread( | ||
| 181 | 183 | /// One thread with its strings in `lang`. See `review_thread` for the arguments. |
| 182 | 184 | #[component] |
| 183 | 185 | pub async fn review_thread_in( |
| 186 | + cx: &Cx, | |
| 184 | 187 | lang: Lang, |
| 185 | 188 | thread: Thread, |
| 186 | 189 | ctx: ThreadCtx, |
| @@ -261,7 +264,7 @@ pub async fn review_thread_in( | ||
| 261 | 264 | /// The diff hunk, the comments, then the thread's tools and reply form. Split into siblings so |
| 262 | 265 | /// each component's view stays small enough to type-check. |
| 263 | 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 | 268 | let ThreadParts { |
| 266 | 269 | hunk, |
| 267 | 270 | comments, |
| @@ -313,7 +316,7 @@ struct ThreadFooter { | ||
| 313 | 316 | /// The resolve button, and Reply, which opens its form in place. Each is empty when the viewer |
| 314 | 317 | /// may not use it. |
| 315 | 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 | 320 | let ThreadFooter { |
| 318 | 321 | resolve_action, |
| 319 | 322 | resolve_value, |
| @@ -351,6 +354,7 @@ async fn thread_footer(footer: ThreadFooter) -> Result<impl View> { | ||
| 351 | 354 | |
| 352 | 355 | #[component] |
| 353 | 356 | async fn thread_comment( |
| 357 | + cx: &Cx, | |
| 354 | 358 | comment: CommentRow, |
| 355 | 359 | csrf: String, |
| 356 | 360 | return_to: String, |
| @@ -404,6 +408,7 @@ async fn thread_comment( | ||
| 404 | 408 | /// lines, the Apply control when it applies, and a note when it is outdated. |
| 405 | 409 | #[component] |
| 406 | 410 | async fn comment_part( |
| 411 | + cx: &Cx, | |
| 407 | 412 | part: PartRow, |
| 408 | 413 | csrf: String, |
| 409 | 414 | return_to: String, |
crates/forge-web/src/views/timeline.rsmodified+2 -0
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | |
| 5 | 5 | use forge_core::ci::RunState; |
| 6 | 6 | use topcoat::Result; |
| 7 | +use topcoat::context::Cx; | |
| 7 | 8 | use topcoat::view::{View, component, view}; |
| 8 | 9 | |
| 9 | 10 | use super::{repo_href, short_oid}; |
| @@ -54,6 +55,7 @@ struct BarView { | ||
| 54 | 55 | /// counts the bars drawn. |
| 55 | 56 | #[component] |
| 56 | 57 | pub async fn history_strip( |
| 58 | + cx: &Cx, | |
| 57 | 59 | lang: Lang, |
| 58 | 60 | owner: String, |
| 59 | 61 | repo: String, |