From bdda6d84c193b408c131e1e61054862f1eb0ecb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 1 Dec 2026 08:41:33 +0300 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20the=20pages=20?= =?UTF-8?q?split=20into=20forge-web-pages=20(the=20shared=20repo,=20issue,?= =?UTF-8?q?=20CI=20and=20settings=20pages),=20forge-web-account=20(account?= =?UTF-8?q?,=20admin,=20org=20and=20profile)=20and=20forge-web-repo=20(cod?= =?UTF-8?q?e,=20pulls,=20discussions),=20so=20no=20single=20rustc=20compil?= =?UTF-8?q?es=20all=2080k=20lines=20of=20pages;=20the=20two=20upper=20crat?= =?UTF-8?q?es=20build=20in=20parallel=20and=20page=20tests=20that=20span?= =?UTF-8?q?=20crates=20move=20to=20the=20binary?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 124 +++- Cargo.toml | 6 + crates/forge-web-account/Cargo.toml | 49 ++ crates/forge-web-account/src/lib.rs | 15 + .../src/pages/account_tools_tests.rs | 0 .../src/pages/activity.rs | 0 .../src/pages/admin_backups.rs | 0 .../src/pages/admin_health.rs | 0 .../src/pages/admin_live_tests.rs | 0 .../src/pages/admin_mail.rs | 0 .../src/pages/admin_replication.rs | 0 .../src/pages/admin_server.rs | 0 .../src/pages/admin_user_detail.rs | 0 .../src/pages/assets.rs | 6 +- .../src/pages/audit_log.rs | 0 .../src/pages/avatars.rs | 0 .../src/pages/banner.rs | 0 .../src/pages/explore.rs | 0 .../src/pages/forgot.rs | 0 .../src/pages/home.rs | 0 .../src/pages/import.rs | 0 .../src/pages/import_tests.rs | 0 .../src/pages/invites.rs | 0 .../src/pages/login.rs | 0 crates/forge-web-account/src/pages/mod.rs | 64 ++ .../src/pages/needs_you.rs | 0 .../src/pages/new_repo.rs | 24 +- .../src/pages/not_found_page.rs | 0 .../src/pages/org_ctx.rs | 0 .../src/pages/org_live.rs | 0 .../src/pages/org_members.rs | 0 .../src/pages/org_new.rs | 0 .../src/pages/org_settings.rs | 0 .../src/pages/org_teams.rs | 0 .../src/pages/palette.rs | 0 .../src/pages/passkeys.rs | 0 .../src/pages/passkeys_tests.rs | 0 .../src/pages/profile.rs | 0 .../src/pages/profile_calendar.rs | 0 .../src/pages/profile_pins.rs | 0 .../src/pages/register.rs | 0 .../src/pages/releases_tests.rs | 0 .../src/pages/settings_appearance.rs | 0 .../src/pages/settings_export.rs | 0 .../src/pages/settings_gpg.rs | 0 .../src/pages/settings_gpg_tests.rs | 0 .../src/pages/settings_keys.rs | 0 .../src/pages/settings_live.rs | 0 .../src/pages/settings_notifications.rs | 0 .../src/pages/settings_profile.rs | 0 .../src/pages/settings_security.rs | 0 .../src/pages/settings_sessions.rs | 0 .../src/pages/settings_tokens.rs | 0 .../src/pages/setup.rs | 0 .../src/pages/shell_events.rs | 0 .../src/pages/snippets.rs | 0 .../src/pages/snippets_live.rs | 0 .../src/pages/theme_cookie.rs | 0 .../src/pages/user_prefs.rs | 0 crates/forge-web-app/Cargo.toml | 5 - crates/forge-web-app/src/test_support/mod.rs | 25 +- crates/forge-web-pages/Cargo.toml | 46 ++ crates/forge-web-pages/src/lib.rs | 13 + .../src/pages/admin_runners.rs | 2 +- .../src/pages/admin_users.rs | 4 +- .../src/pages/ci_estimate.rs | 0 .../src/pages/ci_fail.rs | 8 +- .../src/pages/ci_job.rs | 18 +- .../src/pages/ci_runs.rs | 16 +- .../src/pages/code_live.rs | 0 .../src/pages/discussion_settings.rs | 2 +- .../src/pages/edit_history.rs | 313 +------- .../src/pages/finder.rs | 0 .../src/pages/issue_meta.rs | 34 +- .../src/pages/issue_parts.rs | 154 ++-- .../src/pages/issues_list.rs | 74 +- .../src/pages/issues_live.rs | 0 crates/forge-web-pages/src/pages/mod.rs | 38 + .../src/pages/notifications.rs | 600 +-------------- .../src/pages/packages.rs | 8 +- .../src/pages/packages_oci.rs | 0 .../src/pages/pull_live.rs | 4 +- .../src/pages/pull_reviews.rs | 684 +----------------- .../src/pages/ref_live.rs | 0 .../src/pages/refs.rs | 2 +- .../src/pages/releases.rs | 4 +- .../src/pages/releases_live.rs | 4 +- .../src/pages/repo.rs | 480 ------------ .../src/pages/repo_ctx.rs | 0 .../src/pages/repo_mirrors.rs | 0 .../src/pages/repo_rename.rs | 2 +- .../src/pages/repo_security.rs | 2 +- .../src/pages/repo_settings.rs | 24 +- .../src/pages/repo_settings_live.rs | 0 .../src/pages/repo_side.rs | 0 .../src/pages/repo_transfer.rs | 10 +- .../src/pages/star.rs | 2 +- .../src/pages/tree.rs | 2 +- .../src/pages/wiki.rs | 6 +- .../src/pages/wiki_live.rs | 0 crates/forge-web-repo/Cargo.toml | 48 ++ crates/forge-web-repo/src/lib.rs | 13 + .../src/pages/archive.rs | 0 .../src/pages/authoring.rs | 0 .../src/pages/authoring_tests.rs | 0 .../src/pages/blame.rs | 0 .../src/pages/blob.rs | 0 .../src/pages/branches.rs | 0 .../src/pages/browse_tests.rs | 0 .../src/pages/ci_badge.rs | 0 .../src/pages/ci_tests.rs | 0 .../src/pages/code_search.rs | 0 .../src/pages/commit.rs | 0 .../src/pages/commits.rs | 0 .../src/pages/compare.rs | 0 .../src/pages/discussion_actions.rs | 0 .../src/pages/discussion_live.rs | 0 .../src/pages/discussion_live_tests.rs | 0 .../src/pages/discussion_view.rs | 0 .../src/pages/discussions.rs | 0 .../src/pages/fork.rs | 0 .../src/pages/issue_meta_tests.rs | 0 .../src/pages/issue_pin.rs | 0 .../src/pages/issue_pin_tests.rs | 0 .../src/pages/issue_view.rs | 0 .../src/pages/labels_css.rs | 0 .../src/pages/labels_page.rs | 0 .../src/pages/merge_queue.rs | 0 .../src/pages/milestones_page.rs | 0 crates/forge-web-repo/src/pages/mod.rs | 56 ++ .../src/pages/pull_branch.rs | 0 .../src/pages/pull_files.rs | 0 .../src/pages/pull_flow.rs | 0 .../src/pages/pull_view.rs | 0 .../src/pages/pulls_list.rs | 0 .../src/pages/pulls_merge.rs | 0 .../src/pages/push.rs | 9 +- .../src/pages/reactions.rs | 0 .../src/pages/reactions_tests.rs | 0 .../src/pages/repo_collaborators.rs | 0 .../src/pages/repo_scrub.rs | 0 .../src/pages/repo_secrets.rs | 0 .../src/pages/repo_settings_live_tests.rs | 0 .../src/pages/repo_webhooks.rs | 0 .../src/pages/review_requests.rs | 0 .../src/pages/security_tab_tests.rs | 0 crates/forge-web/Cargo.toml | 28 +- crates/forge-web/src/boot.rs | 2 +- crates/forge-web/src/lib.rs | 1 - crates/forge-web/src/main.rs | 19 +- .../src/page_route_tests/edit_history.rs | 303 ++++++++ crates/forge-web/src/page_route_tests/mod.rs | 6 + .../src/page_route_tests/notifications.rs | 570 +++++++++++++++ .../src/page_route_tests/pull_reviews.rs | 647 +++++++++++++++++ crates/forge-web/src/page_route_tests/repo.rs | 470 ++++++++++++ crates/forge-web/src/pages/mod.rs | 150 ---- crates/forge-web/src/templates_route_tests.rs | 2 +- 157 files changed, 2706 insertions(+), 2492 deletions(-) create mode 100644 crates/forge-web-account/Cargo.toml create mode 100644 crates/forge-web-account/src/lib.rs rename crates/{forge-web => forge-web-account}/src/pages/account_tools_tests.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/activity.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/admin_backups.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/admin_health.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/admin_live_tests.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/admin_mail.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/admin_replication.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/admin_server.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/admin_user_detail.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/assets.rs (98%) rename crates/{forge-web => forge-web-account}/src/pages/audit_log.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/avatars.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/banner.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/explore.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/forgot.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/home.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/import.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/import_tests.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/invites.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/login.rs (100%) create mode 100644 crates/forge-web-account/src/pages/mod.rs rename crates/{forge-web => forge-web-account}/src/pages/needs_you.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/new_repo.rs (97%) rename crates/{forge-web => forge-web-account}/src/pages/not_found_page.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/org_ctx.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/org_live.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/org_members.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/org_new.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/org_settings.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/org_teams.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/palette.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/passkeys.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/passkeys_tests.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/profile.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/profile_calendar.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/profile_pins.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/register.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/releases_tests.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/settings_appearance.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/settings_export.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/settings_gpg.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/settings_gpg_tests.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/settings_keys.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/settings_live.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/settings_notifications.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/settings_profile.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/settings_security.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/settings_sessions.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/settings_tokens.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/setup.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/shell_events.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/snippets.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/snippets_live.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/theme_cookie.rs (100%) rename crates/{forge-web => forge-web-account}/src/pages/user_prefs.rs (100%) create mode 100644 crates/forge-web-pages/Cargo.toml create mode 100644 crates/forge-web-pages/src/lib.rs rename crates/{forge-web => forge-web-pages}/src/pages/admin_runners.rs (99%) rename crates/{forge-web => forge-web-pages}/src/pages/admin_users.rs (99%) rename crates/{forge-web => forge-web-pages}/src/pages/ci_estimate.rs (100%) rename crates/{forge-web => forge-web-pages}/src/pages/ci_fail.rs (96%) rename crates/{forge-web => forge-web-pages}/src/pages/ci_job.rs (98%) rename crates/{forge-web => forge-web-pages}/src/pages/ci_runs.rs (99%) rename crates/{forge-web => forge-web-pages}/src/pages/code_live.rs (100%) rename crates/{forge-web => forge-web-pages}/src/pages/discussion_settings.rs (98%) rename crates/{forge-web => forge-web-pages}/src/pages/edit_history.rs (53%) rename crates/{forge-web => forge-web-pages}/src/pages/finder.rs (100%) rename crates/{forge-web => forge-web-pages}/src/pages/issue_meta.rs (94%) rename crates/{forge-web => forge-web-pages}/src/pages/issue_parts.rs (94%) rename crates/{forge-web => forge-web-pages}/src/pages/issues_list.rs (97%) rename crates/{forge-web => forge-web-pages}/src/pages/issues_live.rs (100%) create mode 100644 crates/forge-web-pages/src/pages/mod.rs rename crates/{forge-web => forge-web-pages}/src/pages/notifications.rs (67%) rename crates/{forge-web => forge-web-pages}/src/pages/packages.rs (98%) rename crates/{forge-web => forge-web-pages}/src/pages/packages_oci.rs (100%) rename crates/{forge-web => forge-web-pages}/src/pages/pull_live.rs (99%) rename crates/{forge-web => forge-web-pages}/src/pages/pull_reviews.rs (53%) rename crates/{forge-web => forge-web-pages}/src/pages/ref_live.rs (100%) rename crates/{forge-web => forge-web-pages}/src/pages/refs.rs (99%) rename crates/{forge-web => forge-web-pages}/src/pages/releases.rs (99%) rename crates/{forge-web => forge-web-pages}/src/pages/releases_live.rs (97%) rename crates/{forge-web => forge-web-pages}/src/pages/repo.rs (54%) rename crates/{forge-web => forge-web-pages}/src/pages/repo_ctx.rs (100%) rename crates/{forge-web => forge-web-pages}/src/pages/repo_mirrors.rs (100%) rename crates/{forge-web => forge-web-pages}/src/pages/repo_rename.rs (99%) rename crates/{forge-web => forge-web-pages}/src/pages/repo_security.rs (99%) rename crates/{forge-web => forge-web-pages}/src/pages/repo_settings.rs (99%) rename crates/{forge-web => forge-web-pages}/src/pages/repo_settings_live.rs (100%) rename crates/{forge-web => forge-web-pages}/src/pages/repo_side.rs (100%) rename crates/{forge-web => forge-web-pages}/src/pages/repo_transfer.rs (98%) rename crates/{forge-web => forge-web-pages}/src/pages/star.rs (98%) rename crates/{forge-web => forge-web-pages}/src/pages/tree.rs (99%) rename crates/{forge-web => forge-web-pages}/src/pages/wiki.rs (99%) rename crates/{forge-web => forge-web-pages}/src/pages/wiki_live.rs (100%) create mode 100644 crates/forge-web-repo/Cargo.toml create mode 100644 crates/forge-web-repo/src/lib.rs rename crates/{forge-web => forge-web-repo}/src/pages/archive.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/authoring.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/authoring_tests.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/blame.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/blob.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/branches.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/browse_tests.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/ci_badge.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/ci_tests.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/code_search.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/commit.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/commits.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/compare.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/discussion_actions.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/discussion_live.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/discussion_live_tests.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/discussion_view.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/discussions.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/fork.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/issue_meta_tests.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/issue_pin.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/issue_pin_tests.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/issue_view.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/labels_css.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/labels_page.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/merge_queue.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/milestones_page.rs (100%) create mode 100644 crates/forge-web-repo/src/pages/mod.rs rename crates/{forge-web => forge-web-repo}/src/pages/pull_branch.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/pull_files.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/pull_flow.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/pull_view.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/pulls_list.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/pulls_merge.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/push.rs (98%) rename crates/{forge-web => forge-web-repo}/src/pages/reactions.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/reactions_tests.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/repo_collaborators.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/repo_scrub.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/repo_secrets.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/repo_settings_live_tests.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/repo_webhooks.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/review_requests.rs (100%) rename crates/{forge-web => forge-web-repo}/src/pages/security_tab_tests.rs (100%) delete mode 100644 crates/forge-web/src/lib.rs create mode 100644 crates/forge-web/src/page_route_tests/edit_history.rs create mode 100644 crates/forge-web/src/page_route_tests/mod.rs create mode 100644 crates/forge-web/src/page_route_tests/notifications.rs create mode 100644 crates/forge-web/src/page_route_tests/pull_reviews.rs create mode 100644 crates/forge-web/src/page_route_tests/repo.rs delete mode 100644 crates/forge-web/src/pages/mod.rs diff --git a/Cargo.lock b/Cargo.lock index cfaa738..d18e15c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2105,42 +2105,59 @@ dependencies = [ name = "forge-web" version = "0.1.0" dependencies = [ - "aes-gcm 0.11.1", - "async-compression", "base64 0.23.1", "bytes", - "flate2", "forge-ci", "forge-core", "forge-git", "forge-runner", "forge-ssh", + "forge-web-account", + "forge-web-app", + "forge-web-base", + "forge-web-pages", + "forge-web-repo", + "futures-util", + "hex", + "http", + "nix 0.31.4", + "rand 0.10.4", + "reqwest", + "rpassword", + "serde_json", + "tar", + "tempfile", + "time", + "tokio", + "topcoat", + "tracing", + "tracing-subscriber", + "zip", +] + +[[package]] +name = "forge-web-account" +version = "0.1.0" +dependencies = [ + "base64 0.23.1", + "bytes", + "forge-ci", + "forge-core", + "forge-git", "forge-web-app", "forge-web-base", + "forge-web-pages", "form_urlencoded", "futures-util", "hex", - "hkdf 0.13.0", - "hmac 0.13.0", "http", "http-body", "http-body-util", "image", - "ipnet", "jiff 1.0.3", - "lettre", - "multer", - "nix 0.31.4", - "p256", - "rand 0.10.4", - "reqwest", - "rpassword", - "scraper", "serde", "serde_json", "sha2 0.11.1", - "similar", - "subtle", "tar", "tempfile", "time", @@ -2148,7 +2165,6 @@ dependencies = [ "tokio-util", "topcoat", "tracing", - "tracing-subscriber", "ulid", "webauthn-authenticator-rs", "webauthn-rs", @@ -2183,17 +2199,14 @@ dependencies = [ "ipnet", "jiff 1.0.3", "lettre", - "multer", "nix 0.31.4", "p256", "rand 0.10.4", "reqwest", - "scraper", "serde", "serde_json", "sha2 0.11.1", "similar", - "subtle", "tar", "tempfile", "time", @@ -2201,9 +2214,7 @@ dependencies = [ "tokio-util", "topcoat", "tracing", - "tracing-subscriber", "ulid", - "webauthn-authenticator-rs", "zip", ] @@ -2234,6 +2245,75 @@ dependencies = [ "tracing", ] +[[package]] +name = "forge-web-pages" +version = "0.1.0" +dependencies = [ + "bytes", + "forge-ci", + "forge-core", + "forge-git", + "forge-web-app", + "forge-web-base", + "form_urlencoded", + "futures-util", + "hex", + "http", + "http-body", + "http-body-util", + "image", + "multer", + "nix 0.31.4", + "reqwest", + "serde", + "serde_json", + "similar", + "tar", + "tempfile", + "time", + "tokio", + "topcoat", + "tracing", + "zip", +] + +[[package]] +name = "forge-web-repo" +version = "0.1.0" +dependencies = [ + "bytes", + "forge-core", + "forge-git", + "forge-web-app", + "forge-web-base", + "forge-web-pages", + "form_urlencoded", + "futures-util", + "hex", + "http", + "http-body", + "http-body-util", + "image", + "jiff 1.0.3", + "multer", + "nix 0.31.4", + "p256", + "reqwest", + "scraper", + "serde", + "serde_json", + "sha2 0.11.1", + "tar", + "tempfile", + "time", + "tokio", + "tokio-util", + "topcoat", + "tracing", + "ulid", + "zip", +] + [[package]] name = "form_urlencoded" version = "1.2.3" diff --git a/Cargo.toml b/Cargo.toml index 89efadd..27e52ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,9 @@ members = [ "crates/forge-web", "crates/forge-web-base", "crates/forge-web-app", + "crates/forge-web-pages", + "crates/forge-web-account", + "crates/forge-web-repo", "crates/forge-ci", "crates/forge-runner", "crates/forge-e2e", @@ -36,6 +39,9 @@ forge-ssh = { path = "crates/forge-ssh" } forge-runner = { path = "crates/forge-runner" } forge-web-base = { path = "crates/forge-web-base" } forge-web-app = { path = "crates/forge-web-app" } +forge-web-pages = { path = "crates/forge-web-pages" } +forge-web-account = { path = "crates/forge-web-account" } +forge-web-repo = { path = "crates/forge-web-repo" } # async runtime and HTTP plumbing tokio = { version = "1.54.1", features = ["full"] } diff --git a/crates/forge-web-account/Cargo.toml b/crates/forge-web-account/Cargo.toml new file mode 100644 index 0000000..07c6fc6 --- /dev/null +++ b/crates/forge-web-account/Cargo.toml @@ -0,0 +1,49 @@ +[package] +name = "forge-web-account" +description = "forge account, admin, org and profile pages" +version.workspace = true +edition.workspace = true +license.workspace = true +publish = false + +[dependencies] +forge-web-app.workspace = true +forge-web-pages.workspace = true +forge-core.workspace = true +forge-git.workspace = true +forge-ci.workspace = true +forge-web-base.workspace = true +topcoat = { workspace = true, default-features = false, features = ["router", "view", "runtime", "cookie", "asset", "serve", "sse", "discover", "compression", "multipart", "tower"] } +tokio.workspace = true +futures-util.workspace = true +bytes.workspace = true +http.workspace = true +http-body-util.workspace = true +serde.workspace = true +serde_json.workspace = true +form_urlencoded.workspace = true +jiff.workspace = true +base64.workspace = true +tracing.workspace = true +tokio-util = { workspace = true, features = ["io"] } +http-body.workspace = true +hex.workspace = true +sha2.workspace = true +time.workspace = true +ulid.workspace = true +zip = { workspace = true } +tar.workspace = true + + +webauthn-rs = { version = "0.6.2", features = ["danger-allow-state-serialisation", "conditional-ui"] } +webauthn-rs-proto = "0.6.2" + +[dev-dependencies] +forge-web-pages = { workspace = true, features = ["test-support"] } +forge-web-app = { workspace = true, features = ["test-support"] } +tempfile.workspace = true +image = { workspace = true } +webauthn-authenticator-rs = { version = "0.6.2", features = ["softpasskey"] } + +[lints] +workspace = true diff --git a/crates/forge-web-account/src/lib.rs b/crates/forge-web-account/src/lib.rs new file mode 100644 index 0000000..f67f849 --- /dev/null +++ b/crates/forge-web-account/src/lib.rs @@ -0,0 +1,15 @@ +//! forge pages. + +#![recursion_limit = "256"] + +#[cfg(test)] +pub(crate) use forge_web_app::test_support; +pub(crate) use forge_web_app::{ + accent, alerts, api, audit, auth, backup, client_ip, custom_colour, exporter, i18n, importer, + live, mail, mirrors, raw, render, self_update, signatures, state, theme, throttle, views, + web_push, webhooks, +}; +#[cfg(test)] +pub(crate) use forge_web_app::{blobs, ci, notify_hub, packages_live, release_ops, replication}; + +pub mod pages; diff --git a/crates/forge-web/src/pages/account_tools_tests.rs b/crates/forge-web-account/src/pages/account_tools_tests.rs similarity index 100% rename from crates/forge-web/src/pages/account_tools_tests.rs rename to crates/forge-web-account/src/pages/account_tools_tests.rs diff --git a/crates/forge-web/src/pages/activity.rs b/crates/forge-web-account/src/pages/activity.rs similarity index 100% rename from crates/forge-web/src/pages/activity.rs rename to crates/forge-web-account/src/pages/activity.rs diff --git a/crates/forge-web/src/pages/admin_backups.rs b/crates/forge-web-account/src/pages/admin_backups.rs similarity index 100% rename from crates/forge-web/src/pages/admin_backups.rs rename to crates/forge-web-account/src/pages/admin_backups.rs diff --git a/crates/forge-web/src/pages/admin_health.rs b/crates/forge-web-account/src/pages/admin_health.rs similarity index 100% rename from crates/forge-web/src/pages/admin_health.rs rename to crates/forge-web-account/src/pages/admin_health.rs diff --git a/crates/forge-web/src/pages/admin_live_tests.rs b/crates/forge-web-account/src/pages/admin_live_tests.rs similarity index 100% rename from crates/forge-web/src/pages/admin_live_tests.rs rename to crates/forge-web-account/src/pages/admin_live_tests.rs diff --git a/crates/forge-web/src/pages/admin_mail.rs b/crates/forge-web-account/src/pages/admin_mail.rs similarity index 100% rename from crates/forge-web/src/pages/admin_mail.rs rename to crates/forge-web-account/src/pages/admin_mail.rs diff --git a/crates/forge-web/src/pages/admin_replication.rs b/crates/forge-web-account/src/pages/admin_replication.rs similarity index 100% rename from crates/forge-web/src/pages/admin_replication.rs rename to crates/forge-web-account/src/pages/admin_replication.rs diff --git a/crates/forge-web/src/pages/admin_server.rs b/crates/forge-web-account/src/pages/admin_server.rs similarity index 100% rename from crates/forge-web/src/pages/admin_server.rs rename to crates/forge-web-account/src/pages/admin_server.rs diff --git a/crates/forge-web/src/pages/admin_user_detail.rs b/crates/forge-web-account/src/pages/admin_user_detail.rs similarity index 100% rename from crates/forge-web/src/pages/admin_user_detail.rs rename to crates/forge-web-account/src/pages/admin_user_detail.rs diff --git a/crates/forge-web/src/pages/assets.rs b/crates/forge-web-account/src/pages/assets.rs similarity index 98% rename from crates/forge-web/src/pages/assets.rs rename to crates/forge-web-account/src/pages/assets.rs index 54488ea..97c778f 100644 --- a/crates/forge-web/src/pages/assets.rs +++ b/crates/forge-web-account/src/pages/assets.rs @@ -44,7 +44,7 @@ async fn main_css(cx: &Cx) -> Result<(StatusCode, HeaderMap, &'static str)> { /// The soft-navigation script (`assets/nav.js`). Served from the same origin, so the CSP's /// `script-src 'self'` covers it; the page loads it with `defer`, and without it pages still work. -const NAV_JS: &str = include_str!("../../assets/nav.js"); +const NAV_JS: &str = include_str!("../../../forge-web/assets/nav.js"); /// Immutable like `main.css`: the URL carries a content hash. #[route(GET "/assets/nav.js")] @@ -119,8 +119,8 @@ async fn custom_css_route(cx: &Cx) -> Result<(StatusCode, HeaderMap, String)> { // The offline page (shown by the service worker when a page load finds the server down) and its // script. Not hashed and not immutable: the service worker fetches them again on each update. -const OFFLINE_HTML: &str = include_str!("../../assets/offline.html"); -const OFFLINE_JS: &str = include_str!("../../assets/offline.js"); +const OFFLINE_HTML: &str = include_str!("../../../forge-web/assets/offline.html"); +const OFFLINE_JS: &str = include_str!("../../../forge-web/assets/offline.js"); #[route(GET "/assets/offline.html")] async fn offline_html(cx: &Cx) -> Result<(StatusCode, HeaderMap, &'static str)> { diff --git a/crates/forge-web/src/pages/audit_log.rs b/crates/forge-web-account/src/pages/audit_log.rs similarity index 100% rename from crates/forge-web/src/pages/audit_log.rs rename to crates/forge-web-account/src/pages/audit_log.rs diff --git a/crates/forge-web/src/pages/avatars.rs b/crates/forge-web-account/src/pages/avatars.rs similarity index 100% rename from crates/forge-web/src/pages/avatars.rs rename to crates/forge-web-account/src/pages/avatars.rs diff --git a/crates/forge-web/src/pages/banner.rs b/crates/forge-web-account/src/pages/banner.rs similarity index 100% rename from crates/forge-web/src/pages/banner.rs rename to crates/forge-web-account/src/pages/banner.rs diff --git a/crates/forge-web/src/pages/explore.rs b/crates/forge-web-account/src/pages/explore.rs similarity index 100% rename from crates/forge-web/src/pages/explore.rs rename to crates/forge-web-account/src/pages/explore.rs diff --git a/crates/forge-web/src/pages/forgot.rs b/crates/forge-web-account/src/pages/forgot.rs similarity index 100% rename from crates/forge-web/src/pages/forgot.rs rename to crates/forge-web-account/src/pages/forgot.rs diff --git a/crates/forge-web/src/pages/home.rs b/crates/forge-web-account/src/pages/home.rs similarity index 100% rename from crates/forge-web/src/pages/home.rs rename to crates/forge-web-account/src/pages/home.rs diff --git a/crates/forge-web/src/pages/import.rs b/crates/forge-web-account/src/pages/import.rs similarity index 100% rename from crates/forge-web/src/pages/import.rs rename to crates/forge-web-account/src/pages/import.rs diff --git a/crates/forge-web/src/pages/import_tests.rs b/crates/forge-web-account/src/pages/import_tests.rs similarity index 100% rename from crates/forge-web/src/pages/import_tests.rs rename to crates/forge-web-account/src/pages/import_tests.rs diff --git a/crates/forge-web/src/pages/invites.rs b/crates/forge-web-account/src/pages/invites.rs similarity index 100% rename from crates/forge-web/src/pages/invites.rs rename to crates/forge-web-account/src/pages/invites.rs diff --git a/crates/forge-web/src/pages/login.rs b/crates/forge-web-account/src/pages/login.rs similarity index 100% rename from crates/forge-web/src/pages/login.rs rename to crates/forge-web-account/src/pages/login.rs diff --git a/crates/forge-web-account/src/pages/mod.rs b/crates/forge-web-account/src/pages/mod.rs new file mode 100644 index 0000000..ccd7e52 --- /dev/null +++ b/crates/forge-web-account/src/pages/mod.rs @@ -0,0 +1,64 @@ +//! Server-rendered pages. + +pub use forge_web_pages::pages::*; + +#[cfg(test)] +mod account_tools_tests; +pub mod activity; +pub mod admin_backups; +pub mod admin_health; +#[cfg(test)] +mod admin_live_tests; +pub mod admin_mail; +pub mod admin_replication; +pub mod admin_server; +pub mod admin_user_detail; +pub mod assets; +pub mod audit_log; +pub mod avatars; +pub mod banner; +pub mod explore; +pub mod forgot; +pub mod home; +pub mod import; +#[cfg(test)] +mod import_tests; +pub mod invites; +pub mod login; +pub mod needs_you; +pub mod new_repo; +pub mod not_found_page; +pub mod org_ctx; +pub mod org_live; +pub mod org_members; +pub mod org_new; +pub mod org_settings; +pub mod org_teams; +pub mod palette; +pub mod passkeys; +#[cfg(test)] +mod passkeys_tests; +pub mod profile; +pub mod profile_calendar; +pub mod profile_pins; +pub mod register; +#[cfg(test)] +mod releases_tests; +pub mod settings_appearance; +pub mod settings_export; +pub mod settings_gpg; +#[cfg(test)] +mod settings_gpg_tests; +pub mod settings_keys; +pub mod settings_live; +pub mod settings_notifications; +pub mod settings_profile; +pub mod settings_security; +pub mod settings_sessions; +pub mod settings_tokens; +pub mod setup; +pub mod shell_events; +pub mod snippets; +pub mod snippets_live; +pub mod theme_cookie; +pub mod user_prefs; diff --git a/crates/forge-web/src/pages/needs_you.rs b/crates/forge-web-account/src/pages/needs_you.rs similarity index 100% rename from crates/forge-web/src/pages/needs_you.rs rename to crates/forge-web-account/src/pages/needs_you.rs diff --git a/crates/forge-web/src/pages/new_repo.rs b/crates/forge-web-account/src/pages/new_repo.rs similarity index 97% rename from crates/forge-web/src/pages/new_repo.rs rename to crates/forge-web-account/src/pages/new_repo.rs index d32bb80..e2822f9 100644 --- a/crates/forge-web/src/pages/new_repo.rs +++ b/crates/forge-web-account/src/pages/new_repo.rs @@ -34,62 +34,62 @@ const LICENSES: &[(&str, &str, &str)] = &[ ( "MIT", "MIT License", - include_str!("../../assets/licenses/MIT.txt"), + include_str!("../../../forge-web/assets/licenses/MIT.txt"), ), ( "Apache-2.0", "Apache License 2.0", - include_str!("../../assets/licenses/Apache-2.0.txt"), + include_str!("../../../forge-web/assets/licenses/Apache-2.0.txt"), ), ( "GPL-3.0-only", "GNU GPL v3", - include_str!("../../assets/licenses/GPL-3.0-only.txt"), + include_str!("../../../forge-web/assets/licenses/GPL-3.0-only.txt"), ), ( "AGPL-3.0-only", "GNU AGPL v3", - include_str!("../../assets/licenses/AGPL-3.0-only.txt"), + include_str!("../../../forge-web/assets/licenses/AGPL-3.0-only.txt"), ), ( "LGPL-3.0-only", "GNU LGPL v3", - include_str!("../../assets/licenses/LGPL-3.0-only.txt"), + include_str!("../../../forge-web/assets/licenses/LGPL-3.0-only.txt"), ), ( "GPL-2.0-only", "GNU GPL v2", - include_str!("../../assets/licenses/GPL-2.0-only.txt"), + include_str!("../../../forge-web/assets/licenses/GPL-2.0-only.txt"), ), ( "MPL-2.0", "Mozilla Public License 2.0", - include_str!("../../assets/licenses/MPL-2.0.txt"), + include_str!("../../../forge-web/assets/licenses/MPL-2.0.txt"), ), ( "BSD-3-Clause", "BSD 3-Clause", - include_str!("../../assets/licenses/BSD-3-Clause.txt"), + include_str!("../../../forge-web/assets/licenses/BSD-3-Clause.txt"), ), ( "BSD-2-Clause", "BSD 2-Clause", - include_str!("../../assets/licenses/BSD-2-Clause.txt"), + include_str!("../../../forge-web/assets/licenses/BSD-2-Clause.txt"), ), ( "ISC", "ISC License", - include_str!("../../assets/licenses/ISC.txt"), + include_str!("../../../forge-web/assets/licenses/ISC.txt"), ), ( "BSL-1.0", "Boost Software License 1.0", - include_str!("../../assets/licenses/BSL-1.0.txt"), + include_str!("../../../forge-web/assets/licenses/BSL-1.0.txt"), ), ( "Unlicense", "The Unlicense", - include_str!("../../assets/licenses/Unlicense.txt"), + include_str!("../../../forge-web/assets/licenses/Unlicense.txt"), ), ]; diff --git a/crates/forge-web/src/pages/not_found_page.rs b/crates/forge-web-account/src/pages/not_found_page.rs similarity index 100% rename from crates/forge-web/src/pages/not_found_page.rs rename to crates/forge-web-account/src/pages/not_found_page.rs diff --git a/crates/forge-web/src/pages/org_ctx.rs b/crates/forge-web-account/src/pages/org_ctx.rs similarity index 100% rename from crates/forge-web/src/pages/org_ctx.rs rename to crates/forge-web-account/src/pages/org_ctx.rs diff --git a/crates/forge-web/src/pages/org_live.rs b/crates/forge-web-account/src/pages/org_live.rs similarity index 100% rename from crates/forge-web/src/pages/org_live.rs rename to crates/forge-web-account/src/pages/org_live.rs diff --git a/crates/forge-web/src/pages/org_members.rs b/crates/forge-web-account/src/pages/org_members.rs similarity index 100% rename from crates/forge-web/src/pages/org_members.rs rename to crates/forge-web-account/src/pages/org_members.rs diff --git a/crates/forge-web/src/pages/org_new.rs b/crates/forge-web-account/src/pages/org_new.rs similarity index 100% rename from crates/forge-web/src/pages/org_new.rs rename to crates/forge-web-account/src/pages/org_new.rs diff --git a/crates/forge-web/src/pages/org_settings.rs b/crates/forge-web-account/src/pages/org_settings.rs similarity index 100% rename from crates/forge-web/src/pages/org_settings.rs rename to crates/forge-web-account/src/pages/org_settings.rs diff --git a/crates/forge-web/src/pages/org_teams.rs b/crates/forge-web-account/src/pages/org_teams.rs similarity index 100% rename from crates/forge-web/src/pages/org_teams.rs rename to crates/forge-web-account/src/pages/org_teams.rs diff --git a/crates/forge-web/src/pages/palette.rs b/crates/forge-web-account/src/pages/palette.rs similarity index 100% rename from crates/forge-web/src/pages/palette.rs rename to crates/forge-web-account/src/pages/palette.rs diff --git a/crates/forge-web/src/pages/passkeys.rs b/crates/forge-web-account/src/pages/passkeys.rs similarity index 100% rename from crates/forge-web/src/pages/passkeys.rs rename to crates/forge-web-account/src/pages/passkeys.rs diff --git a/crates/forge-web/src/pages/passkeys_tests.rs b/crates/forge-web-account/src/pages/passkeys_tests.rs similarity index 100% rename from crates/forge-web/src/pages/passkeys_tests.rs rename to crates/forge-web-account/src/pages/passkeys_tests.rs diff --git a/crates/forge-web/src/pages/profile.rs b/crates/forge-web-account/src/pages/profile.rs similarity index 100% rename from crates/forge-web/src/pages/profile.rs rename to crates/forge-web-account/src/pages/profile.rs diff --git a/crates/forge-web/src/pages/profile_calendar.rs b/crates/forge-web-account/src/pages/profile_calendar.rs similarity index 100% rename from crates/forge-web/src/pages/profile_calendar.rs rename to crates/forge-web-account/src/pages/profile_calendar.rs diff --git a/crates/forge-web/src/pages/profile_pins.rs b/crates/forge-web-account/src/pages/profile_pins.rs similarity index 100% rename from crates/forge-web/src/pages/profile_pins.rs rename to crates/forge-web-account/src/pages/profile_pins.rs diff --git a/crates/forge-web/src/pages/register.rs b/crates/forge-web-account/src/pages/register.rs similarity index 100% rename from crates/forge-web/src/pages/register.rs rename to crates/forge-web-account/src/pages/register.rs diff --git a/crates/forge-web/src/pages/releases_tests.rs b/crates/forge-web-account/src/pages/releases_tests.rs similarity index 100% rename from crates/forge-web/src/pages/releases_tests.rs rename to crates/forge-web-account/src/pages/releases_tests.rs diff --git a/crates/forge-web/src/pages/settings_appearance.rs b/crates/forge-web-account/src/pages/settings_appearance.rs similarity index 100% rename from crates/forge-web/src/pages/settings_appearance.rs rename to crates/forge-web-account/src/pages/settings_appearance.rs diff --git a/crates/forge-web/src/pages/settings_export.rs b/crates/forge-web-account/src/pages/settings_export.rs similarity index 100% rename from crates/forge-web/src/pages/settings_export.rs rename to crates/forge-web-account/src/pages/settings_export.rs diff --git a/crates/forge-web/src/pages/settings_gpg.rs b/crates/forge-web-account/src/pages/settings_gpg.rs similarity index 100% rename from crates/forge-web/src/pages/settings_gpg.rs rename to crates/forge-web-account/src/pages/settings_gpg.rs diff --git a/crates/forge-web/src/pages/settings_gpg_tests.rs b/crates/forge-web-account/src/pages/settings_gpg_tests.rs similarity index 100% rename from crates/forge-web/src/pages/settings_gpg_tests.rs rename to crates/forge-web-account/src/pages/settings_gpg_tests.rs diff --git a/crates/forge-web/src/pages/settings_keys.rs b/crates/forge-web-account/src/pages/settings_keys.rs similarity index 100% rename from crates/forge-web/src/pages/settings_keys.rs rename to crates/forge-web-account/src/pages/settings_keys.rs diff --git a/crates/forge-web/src/pages/settings_live.rs b/crates/forge-web-account/src/pages/settings_live.rs similarity index 100% rename from crates/forge-web/src/pages/settings_live.rs rename to crates/forge-web-account/src/pages/settings_live.rs diff --git a/crates/forge-web/src/pages/settings_notifications.rs b/crates/forge-web-account/src/pages/settings_notifications.rs similarity index 100% rename from crates/forge-web/src/pages/settings_notifications.rs rename to crates/forge-web-account/src/pages/settings_notifications.rs diff --git a/crates/forge-web/src/pages/settings_profile.rs b/crates/forge-web-account/src/pages/settings_profile.rs similarity index 100% rename from crates/forge-web/src/pages/settings_profile.rs rename to crates/forge-web-account/src/pages/settings_profile.rs diff --git a/crates/forge-web/src/pages/settings_security.rs b/crates/forge-web-account/src/pages/settings_security.rs similarity index 100% rename from crates/forge-web/src/pages/settings_security.rs rename to crates/forge-web-account/src/pages/settings_security.rs diff --git a/crates/forge-web/src/pages/settings_sessions.rs b/crates/forge-web-account/src/pages/settings_sessions.rs similarity index 100% rename from crates/forge-web/src/pages/settings_sessions.rs rename to crates/forge-web-account/src/pages/settings_sessions.rs diff --git a/crates/forge-web/src/pages/settings_tokens.rs b/crates/forge-web-account/src/pages/settings_tokens.rs similarity index 100% rename from crates/forge-web/src/pages/settings_tokens.rs rename to crates/forge-web-account/src/pages/settings_tokens.rs diff --git a/crates/forge-web/src/pages/setup.rs b/crates/forge-web-account/src/pages/setup.rs similarity index 100% rename from crates/forge-web/src/pages/setup.rs rename to crates/forge-web-account/src/pages/setup.rs diff --git a/crates/forge-web/src/pages/shell_events.rs b/crates/forge-web-account/src/pages/shell_events.rs similarity index 100% rename from crates/forge-web/src/pages/shell_events.rs rename to crates/forge-web-account/src/pages/shell_events.rs diff --git a/crates/forge-web/src/pages/snippets.rs b/crates/forge-web-account/src/pages/snippets.rs similarity index 100% rename from crates/forge-web/src/pages/snippets.rs rename to crates/forge-web-account/src/pages/snippets.rs diff --git a/crates/forge-web/src/pages/snippets_live.rs b/crates/forge-web-account/src/pages/snippets_live.rs similarity index 100% rename from crates/forge-web/src/pages/snippets_live.rs rename to crates/forge-web-account/src/pages/snippets_live.rs diff --git a/crates/forge-web/src/pages/theme_cookie.rs b/crates/forge-web-account/src/pages/theme_cookie.rs similarity index 100% rename from crates/forge-web/src/pages/theme_cookie.rs rename to crates/forge-web-account/src/pages/theme_cookie.rs diff --git a/crates/forge-web/src/pages/user_prefs.rs b/crates/forge-web-account/src/pages/user_prefs.rs similarity index 100% rename from crates/forge-web/src/pages/user_prefs.rs rename to crates/forge-web-account/src/pages/user_prefs.rs diff --git a/crates/forge-web-app/Cargo.toml b/crates/forge-web-app/Cargo.toml index 5be67e6..1c345ef 100644 --- a/crates/forge-web-app/Cargo.toml +++ b/crates/forge-web-app/Cargo.toml @@ -28,9 +28,7 @@ serde_json.workspace = true form_urlencoded.workspace = true jiff.workspace = true base64.workspace = true -subtle.workspace = true tracing.workspace = true -tracing-subscriber = { workspace = true, features = ["env-filter"] } tokio-util = { workspace = true, features = ["io"] } http-body.workspace = true rand.workspace = true @@ -41,7 +39,6 @@ time.workspace = true reqwest = { workspace = true } hmac.workspace = true similar = { workspace = true } -multer.workspace = true ulid.workspace = true lettre.workspace = true zip = { workspace = true } @@ -61,8 +58,6 @@ sha2.workspace = true [dev-dependencies] tempfile.workspace = true image = { workspace = true } -scraper = { workspace = true } -webauthn-authenticator-rs = { version = "0.6.2", features = ["softpasskey"] } [lints] workspace = true diff --git a/crates/forge-web-app/src/test_support/mod.rs b/crates/forge-web-app/src/test_support/mod.rs index 2585a86..689ab17 100644 --- a/crates/forge-web-app/src/test_support/mod.rs +++ b/crates/forge-web-app/src/test_support/mod.rs @@ -19,7 +19,6 @@ use topcoat::cookie::CookieLayer; use topcoat::router::tower::TowerLayer; use topcoat::router::{Compression, Router, RouterBuilderDiscoverExt}; -#[cfg(not(test))] use crate::layers::RepoMovedLayer; use crate::state::AppState; use crate::throttle::Throttle; @@ -103,26 +102,32 @@ pub async fn test_state(dir: &Path) -> AppState { } } -/// The public router as boot.rs builds it, minus the listeners. This crate's own tests have no -/// pages, so the layers scoped to page paths are left out there. +/// The public router as boot.rs builds it, minus the listeners. A crate's own tests link only +/// the routes below it, so the account layer joins only when its `/settings` pages are there. pub fn app_router(state: AppState) -> Router { let builder = Router::builder().discover().with(state); - #[cfg(not(test))] - let builder = builder.layer(crate::layers::AccountWriteLayer); - let builder = builder.layer(CookieLayer::new()); - #[cfg(not(test))] - let builder = builder + let builder = if has_settings_pages() { + builder.layer(crate::layers::AccountWriteLayer) + } else { + builder + }; + builder + .layer(CookieLayer::new()) .layer(RepoMovedLayer) .layer(crate::layers::RepoSettingsWriteLayer) .layer(crate::layers::PullWriteLayer) .layer(crate::layers::DiscussionWriteLayer) - .layer(crate::layers::OrgWriteLayer); - builder + .layer(crate::layers::OrgWriteLayer) .layer(TowerLayer::new(crate::compression::ResponseCompression)) .with(Compression::disable()) .build() } +fn has_settings_pages() -> bool { + topcoat::internal::inventory::iter::<&'static dyn topcoat::router::Page>() + .any(|page| page.path().to_string().starts_with("/settings")) +} + /// Creates a session for `user_id` that expires in an hour and has no user agent. pub async fn create_session(store: &Store, user_id: &str, token: &str, csrf: &str) { store diff --git a/crates/forge-web-pages/Cargo.toml b/crates/forge-web-pages/Cargo.toml new file mode 100644 index 0000000..f4bee3d --- /dev/null +++ b/crates/forge-web-pages/Cargo.toml @@ -0,0 +1,46 @@ +[package] +name = "forge-web-pages" +description = "forge pages that the rest build on: repo, issues, CI runs, wiki, releases and settings" +version.workspace = true +edition.workspace = true +license.workspace = true +publish = false + +[features] +test-support = ["forge-web-app/test-support", "dep:tempfile"] + +[dependencies] +forge-web-app.workspace = true +forge-core.workspace = true +forge-git.workspace = true +forge-ci.workspace = true +forge-web-base.workspace = true +topcoat = { workspace = true, default-features = false, features = ["router", "view", "runtime", "cookie", "asset", "serve", "sse", "discover", "compression", "multipart", "tower"] } +tokio.workspace = true +futures-util.workspace = true +bytes.workspace = true +http.workspace = true +http-body-util.workspace = true +serde.workspace = true +serde_json.workspace = true +form_urlencoded.workspace = true +tracing.workspace = true +http-body.workspace = true +hex.workspace = true +nix = { workspace = true } +time.workspace = true +reqwest = { workspace = true } +similar = { workspace = true } +multer.workspace = true +zip = { workspace = true } +tar.workspace = true + +tempfile = { workspace = true, optional = true } + +[dev-dependencies] +forge-web-app = { workspace = true, features = ["test-support"] } +tempfile.workspace = true +image = { workspace = true } + +[lints] +workspace = true diff --git a/crates/forge-web-pages/src/lib.rs b/crates/forge-web-pages/src/lib.rs new file mode 100644 index 0000000..1be235f --- /dev/null +++ b/crates/forge-web-pages/src/lib.rs @@ -0,0 +1,13 @@ +//! forge pages. + +#![recursion_limit = "256"] + +#[cfg(any(test, feature = "test-support"))] +pub(crate) use forge_web_app::test_support; +pub(crate) use forge_web_app::{ + api, audit, auth, automerge, blobs, ci, client_ip, i18n, internal, layers, live, merge, + merge_queue, notify, notify_hub, oci, package_ops, post_update, raw, release_ops, render, + replication, repo_stats, state, templates, views, webhooks, +}; + +pub mod pages; diff --git a/crates/forge-web/src/pages/admin_runners.rs b/crates/forge-web-pages/src/pages/admin_runners.rs similarity index 99% rename from crates/forge-web/src/pages/admin_runners.rs rename to crates/forge-web-pages/src/pages/admin_runners.rs index c957b5f..f364740 100644 --- a/crates/forge-web/src/pages/admin_runners.rs +++ b/crates/forge-web-pages/src/pages/admin_runners.rs @@ -380,7 +380,7 @@ fn list_href(page: u64, notice: &str) -> String { /// A text link that asks first, in place; the POST only fires from the confirm button. For actions /// that are not destructive, so the confirm button is soft. #[component] -pub(crate) async fn confirm_post( +pub async fn confirm_post( cx: &Cx, lang: Lang, csrf: &str, diff --git a/crates/forge-web/src/pages/admin_users.rs b/crates/forge-web-pages/src/pages/admin_users.rs similarity index 99% rename from crates/forge-web/src/pages/admin_users.rs rename to crates/forge-web-pages/src/pages/admin_users.rs index a465057..5738678 100644 --- a/crates/forge-web/src/pages/admin_users.rs +++ b/crates/forge-web-pages/src/pages/admin_users.rs @@ -290,7 +290,7 @@ async fn users_view( /// The rail of the Users tab: Users and Invites. `current` is `users` or `invites`. #[component] -pub(crate) async fn users_rail(cx: &Cx, lang: Lang, current: &'static str) -> Result { +pub async fn users_rail(cx: &Cx, lang: Lang, current: &'static str) -> Result { let items = vec![ RailItem { name: g::t(lang, K::Users).to_owned(), @@ -395,7 +395,7 @@ async fn users_create(cx: &Cx, Form(form): Form) -> Result Result<(User, Session)> { +pub async fn admin_only(cx: &Cx) -> Result<(User, Session)> { match current_user(cx).await? { Some(viewer) if viewer.0.is_admin => Ok(viewer), _ => Err(not_found().into()), diff --git a/crates/forge-web/src/pages/ci_estimate.rs b/crates/forge-web-pages/src/pages/ci_estimate.rs similarity index 100% rename from crates/forge-web/src/pages/ci_estimate.rs rename to crates/forge-web-pages/src/pages/ci_estimate.rs diff --git a/crates/forge-web/src/pages/ci_fail.rs b/crates/forge-web-pages/src/pages/ci_fail.rs similarity index 96% rename from crates/forge-web/src/pages/ci_fail.rs rename to crates/forge-web-pages/src/pages/ci_fail.rs index a9cb766..3f64a16 100644 --- a/crates/forge-web/src/pages/ci_fail.rs +++ b/crates/forge-web-pages/src/pages/ci_fail.rs @@ -38,7 +38,7 @@ fn first_error(lines: &[String]) -> Option { /// The values of the failure block, read once per run page. #[derive(Clone)] -pub(crate) struct FailFirst { +pub struct FailFirst { job_name: String, job_href: String, message: String, @@ -53,7 +53,7 @@ pub(crate) struct FailFirst { impl FailFirst { /// The log line the page opens at. - pub(crate) fn line_no(&self) -> Option { + pub fn line_no(&self) -> Option { self.line_no } } @@ -78,7 +78,7 @@ fn place_in(lines: &[String]) -> Option { } /// Reads the failed job's log tail (the same bounded read as the job page) and picks the lines to show. -pub(crate) async fn read( +pub async fn read( state: &AppState, title: &str, job_id: &str, @@ -116,7 +116,7 @@ pub(crate) async fn read( /// The failure row, pinned above the log, which opens at the first error line: why it failed, the /// place in the code, and a link to that line in the job's log. #[component] -pub(crate) async fn fail_first_block(cx: &Cx, lang: Lang, fail: FailFirst) -> Result { +pub async fn fail_first_block(cx: &Cx, lang: Lang, fail: FailFirst) -> Result { let line_href = fail.line_no.map(|no| format!("{}#L{no}", fail.job_href)); let why = if fail.message.is_empty() { fail.error.clone().unwrap_or_else(|| fail.job_name.clone()) diff --git a/crates/forge-web/src/pages/ci_job.rs b/crates/forge-web-pages/src/pages/ci_job.rs similarity index 98% rename from crates/forge-web/src/pages/ci_job.rs rename to crates/forge-web-pages/src/pages/ci_job.rs index 19515ee..4a502eb 100644 --- a/crates/forge-web/src/pages/ci_job.rs +++ b/crates/forge-web-pages/src/pages/ci_job.rs @@ -83,11 +83,11 @@ fn whole_utf8_len(buf: &[u8]) -> usize { /// What the job page shows of a log: the text, whether the start was cut, the byte offset just /// past the text, and the number of its first line in the whole log. -pub(crate) struct Tail { - pub(crate) text: String, - pub(crate) truncated: bool, - pub(crate) offset: u64, - pub(crate) first_line: u64, +pub struct Tail { + pub text: String, + pub truncated: bool, + pub offset: u64, + pub first_line: u64, } /// Most logs the newline cache keeps. A full cache drops an arbitrary entry. @@ -144,12 +144,12 @@ async fn newlines_before(path: &Path, end: u64) -> Result { } /// The last `TAIL_BYTES` of a log, from a line boundary. A log that does not exist yet is empty. -pub(crate) async fn log_tail(path: &Path) -> Result { +pub async fn log_tail(path: &Path) -> Result { log_tail_of(path, TAIL_BYTES).await } /// The last `max` bytes of a log, from a line boundary. -pub(crate) async fn log_tail_of(path: &Path, max: u64) -> Result { +pub async fn log_tail_of(path: &Path, max: u64) -> Result { let mut file = match tokio::fs::File::open(path).await { Ok(file) => file, Err(e) if e.kind() == std::io::ErrorKind::NotFound => { @@ -199,7 +199,7 @@ pub(crate) async fn log_tail_of(path: &Path, max: u64) -> Result { /// The log from byte `offset`, at most `max` bytes. `offset` should be the start of a line, such as a /// step's. When the file goes on past the bytes read, the text is cut back to its last newline. A log /// that does not exist yet is empty. `truncated` is never set: nothing is cut at the start. -pub(crate) async fn log_from(path: &Path, offset: u64, max: u64) -> Result { +pub async fn log_from(path: &Path, offset: u64, max: u64) -> Result { let mut file = match tokio::fs::File::open(path).await { Ok(file) => file, Err(e) if e.kind() == std::io::ErrorKind::NotFound => { @@ -248,7 +248,7 @@ pub(crate) async fn log_from(path: &Path, offset: u64, max: u64) -> Result /// log grew or its state did). The stream ends when the job is terminal and a read after seeing /// that returns nothing, so every byte the runner wrote is sent. A job that is gone, a read /// error, or a repo the viewer can no longer read ends the stream. -pub(crate) fn follow_log( +pub fn follow_log( store: Store, live: Arc, job_id: String, diff --git a/crates/forge-web/src/pages/ci_runs.rs b/crates/forge-web-pages/src/pages/ci_runs.rs similarity index 99% rename from crates/forge-web/src/pages/ci_runs.rs rename to crates/forge-web-pages/src/pages/ci_runs.rs index a350f9d..7d96ebe 100644 --- a/crates/forge-web/src/pages/ci_runs.rs +++ b/crates/forge-web-pages/src/pages/ci_runs.rs @@ -101,7 +101,7 @@ fn viewer_user(ctx: &RepoCtx) -> Option<&User> { } /// Whether the viewer may change CI runs of this repo. Archived repos refuse. -pub(crate) fn can_write(ctx: &RepoCtx) -> bool { +pub fn can_write(ctx: &RepoCtx) -> bool { authorize( viewer_user(ctx), &ctx.repo, @@ -191,7 +191,7 @@ fn unix_of(stamp: &str) -> Option { } /// "3 minutes ago" for a stamp. An unreadable stamp is shown as it is stored. -pub(crate) fn age_text(lang: Lang, stamp: &str) -> String { +pub fn age_text(lang: Lang, stamp: &str) -> String { match unix_of(stamp) { Some(unix) => relative_time(lang, unix, now_unix()), None => stamp.to_owned(), @@ -199,7 +199,7 @@ pub(crate) fn age_text(lang: Lang, stamp: &str) -> String { } /// "1m 5s", or "" when the job never started. A running job counts up to now. -pub(crate) fn duration_text(lang: Lang, started: Option<&str>, finished: Option<&str>) -> String { +pub fn duration_text(lang: Lang, started: Option<&str>, finished: Option<&str>) -> String { let Some(start) = started.and_then(unix_of) else { return String::new(); }; @@ -218,7 +218,7 @@ fn secs_text(lang: Lang, secs: i64) -> String { /// The duration formats of `lang` with `{m}` and `{s}` where the numbers go, for the client ticker: /// the one with minutes and the seconds-only one. -pub(crate) fn duration_templates(lang: Lang) -> (String, String) { +pub fn duration_templates(lang: Lang) -> (String, String) { ( g::duration_minutes(lang, 111_111, 222_222) .replace("111111", "{m}") @@ -1472,7 +1472,7 @@ fn row_meta(run: &CiRun, jobs: &[Timing], actor: &str, lang: Lang) -> RowMeta { } /// Drops the ANSI escape sequences and the other control characters (a tab stays) of a log line. -pub(crate) fn strip_ansi(line: &str) -> String { +pub fn strip_ansi(line: &str) -> String { let mut out = String::with_capacity(line.len()); let mut chars = line.chars().peekable(); while let Some(c) = chars.next() { @@ -1863,7 +1863,7 @@ struct RunHeader { /// Whether a branch, tag or pull request still reaches `oid`. A force push that overwrote the commit /// leaves it unreachable: its run then has no commit link and cannot be run again. -pub(crate) async fn commit_reachable_for(path: &Path, oid: &str) -> Result { +pub async fn commit_reachable_for(path: &Path, oid: &str) -> Result { let (path, oid) = (path.to_path_buf(), oid.to_owned()); Ok(tokio::task::spawn_blocking(move || commit_reachable(&path, &oid)).await??) } @@ -2771,7 +2771,7 @@ async fn run_page(cx: &Cx) -> Result { /// The dock's bars: the newest commits of the default branch, oldest first, each with its latest CI /// state. Empty when the branch cannot be read, which draws no strip. -pub(crate) async fn dock_bars(state: &AppState, ctx: &RepoCtx) -> Vec { +pub async fn dock_bars(state: &AppState, ctx: &RepoCtx) -> Vec { let path = ctx.path.clone(); let branch = ctx.repo.default_branch.clone(); let head = tokio::task::spawn_blocking(move || { @@ -2832,7 +2832,7 @@ async fn manual_run_post(cx: &Cx, Form(form): Form) -> Result Result { +pub async fn run_status(store: &Store, run_id: &str) -> Result { Ok(store .run_by_id(run_id) .await? diff --git a/crates/forge-web/src/pages/code_live.rs b/crates/forge-web-pages/src/pages/code_live.rs similarity index 100% rename from crates/forge-web/src/pages/code_live.rs rename to crates/forge-web-pages/src/pages/code_live.rs diff --git a/crates/forge-web/src/pages/discussion_settings.rs b/crates/forge-web-pages/src/pages/discussion_settings.rs similarity index 98% rename from crates/forge-web/src/pages/discussion_settings.rs rename to crates/forge-web-pages/src/pages/discussion_settings.rs index 4324215..66b220f 100644 --- a/crates/forge-web/src/pages/discussion_settings.rs +++ b/crates/forge-web-pages/src/pages/discussion_settings.rs @@ -25,7 +25,7 @@ path_param!(repo); /// The Discussions feature: one switch, then its hint. `enabled` is the current state. The switch submits /// the form on change (`data-autosubmit`); an unchecked box sends no `enabled`, which the handler reads as off. #[component] -pub(crate) async fn discussions_switch( +pub async fn discussions_switch( cx: &Cx, lang: Lang, action: String, diff --git a/crates/forge-web/src/pages/edit_history.rs b/crates/forge-web-pages/src/pages/edit_history.rs similarity index 53% rename from crates/forge-web/src/pages/edit_history.rs rename to crates/forge-web-pages/src/pages/edit_history.rs index 633e0ea..f1f80c4 100644 --- a/crates/forge-web/src/pages/edit_history.rs +++ b/crates/forge-web-pages/src/pages/edit_history.rs @@ -40,7 +40,7 @@ const CONTEXT_LINES: usize = 3; const KINDS: [&str; 3] = ["issue", "comment", "review_comment"]; /// The history URL of one target of an item: `/{o}/{r}/{issues|pulls}/{n}/history/{kind}/{id}`. -pub(crate) fn history_href( +pub fn history_href( owner: &str, repo_name: &str, kind: ItemKind, @@ -57,7 +57,7 @@ pub(crate) fn history_href( } /// Edit counts for a batch of targets, one query per call. Targets never edited are absent. -pub(crate) async fn edit_counts( +pub async fn edit_counts( state: &AppState, target_kind: &str, ids: &[&str], @@ -66,7 +66,7 @@ pub(crate) async fn edit_counts( } /// Edit counts for the root comments and replies of `threads`, shared by every thread of a page. -pub(crate) async fn thread_edit_counts( +pub async fn thread_edit_counts( state: &AppState, threads: &[Thread], ) -> Result>> { @@ -331,310 +331,3 @@ async fn issue_history(cx: &Cx) -> Result { async fn pull_history(cx: &Cx) -> Result { history_route(cx, ItemKind::Pull).await } - -#[cfg(test)] -mod tests { - use forge_core::{Side, Visibility}; - use topcoat::router::request::Request; - use topcoat::router::{Body, Router, to_bytes}; - - use crate::auth::SESSION_COOKIE; - use crate::test_support::fixture::{Fixture, OWNER, REPO}; - - /// Sends one request and returns `(status, body)`. - async fn send(router: &Router, uri: &str, token: Option<&str>) -> (u16, String) { - let mut req = Request::builder().method("GET").uri(uri); - if let Some(token) = token { - req = req.header("cookie", format!("__Host-{SESSION_COOKIE}={token}")); - } - let res = router.handle(req.body(Body::empty()).unwrap()).await; - let status = res.status().as_u16(); - let bytes = to_bytes(res.into_body(), usize::MAX).await.unwrap(); - (status, String::from_utf8_lossy(&bytes).into_owned()) - } - - /// The repo owner with a session whose token is `tahinli`. - async fn tahinli(fx: &Fixture) -> forge_core::User { - let owner = fx.store.user_by_username(OWNER).await.unwrap().unwrap(); - crate::test_support::create_session(&fx.store, &owner.id, "tahinli", "tahinli-csrf").await; - owner - } - - async fn repo_id(fx: &Fixture) -> String { - fx.store - .repo_by_owner_and_name(OWNER, REPO) - .await - .unwrap() - .unwrap() - .id - } - - fn hex_oid(c: char) -> String { - std::iter::repeat_n(c, 40).collect() - } - - /// Every scenario on the public repo shares one fixture. Each makes its own issue or pull and - /// reads its numbers from the store, so no scenario depends on another's data. - #[tokio::test] - async fn public_histories_show_diffs_markers_and_refusals() { - let fx = Fixture::new(Visibility::Public).await; - let owner = tahinli(&fx).await; - let id = repo_id(&fx).await; - - // A comment edited twice: a marker on the item page and two versions with diffs. - let issue = fx - .store - .create_issue(&id, &owner.id, "bug", "body") - .await - .unwrap(); - let comment = fx - .store - .add_comment(&issue.id, &owner.id, "one\ntwo\nthree") - .await - .unwrap(); - fx.store - .edit_comment(&comment.id, &owner.id, "one\nTWO\nthree") - .await - .unwrap(); - fx.store - .edit_comment(&comment.id, &owner.id, "one\nTWO\nthree\nfour") - .await - .unwrap(); - let item = format!("/tahinli/demo/issues/{}", issue.number); - let link = format!("{item}/history/comment/{}", comment.id); - - let (status, page) = send(&fx.router, &item, None).await; - assert_eq!(status, 200, "edited comment: item page"); - assert!( - page.contains("issue-edited"), - "edited comment: marker {page}" - ); - assert!( - page.contains(&format!("href=\"{link}\"")), - "edited comment: link {page}" - ); - - let (status, history) = send(&fx.router, &link, None).await; - assert_eq!(status, 200, "edited comment: history"); - assert_eq!( - history.matches(" bool { +pub fn can_triage(ctx: &RepoCtx) -> bool { let actor = ctx.viewer.as_ref().map(|(user, _)| user); !ctx.repo.archived && authorize(actor, &ctx.repo, ctx.role, ctx.org_role, Action::Triage).is_ok() } /// The repo fields and viewer flags that the label and milestone pages share. -pub(crate) struct RepoFrame { +pub struct RepoFrame { /// `owner/name`. pub title: String, pub csrf: String, @@ -53,7 +53,7 @@ pub(crate) struct RepoFrame { impl RepoFrame { /// The frame for a page on the Issues tab group. `active` is the header tab to mark. - pub(crate) async fn new(ctx: &RepoCtx, state: &AppState, active: &'static str) -> Result { + pub async fn new(ctx: &RepoCtx, state: &AppState, active: &'static str) -> Result { let csrf = ctx .viewer .as_ref() @@ -72,7 +72,7 @@ impl RepoFrame { /// The message for a failed store write that the form can show, or the error to propagate. A /// missing row is 404 and anything that is not a validation error is a server error. -pub(crate) fn refusal_message(e: forge_core::Error) -> Result { +pub fn refusal_message(e: forge_core::Error) -> Result { if matches!(e, forge_core::Error::NotFound) { return Err(not_found().into()); } @@ -85,12 +85,7 @@ pub(crate) fn refusal_message(e: forge_core::Error) -> Result { /// Links between the issue-adjacent pages of a repo: Issues, Labels and Milestones. The one named /// by `active` is the current page. #[component] -pub(crate) async fn issue_subnav( - cx: &Cx, - lang: Lang, - title: String, - active: String, -) -> Result { +pub async fn issue_subnav(cx: &Cx, lang: Lang, title: String, active: String) -> Result { let issues = format!("/{title}/issues"); let labels = format!("/{title}/labels"); let milestones = format!("/{title}/milestones"); @@ -121,14 +116,14 @@ pub(crate) async fn issue_subnav( } /// Every `key=value` pair of a urlencoded body, in order, with repeated keys kept. -pub(crate) fn form_pairs(raw: &[u8]) -> Vec<(String, String)> { +pub fn form_pairs(raw: &[u8]) -> Vec<(String, String)> { form_urlencoded::parse(raw) .map(|(k, v)| (k.into_owned(), v.into_owned())) .collect() } /// The first value for `key`, or an empty string. -pub(crate) fn form_field(pairs: &[(String, String)], key: &str) -> String { +pub fn form_field(pairs: &[(String, String)], key: &str) -> String { pairs .iter() .find(|(k, _)| k == key) @@ -137,7 +132,7 @@ pub(crate) fn form_field(pairs: &[(String, String)], key: &str) -> String { } /// Every value for `key`, in order. -pub(crate) fn form_all(pairs: &[(String, String)], key: &str) -> Vec { +pub fn form_all(pairs: &[(String, String)], key: &str) -> Vec { pairs .iter() .filter(|(k, _)| k == key) @@ -147,7 +142,7 @@ pub(crate) fn form_all(pairs: &[(String, String)], key: &str) -> Vec { /// The CSRF check and triage gate for a write. Returns the signed-in user. Anonymous viewers are /// sent to log in, a bad token is 403, and a viewer without Triage (or an archived repo) is 403. -pub(crate) async fn triage_guard(cx: &Cx, ctx: &RepoCtx, csrf: &str) -> Result { +pub async fn triage_guard(cx: &Cx, ctx: &RepoCtx, csrf: &str) -> Result { let (user, _session) = require_csrf(cx, csrf).await?; if ctx.repo.archived || authorize( @@ -166,12 +161,7 @@ pub(crate) async fn triage_guard(cx: &Cx, ctx: &RepoCtx, csrf: &str) -> Result Result { +pub async fn item_from_path(cx: &Cx, ctx: &RepoCtx, kind: ItemKind, number: &str) -> Result { let Some(n) = number.parse::().ok() else { return Err(not_found().into()); }; @@ -190,7 +180,7 @@ pub(crate) async fn item_from_path( } /// `/{owner}/{repo}/issues/{n}` or `/{owner}/{repo}/pulls/{n}` for this repo. -pub(crate) fn item_href(ctx: &RepoCtx, kind: ItemKind, number: i64) -> String { +pub fn item_href(ctx: &RepoCtx, kind: ItemKind, number: i64) -> String { format!( "/{}/{}/{}/{number}", ctx.repo.owner_name, @@ -201,7 +191,7 @@ pub(crate) fn item_href(ctx: &RepoCtx, kind: ItemKind, number: i64) -> String { /// The error box with a link back to where the action came from, in the viewer's language. #[component] -pub(crate) async fn action_error_at( +pub async fn action_error_at( cx: &Cx, lang: Lang, message: String, diff --git a/crates/forge-web/src/pages/issue_parts.rs b/crates/forge-web-pages/src/pages/issue_parts.rs similarity index 94% rename from crates/forge-web/src/pages/issue_parts.rs rename to crates/forge-web-pages/src/pages/issue_parts.rs index 2a7d4d2..29650e1 100644 --- a/crates/forge-web/src/pages/issue_parts.rs +++ b/crates/forge-web-pages/src/pages/issue_parts.rs @@ -38,13 +38,13 @@ use crate::webhooks::emit::{Sender, emit_comment, emit_item_action}; /// Which kind of item a page shows. It decides the URL segment of the item's own links and which /// row `{number}` names (an issue row or a pull request's issue row). #[derive(Clone, Copy, PartialEq, Eq)] -pub(crate) enum ItemKind { +pub enum ItemKind { Issue, Pull, } impl ItemKind { - pub(crate) fn segment(self) -> &'static str { + pub fn segment(self) -> &'static str { match self { ItemKind::Issue => "issues", ItemKind::Pull => "pulls", @@ -54,12 +54,12 @@ impl ItemKind { // Permissions -pub(crate) fn viewer(ctx: &RepoCtx) -> Option<&User> { +pub fn viewer(ctx: &RepoCtx) -> Option<&User> { ctx.viewer.as_ref().map(|(user, _)| user) } /// Triage or better on this repo (owner and instance admins included). Anonymous viewers never have it. -pub(crate) fn triage(ctx: &RepoCtx) -> bool { +pub fn triage(ctx: &RepoCtx) -> bool { authorize( viewer(ctx), &ctx.repo, @@ -72,12 +72,12 @@ pub(crate) fn triage(ctx: &RepoCtx) -> bool { /// Whether the viewer may add to an item's conversation: comments, reactions, review threads and /// reviews. A locked conversation takes these from Triage holders only. Authors keep their edits. -pub(crate) fn may_converse(ctx: &RepoCtx, item: &Issue) -> bool { +pub fn may_converse(ctx: &RepoCtx, item: &Issue) -> bool { !item.locked || triage(ctx) } /// The notice shown in place of the comment form on a conversation the viewer may not add to. -pub(crate) fn lock_message(lang: Lang, item: &Issue) -> String { +pub fn lock_message(lang: Lang, item: &Issue) -> String { match item.lock_reason.as_deref() { Some(reason) => g::conversation_locked_for(lang, lock_reason_label(lang, reason)), None => g::t(lang, K::ConversationLocked).to_owned(), @@ -85,7 +85,7 @@ pub(crate) fn lock_message(lang: Lang, item: &Issue) -> String { } /// The reader-facing text of a lock reason. Unknown values are shown as stored. -pub(crate) fn lock_reason_label(lang: Lang, reason: &str) -> &str { +pub fn lock_reason_label(lang: Lang, reason: &str) -> &str { match reason { "off_topic" => g::t(lang, K::LockOffTopic), "too_heated" => g::t(lang, K::LockTooHeated), @@ -97,19 +97,19 @@ pub(crate) fn lock_reason_label(lang: Lang, reason: &str) -> &str { /// Whether the viewer may edit or delete an item by `author_id`: its author or a Triage holder, /// signed in, on a repo that is not archived. -pub(crate) fn may_change(ctx: &RepoCtx, author_id: &str) -> bool { +pub fn may_change(ctx: &RepoCtx, author_id: &str) -> bool { !ctx.repo.archived && viewer(ctx).is_some_and(|user| user.id == author_id || triage(ctx)) } /// Write requests need an unarchived repo and a matching CSRF token. -pub(crate) fn check_write(ctx: &RepoCtx, session: &Session, csrf: &str) -> Result<()> { +pub fn check_write(ctx: &RepoCtx, session: &Session, csrf: &str) -> Result<()> { if ctx.repo.archived || !check_csrf(session, csrf) { return Err(forbidden().into()); } Ok(()) } -pub(crate) fn csrf_of(ctx: &RepoCtx) -> String { +pub fn csrf_of(ctx: &RepoCtx) -> String { ctx.viewer .as_ref() .map(|(_, session)| session.csrf_token.clone()) @@ -119,7 +119,7 @@ pub(crate) fn csrf_of(ctx: &RepoCtx) -> String { // Lookups /// Parses an issue number: digits only, greater than zero. Anything else is 404. -pub(crate) fn parse_number(raw: &str) -> Result { +pub fn parse_number(raw: &str) -> Result { match raw.parse::() { Ok(n) if n > 0 && raw.bytes().all(|b| b.is_ascii_digit()) => Ok(n), _ => Err(not_found().into()), @@ -128,13 +128,13 @@ pub(crate) fn parse_number(raw: &str) -> Result { /// Wakes the live pages of an issue after a successful write to it. Pull requests have no live /// page, so their writes wake nothing. -pub(crate) fn bump_live(state: &AppState, repo_id: &str, item: &Issue, kind: ItemKind) { +pub fn bump_live(state: &AppState, repo_id: &str, item: &Issue, kind: ItemKind) { if kind == ItemKind::Issue { state.live.bump_issue(repo_id, &item.id); } } -pub(crate) async fn issue_for(state: &AppState, ctx: &RepoCtx, number: i64) -> Result { +pub async fn issue_for(state: &AppState, ctx: &RepoCtx, number: i64) -> Result { match state.store.issue_by_number(&ctx.repo.id, number).await? { Some(issue) => Ok(issue), None => Err(not_found().into()), @@ -143,7 +143,7 @@ pub(crate) async fn issue_for(state: &AppState, ctx: &RepoCtx, number: i64) -> R /// The item of `kind` numbered `number` in this repo, as its issue row, or 404. A pull request /// is the issue row it carries, so the comments and edit history are the same for both kinds. -pub(crate) async fn item_for( +pub async fn item_for( state: &AppState, ctx: &RepoCtx, kind: ItemKind, @@ -159,24 +159,20 @@ pub(crate) async fn item_for( } /// A comment of this item. A comment id from another item is 404. -pub(crate) async fn comment_for( - state: &AppState, - item: &Issue, - comment_id: &str, -) -> Result { +pub async fn comment_for(state: &AppState, item: &Issue, comment_id: &str) -> Result { match state.store.comment_by_id(&item.id, comment_id).await? { Some(comment) => Ok(comment), None => Err(not_found().into()), } } -pub(crate) fn is_hex_oid(s: &str) -> bool { +pub fn is_hex_oid(s: &str) -> bool { (4..=64).contains(&s.len()) && s.bytes().all(|b| b.is_ascii_hexdigit()) } /// The ids in `oids` that a branch, tag or pull request still reaches, read in one git walk. A /// failed read yields none, so no stored hash links to a page that would 404. -pub(crate) async fn reachable_among(path: &std::path::Path, oids: Vec) -> HashSet { +pub async fn reachable_among(path: &std::path::Path, oids: Vec) -> HashSet { let path = path.to_owned(); tokio::task::spawn_blocking(move || forge_git::browse::reachable_commits(&path, &oids)) .await @@ -188,7 +184,7 @@ pub(crate) async fn reachable_among(path: &std::path::Path, oids: Vec) - // Timeline /// One comment, or the item body (which uses the same item shape without a delete action). -pub(crate) struct CommentView { +pub struct CommentView { anchor: String, author: String, /// The author's username, the link target of the name and avatar. @@ -208,7 +204,7 @@ pub(crate) struct CommentView { } /// Where a task checkbox toggle is posted, and which text it changes. -pub(crate) struct TaskTarget { +pub struct TaskTarget { action: String, /// `issue` for the item body, `comment` for a comment. kind: &'static str, @@ -216,29 +212,29 @@ pub(crate) struct TaskTarget { } /// One reaction button: a POST toggle when `enabled`, a plain count otherwise. -pub(crate) struct ReactionButton { - pub(crate) action: String, - pub(crate) csrf: String, - pub(crate) target_kind: &'static str, - pub(crate) target_id: String, - pub(crate) name: &'static str, - pub(crate) emoji: &'static str, - pub(crate) count: usize, - pub(crate) title: String, - pub(crate) active: bool, - pub(crate) enabled: bool, +pub struct ReactionButton { + pub action: String, + pub csrf: String, + pub target_kind: &'static str, + pub target_id: String, + pub name: &'static str, + pub emoji: &'static str, + pub count: usize, + pub title: String, + pub active: bool, + pub enabled: bool, } /// The reactions of one target: the existing ones, then the picker of every emoji. The picker is /// only shown when `enabled`. -pub(crate) struct ReactionBar { - pub(crate) chips: Vec, - pub(crate) picker: Vec, - pub(crate) enabled: bool, +pub struct ReactionBar { + pub chips: Vec, + pub picker: Vec, + pub enabled: bool, } /// One timeline event as a line: the actor, `before`, an optional commit link, then `after`. -pub(crate) struct EventLine { +pub struct EventLine { actor: String, actor_id: String, when: When, @@ -257,7 +253,7 @@ const RUN_GAP_SECS: i64 = 300; /// A submitted review of a pull request: its verb, its body (when it has one) and the threads it /// opened, which render under it with their diff hunks. -pub(crate) struct ReviewView { +pub struct ReviewView { anchor: String, author: String, login: String, @@ -271,7 +267,7 @@ pub(crate) struct ReviewView { ctx: ThreadCtx, } -pub(crate) enum Entry { +pub enum Entry { Comment(CommentView), Event(EventLine), /// Consecutive events by one actor within a few minutes, one line. @@ -280,14 +276,14 @@ pub(crate) enum Entry { } /// The item body and its timeline: comments and events merged by creation time. -pub(crate) struct Discussion { +pub struct Discussion { /// The item's author, by display name, and when it was opened. - pub(crate) author: String, + pub author: String, /// The author's username, for the profile link. - pub(crate) author_login: String, - pub(crate) opened: When, - pub(crate) body: CommentView, - pub(crate) entries: Vec, + pub author_login: String, + pub opened: When, + pub body: CommentView, + pub entries: Vec, } /// The one-line text for an event. `base` is `/{owner}/{repo}`; `base_branch` names the target @@ -382,7 +378,7 @@ fn event_line( } #[component] -pub(crate) async fn comment_item(cx: &Cx, lang: Lang, item: CommentView) -> Result { +pub async fn comment_item(cx: &Cx, lang: Lang, item: CommentView) -> Result { let CommentView { anchor, author, @@ -448,7 +444,7 @@ pub(crate) async fn comment_item(cx: &Cx, lang: Lang, item: CommentView) -> Resu /// The reaction row under an item or comment: the buttons, then the picker when the viewer may react. #[component] -pub(crate) async fn reaction_row(cx: &Cx, lang: Lang, bar: ReactionBar) -> Result { +pub async fn reaction_row(cx: &Cx, lang: Lang, bar: ReactionBar) -> Result { let ReactionBar { chips, picker, @@ -468,7 +464,7 @@ pub(crate) async fn reaction_row(cx: &Cx, lang: Lang, bar: ReactionBar) -> Resul /// The React tool: a word that opens the reaction options in place. #[component] -pub(crate) async fn reaction_picker( +pub async fn reaction_picker( cx: &Cx, lang: Lang, picker: Vec, @@ -488,7 +484,7 @@ pub(crate) async fn reaction_picker( /// One reaction button. Enabled buttons are POST forms that toggle the viewer's reaction; the /// others only show the emoji and count. #[component] -pub(crate) async fn reaction_button(cx: &Cx, button: ReactionButton) -> Result { +pub async fn reaction_button(cx: &Cx, button: ReactionButton) -> Result { let ReactionButton { action, csrf, @@ -534,7 +530,7 @@ pub(crate) async fn reaction_button(cx: &Cx, button: ReactionButton) -> Result Result { +pub async fn event_item(cx: &Cx, line: EventLine) -> Result { let EventLine { actor, when, @@ -570,7 +566,7 @@ pub(crate) async fn event_item(cx: &Cx, line: EventLine) -> Result { /// Consecutive events by one actor, one line: the actor, each event's words joined with " · ", then /// the time of the last one. #[component] -pub(crate) async fn event_run(cx: &Cx, lines: Vec) -> Result { +pub async fn event_run(cx: &Cx, lines: Vec) -> Result { let actor = lines .first() .map(|line| line.actor.clone()) @@ -619,7 +615,7 @@ fn dismissed_verb(lang: Lang, from: Option) -> &'static str { /// One submitted review: the reviewer, the verb, the dismissal reason, the body, then its threads. #[component] -pub(crate) async fn review_item(cx: &Cx, lang: Lang, review: ReviewView) -> Result { +pub async fn review_item(cx: &Cx, lang: Lang, review: ReviewView) -> Result { let ReviewView { anchor, author, @@ -661,7 +657,7 @@ pub(crate) async fn review_item(cx: &Cx, lang: Lang, review: ReviewView) -> Resu } #[component] -pub(crate) async fn timeline_entry(cx: &Cx, lang: Lang, entry: Entry) -> Result { +pub async fn timeline_entry(cx: &Cx, lang: Lang, entry: Entry) -> Result { Ok(view! { match entry { Entry::Comment(item) => comment_item(lang: lang, item: item), @@ -674,11 +670,7 @@ pub(crate) async fn timeline_entry(cx: &Cx, lang: Lang, entry: Entry) -> Result< /// The body followed by every timeline entry. #[component] -pub(crate) async fn discussion_timeline( - cx: &Cx, - lang: Lang, - discussion: Discussion, -) -> Result { +pub async fn discussion_timeline(cx: &Cx, lang: Lang, discussion: Discussion) -> Result { let Discussion { body, entries, .. } = discussion; Ok(view! {
@@ -692,7 +684,7 @@ pub(crate) async fn discussion_timeline( /// Loads the body and the timeline of `item`, which is an issue or a pull request. Authors and /// event actors are looked up in one batch. -pub(crate) async fn load_discussion( +pub async fn load_discussion( lang: Lang, state: &AppState, ctx: &RepoCtx, @@ -941,7 +933,7 @@ fn push_label_group(lang: Lang, group: &mut Vec, out: &mut Vec>, can_react: bool, @@ -1118,21 +1110,21 @@ async fn review_entries( // Sidebar -pub(crate) struct LabelRow { +pub struct LabelRow { id: String, name: String, chip: String, attached: bool, } -pub(crate) struct MilestoneRow { +pub struct MilestoneRow { id: String, title: String, selected: bool, } /// The sidebar data of one item: its labels, assignees and milestone, and the repo's choices. -pub(crate) struct Sidebar { +pub struct Sidebar { labels: Vec, assignees: Vec, milestones: Vec, @@ -1142,7 +1134,7 @@ pub(crate) struct Sidebar { lock_reason: Option, } -pub(crate) async fn load_sidebar(state: &AppState, repo_id: &str, item: &Issue) -> Result { +pub async fn load_sidebar(state: &AppState, repo_id: &str, item: &Issue) -> Result { let store = &state.store; let all_labels = store.list_labels(repo_id).await?; let attached = store.issue_labels(&item.id).await?; @@ -1186,7 +1178,7 @@ pub(crate) async fn load_sidebar(state: &AppState, repo_id: &str, item: &Issue) } #[component] -pub(crate) async fn labels_box( +pub async fn labels_box( cx: &Cx, lang: Lang, write: bool, @@ -1234,7 +1226,7 @@ pub(crate) async fn labels_box( } #[component] -pub(crate) async fn assignees_box( +pub async fn assignees_box( cx: &Cx, lang: Lang, write: bool, @@ -1281,7 +1273,7 @@ pub(crate) async fn assignees_box( } #[component] -pub(crate) async fn milestone_box( +pub async fn milestone_box( cx: &Cx, lang: Lang, write: bool, @@ -1328,7 +1320,7 @@ pub(crate) async fn milestone_box( /// The conversation row, shown only when the conversation is locked, with its unlock word for /// triage holders. Locking is one of the tools at the foot of the sidebar (`item_tools`). #[component] -pub(crate) async fn lock_box( +pub async fn lock_box( cx: &Cx, lang: Lang, write: bool, @@ -1366,7 +1358,7 @@ pub(crate) async fn lock_box( /// The tools at the foot of the sidebar, one quiet line: Pin issue, and Lock conversation with its /// reason. `pin` is the pin action when the issue is not pinned and the viewer may pin it. #[component] -pub(crate) async fn item_tools( +pub async fn item_tools( cx: &Cx, lang: Lang, pin: Option, @@ -1411,7 +1403,7 @@ pub(crate) async fn item_tools( /// `/milestone` and `/lock`. `write` shows the forms instead of the read-only lists. `pin` is /// `(pinned, action)` for an issue; the pinned row sits in the page (`pin_box`). #[component] -pub(crate) async fn item_sidebar( +pub async fn item_sidebar( cx: &Cx, lang: Lang, write: bool, @@ -1459,13 +1451,13 @@ pub(crate) async fn item_sidebar( /// The id of the comment form. The head's Close and Reopen buttons post it with `form=`, so a /// close can carry the draft text as its comment, as it always did. -pub(crate) const COMMENT_FORM: &str = "item-comment"; +pub const COMMENT_FORM: &str = "item-comment"; /// The head tools of an item: Close (a menu of the two ways) or Reopen when closed, and the /// Subscribe or Unsubscribe pill, whose reason is its title. `close` is `(open, state action)` /// and is given only when the viewer may close the item. #[component] -pub(crate) async fn item_head_tools( +pub async fn item_head_tools( cx: &Cx, lang: Lang, close: Option<(bool, String)>, @@ -1497,7 +1489,7 @@ pub(crate) async fn item_head_tools( /// The comment box: the text, and Comment as its one filled button. Its label is for screen /// readers only. #[component] -pub(crate) async fn comment_form( +pub async fn comment_form( cx: &Cx, lang: Lang, action: String, @@ -1526,17 +1518,17 @@ pub(crate) async fn comment_form( /// The form fields of a comment or state POST. #[derive(Deserialize)] -pub(crate) struct CommentForm { +pub struct CommentForm { #[serde(default)] - pub(crate) csrf: String, + pub csrf: String, #[serde(default)] - pub(crate) body: String, + pub body: String, #[serde(default)] - pub(crate) action: String, + pub action: String, } /// What a comment or state POST did. -pub(crate) enum Posted { +pub enum Posted { /// Written. `comment_id` is the new comment, when there was text. Saved { comment_id: Option }, /// Not written; `message` goes back to the form. @@ -1546,7 +1538,7 @@ pub(crate) enum Posted { /// Adds a comment and/or changes the state of an issue or pull request (`pull` says which). Only /// the author or a Triage holder may close or reopen; otherwise 403 and nothing is written. An /// empty comment with no state change, or a body that fails validation, is `Refused`. -pub(crate) async fn post_comment( +pub async fn post_comment( lang: Lang, state: &AppState, ctx: &RepoCtx, diff --git a/crates/forge-web/src/pages/issues_list.rs b/crates/forge-web-pages/src/pages/issues_list.rs similarity index 97% rename from crates/forge-web/src/pages/issues_list.rs rename to crates/forge-web-pages/src/pages/issues_list.rs index dd58177..667bc52 100644 --- a/crates/forge-web/src/pages/issues_list.rs +++ b/crates/forge-web-pages/src/pages/issues_list.rs @@ -44,7 +44,7 @@ const MAX_PAGE: u32 = 1000; const MAX_FILTER_CHARS: usize = 256; #[query_params(error = bad_request)] -pub(crate) struct ListQuery { +pub struct ListQuery { state: Option, label: Option, milestone: Option, @@ -58,22 +58,22 @@ pub(crate) struct ListQuery { } /// The list's filters as the page shows them. Every value here is already a valid choice. -pub(crate) struct Selection { +pub struct Selection { /// `open`, `closed` or `all`. - pub(crate) state: &'static str, - pub(crate) label: String, - pub(crate) milestone: String, - pub(crate) author: String, - pub(crate) assignee: String, + pub state: &'static str, + pub label: String, + pub milestone: String, + pub author: String, + pub assignee: String, /// Username with a pending review request, or `@me` (pull requests only). - pub(crate) review_requested: String, - pub(crate) query: String, + pub review_requested: String, + pub query: String, /// Pull requests only: `true` (drafts), `false` (ready) or empty (both). A `draft:true` or /// `draft:false` word in the search text sets it too. - pub(crate) draft: &'static str, + pub draft: &'static str, /// `newest`, `oldest` or `updated`. - pub(crate) sort: &'static str, - pub(crate) page: u32, + pub sort: &'static str, + pub page: u32, } /// Trimmed and cut to `MAX_FILTER_CHARS`. A missing value is empty. @@ -92,7 +92,7 @@ fn non_empty(value: &str) -> Option { } impl Selection { - pub(crate) fn parse(query: &ListQuery) -> Self { + pub fn parse(query: &ListQuery) -> Self { let mut draft = match query.draft.as_deref().map(str::trim) { Some("true") => "true", Some("false") => "false", @@ -140,7 +140,7 @@ impl Selection { } } - pub(crate) fn filter(&self) -> IssueFilter { + pub fn filter(&self) -> IssueFilter { IssueFilter { state: match self.state { "closed" => Some(IssueState::Closed), @@ -170,7 +170,7 @@ impl Selection { } /// Whether any filter besides the state is set. - pub(crate) fn has_filters(&self) -> bool { + pub fn has_filters(&self) -> bool { !(self.label.is_empty() && self.milestone.is_empty() && self.author.is_empty() @@ -181,7 +181,7 @@ impl Selection { } /// The search box text: the title query plus the `review-requested:` token when one is set. - pub(crate) fn search_text(&self) -> String { + pub fn search_text(&self) -> String { if self.review_requested.is_empty() { self.query.clone() } else { @@ -192,14 +192,14 @@ impl Selection { } /// Resolves `@me` to the viewer's username. Anonymous viewers lose the filter. - pub(crate) fn resolve_me(&mut self, viewer: Option<&str>) { + pub fn resolve_me(&mut self, viewer: Option<&str>) { if self.review_requested == "@me" { self.review_requested = viewer.map(str::to_owned).unwrap_or_default(); } } /// The list URL with this selection, but a different state and page. - pub(crate) fn href(&self, base: &str, state: &str, page: u32) -> String { + pub fn href(&self, base: &str, state: &str, page: u32) -> String { let page_text = if page > 1 { page.to_string() } else { @@ -225,7 +225,7 @@ impl Selection { } /// `base` followed by a query string holding the non-empty parameters, percent-encoded. -pub(crate) fn list_href(base: &str, params: &[(&str, &str)]) -> String { +pub fn list_href(base: &str, params: &[(&str, &str)]) -> String { let query: Vec = params .iter() .filter(|(_, value)| !value.is_empty()) @@ -239,26 +239,26 @@ pub(crate) fn list_href(base: &str, params: &[(&str, &str)]) -> String { } /// Unix seconds of a stored RFC 3339 stamp. An unreadable stamp gives 0. -pub(crate) fn stamp_unix(stamp: &str) -> i64 { +pub fn stamp_unix(stamp: &str) -> i64 { time::OffsetDateTime::parse(stamp, &time::format_description::well_known::Rfc3339) .map_or(0, |t| t.unix_timestamp()) } -pub(crate) struct AssigneeView { - pub(crate) name: String, - pub(crate) avatar: String, +pub struct AssigneeView { + pub name: String, + pub avatar: String, } -pub(crate) struct LabelView { - pub(crate) class: String, - pub(crate) name: String, - pub(crate) href: String, +pub struct LabelView { + pub class: String, + pub name: String, + pub href: String, } #[derive(Clone)] -pub(crate) struct MilestoneView { - pub(crate) title: String, - pub(crate) href: String, +pub struct MilestoneView { + pub title: String, + pub href: String, } /// One issue row, with every string the template shows already built. @@ -359,7 +359,7 @@ fn row_view(row: RowCtx<'_>, item: &IssueListItem) -> RowView { } /// The "N of M tasks" label for a body, or `None` without task items. -pub(crate) fn tasks_text(lang: Lang, body: &str) -> Option { +pub fn tasks_text(lang: Lang, body: &str) -> Option { let (done, total) = crate::render::markdown::task_progress(body); (total > 0).then(|| crate::i18n::authoring::tasks_progress(lang, done, total)) } @@ -392,10 +392,10 @@ fn pinned_card(lang: Lang, owner: &str, repo: &str, issue: &forge_core::Issue) - } /// One option of the sort select. -pub(crate) struct SortOption { - pub(crate) value: &'static str, - pub(crate) label: &'static str, - pub(crate) selected: bool, +pub struct SortOption { + pub value: &'static str, + pub label: &'static str, + pub selected: bool, } /// How many open issues match one assignee or author, from the list's total with one row asked for. @@ -958,8 +958,8 @@ async fn new_issue_submit(cx: &Cx, RawForm(raw): RawForm) -> Result { /// Shared test fixture for the issue and label pages: a store with one owner, one repo and a /// signed-in session for the owner. The pages need no git data, so no repository is created. -#[cfg(test)] -pub(crate) mod test_util { +#[cfg(any(test, feature = "test-support"))] +pub mod test_util { use forge_core::{Repo, Store, User, Visibility}; use http::HeaderMap; use topcoat::router::request::Request; diff --git a/crates/forge-web/src/pages/issues_live.rs b/crates/forge-web-pages/src/pages/issues_live.rs similarity index 100% rename from crates/forge-web/src/pages/issues_live.rs rename to crates/forge-web-pages/src/pages/issues_live.rs diff --git a/crates/forge-web-pages/src/pages/mod.rs b/crates/forge-web-pages/src/pages/mod.rs new file mode 100644 index 0000000..370f563 --- /dev/null +++ b/crates/forge-web-pages/src/pages/mod.rs @@ -0,0 +1,38 @@ +//! Server-rendered pages. + +pub mod admin_runners; +pub mod admin_users; +pub mod ci_estimate; +pub mod ci_fail; +pub mod ci_job; +pub mod ci_runs; +pub mod code_live; +pub mod discussion_settings; +pub mod edit_history; +pub mod finder; +pub mod issue_meta; +pub mod issue_parts; +pub mod issues_list; +pub mod issues_live; +pub mod notifications; +pub mod packages; +pub mod packages_oci; +pub mod pull_live; +pub mod pull_reviews; +pub mod ref_live; +pub mod refs; +pub mod releases; +pub mod releases_live; +pub mod repo; +pub mod repo_ctx; +pub mod repo_mirrors; +pub mod repo_rename; +pub mod repo_security; +pub mod repo_settings; +pub mod repo_settings_live; +pub mod repo_side; +pub mod repo_transfer; +pub mod star; +pub mod tree; +pub mod wiki; +pub mod wiki_live; diff --git a/crates/forge-web/src/pages/notifications.rs b/crates/forge-web-pages/src/pages/notifications.rs similarity index 67% rename from crates/forge-web/src/pages/notifications.rs rename to crates/forge-web-pages/src/pages/notifications.rs index c2abebe..b672738 100644 --- a/crates/forge-web/src/pages/notifications.rs +++ b/crates/forge-web-pages/src/pages/notifications.rs @@ -87,7 +87,7 @@ struct WatchForm { } /// One inbox row, with its strings ready for the view. -pub(crate) struct RowView { +pub struct RowView { item_class: &'static str, icon_class: &'static str, kind_label: &'static str, @@ -103,7 +103,7 @@ pub(crate) struct RowView { } /// The rows of one repo, in the order they first appear in the inbox. -pub(crate) struct RepoGroup { +pub struct RepoGroup { heading: String, href: String, mark_action: String, @@ -742,7 +742,7 @@ fn unread_event(count: u64) -> topcoat::Result { /// The viewer's unread count as `unread` events: one now, then one after each change to the inbox. /// Subscribed before the count is read, so a change in between is pushed again, never missed. -pub(crate) async fn unread_changes( +pub async fn unread_changes( state: &AppState, user_id: &str, ) -> Result> + Send + 'static> { @@ -876,7 +876,7 @@ async fn can_manage_alerts(state: &AppState, user: &User, repo_id: &str) -> Resu } /// Whether the viewer may read the repo right now, by their current collaborator role. -pub(crate) async fn can_read(state: &AppState, user: &User, repo_id: &str) -> Result { +pub async fn can_read(state: &AppState, user: &User, repo_id: &str) -> Result { let Some(repo) = state.store.repo_by_id(repo_id).await? else { return Ok(false); }; @@ -890,7 +890,7 @@ pub(crate) async fn can_read(state: &AppState, user: &User, repo_id: &str) -> Re /// The sidebar box of an issue or pull for a signed-in viewer. Viewing the thread marks the /// viewer's inbox row for it read. `base` is the item's URL. `None` for anonymous viewers. -pub(crate) async fn notify_box_for( +pub async fn notify_box_for( state: &AppState, ctx: &RepoCtx, issue_id: &str, @@ -921,10 +921,10 @@ pub(crate) async fn notify_box_for( /// The notification sidebar box data: where the form posts, the session CSRF token, and whether the /// viewer is receiving notifications. -pub(crate) struct NotifyBox { - pub(crate) action: String, - pub(crate) csrf: String, - pub(crate) subscribed: bool, +pub struct NotifyBox { + pub action: String, + pub csrf: String, + pub subscribed: bool, } /// The human label of a notification reason. @@ -966,7 +966,7 @@ fn back(cx: &Cx) -> String { /// The inbox rail's places, the same on Notifications, Needs you and Review requests, so each /// reaches the others: Unread with its count, All, Needs you, Review requests. `current` is the /// key of the page showing it. -pub(crate) fn inbox_items(lang: Lang, current: &str, unread_count: u64) -> Vec { +pub fn inbox_items(lang: Lang, current: &str, unread_count: u64) -> Vec { let item = |key: &str, name: &str, val: String, href: &str| RailItem { name: name.to_owned(), val, @@ -1003,7 +1003,7 @@ pub(crate) fn inbox_items(lang: Lang, current: &str, unread_count: u64) -> Vec }) } - -#[cfg(test)] -mod tests { - use forge_core::{Issue, Reason, Role, Store, SubState, Visibility, WatchLevel}; - use futures_util::StreamExt; - use topcoat::router::request::Request; - use topcoat::router::{Body, Router, to_bytes}; - - use crate::auth::SESSION_COOKIE; - - const CSRF: &str = "notif-test-csrf"; - - struct Site { - router: Router, - store: Store, - git: std::sync::Arc, - _dir: tempfile::TempDir, - } - - struct Reply { - status: u16, - location: Option, - body: String, - } - - async fn site() -> Site { - let dir = tempfile::tempdir().expect("tempdir"); - let state = crate::test_support::test_state(dir.path()).await; - let store = state.store.clone(); - let git = state.git.clone(); - let router = crate::test_support::app_router(state); - Site { - router, - store, - git, - _dir: dir, - } - } - - /// Signs `user_id` in with `token` and returns the cookie header value. - async fn sign_in(store: &Store, user_id: &str, token: &str) -> String { - crate::test_support::create_session(store, user_id, token, CSRF).await; - format!("__Host-{SESSION_COOKIE}={token}") - } - - async fn call( - site: &Site, - method: &str, - uri: &str, - cookie: Option<&str>, - form: Option, - ) -> Reply { - let mut builder = Request::builder().method(method).uri(uri); - if let Some(cookie) = cookie { - builder = builder.header("cookie", cookie); - } - let body = match form { - Some(form) => { - builder = builder.header("content-type", "application/x-www-form-urlencoded"); - Body::from(form) - } - None => Body::empty(), - }; - let res = site - .router - .handle(builder.body(body).expect("request")) - .await; - let status = res.status().as_u16(); - let location = res - .headers() - .get("location") - .and_then(|v| v.to_str().ok()) - .map(str::to_owned); - let bytes = to_bytes(res.into_body(), usize::MAX).await.expect("body"); - Reply { - status, - location, - body: String::from_utf8_lossy(&bytes).into_owned(), - } - } - - async fn get(site: &Site, uri: &str, cookie: Option<&str>) -> Reply { - call(site, "GET", uri, cookie, None).await - } - - async fn post(site: &Site, uri: &str, cookie: &str, extra: &str) -> Reply { - call( - site, - "POST", - uri, - Some(cookie), - Some(format!("csrf={CSRF}{extra}")), - ) - .await - } - - /// Tahinli owns `demo` with one issue (#1), and Bob has a notification row for it. - struct World { - tahinli: forge_core::User, - bob: forge_core::User, - repo: forge_core::Repo, - issue: Issue, - } - - async fn world(site: &Site, visibility: Visibility) -> World { - let store = &site.store; - let tahinli = store - .create_user("tahinli", None, "x", false) - .await - .expect("tahinli"); - let bob = store - .create_user("bob", None, "x", false) - .await - .expect("bob"); - let repo = store - .create_repo(&tahinli.id, "demo", "", visibility, "main") - .await - .expect("repo"); - let issue = store - .create_issue(&repo.id, &tahinli.id, "First", "body") - .await - .expect("issue"); - World { - tahinli, - bob, - repo, - issue, - } - } - - async fn notify(site: &Site, w: &World, reason: Reason) { - site.store - .upsert_notification( - &w.bob.id, - &w.repo.id, - &w.issue.id, - reason, - "comment", - Some(&w.tahinli.id), - ) - .await - .expect("notification"); - } - - async fn first_note_id(site: &Site, user_id: &str) -> String { - site.store - .list_notifications(user_id, false, None, 50) - .await - .expect("list") - .first() - .expect("one notification") - .id - .clone() - } - - #[tokio::test] - async fn inbox_lists_unread_and_all_shows_read() { - let site = site().await; - let w = world(&site, Visibility::Public).await; - let cookie = sign_in(&site.store, &w.bob.id, "bob-token").await; - notify(&site, &w, Reason::Mention).await; - let id = first_note_id(&site, &w.bob.id).await; - site.store.mark_read(&w.bob.id, &id).await.expect("read"); - - let unread = get(&site, "/notifications", Some(&cookie)).await; - assert_eq!(unread.status, 200); - assert!(!unread.body.contains("tahinli/demo #1 First")); - assert!(unread.body.contains("No unread notifications.")); - - let all = get(&site, "/notifications?all=1", Some(&cookie)).await; - assert_eq!(all.status, 200); - assert!(all.body.contains("tahinli/demo #1 First")); - assert!(all.body.contains("mentioned")); - } - - #[tokio::test] - async fn unread_inbox_lists_unread_rows_grouped_by_repo() { - let site = site().await; - let w = world(&site, Visibility::Public).await; - let cookie = sign_in(&site.store, &w.bob.id, "bob-token").await; - notify(&site, &w, Reason::Assign).await; - - let page = get(&site, "/notifications", Some(&cookie)).await; - assert_eq!(page.status, 200); - assert!(page.body.contains("tahinli/demo #1 First")); - assert!(page.body.contains("assigned")); - assert!(page.body.contains("/notifications/mark_all_read?repo=")); - assert!(page.body.contains("Mark all as read")); - } - - /// Another user cannot open or mark read a row that is not theirs. The owner's open redirects - /// to the issue and marks the row read. - #[tokio::test] - async fn another_users_notification_is_404_and_the_owner_opens_it() { - let site = site().await; - let w = world(&site, Visibility::Public).await; - let tahinli_cookie = sign_in(&site.store, &w.tahinli.id, "tahinli-token").await; - let bob_cookie = sign_in(&site.store, &w.bob.id, "bob-token").await; - notify(&site, &w, Reason::Comment).await; - let id = first_note_id(&site, &w.bob.id).await; - - let res = get( - &site, - &format!("/notifications/{id}/open"), - Some(&tahinli_cookie), - ) - .await; - assert_eq!(res.status, 404); - assert_eq!(site.store.unread_count(&w.bob.id).await.expect("count"), 1); - - let read = post( - &site, - &format!("/notifications/{id}/read"), - &tahinli_cookie, - "", - ) - .await; - assert_eq!(read.status, 303); - assert_eq!(site.store.unread_count(&w.bob.id).await.expect("count"), 1); - - // Bob opens his own row: it redirects to the issue and marks the row read. - let res = get( - &site, - &format!("/notifications/{id}/open"), - Some(&bob_cookie), - ) - .await; - assert_eq!(res.status, 303); - assert_eq!(res.location.as_deref(), Some("/tahinli/demo/issues/1")); - assert_eq!(site.store.unread_count(&w.bob.id).await.expect("count"), 0); - } - - #[tokio::test] - async fn mark_all_read_clears_the_inbox() { - let site = site().await; - let w = world(&site, Visibility::Public).await; - let cookie = sign_in(&site.store, &w.bob.id, "bob-token").await; - notify(&site, &w, Reason::Comment).await; - - let res = post(&site, "/notifications/mark_all_read", &cookie, "").await; - assert_eq!(res.status, 303); - assert_eq!(site.store.unread_count(&w.bob.id).await.expect("count"), 0); - } - - #[tokio::test] - async fn the_stream_sends_the_count_then_each_change() { - let site = site().await; - let w = world(&site, Visibility::Public).await; - let cookie = sign_in(&site.store, &w.bob.id, "bob-token").await; - notify(&site, &w, Reason::Mention).await; - - let request = Request::builder() - .method("GET") - .uri("/notifications/stream") - .header("cookie", cookie.as_str()) - .body(Body::empty()) - .expect("request"); - let res = site.router.handle(request).await; - assert_eq!(res.status().as_u16(), 200); - assert_eq!( - res.headers().get("content-type").unwrap(), - "text/event-stream" - ); - assert_eq!(res.headers().get("x-accel-buffering").unwrap(), "no"); - - let mut frames = res.into_body().into_data_stream(); - // The stream opens with its retry field, then the count. - let retry = frames.next().await.expect("a frame").expect("data"); - assert!(retry.starts_with(b"retry: 1000"), "{retry:?}"); - let first = frames.next().await.expect("a frame").expect("data"); - assert_eq!(&first[..], b"event: unread\ndata: 1\n\n"); - - // Marking the row read pushes the new count to the open stream. - let read = post(&site, "/notifications/mark_all_read", &cookie, "").await; - assert_eq!(read.status, 303); - let next = frames.next().await.expect("a frame").expect("data"); - assert_eq!(&next[..], b"event: unread\ndata: 0\n\n"); - } - - #[tokio::test] - async fn corner_bell_shows_the_unread_count() { - let site = site().await; - let w = world(&site, Visibility::Public).await; - let cookie = sign_in(&site.store, &w.bob.id, "bob-token").await; - - let none = get(&site, "/explore", Some(&cookie)).await; - assert!(none.body.contains("href=\"/notifications\"")); - assert!(!none.body.contains("")); - - notify(&site, &w, Reason::Mention).await; - let one = get(&site, "/explore", Some(&cookie)).await; - assert!(one.body.contains("1")); - } - - #[tokio::test] - async fn subscription_toggles_on_an_issue_and_unknown_pull_is_404() { - let site = site().await; - let w = world(&site, Visibility::Public).await; - let cookie = sign_in(&site.store, &w.bob.id, "bob-token").await; - - let res = post( - &site, - "/tahinli/demo/issues/1/subscription", - &cookie, - "&action=subscribe", - ) - .await; - assert_eq!(res.status, 303); - assert_eq!(res.location.as_deref(), Some("/tahinli/demo/issues/1")); - let sub = site - .store - .subscription(&w.bob.id, &w.issue.id) - .await - .expect("sub"); - assert_eq!(sub, Some((SubState::Subscribed, Reason::Subscribed))); - - let page = get(&site, "/tahinli/demo/issues/1", Some(&cookie)).await; - assert!(page.body.contains("value=\"unsubscribe\"")); - - post( - &site, - "/tahinli/demo/issues/1/subscription", - &cookie, - "&action=unsubscribe", - ) - .await; - let sub = site - .store - .subscription(&w.bob.id, &w.issue.id) - .await - .expect("sub"); - assert_eq!(sub, Some((SubState::Ignored, Reason::Subscribed))); - - // A pull request number that does not exist is a 404 on the pulls subscription. - let res = post( - &site, - "/tahinli/demo/pulls/1/subscription", - &cookie, - "&action=subscribe", - ) - .await; - assert_eq!(res.status, 404); - } - - #[tokio::test] - async fn watch_form_sets_the_level() { - let site = site().await; - let w = world(&site, Visibility::Public).await; - let cookie = sign_in(&site.store, &w.bob.id, "bob-token").await; - - let res = post(&site, "/tahinli/demo/watch", &cookie, "&level=watching").await; - assert_eq!(res.status, 303); - assert_eq!( - site.store - .watch_level(&w.bob.id, &w.repo.id) - .await - .expect("level"), - WatchLevel::Watching - ); - - // The watch menu sits in the repo head on the code tab, which reads the repository. - let bare = forge_git::repo::repo_path(&site.git.data_dir, &w.repo.id).expect("repo path"); - forge_git::repo::init_bare(&site.git, &bare, "main") - .await - .expect("init bare"); - let header = get(&site, "/tahinli/demo", Some(&cookie)).await; - assert!(header.body.contains("action=\"/tahinli/demo/watch\"")); - assert!(header.body.contains("
")); - assert!(!header.body.contains("