From 44c350f5baafeb4e3976fd71ff1e825b6af436db Mon Sep 17 00:00:00 2001 From: Will Eastler <32074613+weastler@users.noreply.github.com> Date: Mon, 30 Nov 2026 19:18:11 -0800 Subject: [PATCH 1/8] feat(hub): export public share links to the isolated reader Hub copies eligible Builds into public export storage, writes and revokes their policies, supports optional link passwords, and shows export status on the Share links page. Legacy share links stay on their backend. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- hub/.env.example | 8 + .../hub/product-contracts/index.ts | 25 + .../hub/routes/expanded-flows.test.tsx | 97 ++++ .../hub/routes/product-share-links/index.tsx | 27 + .../product-share-links-data/index.ts | 89 +++- hub/client/features/share-link-item/index.tsx | 95 +++- .../features/share-link-item/stories.tsx | 48 ++ .../features/share-link-item/styles.css | 21 + hub/client/features/share-link-item/types.ts | 15 + hub/client/features/share-link-row/index.tsx | 11 +- .../features/share-link-row/stories.tsx | 15 + hub/client/features/share-link-row/styles.css | 5 + hub/client/features/share-link-row/types.ts | 3 + .../features/share-links-form/index.tsx | 20 +- .../features/share-links-form/stories.tsx | 10 + .../features/share-links-form/styles.css | 10 +- hub/client/features/share-links-form/types.ts | 3 + .../pages/share-links-index-page/index.tsx | 23 +- .../pages/share-links-index-page/stories.tsx | 83 +++ .../pages/share-links-index-page/types.ts | 6 +- hub/docs/architecture.md | 4 +- hub/docs/background-jobs.md | 2 +- hub/docs/public-share-reader.md | 4 +- hub/docs/share-links.md | 58 ++- .../migration.sql | 37 ++ hub/schema/share-link-backend.enum.prisma | 4 + .../share-link-export-state.enum.prisma | 7 + hub/schema/share-link.prisma | 8 + hub/server/create-app/index.test.ts | 2 + .../copy-public-share-files/index.ts | 93 ++++ .../create-public-sharing-service/index.ts | 240 ++++++++- .../delete-public-share-export-files/index.ts | 89 ++++ .../enqueue-public-share-export/index.ts | 28 + hub/server/domains/public-sharing/errors.ts | 24 + .../is-public-share-eligible/index.ts | 19 + .../jobs/delete-public-share-exports.ts | 10 + .../jobs/export-public-share.ts | 10 + .../jobs/recover-public-share-exports.ts | 10 + .../public-share-exports.db.test.ts | 483 ++++++++++++++++++ .../publish-public-share-policy/index.ts | 58 +++ .../index.test.ts | 91 ++++ .../index.ts | 108 ++++ .../read-public-share-source/index.ts | 44 ++ .../recover-public-share-exports/index.ts | 24 + .../synchronize-public-share-export/index.ts | 55 ++ hub/server/domains/public-sharing/types.ts | 85 +-- hub/server/index.test.ts | 30 ++ hub/server/index.ts | 21 +- .../index.test.ts | 127 +++++ .../index.ts | 83 +++ .../types.ts | 27 + .../public-sharing/create-share-link/index.ts | 15 +- .../fail-stale-public-share-exports/index.ts | 14 + .../find-public-share-export/index.ts | 36 ++ .../find-shareable-build/index.ts | 3 +- .../index.ts | 27 + .../list-public-share-export-work/index.ts | 24 + .../list-share-link-expirations/index.ts | 2 +- .../public-sharing/list-share-links/index.ts | 7 +- .../mark-public-share-export-failed/index.ts | 9 + .../mark-public-share-files-deleted/index.ts | 17 + .../mark-public-share-policy-written/index.ts | 27 + .../start-revoking-share-links/index.ts | 21 + .../index.db.test.ts | 8 +- .../update-share-link-expirations/index.ts | 7 +- .../update-share-link-password/index.ts | 28 + .../record-repository-audit/index.ts | 6 +- .../index.ts | 42 +- .../routes/api/public-sharing/index.test.ts | 2 + .../api/public-sharing/links/delete/index.ts | 27 +- .../api/public-sharing/links/get/index.ts | 13 + .../api/public-sharing/links/patch/index.ts | 73 +++ .../api/public-sharing/links/post/index.ts | 4 + .../present-share-link-export/index.ts | 11 + .../public-preview/get/index.ts | 5 +- .../public-share-exports.db.test.ts | 213 ++++++++ .../api/public-sharing/public/get/index.ts | 5 +- .../respond-public-sharing-error/index.ts | 1 + .../present-security-audit/index.ts | 3 +- .../share-authorize/get/index.test.ts | 2 + hub/server/routes/index.ts | 9 + hub/server/utils/run-in-batches/index.ts | 19 + hub/server/workers/configuration.test.ts | 13 + hub/server/workers/configuration.ts | 26 + .../index.ts | 23 + .../delete-public-share-exports/index.ts | 7 + .../workers/export-public-share/index.ts | 10 + hub/server/workers/index.test.ts | 12 + hub/server/workers/index.ts | 15 +- .../recover-public-share-exports/index.ts | 14 + .../index.db.test.ts | 106 ++++ hub/test/public-share-export-storage/index.ts | 71 +++ 92 files changed, 3344 insertions(+), 132 deletions(-) create mode 100644 hub/client/features/share-link-item/styles.css create mode 100644 hub/schema/migrations/20261221120000_public_share_exports/migration.sql create mode 100644 hub/schema/share-link-backend.enum.prisma create mode 100644 hub/schema/share-link-export-state.enum.prisma create mode 100644 hub/server/domains/public-sharing/copy-public-share-files/index.ts create mode 100644 hub/server/domains/public-sharing/delete-public-share-export-files/index.ts create mode 100644 hub/server/domains/public-sharing/enqueue-public-share-export/index.ts create mode 100644 hub/server/domains/public-sharing/is-public-share-eligible/index.ts create mode 100644 hub/server/domains/public-sharing/jobs/delete-public-share-exports.ts create mode 100644 hub/server/domains/public-sharing/jobs/export-public-share.ts create mode 100644 hub/server/domains/public-sharing/jobs/recover-public-share-exports.ts create mode 100644 hub/server/domains/public-sharing/public-share-exports.db.test.ts create mode 100644 hub/server/domains/public-sharing/publish-public-share-policy/index.ts create mode 100644 hub/server/domains/public-sharing/read-public-share-export-settings/index.test.ts create mode 100644 hub/server/domains/public-sharing/read-public-share-export-settings/index.ts create mode 100644 hub/server/domains/public-sharing/read-public-share-source/index.ts create mode 100644 hub/server/domains/public-sharing/recover-public-share-exports/index.ts create mode 100644 hub/server/domains/public-sharing/synchronize-public-share-export/index.ts create mode 100644 hub/server/integrations/azure-blob/create-public-share-export-storage/index.test.ts create mode 100644 hub/server/integrations/azure-blob/create-public-share-export-storage/index.ts create mode 100644 hub/server/integrations/azure-blob/create-public-share-export-storage/types.ts create mode 100644 hub/server/repositories/public-sharing/fail-stale-public-share-exports/index.ts create mode 100644 hub/server/repositories/public-sharing/find-public-share-export/index.ts create mode 100644 hub/server/repositories/public-sharing/list-expired-public-share-exports/index.ts create mode 100644 hub/server/repositories/public-sharing/list-public-share-export-work/index.ts create mode 100644 hub/server/repositories/public-sharing/mark-public-share-export-failed/index.ts create mode 100644 hub/server/repositories/public-sharing/mark-public-share-files-deleted/index.ts create mode 100644 hub/server/repositories/public-sharing/mark-public-share-policy-written/index.ts create mode 100644 hub/server/repositories/public-sharing/start-revoking-share-links/index.ts create mode 100644 hub/server/repositories/public-sharing/update-share-link-password/index.ts create mode 100644 hub/server/routes/api/public-sharing/links/patch/index.ts create mode 100644 hub/server/routes/api/public-sharing/present-share-link-export/index.ts create mode 100644 hub/server/routes/api/public-sharing/public-share-exports.db.test.ts create mode 100644 hub/server/utils/run-in-batches/index.ts create mode 100644 hub/server/workers/create-public-share-export-dependencies/index.ts create mode 100644 hub/server/workers/delete-public-share-exports/index.ts create mode 100644 hub/server/workers/export-public-share/index.ts create mode 100644 hub/server/workers/recover-public-share-exports/index.ts create mode 100644 hub/test/database/public-share-export-migration/index.db.test.ts create mode 100644 hub/test/public-share-export-storage/index.ts diff --git a/hub/.env.example b/hub/.env.example index 96a42ecbd..693dbbc02 100644 --- a/hub/.env.example +++ b/hub/.env.example @@ -84,6 +84,14 @@ TEST_DATABASE_URL=postgresql://replica:replica@127.0.0.1:5432/postgres # HUB_HOSTED_PUBLIC_SHARING_ENABLED=false # Public share-link maximum: 1, 7, or 30 days. Defaults to 7. # HUB_SHARE_LINK_MAX_DAYS=7 +# Public share exports are off by default. When true, set the reader origin and export storage; +# Hub refuses a generated azurecontainerapps.io Hub hostname unless the shared-site override is +# true, which is for non-production installations only. See docs/share-links.md. +# HUB_PUBLIC_SHARE_ENABLED=false +# HUB_PUBLIC_SHARE_ORIGIN=https://share.example.net +# HUB_PUBLIC_SHARE_STORAGE_ACCOUNT= +# HUB_PUBLIC_SHARE_STORAGE_CONTAINER=public-share-exports +# HUB_PUBLIC_SHARE_ALLOW_SHARED_SITE=false # Generate 32 random bytes and encode them as base64. # HUB_AUTHENTICATION_ENCRYPTION_KEY= # Use a random value containing at least 32 characters. diff --git a/hub/client/application/hub/product-contracts/index.ts b/hub/client/application/hub/product-contracts/index.ts index 161be3333..f6358df10 100644 --- a/hub/client/application/hub/product-contracts/index.ts +++ b/hub/client/application/hub/product-contracts/index.ts @@ -79,8 +79,30 @@ export const productShareLinkSchema = z.object({ createdAt: timestamp, expiresAt: timestamp, revokedAt: timestamp.nullable(), + // Public share export links only. + url: httpUrl.optional(), + exportStatus: z + .enum(["pending", "ready", "updating", "failed", "revoking"]) + .nullable() + .optional(), + hasPassword: z.boolean().optional(), }) +const productSharePasswordSchema = z + .string() + .refine( + (value) => [...value.normalize("NFC")].length >= 8, + "Use a password with at least 8 characters.", + ) + .refine( + (value) => new TextEncoder().encode(value).byteLength <= 256, + "Use at most 256 bytes for the password.", + ) + +export const productSharePasswordInputSchema = z + .object({ password: productSharePasswordSchema.nullable() }) + .strict() + export const productShareInputSchema = z .object({ label: z @@ -93,6 +115,7 @@ export const productShareInputSchema = z ), expiration: z.enum(["one_day", "seven_days", "thirty_days"]), buildNumber: identifier, + password: productSharePasswordSchema.optional(), }) .strict() @@ -102,6 +125,8 @@ export const productSharingResponseSchema = z.object({ enabled: z.boolean(), canManage: z.boolean(), expirationOptions: z.array(z.enum(["one_day", "seven_days", "thirty_days"])), + backend: z.enum(["legacy", "export"]).optional(), + selectedBuildShareable: z.boolean().optional(), }) export const productSharingSettingsSchema = z.object({ diff --git a/hub/client/application/hub/routes/expanded-flows.test.tsx b/hub/client/application/hub/routes/expanded-flows.test.tsx index 2802fc2ab..cba10857a 100644 --- a/hub/client/application/hub/routes/expanded-flows.test.tsx +++ b/hub/client/application/hub/routes/expanded-flows.test.tsx @@ -185,6 +185,103 @@ describe("Hub Build share links", () => { expect(screen.queryByRole("button", { name: /Account menu/ })).not.toBeInTheDocument() }) + it("creates public export links with a password and manages the password from the link", async () => { + const { path, repository, prototype, latest } = previewRecords({ canManageSharing: true }) + const sharePath = `${path}/share-links` + const create = vi.fn() + const changePassword = vi.fn() + let link: ProductShareLink | undefined + const api = stubHubFetch( + ...authenticatedWorkspace([repository]), + http.get(`/api${sharePath}`, () => + Response.json({ + resource: { repository, prototype, selectedBuild: { ...latest, previewUrl: null } }, + links: link ? [link] : [], + enabled: true, + canManage: true, + expirationOptions: ["seven_days"], + backend: "export", + selectedBuildShareable: true, + }), + ), + http.post(`/api${sharePath}`, async ({ request }) => { + const input = (await request.json()) as { label: string; buildNumber: number } + create(input) + link = { + ...linkRecord(prototype, input.buildNumber, input.label), + url: "https://reader.example.net/s/12345678-1234-4234-8234-123456789abc", + exportStatus: "pending", + hasPassword: true, + } + return Response.json({ notice: "Share link created.", link }, { status: 201 }) + }), + http.patch(`/api${sharePath}/:shareId`, async ({ request }) => { + changePassword(await request.json()) + link = { ...link!, hasPassword: false } + return Response.json({ notice: "Password removed." }) + }), + ) + const router = await renderHubFlow(api, `${sharePath}?build=3`) + + fireEvent.change(screen.getByRole("textbox", { name: "Label" }), { + target: { value: "Partner review" }, + }) + fireEvent.change(screen.getByLabelText("Password (optional)"), { + target: { value: "correct horse battery" }, + }) + await router.settle(() => + fireEvent.click(screen.getByRole("button", { name: "Create share link" })), + ) + expect(create).toHaveBeenCalledExactlyOnceWith({ + label: "Partner review", + expiration: "seven_days", + buildNumber: 3, + password: "correct horse battery", + }) + const pending = (await screen.findByRole("heading", { name: "Partner review" })).closest("li")! + expect(within(pending).getByRole("status")).toHaveTextContent(/Preparing the public copy/) + expect(within(pending).queryByRole("link", { name: "Open" })).not.toBeInTheDocument() + + link = { ...link!, exportStatus: "ready" } + await router.settle(() => router.navigate(`${sharePath}?build=3`)) + const ready = screen.getByRole("heading", { name: "Partner review" }).closest("li")! + expect(within(ready).getByRole("link", { name: "Open" })).toHaveAttribute( + "href", + "https://reader.example.net/s/12345678-1234-4234-8234-123456789abc", + ) + expect(ready).toHaveTextContent("Password protected") + fireEvent.click(within(ready).getByText("Password")) + await router.settle(() => + fireEvent.click(within(ready).getByRole("button", { name: "Remove password" })), + ) + expect(changePassword).toHaveBeenCalledExactlyOnceWith({ password: null }) + expect(await screen.findByText("Password removed.")).toBeVisible() + }) + + it("explains that a Build the private prototype service cannot play can't be shared publicly", async () => { + const { path, repository, prototype, latest } = previewRecords({ canManageSharing: true }) + const api = stubHubFetch( + ...authenticatedWorkspace([repository]), + http.get(`/api${path}/share-links`, () => + Response.json({ + resource: { repository, prototype, selectedBuild: latest }, + links: [], + enabled: true, + canManage: true, + expirationOptions: ["seven_days"], + backend: "export", + selectedBuildShareable: false, + }), + ), + ) + await renderHubFlow(api, `${path}/share-links?build=3`) + + expect( + screen.getByRole("heading", { name: "This Build can't be shared publicly" }), + ).toBeVisible() + expect(screen.queryByRole("button", { name: "Create share link" })).not.toBeInTheDocument() + }) + it("hides creation controls and previously created URLs when deployment sharing is disabled", async () => { const { path, repository, prototype, latest } = previewRecords({ canManageSharing: true }) const api = stubHubFetch( diff --git a/hub/client/application/hub/routes/product-share-links/index.tsx b/hub/client/application/hub/routes/product-share-links/index.tsx index 8e5e2a0af..665e6d583 100644 --- a/hub/client/application/hub/routes/product-share-links/index.tsx +++ b/hub/client/application/hub/routes/product-share-links/index.tsx @@ -8,6 +8,7 @@ import { productMutationResponseSchema, productShareIdSchema, productShareInputSchema, + productSharePasswordInputSchema, productSharingResponseSchema, } from "@application/hub/product-contracts" import type { @@ -55,10 +56,12 @@ export async function clientAction({ const action = typeof actionValue === "string" ? actionValue.split("?")[0] : null try { if (action === base && !form.has("_method")) { + const password = form.get("share_link[password]") const parsed = productShareInputSchema.safeParse({ label: form.get("share_link[label]"), expiration: form.get("share_link[expiration]"), buildNumber: Number(form.get("share_link[build_number]")), + ...(typeof password === "string" && password ? { password } : {}), }) if (!parsed.success) { return data( @@ -86,6 +89,30 @@ export async function clientAction({ return data({ saved: true, notice: response.notice }) } } + if (action?.startsWith(`${base}/`) && form.get("_method") === "patch") { + const shareId = productShareIdSchema.safeParse(action.slice(base.length + 1)) + const parsed = productSharePasswordInputSchema.safeParse({ + password: + form.get("share_link[password_action]") === "remove" + ? null + : form.get("share_link[password]"), + }) + if (shareId.success && !parsed.success) { + return data( + { saved: false, error: parsed.error.issues.map(({ message }) => message).join(" ") }, + { status: 422 }, + ) + } + if (shareId.success && parsed.success) { + const response = await requestProductJson( + request, + `/api${base}/${shareId.data}`, + productMutationResponseSchema, + { method: "PATCH", body: parsed.data }, + ) + return data({ saved: true, notice: response.notice }) + } + } return data( { saved: false, error: "This share-link action is not connected." }, { status: 400 }, diff --git a/hub/client/application/hub/view-models/product-share-links-data/index.ts b/hub/client/application/hub/view-models/product-share-links-data/index.ts index 76b5646ff..1c75328c1 100644 --- a/hub/client/application/hub/view-models/product-share-links-data/index.ts +++ b/hub/client/application/hub/view-models/product-share-links-data/index.ts @@ -5,6 +5,32 @@ import type { ProductSharingResponse } from "@application/hub/product-contracts/ import { prototypeWorkspace } from "../prototype-workspace" import { resourcePath } from "../resource-path" +const exportStatusLabels = { + pending: "Preparing the public copy. The link works when it's ready.", + ready: null, + updating: "Updating the public link. The previous password applies until Hub finishes.", + failed: "This link couldn't be prepared. Delete it and create a new one.", + revoking: "Revoked. Hub is still turning off the public copy and will keep retrying.", +} + +function exportLinkState( + status: keyof typeof exportStatusLabels | null, + hasPassword: boolean, + passwordPath: string, +) { + const statusLabel = status ? exportStatusLabels[status] : null + const live = status === "ready" || status === "updating" + return { + ...(statusLabel ? { statusLabel } : {}), + ...(live ? {} : { unavailable: true }), + canDelete: status !== "revoking", + ...(status === "ready" || status === "pending" + ? { password: { hasPassword, path: passwordPath } } + : {}), + protectedLabel: hasPassword ? "Password protected" : undefined, + } +} + export function productShareLinksData( workspace: WorkspaceResponse, response: ProductSharingResponse, @@ -14,11 +40,17 @@ export function productShareLinksData( const { resource } = response const { repository, prototype, selectedBuild } = resource const base = `/repositories/${repository.id}/prototypes/${prototype.id}` - const selected = - selectedBuild?.state === "successful" && selectedBuild.previewUrl ? selectedBuild : null + const exports = response.backend === "export" + // Export links copy stored Build files, so they do not need the legacy preview address. + function hasPreview(build: { state: string; previewUrl?: string | null }) { + return build.state === "successful" && (exports || Boolean(build.previewUrl)) + } + const selected = selectedBuild && hasPreview(selectedBuild) ? selectedBuild : null const now = Date.now() const active = response.links.filter( - (link) => response.enabled && !link.revokedAt && Date.parse(link.expiresAt) > now, + (link) => + response.enabled && + ((!link.revokedAt && Date.parse(link.expiresAt) > now) || link.exportStatus === "revoking"), ) return { ...prototypeWorkspace({ @@ -28,15 +60,13 @@ export function productShareLinksData( search, surface: "build", }), - buildOptions: prototype.builds - .filter((build) => build.state === "successful" && build.previewUrl) - .map((build) => ({ - number: build.number, - label: `v${build.number}`, - path: resourcePath(`${base}/share-links`, { build: build.number }), - state: build.state, - stateLabel: "Successful", - })), + buildOptions: prototype.builds.filter(hasPreview).map((build) => ({ + number: build.number, + label: `v${build.number}`, + path: resourcePath(`${base}/share-links`, { build: build.number }), + state: build.state, + stateLabel: "Successful", + })), closePath: resourcePath(base, { build: selected?.number ?? null }), closeLabel: "Return to prototype", alert: null, @@ -68,7 +98,31 @@ export function productShareLinksData( labelMaximumBytes: 100, labelPlaceholder: "Usability review", submitLabel: "Create share link", + ...(exports + ? { + passwordLabel: "Password (optional)", + passwordHint: "At least 8 characters. Leave blank for a link without a password.", + } + : {}), }, + ...(exports + ? { + passwordLabels: { + summary: "Password", + field: "New password", + hint: "At least 8 characters. Changing it signs out viewers who used the old password.", + save: "Save password", + remove: "Remove password", + }, + } + : {}), + ...(exports && selected && response.selectedBuildShareable === false + ? { + unshareableHeading: "This Build can't be shared publicly", + unshareableLabel: + "Public links open Builds that Hub's private prototype service can already play. Choose another Build, or push a new Build from a proto/ branch.", + } + : {}), heading: "Share links", noBuildHeading: "No successful Build", noBuildLabel: "A successful Build is required before creating a share link.", @@ -88,12 +142,19 @@ export function productShareLinksData( shareLinks: active.map((link) => ({ id: link.id, label: link.label, + ...(link.exportStatus !== undefined + ? exportLinkState( + link.exportStatus ?? null, + link.hasPassword === true, + `${base}/share-links/${link.shareId}`, + ) + : {}), buildLabel: `Build ${link.buildNumber}`, createdAt: link.createdAt, createdLabel: `Created by @${link.createdBy}`, expiresAt: link.expiresAt, expiresLabel: `Expires ${new Date(link.expiresAt).toLocaleDateString()}`, - url: new URL(`/shared/${link.shareId}`, origin).href, + url: link.url ?? new URL(`/shared/${link.shareId}`, origin).href, deletePath: `${base}/share-links/${link.shareId}`, deletePrompt: `Delete “${link.label}”?`, })), @@ -104,7 +165,7 @@ export function productShareLinksData( id: link.id, label: link.label, stateLabel: link.revokedAt ? "Revoked" : "Expired", - url: new URL(`/shared/${link.shareId}`, origin).href, + url: link.url ?? new URL(`/shared/${link.shareId}`, origin).href, })) : [], } diff --git a/hub/client/features/share-link-item/index.tsx b/hub/client/features/share-link-item/index.tsx index a940805f4..754f76ca9 100644 --- a/hub/client/features/share-link-item/index.tsx +++ b/hub/client/features/share-link-item/index.tsx @@ -1,10 +1,13 @@ import { TrashIcon } from "@primer/octicons-react" -import { Button } from "@primer/react-brand" +import { Button, FormControl, TextInput } from "@primer/react-brand" +import { useId } from "react" import { HubIconButton } from "@components/hub-icon-button" import { ShareLinkRow } from "@features/share-link-row" import type { ShareLinkItemProps } from "./types" +import "./styles.css" + /** Shows one active share link and owns its browser actions. */ export function ShareLinkItem({ authenticityToken, @@ -19,25 +22,40 @@ export function ShareLinkItem({ canDelete = true, openInNewTab = true, busy = false, + passwordLabels, }: ShareLinkItemProps) { + const passwordId = useId() + const hiddenFields = ( + <> + + + {managementBuildNumber ? ( + + ) : null} + + ) + return ( - + {shareLink.unavailable ? null : ( + + )} - {canDelete ? ( + {canDelete && shareLink.canDelete !== false ? (
- - - {managementBuildNumber ? ( - - ) : null} + {hiddenFields} ) : null} + + {canDelete && shareLink.password && passwordLabels ? ( +
+ {passwordLabels.summary} +
+ + {hiddenFields} + + {passwordLabels.field} + + {passwordLabels.hint} + +
+ + {shareLink.password.hasPassword ? ( + + ) : null} +
+
+
+ ) : null}
) } diff --git a/hub/client/features/share-link-item/stories.tsx b/hub/client/features/share-link-item/stories.tsx index b540cfef0..56dd0173a 100644 --- a/hub/client/features/share-link-item/stories.tsx +++ b/hub/client/features/share-link-item/stories.tsx @@ -62,3 +62,51 @@ export const Permanent: Story = { export const ReadOnly: Story = { args: { canDelete: false }, } + +const passwordLabels = { + summary: "Password", + field: "New password", + hint: "At least 8 characters. Changing it signs out viewers who used the old password.", + save: "Save password", + remove: "Remove password", +} + +export const PublicCopyPreparing: Story = { + args: { + shareLink: { + ...shareLink, + url: "https://reader.example.net/s/12345678-1234-4234-8234-123456789abc", + statusLabel: "Preparing the public copy. The link works when it's ready.", + unavailable: true, + password: { hasPassword: false, path: "/repositories/2001/prototypes/1/share-links/1" }, + }, + passwordLabels, + }, +} + +export const PasswordProtected: Story = { + args: { + shareLink: { + ...shareLink, + url: "https://reader.example.net/s/12345678-1234-4234-8234-123456789abc", + protectedLabel: "Password protected", + password: { hasPassword: true, path: "/repositories/2001/prototypes/1/share-links/1" }, + }, + passwordLabels, + }, + play: async ({ canvas, userEvent }) => { + await userEvent.click(canvas.getByText("Password")) + }, +} + +export const Revoking: Story = { + args: { + shareLink: { + ...shareLink, + url: "https://reader.example.net/s/12345678-1234-4234-8234-123456789abc", + statusLabel: "Revoked. Hub is still turning off the public copy and will keep retrying.", + unavailable: true, + canDelete: false, + }, + }, +} diff --git a/hub/client/features/share-link-item/styles.css b/hub/client/features/share-link-item/styles.css new file mode 100644 index 000000000..2c36d965a --- /dev/null +++ b/hub/client/features/share-link-item/styles.css @@ -0,0 +1,21 @@ +.share-link-item__password { + flex-basis: 100%; +} + +.share-link-item__password > summary { + cursor: pointer; + color: var(--hub-fg-link); +} + +.share-link-item__password-form { + display: grid; + gap: var(--hub-space-8); + max-width: 24rem; + padding-top: var(--hub-space-8); +} + +.share-link-item__password-actions { + display: flex; + flex-wrap: wrap; + gap: var(--hub-space-8); +} diff --git a/hub/client/features/share-link-item/types.ts b/hub/client/features/share-link-item/types.ts index 2e183250d..ee45cd1fc 100644 --- a/hub/client/features/share-link-item/types.ts +++ b/hub/client/features/share-link-item/types.ts @@ -5,6 +5,20 @@ export interface ShareLinkData extends ShareLinkDisplayData { createdLabel: string deletePath: string deletePrompt: string + /** True while the public link does not work yet, such as an export still being prepared. */ + unavailable?: boolean + /** False while a revocation is finishing. */ + canDelete?: boolean + /** Present when the link's password can be replaced or removed. */ + password?: { hasPassword: boolean; path: string } +} + +export interface ShareLinkPasswordLabels { + summary: string + field: string + hint: string + save: string + remove: string } export interface ShareLinkItemProps { @@ -20,4 +34,5 @@ export interface ShareLinkItemProps { canDelete?: boolean openInNewTab?: boolean busy?: boolean + passwordLabels?: ShareLinkPasswordLabels } diff --git a/hub/client/features/share-link-row/index.tsx b/hub/client/features/share-link-row/index.tsx index ed2602242..a6cecc48b 100644 --- a/hub/client/features/share-link-row/index.tsx +++ b/hub/client/features/share-link-row/index.tsx @@ -37,12 +37,21 @@ export function ShareLinkRow({ ) : ( shareLink.expiresLabel )} + {shareLink.protectedLabel ? ` · ${shareLink.protectedLabel}` : null} + + {shareLink.statusLabel && !unavailableLabel ? ( +

+ {shareLink.statusLabel} +

+ ) : null}
{unavailableLabel ? ( -

{unavailableLabel}

+

+ {unavailableLabel} +

) : ( ({ + ...args, + shareLink: { + ...shareLink, + protectedLabel: "Password protected", + statusLabel: "Updating the public link. The previous password applies until Hub finishes.", + }, + }))(meta.args), +} diff --git a/hub/client/features/share-link-row/styles.css b/hub/client/features/share-link-row/styles.css index 968a98129..0205ee080 100644 --- a/hub/client/features/share-link-row/styles.css +++ b/hub/client/features/share-link-row/styles.css @@ -54,3 +54,8 @@ outline: 1px solid var(--hub-accent); outline-offset: -1px; } + +.share-link-item__status { + margin: 0; + color: var(--hub-fg-muted); +} diff --git a/hub/client/features/share-link-row/types.ts b/hub/client/features/share-link-row/types.ts index 650bdf67c..9405407af 100644 --- a/hub/client/features/share-link-row/types.ts +++ b/hub/client/features/share-link-row/types.ts @@ -9,6 +9,9 @@ export interface ShareLinkDisplayData { id: number | string label: string url: string + /** Extra state, such as an export that is still being prepared. */ + statusLabel?: string + protectedLabel?: string } export interface ShareLinkRowProps { diff --git a/hub/client/features/share-links-form/index.tsx b/hub/client/features/share-links-form/index.tsx index 2a8ae7a1f..8074a6201 100644 --- a/hub/client/features/share-links-form/index.tsx +++ b/hub/client/features/share-links-form/index.tsx @@ -25,6 +25,7 @@ export function ShareLinksForm({ }: ShareLinksFormProps) { const labelId = useId() const expirationId = useId() + const passwordId = useId() return (
@@ -44,7 +45,9 @@ export function ShareLinksForm({ > {hiddenFields} -
+
{data.labelLabel} + {data.passwordLabel ? ( + + {data.passwordLabel} + + {data.passwordHint ? {data.passwordHint} : null} + + ) : null} +