Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .changeset/36444-studio-public-form-designer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
'@objectstack/spec': patch
---

feat(studio): design an object's public forms under the object, in Studio's Form tab

Clause-②: yes (widening) — new Studio language-pack keys (`engine.studio.data.form.surface*` and the `engine.studio.publicForms.*` block) in en and zh
Metadata-protocol: none

Studio → Data → an object → Form now switches between the **Record form** (the New and Edit dialogs' layout, as before) and the object's **Public forms**, the forms anyone can fill in without signing in, each submission a record of the object. No new tab: the Data pillar keeps its seven.

The designer lists the object's public forms (published ones, and ones only drafted) and:

- creates one (a title and an address; it starts with the fields the object requires) and deletes one;
- picks its fields from the object's fillable ones only: never a hidden, read-only, system, formula, roll-up or auto-number field;
- reorders fields by dragging (or the move buttons), marks them required, and groups them into named sections;
- sets the title, the description, the after-submit heading and message (`submitBehavior: { kind: 'thank-you' }`) and the address;
- shows the form live as it is edited.

Two refusals, each with its reason on screen:

- **A field the object requires** cannot be removed and is always required on the form. "Requires" means required with no default value and no default choice: a field the write path fills in, such as a status with `defaultValue`, is not held.
- **An address another form already uses** is refused, switched-off forms included, and nothing is saved.

Saves follow Studio's draft → publish path: Save draft writes the form's draft, and Publish puts it live.

- A form of a writable package is saved in that package.
- On an installed app, a form the app ships is saved as a declared override in the app's customization package (ADR-0146), never in the app. A new form goes into the customization package.
- A form the app ships cannot be deleted; the designer says to switch it off in Setup → Public forms instead.

Switching a form on or off stays Setup's. The stored shape is the form view item it always was (`viewKind: 'form'`, `config.sharing`); no key is added. Access restrictions (password, expiry, domains) are not offered.

Setup → Public forms names a form by the same rule: its label, else its title, else its first section's label, else its key.

New locale keys: `engine.studio.data.form.surface*` and `engine.studio.publicForms.*` in the studio catalogue (en, zh).

Alongside, from the review of the Setup page (#36697):

- The designer's list reads an installed app's forms the way Setup → Public forms does: a form its app ships switched off (withdrawn by the app's own document, which no customization re-opens) is listed as "Off (its app ships it off)", never On, and a form whose app document cannot be read as "Unknown".
- On Setup → Public forms, a row whose status is unknown offers no switch; Refresh reads it again.
- `anonymousFormIntakeWithdrawnIn`'s docblock (`@objectstack/spec/ui`) names its callers as they are: the anonymous form doors, the v18 organization-ownership migration and the console's Setup → Public forms page. It no longer names an organization-scoped write door that does not call it. Prose only; the function is unchanged.
8 changes: 4 additions & 4 deletions docs/qa/platform-checklist/areas/access-security.json
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,7 @@
{
"clause": "an administrator's save is environment-wide whatever organization the session has active, and its withdrawal closes the form: with ORG active, the save that sets allowAnonymous false with the link kept answers 200 and names the environment-wide scope (never org=ORG), the item read with no organization active serves that withdrawal, and both doors answer 404 with code FORM_NOT_FOUND and the probe leaves no row",
"oracle": "api",
"verify": "step 2's baseline probe is recorded first (a form already closed is closed for an unrelated reason); then step 4's save status and message, the no-organization read, and the GET and POST status and body code with the admin's count for the marker, which is 0. Mechanism: the /meta doors hand the protocol no organization, and an organization-scoped write is refused by packages/metadata-protocol/src/protocol.ts#organizationScopedWriteRefusal (403 NOT_OVERRIDABLE, ADR-0131 D6); packages/rest/src/form-routes.ts#registerFormEndpoints reads the environment's view list alone and drops a candidate that packages/metadata-core/src/anonymous-form-intake.ts#anonymousFormIntakeWithdrawnIn finds withdrawn in that same list",
"verify": "step 2's baseline probe is recorded first (a form already closed is closed for an unrelated reason); then step 4's save status and message, the no-organization read, and the GET and POST status and body code with the admin's count for the marker, which is 0. Mechanism: the /meta doors hand the protocol no organization, and an organization-scoped write is refused by packages/metadata-protocol/src/protocol.ts#organizationScopedWriteRefusal (403 NOT_OVERRIDABLE, ADR-0131 D6); packages/rest/src/form-routes.ts#registerFormEndpoints reads the environment's view list alone and drops a candidate that packages/spec/src/ui/anonymous-form-intake.ts#anonymousFormIntakeWithdrawnIn finds withdrawn in that same list",
"evidence": "the baseline and step 4 probes (status, code, row count), the save response with the scope it names, and the no-organization read"
},
{
Expand All @@ -1835,7 +1835,7 @@
{
"clause": "only an explicit false withdraws (#21835 comment 5994082238, 「不算,写进文档」): another package's body of the view name that keeps the link with enabled true and allowAnonymous absent, or that names no public link, closes nothing, so the open form is still served (GET 200, POST 201)",
"oracle": "test",
"verify": "pnpm --filter @objectstack/rest exec vitest run --maxWorkers=2 src/public-form-withdrawal.test.ts, the cases 'only an explicit false withdraws: a body with the link, enabled true and allowAnonymous absent closes nothing' and 'not a withdrawal: another package's body with the public link cleared leaves the form served'; and pnpm --filter @objectstack/metadata-core exec vitest run --maxWorkers=2 src/anonymous-form-intake.test.ts, the cases 'only an explicit false withdraws: an absent switch is not a withdrawal' and 'not a withdrawal: no body of the row, no sharing, the link cleared'. Mechanism: packages/metadata-core/src/anonymous-form-intake.ts#anonymousFormExplicitWithdrawals (a sharing withdraws only when it keeps a non-empty publicLink and sets enabled or allowAnonymous to false). No stock fixture (knownGaps)",
"verify": "pnpm --filter @objectstack/rest exec vitest run --maxWorkers=2 src/public-form-withdrawal.test.ts, the cases 'only an explicit false withdraws: a body with the link, enabled true and allowAnonymous absent closes nothing' and 'not a withdrawal: another package's body with the public link cleared leaves the form served'; and pnpm --filter @objectstack/metadata-core exec vitest run --maxWorkers=2 src/anonymous-form-intake.test.ts, the cases 'only an explicit false withdraws: an absent switch is not a withdrawal' and 'not a withdrawal: no body of the row, no sharing, the link cleared'. Mechanism: packages/spec/src/ui/anonymous-form-intake.ts#anonymousFormExplicitWithdrawals (a sharing withdraws only when it keeps a non-empty publicLink and sets enabled or allowAnonymous to false). No stock fixture (knownGaps)",
"evidence": "the two test runs, naming the cases above as passed"
},
{
Expand Down Expand Up @@ -1873,8 +1873,8 @@
"ref": "packages/qa/dogfood/test/showcase-public-form-withdrawal-layers.dogfood.test.ts ('showcase: a public form withdrawal at any metadata layer holds', 4 cases on a showcase boot with an organization active: the precondition, acceptance[0] and negative[1] through the save — 200, a message naming the env-wide scope and never the active organization's id, both doors 404 FORM_NOT_FOUND, 0 landed rows — then the no-organization read: set-active null, GET /meta/view/showcase_inquiry.contact serves config.sharing.allowAnonymous false with the link kept, set-active the organization again; and acceptance[1], both doors open with the row landing in the organization) + packages/rest/src/public-form-withdrawal.test.ts (the doors: '[#21331] public form withdrawal reaches every intake door', including '[ADR-0131 C7] no view read names an organization, whatever the tenancy answers: one environment read per door', and 'a public form withdrawal is a kill switch: one package's withdrawal of a view name closes its form') + packages/metadata-protocol/src/protocol.org-scoped-write-refused.test.ts ('[ADR-0131 D6] no organization-scoped metadata write is accepted', 'two packages shipping a view name' and 'each package's copy of a view container expands into its own package's slot', blocks (a) to (f)) + packages/metadata-core/src/anonymous-form-intake.test.ts (the anonymousFormIntakeWithdrawnIn cases). acceptance[0], acceptance[1], negative[0] and negative[1] score from the dogfood pin. acceptance[2] to acceptance[5] have no stock fixture (knownGaps); their pins are a unit (the rest file drives RestServer over a mocked protocol) and an in-process protocol over a stub registry (the metadata-protocol file), which is the layer their test oracle asks for. negative[2] is the dogfood pin's save at 200; negative[3] to negative[5] are procedural"
},
"source": [
"packages/metadata-core/src/anonymous-form-intake.ts#anonymousFormIntakeWithdrawnIn (the one judgement the doors make over the environment's list: a body of the same view name withdraws a candidate matched by slot or by slug; the package is not compared)",
"packages/metadata-core/src/anonymous-form-intake.ts#anonymousFormExplicitWithdrawals (explicit only: a sharing that keeps its publicLink and sets enabled or allowAnonymous to false; a schema-parsed artifact carries the default enabled false, which counts)",
"packages/spec/src/ui/anonymous-form-intake.ts#anonymousFormIntakeWithdrawnIn (the one judgement the doors make over the environment's list: a body of the same view name withdraws a candidate matched by slot or by slug; the package is not compared)",
"packages/spec/src/ui/anonymous-form-intake.ts#anonymousFormExplicitWithdrawals (explicit only: a sharing that keeps its publicLink and sets enabled or allowAnonymous to false; a schema-parsed artifact carries the default enabled false, which counts)",
"packages/rest/src/form-routes.ts#registerFormEndpoints (resolveFormBySlug: the environment's view list alone, judged against itself as the layer beneath each candidate; the Default Organization's legacy read was deleted with ADR-0131 C7, and the tenancy service is still read for the posture; a withdrawn form answers 404 FORM_NOT_FOUND on both doors)",
"packages/metadata-protocol/src/protocol.ts#getMetaItems (the environment's view list the doors read: one item per package that ships a view name, ADR-0048; a package-less copy stands in for every package with no copy of its own, packages/metadata-protocol/src/protocol.ts#servedViewExpansion)",
"packages/metadata-protocol/src/protocol.ts#organizationScopedWriteRefusal (every organization-scoped write refused 403 NOT_OVERRIDABLE, ADR-0131 D6; PR #22515 deleted the intake-specific organization refusals and the row anchor revision 1 cited, and since PR #22447 the /meta doors hand the protocol no organization, so an organization-active administrator's save is environment-wide)",
Expand Down
27 changes: 15 additions & 12 deletions packages/spec/src/ui/anonymous-form-intake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,22 @@ function anonymousFormExplicitWithdrawals(view: unknown): Array<{ slot: string;
* Does one metadata layer withdraw an open form candidate? A WITHDRAWAL IS A
* KILL SWITCH: layering may only narrow anonymous intake, never re-open it, so
* the anonymous form doors serve a candidate only when no layer beneath it
* withdraws it, and the organization-scoped write door refuses a save that
* would leave one open.
* withdraws it.
*
* Three callers judge by it. The anonymous form doors (`registerFormEndpoints`
* in `@objectstack/rest`) pass the environment's view list as the layer. The
* v18 organization-ownership migration (`os migrate organization-ownership
* --apply`, `@objectstack/cli`) passes the organization rows it carries onto
* the environment. The console's Setup → Public forms page passes an installed
* app's own document, so it never shows on, or switches on, a form the app
* ships withdrawn (objectstack#36444).
*
* Identity is the `name`: the layer withdraws the candidate only through a
* body of the same `name` as the candidate's `view`. What that name is depends
* on the caller. The organization-scoped write door passes the env-wide body
* of the stored row the overlay is keyed by, so a key rename, a `form.name`,
* a slot move or an expansion rename is still judged against the form it was.
* The anonymous doors pass the env-wide view list and the item they serve, so
* they judge by the served item name (a known limit: an overlay stored before
* the withdrawal, or restored by rollback or revert, that moves its form to
* another key or slot is not matched there). The layer withdraws the
* body of the same `name` as the candidate's `view`. The anonymous doors pass
* the env-wide view list and the item they serve, so they judge by the served
* item name (a known limit: an overlay stored before the withdrawal, or
* restored by rollback or revert, that moves its form to another key or slot
* is not matched there). The layer withdraws the
* candidate when its body of that name EXPLICITLY
* withdraws a form ({@link anonymousFormExplicitWithdrawals}) that matches the
* candidate by slot (the same `form`, `formViews` key or `config`) OR by slug
Expand All @@ -205,8 +209,7 @@ function anonymousFormExplicitWithdrawals(view: unknown): Array<{ slot: string;
* limit that fails closed: it may over-close another package's form of the
* same name). It judges only the bodies the layer holds, so a caller closes a
* name in every package only when its layer holds every package's body of the
* name. The organization-scoped write door anchors one body per package. The
* env-wide view list the anonymous doors read holds one item per package of a
* name. The env-wide view list the anonymous doors read holds one item per package of a
* name: a package's saved env-wide copy of a view container serves that
* package's item of each form it expands, and a package-less copy stands in
* for every package with no copy of its own. A layer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ describe('PublicFormsSetupPage', () => {
await waitFor(() => expect(row).toHaveAttribute('data-unknown', 'true'));
expect(row).toHaveAttribute('data-on', 'false');
expect(screen.getByTestId('public-form-unknown-web_to_lead')).toHaveTextContent('«publicFormsSetup.statusUnknown»');
// Not knowing whether it is live, the page offers no switch: Refresh reads it again.
expect(screen.getByTestId('public-form-switch-web_to_lead')).toBeDisabled();
});

it('a switch over a pending draft says so and does not read as done', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ function PublicFormsSetupBody() {
<div className="inline-flex items-center gap-2">
<Switch
checked={row.on}
disabled={busy !== null || !canSwitch || !!row.shippedOff}
disabled={busy !== null || !canSwitch || !!row.shippedOff || !!row.unknown}
onCheckedChange={(next) => void flip(row, next)}
aria-label={t(row.on ? 'publicFormsSetup.switchOffLabel' : 'publicFormsSetup.switchOnLabel', {
name: row.title,
Expand Down
32 changes: 6 additions & 26 deletions ui/packages/app-shell/src/views/setup/publicForms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import {
} from '../runtime-metadata-persistence.js';
import { declaredOverrideOf, overrideDraftBody } from '../studio-design/StudioCustomizeControls.js';
import { fetchListedPackageManifests } from '../studio-design/packages-io.js';
import { publicFormShownName } from '../studio-design/publicForm/publicFormDesign.js';

type FormDoc = Record<string, any>;

Expand All @@ -86,7 +87,7 @@ const isDoc = (v: unknown): v is FormDoc => !!v && typeof v === 'object' && !Arr
export interface PublicFormRow {
/** The form view item's name: the metadata address every write names. */
name: string;
/** What the page shows as its name ({@link shownName}). */
/** What the page shows as its name (`publicFormShownName`, Studio's designer names it the same way). */
title: string;
/** The object a submission creates a record of. */
object?: string;
Expand Down Expand Up @@ -114,27 +115,6 @@ function withSwitch(form: FormDoc, on: boolean): FormDoc {
return { ...form, sharing: { ...(isDoc(form.sharing) ? form.sharing : {}), enabled: on } };
}

const text = (v: unknown): string | undefined => (typeof v === 'string' && v.trim() ? v : undefined);

/**
* The name a form is shown by, in the words its author gave it: the served
* (translated) label, else the form's title or label, else the label of its
* first section (what the form's own page heads it with), else its name
* without the object prefix (`crm_lead.web_to_lead` → `web_to_lead`).
*/
function shownName(item: FormDoc): string {
const config: FormDoc = isDoc(item.config) ? item.config : {};
const first = Array.isArray(config.sections) ? config.sections.find(isDoc) : undefined;
const dot = item.name.lastIndexOf('.');
return (
text(item.label) ??
text(config.title) ??
text(config.label) ??
text(first?.label) ??
(dot >= 0 && dot < item.name.length - 1 ? item.name.slice(dot + 1) : item.name)
);
}

/**
* The public form a served view item carries, or `null` (module header): a
* `viewKind: 'form'` item whose `config` the rule opens once its switch is on.
Expand All @@ -149,7 +129,7 @@ export function publicFormRowOf(item: unknown): PublicFormRow | null {
const packageId = typeof item._packageId === 'string' && item._packageId ? item._packageId : null;
return {
name: item.name,
title: shownName(item),
title: publicFormShownName(item),
object: anonymousFormObjectName(item, item.config),
slug: listed.slug,
on,
Expand Down Expand Up @@ -280,11 +260,11 @@ async function readFormLayers(name: string, target: ResolvedTarget, client: Pick
* app's form; a row whose layers cannot be read is marked `unknown` and is not
* shown as on.
*/
export async function markShippedOff(
rows: readonly PublicFormRow[],
export async function markShippedOff<R extends Pick<PublicFormRow, 'name' | 'on' | 'packageId' | 'shippedOff' | 'unknown'>>(
rows: readonly R[],
client: Pick<PublicFormSwitchClient, 'layered'>,
doors?: Pick<DashboardSaveTargetDoors, 'listPackages'>,
): Promise<PublicFormRow[]> {
): Promise<R[]> {
if (!rows.some((r) => r.packageId)) return [...rows];
const listPackages = doors?.listPackages ?? fetchListedPackageManifests;
let listing: ReturnType<typeof listPackages> | undefined;
Expand Down
Loading
Loading