Skip to content

Commit 192c15c

Browse files
fix(app-shell): four Studio editors open no buffer over a draft the server refuses to read (#29275)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9Ubb6XXaS1k5WoFSG9mHkAJSe5)_ Part of #29148 (PR 1 of 2, the split the claim amendment 6574316242 records; PR 2 takes the Interfaces app nav, object, object-extension and flow loads in `StudioDesignSurface.tsx` and `ResourceEditPage.tsx`, and is the one that completes the card). Clause-②: no Metadata-protocol: none The two lines are copied from the claim (comment 6574269114) and its amendment (comment 6574316242). ## 维护者速读 - 改了什么:列表视图检查器、邮件模板/翻译表单编辑器、权限矩阵(包草稿入口)、钩子面板这四个 Studio 编辑器,读草稿遇到服务器 403(草稿带受众门 `requiredPermissions`,作者无权读)时,不再当成"没有草稿"去打开已发布版本,而是显示同一条拒绝说明,服务器原话放在"详情"里,自动保存没有内容可发。 - 为什么改:之前这几个编辑器会把已发布版本当作编辑起点,下一次自动保存把它写成草稿,悄悄抹掉草稿里的权限门和其他未发布改动,发布后该项对所有人可见。#29015 只修了 Interfaces 的叶子项,本 PR 修其中四个编辑器,其余在 PR 2。 - 风险与回滚:只影响草稿读取返回 403 的项;无草稿、可读草稿、其他读取失败的路径不变。钩子面板只拦被拒的那个钩子,其余钩子照常。回滚即撤销本 PR。 - 先看:`ObjectHooksPanel.tsx`(部分拒绝的处理);`PermissionMatrixEditor.tsx` 加载处的 `'refused' in pendingRead` 分支与两处渲染;`StudioBundleItemEditor.tsx` 错误条新增的"详情"。 - 两分钟验证:`pnpm --dir ui exec vitest run packages/app-shell/src/views/studio-design/ObjectHooksPanel.draftUnreadable-29148.test.tsx`,预期 3 个用例通过。 - 需要你做的:无,席位落地。 ## What changes `readDraftForSave` has handed a draft read refused `403` back as `refused` since #29132. These four editors now act on it the way the Interfaces leaf load does: no buffer is installed, the `engine.studio.refusal.draftUnreadable` sentence shows with the server's own sentence (`formatMetadataError`) behind Details, and the autosave has nothing to send. No new i18n key. - `studio-design/ObjectListViewInspector.tsx` (`useObjectListViewDraft`): a refused view draft read leaves the buffer unloaded (`for: ''`, `row: null`) and sets `failure` to the new `draftUnreadable` arm, which the panel's existing refusal host renders. The published layer is not read. - `studio-design/StudioBundleItemEditor.tsx`: a refused read installs no draft, clears the guard's pins (`forget`), and shows neither the form nor the preview. The editor's error host now renders a Details disclosure when a refusal carries one (only this refusal does today). - `metadata-admin/PermissionMatrixEditor.tsx` (package door, load only): a refused read installs no matrix; the strip replaces it in both presentations (routed page and the Studio Access pillar), and the autosave is blocked. The pre-save re-read (it already refuses the save when the draft read answers nothing) and the post-save verdict re-read (installs nothing) are unchanged, per the claim amendment. - `studio-design/ObjectHooksPanel.tsx`: the list load keeps the refused hooks by name. A refused hook stays listed by its published row, pins nothing, and opens no buffer: selecting it shows the strip in the detail pane. A partial refusal holds only that hook; the other hooks load, edit and save as before. A hook known only by its refused draft is not listed, as today: nothing says it fires on this object. ## Tests One new file per editor, each with a refused case, a control (no pending draft: the published body opens and the first save is pinned `If-None-Match: *`), and for the hooks panel a partial-refusal case. - `ObjectListViewInspector.draftUnreadable-29148.test.tsx` (2): the real hook and panel over a real `MetadataClient` and an in-memory server whose `?state=draft` read answers 403. - `StudioBundleItemEditor.draftUnreadable-29148.test.tsx` (2) - `PermissionMatrixEditor.draftUnreadable-29148.test.tsx` (3): routed page, Studio presentation, control. - `ObjectHooksPanel.draftUnreadable-29148.test.tsx` (3): refused, partial refusal, control. Ablation, one per editor (`scripts/ablation-replace.mjs`, guard turned into `false && …`, restore proven blob == HEAD): each refused case goes red and each control stays green. ## Acceptance notes - Each editor renders the strip in its own refusal host, in the Studio refusal strip's look. Moving `StudioRefusalStrip` into a shared module, so every editor draws the one component, is PR 2's (it edits `StudioDesignSurface.tsx`, which open PR #29224 also edits). - Changed lines 843: 162 in the four editors, 669 in the four new test files, 12 in the changeset. ## Verification Head `fc165c69` (main `47ee57fe` merged in), branched from `10bfd70e`. The new tests and app-shell type-check were re-run on the merged head; the sweep, the ui scripts suite and the gates ran on `b944048d`, before the merge. <details><summary>New tests and ablations</summary> ``` vitest run (4 new files): Test Files 4 passed (4), Tests 10 passed (10) ablation bundle : 1 failed | 1 passed (refused case red, control green), restored blob == HEAD ablation listview : 1 failed | 1 passed, restored ablation perm : 2 failed | 1 passed, restored ablation hooks : 1 failed | 2 passed, restored ``` </details> <details><summary>Type-check and nearby suites</summary> ``` turbo run type-check --filter=@object-ui/app-shell: 65/65 tasks, exit 0 (tsc --noEmit and tsconfig.test.json) vitest, the 80 test files naming the four editors (2 batches of 40): 40/40 (279 tests) and 40/40 (236 tests) pnpm --dir ui exec vitest run scripts/: 169 passed | 2 skipped files, 4900 passed | 2 skipped tests ``` </details> <details><summary>Derived gates</summary> 34 derived families run on b944048 (before the merge of main; main's incoming commits touch none of the four editors), every one exit 0. dispatch-gates --ran: 34 derived, 34 run, 0 NOT-MEASURED, 0 UNRUN. ``` node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0 node scripts/check-adr-0087-registration.mjs --self-test :: exit 0 node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0 node scripts/check-closing-keyword-parity.mjs :: exit 0 node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0 node scripts/check-comment-mask-corpus.mjs :: exit 0 node scripts/check-empty-changeset.mjs --base origin/main :: exit 0 node scripts/check-empty-changeset.mjs --self-test :: exit 0 node scripts/check-sdui-manifest.mjs :: exit 0 node scripts/check-sdui-manifest.mjs --self-test :: exit 0 node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0 node scripts/release-pending-publish.mjs --self-test :: exit 0 pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0 pnpm check:changeset-gate-self-tests :: exit 0 pnpm check:closed-ceremony-text :: exit 0 pnpm check:cross-package-test-inputs :: exit 0 pnpm check:dispatcher-error-vocabulary :: exit 0 pnpm check:driver-memory-census :: exit 0 pnpm check:engine-double-contract :: exit 0 pnpm check:gitlink-declared :: exit 0 pnpm check:nul-bytes :: exit 0 pnpm check:pm-changeset-deadline-census :: exit 0 pnpm check:published-files :: exit 0 pnpm check:query-options-erasure :: exit 0 pnpm check:refd-timer-probe :: exit 0 pnpm check:skill-identifier-liveness :: exit 0 pnpm check:test-source-alias :: exit 0 pnpm check:tier-file-adoption :: exit 0 pnpm check:type-check-coverage :: exit 0 pnpm check:type-check-debt :: exit 0 pnpm check:undeclared-dep-imports :: exit 0 pnpm check:watch-hint-literal :: exit 0 pnpm check:where-matcher :: exit 0 pnpm --dir ui exec vitest run scripts/ :: exit 0 ``` </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QsR2jTCMoEXh1SQzWaNp2v)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 32b9c6b commit 192c15c

9 files changed

Lines changed: 826 additions & 17 deletions
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(app-shell): the list view inspector, the email template and translation form editor, the permission matrix and the hooks panel no longer edit the published version over a draft the author is not allowed to read
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
- **Before.** A pending draft can carry an audience gate (`requiredPermissions`) its author does not hold, for example one written over the API or MCP, and the draft read answers `403 PERMISSION_DENIED` for it by design. `readDraftForSave` hands that refusal back as `refused`, but these four editors still read it as "no pending draft": they opened the published body in its place, and their next save sent that body as the draft, dropping the gate and every other unpublished change.
11+
- **Now.** Each of them installs no buffer for such an item: nothing is shown to edit and the autosave has nothing to send. The refusal strip says the item has an unpublished draft this author may not read and that editing the published version would overwrite it; the server's own sentence is behind Details. The hooks panel holds only the refused hook: the other hooks of the object open and save as before.
12+
- **Unchanged.** An item with no pending draft opens the published body and its first save is still pinned to "no draft row"; a readable draft opens as served. Any other failed draft read is handled as before.
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#29148 — the permission matrix's PACKAGE door takes a pending
5+
* draft the server refuses to read (`403 PERMISSION_DENIED`) for what it is,
6+
* never for "no draft". It installs no matrix over it: the published set is
7+
* not offered to edit, the refusal strip says why with the server's sentence
8+
* behind Details, and the autosave sends nothing, so the draft keeps every
9+
* change it holds. Both presentations: the routed page and the Studio Access
10+
* pillar's (`studio`).
11+
*
12+
* The client double refuses the draft read as the metadata client throws a
13+
* refused read (an `Error` carrying `status` and `code`), and resolves `null`
14+
* for no draft (the client's reading of a 404).
15+
*/
16+
17+
import '@testing-library/jest-dom/vitest';
18+
import { act, cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
19+
import { afterEach, describe, expect, it, vi } from 'vitest';
20+
import { MemoryRouter } from 'react-router-dom';
21+
import { t } from './i18n';
22+
23+
const PUBLISHED = {
24+
name: 'sales_perms',
25+
label: 'Sales',
26+
objects: { a_account: { allowRead: true, allowCreate: true } },
27+
fields: {},
28+
};
29+
const LAYERED = { effective: PUBLISHED, code: null, overlay: null, overlayScope: null };
30+
const GATE_REFUSAL = "You do not have permission to read the pending draft of 'sales_perms'.";
31+
32+
interface Server {
33+
/** The read refuses the pending draft as the read gate does. */
34+
refused: boolean;
35+
draftReads: unknown[][];
36+
savedOpts: Array<Record<string, unknown> | undefined>;
37+
}
38+
39+
// `withPreviewDrafts` answers the client itself, not a promise (objectstack#26840).
40+
type FakeClient = Record<string, (...args: never[]) => unknown>;
41+
42+
function makeClient(server: Server): FakeClient {
43+
return {
44+
layered: async () => LAYERED,
45+
getDraft: async (...args: unknown[]) => {
46+
server.draftReads.push(args);
47+
if (server.refused) {
48+
throw Object.assign(new Error(GATE_REFUSAL), {
49+
status: 403,
50+
code: 'PERMISSION_DENIED',
51+
body: { success: false, error: { code: 'PERMISSION_DENIED', message: GATE_REFUSAL } },
52+
});
53+
}
54+
return null;
55+
},
56+
withPreviewDrafts() {
57+
return this;
58+
},
59+
list: async (type: string) => (type === 'object' ? [{ item: { name: 'a_account' } }] : type === 'permission' ? [PUBLISHED] : []),
60+
get: async () => null,
61+
save: async (_type: string, _name: string, payload: Record<string, unknown>, saveOpts?: Record<string, unknown>) => {
62+
server.savedOpts.push(saveOpts);
63+
return { success: true, version: 'hmac-sha256:receipt', state: 'draft', payload };
64+
},
65+
};
66+
}
67+
68+
let clientImpl: FakeClient;
69+
70+
vi.mock('./useMetadata', () => ({
71+
useMetadataClient: () => clientImpl,
72+
useMetadataTypes: () => ({
73+
loading: false,
74+
error: null,
75+
entries: [{ type: 'permission', label: 'Permission', allowEnvironmentOverlay: true }],
76+
}),
77+
}));
78+
79+
vi.mock('./AssignedUsersSection', () => ({ AssignedUsersSection: () => null }));
80+
81+
import { PermissionMatrixEditPage } from './PermissionMatrixEditor';
82+
83+
afterEach(cleanup);
84+
85+
const AUTOSAVE = { timeout: 4000 };
86+
87+
function renderDoor({ studio = false }: { studio?: boolean } = {}) {
88+
return render(
89+
<MemoryRouter>
90+
<PermissionMatrixEditPage
91+
type="permission"
92+
name="sales_perms"
93+
packageId="app.a"
94+
{...(studio ? { studio: { tab: 'objects' as const, onTabChange: () => {} } } : {})}
95+
/>
96+
</MemoryRouter>,
97+
);
98+
}
99+
100+
/** Longer than the autosave's debounce, so a save that was going to leave has left. */
101+
async function pastTheAutosave() {
102+
await act(async () => {
103+
await new Promise((resolve) => setTimeout(resolve, 2500));
104+
});
105+
}
106+
107+
async function expectRefusedAndHeld(server: Server) {
108+
// Red on base: the refusal was read as "no draft", and the published set
109+
// was installed as the matrix and offered to edit.
110+
const strip = await screen.findByTestId('perm-draft-unreadable', undefined, { timeout: 8000 });
111+
expect(strip).toHaveTextContent(t('engine.studio.refusal.draftUnreadable', 'en-US'));
112+
// The server's own sentence stays reachable, behind Details.
113+
expect(strip.querySelector('details')).toHaveTextContent(GATE_REFUSAL);
114+
expect(server.draftReads).toContainEqual(['permission', 'sales_perms', { packageId: 'app.a' }]);
115+
expect(screen.queryByText('a_account')).toBeNull();
116+
await pastTheAutosave();
117+
expect(server.savedOpts).toEqual([]);
118+
}
119+
120+
describe('the package door opens no matrix over a draft the server refuses to read (objectstack#29148)', () => {
121+
it('the routed page: the strip says why, nothing is editable, and no save is sent', async () => {
122+
const server: Server = { refused: true, draftReads: [], savedOpts: [] };
123+
clientImpl = makeClient(server);
124+
renderDoor();
125+
await expectRefusedAndHeld(server);
126+
});
127+
128+
it('the Studio Access pillar: the strip says why, nothing is editable, and no save is sent', async () => {
129+
const server: Server = { refused: true, draftReads: [], savedOpts: [] };
130+
clientImpl = makeClient(server);
131+
renderDoor({ studio: true });
132+
await expectRefusedAndHeld(server);
133+
});
134+
135+
it('CONTROL: with no pending draft the published set opens, and an edit saves pinned to "no draft row"', async () => {
136+
const server: Server = { refused: false, draftReads: [], savedOpts: [] };
137+
clientImpl = makeClient(server);
138+
renderDoor();
139+
await screen.findByText('a_account', undefined, { timeout: 8000 });
140+
expect(screen.queryByTestId('perm-draft-unreadable')).toBeNull();
141+
142+
const row = screen.getByText('a_account').closest('tr')!;
143+
fireEvent.click(within(row).getByRole('button', { name: 'None' }));
144+
await waitFor(() => expect(server.savedOpts).toHaveLength(1), AUTOSAVE);
145+
expect(server.savedOpts[0]).toMatchObject({ mode: 'draft', packageId: 'app.a', ifNoneMatch: '*' });
146+
expect(server.savedOpts[0]).not.toHaveProperty('ifMatch');
147+
});
148+
});

‎ui/packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.tsx‎

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ import { CatalogItemActiveSwitch } from './CatalogActiveSwitch.js';
126126
import { isEnvironmentScope, useWalledCatalogReadOnly } from './catalog-scope.js';
127127
import { useCanAuthorMetadata, useCanReadAuthoringTrail } from '../../hooks/useCanAuthorMetadata.js';
128128
import { errorCodeIs } from '@object-ui/types';
129-
import type { MetadataError } from '@object-ui/data-objectstack';
129+
import { formatMetadataError, type MetadataError } from '@object-ui/data-objectstack';
130130
import { PermissionSetCloneDialog } from './PermissionSetCloneDialog.js';
131131
import { isStudioHiddenSystemField } from '../studio-design/studioHiddenSystemField.js';
132132
import type { PermissionSetCloned } from './permission-set-clone.js';
@@ -846,6 +846,12 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved,
846846
const [savedAt, setSavedAt] = React.useState<Date | null>(null);
847847
const displayLocale = useDisplayLocale();
848848
const [error, setError] = React.useState<string | null>(null);
849+
// objectstack#29148 — the server refused to read this set's pending package
850+
// draft (`403`: the row is there and withheld from this author). No matrix
851+
// is installed over it, so nothing is shown to edit and the autosave has
852+
// nothing to send: one seeded from the published set would be saved over
853+
// the draft, dropping every change it holds. Held as thrown, worded at render.
854+
const [draftRefused, setDraftRefused] = React.useState<{ error: unknown } | null>(null);
849855
// objectui#9484 — the ENVIRONMENT door's post-save baseline re-read REJECTED.
850856
// The write itself has already landed when that read runs, so this is an
851857
// advisory notice about the DISPLAY being un-refreshed, and it deliberately
@@ -921,6 +927,7 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved,
921927
setSaveRefusedAsLocked(null);
922928
setCloned((c) => (c && c.name === name ? c : null));
923929
setServedLabel(null);
930+
setDraftRefused(null);
924931
(async () => {
925932
try {
926933
// ADR-0086 P2 (D6): under the package door a set is draft/published
@@ -978,6 +985,12 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved,
978985
draftReadForSave,
979986
]);
980987
if (cancelled) return;
988+
// objectstack#29148 — a refused draft read is no absence: see `draftRefused`.
989+
if (pendingRead && 'refused' in pendingRead) {
990+
forgetSetVersion();
991+
setDraftRefused({ error: pendingRead.refused });
992+
return;
993+
}
981994
const pendingDraft = pendingRead?.answer ?? null;
982995
verdictReadSeq.current += 1;
983996
setServedVerdict(
@@ -1634,9 +1647,9 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved,
16341647
const autosaveTarget = `${type}:${name}`;
16351648
useDraftAutoSave({
16361649
target: autosaveTarget,
1637-
loadedFor: loading ? '' : autosaveTarget,
1650+
loadedFor: loading || draftRefused ? '' : autosaveTarget,
16381651
dirty: isDirty,
1639-
blocked: !packageId || !writable || saving || saveHeld || destructive !== null,
1652+
blocked: !packageId || !writable || saving || saveHeld || destructive !== null || draftRefused !== null,
16401653
snapshot: draft,
16411654
save: (sent) => doSave(false, undefined, sent),
16421655
});
@@ -1806,6 +1819,22 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved,
18061819
)}
18071820
</>
18081821
);
1822+
// objectstack#29148 — in place of the matrix: why no set is open, the
1823+
// server's own sentence behind Details (the Studio refusal strip's look).
1824+
const draftRefusedEl = draftRefused && (
1825+
<div
1826+
data-testid="perm-draft-unreadable"
1827+
className="m-4 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive"
1828+
>
1829+
<p role="alert" className="whitespace-pre-line">
1830+
{t('engine.studio.refusal.draftUnreadable')}
1831+
</p>
1832+
<details className="mt-1">
1833+
<summary className="cursor-pointer select-none opacity-80">{t('engine.studio.refusal.details')}</summary>
1834+
<pre className="mt-1 whitespace-pre-wrap break-words font-mono opacity-90">{formatMetadataError(draftRefused.error)}</pre>
1835+
</details>
1836+
</div>
1837+
);
18091838
const noticesEl = (
18101839
<>
18111840
{error && (
@@ -2240,6 +2269,8 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved,
22402269
<div className="flex items-center gap-2 p-6 text-sm text-muted-foreground">
22412270
<Loader2 className="h-4 w-4 animate-spin" /> {t('perm.loading').replace('{name}', name)}
22422271
</div>
2272+
) : draftRefusedEl ? (
2273+
draftRefusedEl
22432274
) : (
22442275
<div className="flex min-h-0 flex-1 flex-col overflow-hidden">
22452276
{noticesEl}
@@ -2337,6 +2368,14 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved,
23372368
);
23382369
}
23392370

2371+
if (draftRefusedEl) {
2372+
return (
2373+
<PageShell entry={entry} itemName={name} embedded={embedded} readOnly={readOnly}>
2374+
{draftRefusedEl}
2375+
</PageShell>
2376+
);
2377+
}
2378+
23402379
return (
23412380
<PageShell
23422381
entry={entry ?? { type, label: type }}

0 commit comments

Comments
 (0)