Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

fix(web): 删除组织的确认框被拒时留着,原因也留在框里(7.40)

lmliheng1f8167e2a5ab
diff --git a/changelog/unreleased/2026-10-25-org-delete-refusal.md b/changelog/unreleased/2026-10-25-org-delete-refusal.md
new file mode 100644
index 00000000..15f8764b
--- /dev/null
+++ b/changelog/unreleased/2026-10-25-org-delete-refusal.md
@@ -0,0 +1,38 @@
+# Organization settings: a refused deletion keeps its question — and the reason
+
+- **Date:** 2026-10-25
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文](2026-10-25-org-delete-refusal.zh.md)
+
+The "delete" row at the bottom of the organization settings dialog asks before it really deletes,
+and it asks for the organization's id typed out. That confirmation used to stay open when the
+write was refused, but the reason only fell into a toast that dismissed itself after a few seconds
+and floated above the card — the card itself said nothing, so all the reader saw was the buttons
+coming alive again with the organization still there.
+
+The card now closes only on the path where its write landed; a refusal draws the server's words
+inside the card, right above the retry button (`ConfirmModal`'s `refusal` slot, the app's existing
+"Refused:" lead-in). Opening the card again drops the previous reason, which belonged to the
+attempt it named; a write in flight takes one press only, and cancelling decides nothing.
+
+## Details
+
+- `features/company/org-dialogs.tsx`: `doDelete()` keeps the server's words in `deleteRefusal`
+ instead of only toasting them, and both `setConfirmDelete(false)` and the success notice moved
+ onto the path after the `await` succeeded. The delete row's button clears the previous reason
+ and the previously typed id before it opens the card; the card's `onClose` stops answering while
+ a write is out (the card's own buttons are already disabled by `busy`; this is the same promise
+ for an escape press).
+- New browser test `e2e/org-delete-refusal.spec.mjs`: with `DELETE …/organizations/<id>` refused at
+ `page.route` 500, the card, its sentence and the organization on the server all stay (nothing in
+ the notification region carries the words); cancelling and reopening shows no stale reason; the
+ retry on the same card really deletes — the card and the settings dialog close, the organization
+ leaves the listing and reads 404.
+
+## Compatibility
+
+- No interface, wire-format, stored-data or dependency change: only *when* this card closes and
+ *where* the reason is drawn. No new copy beyond the existing `S.common.refused` lead-in.
diff --git a/changelog/unreleased/2026-10-25-org-delete-refusal.zh.md b/changelog/unreleased/2026-10-25-org-delete-refusal.zh.md
new file mode 100644
index 00000000..49578781
--- /dev/null
+++ b/changelog/unreleased/2026-10-25-org-delete-refusal.zh.md
@@ -0,0 +1,31 @@
+# 组织设置:删除组织被拒时,确认框留着,原因也留在框里
+
+- **Date:** 2026-10-25
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[English](2026-10-25-org-delete-refusal.md)
+
+组织设置对话框底部那枚「删除」会在真的删之前问一句,并且要求把组织 id 打一遍才算数。过去这张确认框
+被拒时框是留着的,可原因只落进一条几秒后自己消失、还浮在框上方的通知里 —— 框本身一个字都没有,读者
+只看到按钮又亮了,组织却还在。
+
+现在关框只发生在写入落地那条路径上;被拒时服务端原话画进框里、重试按钮正上方(`ConfirmModal` 的
+`refusal` 槽,用的是应用既有的「操作被拒绝:」前缀)。重开这张框会先清掉上一次的原因 —— 那句话属于上次
+那次尝试;一个写入在途时只认一次点击,取消不决定任何事。
+
+## 细节
+
+- `features/company/org-dialogs.tsx`:`doDelete()` 把服务端原话留在 `deleteRefusal` 里,不再只弹通知;
+ `setConfirmDelete(false)` 与那段成功通知都挪到 `await` 之后的成功路径上。删除行那枚按钮在开框前先清掉
+ 旧原因与上一次输入的 id;框的 `onClose` 在一个写入在途时不再响应(框上两个按钮本来就被 `busy` 置灰,
+ 这是同一条保证的第二道)。
+- 新增浏览器用例 `e2e/org-delete-refusal.spec.mjs`:用 `page.route` 把 `DELETE …/organizations/<id>`
+ 拒成 500 之后,框、框里那句话与服务端上的组织都不变(通知区里没有那句原话),取消后重开不带旧原因;
+ 在同一张框上重试才真正删除 —— 框与设置对话框一起关掉,组织从列表里消失、单读 404。
+
+## 兼容性
+
+- 没有接口、传输格式、已存数据或依赖变化:只改了这张框「什么时候关」与「原因画在哪」。除既有的
+ `S.common.refused` 前缀外没有新文案。
diff --git a/packages/web/e2e/org-delete-refusal.spec.mjs b/packages/web/e2e/org-delete-refusal.spec.mjs
new file mode 100644
index 00000000..bca3058d
--- /dev/null
+++ b/packages/web/e2e/org-delete-refusal.spec.mjs
@@ -0,0 +1,171 @@
+/**
+ * Regression: deleting an organization is asked in a confirmation card, and a refused write keeps
+ * that question — with the server's words inside it — instead of leaving only a toast behind.
+ *
+ * The card in `features/company/org-dialogs.tsx` (the settings dialog's delete row) used to stay
+ * open while its reason fell into a toast that dismissed itself after a few seconds and sat over
+ * the card rather than in it. It now closes only once its write landed; a refusal leaves the card
+ * standing with the reason drawn under its sentence (`ConfirmModal`'s `refusal` slot), so the retry
+ * is the button that was pressed and cancelling decides nothing.
+ *
+ * The organization and its CEO are made through the API rather than through the dialog: this spec
+ * is about the confirmation, not about creation. Company mode is off on a fresh server, so the
+ * test turns the admin master switch on first (idempotent), and the Project gets the mock as its
+ * model so the onboarding overlay stays off the page.
+ */
+import { test, expect, request } from "@playwright/test";
+import { ADMIN_ID, ADMIN_PASSWORD, login, provisionAndLogin } from "./auth.mjs";
+
+const BASE = process.env.BASE_URL;
+const MOCK = process.env.MOCK_URL;
+const P = "password123";
+const ORG = "orgdelrefuse";
+const MISSION = "把插件市场上线,做到搜索前三。";
+
+/** The refusal the page paints; a 500 with its own words proves those words came back. */
+const REFUSAL = { code: "org_store_locked", message: "the organization store is mid-rewrite" };
+
+/** The admin master switch, off by default: turned on server-wide before the flow starts. */
+async function enableCompanyMode() {
+ const adminCtx = await request.newContext();
+ try {
+ await login(adminCtx, ADMIN_ID, ADMIN_PASSWORD);
+ const res = await adminCtx.put(`${BASE}/api/admin/settings`, { data: { companyMode: true } });
+ if (!res.ok()) {
+ throw new Error(`enable company mode failed: ${res.status()} ${await res.text()}`);
+ }
+ } finally {
+ await adminCtx.dispose();
+ }
+}
+
+/**
+ * A fresh user with mock-model credentials and an organization whose CEO the server makes on
+ * creation. Returns the ids and a reader over the organization listing as stored.
+ */
+async function setUp(page, tag) {
+ await enableCompanyMode();
+ const user = `${tag}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 6)}`;
+ await provisionAndLogin(page.request, user, P);
+ const project = (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0];
+ const projectId = project.projectId;
+ const put = await page.request.put(`${BASE}/api/projects/${projectId}/models`, {
+ data: {
+ defaultModel: { provider: "custom", modelId: "claude-4-8" },
+ models: [
+ {
+ provider: "custom",
+ modelId: "claude-4-8",
+ apiKey: "sk-mock",
+ baseUrl: MOCK,
+ contextWindow: 200000,
+ },
+ ],
+ },
+ });
+ expect(put.ok(), `put models ${projectId}`).toBeTruthy();
+
+ const orgBase = `${BASE}/api/projects/${projectId}/organizations`;
+ const created = await page.request.post(orgBase, { data: { orgId: ORG, mission: MISSION } });
+ expect(created.ok(), "create organization").toBeTruthy();
+
+ /** The organization ids the server lists — read from the API, so "nothing was written" is a fact. */
+ const listed = async () => {
+ const res = await page.request.get(orgBase);
+ expect(res.ok(), "list the organizations").toBeTruthy();
+ return (await res.json()).organizations.map((o) => o.orgId);
+ };
+ return { projectId, orgBase, listed };
+}
+
+/**
+ * The settings dialog, opened from the switcher's own row: the shell names the open organization
+ * on that trigger (`<project> / <org> · <status>`), and the gear row behind it is a plain button —
+ * the switcher's panel holds no `Menu` list, so its rows carry no menu role.
+ */
+async function openSettings(page, projectId) {
+ await page.goto(`/org/${projectId}/${ORG}/overview`);
+ const trigger = page.getByRole("button", { name: new RegExp(`/ ${ORG} ·`) });
+ await expect(trigger).toBeVisible();
+ await trigger.click();
+ await page.getByRole("button", { name: "组织设置", exact: true }).click();
+ const settings = page.getByRole("dialog", { name: "组织设置" });
+ await expect(settings).toBeVisible();
+ return settings;
+}
+
+/** The delete row's button → the confirmation card (a second dialog, stacked above settings). */
+async function openDeleteCard(settings) {
+ await settings.getByRole("button", { name: "删除", exact: true }).click();
+ const card = settings.page().getByRole("dialog", { name: "删除组织" });
+ await expect(card).toBeVisible();
+ return card;
+}
+
+/**
+ * The card's own text with the refusal line dropped: a refused write adds one line under the
+ * sentence ("操作被拒绝:…"), and that line is the only thing the refusal may change.
+ */
+async function cardText(card) {
+ return (await card.innerText()).replace(/\n操作被拒绝:[^\n]*/, "");
+}
+
+test("a refused organization deletion keeps the card, its sentence and the organization", async ({
+ page,
+}) => {
+ const { projectId, orgBase, listed } = await setUp(page, "r125orgdel");
+ expect(await listed()).toContain(ORG);
+
+ const settings = await openSettings(page, projectId);
+ const card = await openDeleteCard(settings);
+ const sentence = await cardText(card);
+ expect(sentence).toContain("组织会从公司模式里消失");
+
+ const deletes = [];
+ await page.route(`**/api/projects/${projectId}/organizations/${ORG}`, async (route) => {
+ if (route.request().method() !== "DELETE") return route.fallback();
+ deletes.push(route.request().url());
+ await route.fulfill({
+ status: 500,
+ contentType: "application/json",
+ body: JSON.stringify({ error: REFUSAL }),
+ });
+ });
+
+ // The confirm button only unlocks on the typed id: the card's own word for "I mean it".
+ await card.getByRole("textbox").fill(ORG);
+ await card.getByRole("button", { name: "确认", exact: true }).click();
+
+ // The reason is in the card that asked, and it is not a toast: the notification region (which
+ // may still hold the company beta's own notice) never carries the server's words, and the card
+ // reads exactly as before plus the one line.
+ await expect(card.getByText(REFUSAL.message)).toBeVisible();
+ await expect(page.getByRole("region", { name: "通知" })).not.toContainText(REFUSAL.message);
+ expect(deletes).toHaveLength(1);
+ await expect(card).toBeVisible();
+ expect(await cardText(card)).toBe(sentence);
+
+ // Nothing was written: the organization is still on the server, settings still open behind it.
+ expect(await listed()).toContain(ORG);
+ await expect(settings).toBeVisible();
+ const stillThere = await page.request.get(`${orgBase}/${ORG}`);
+ expect(stillThere.ok(), "the organization still reads").toBeTruthy();
+
+ // Closing the card decides nothing, and reopening it does not carry the old reason.
+ await card.getByRole("button", { name: "取消" }).click();
+ await expect(card).toHaveCount(0);
+ await expect(settings).toBeVisible();
+ const again = await openDeleteCard(settings);
+ await expect(again.getByText(REFUSAL.message)).toHaveCount(0);
+ expect(await again.innerText()).toBe(sentence);
+
+ // The retry lands: the card and the settings dialog both go, and the organization is gone.
+ await page.unroute(`**/api/projects/${projectId}/organizations/${ORG}`);
+ await again.getByRole("textbox").fill(ORG);
+ await again.getByRole("button", { name: "确认", exact: true }).click();
+ await expect(again).toHaveCount(0);
+ await expect(settings).toHaveCount(0);
+ await expect.poll(listed).not.toContain(ORG);
+ const gone = await page.request.get(`${orgBase}/${ORG}`);
+ expect(gone.status(), "the organization is gone").toBe(404);
+});
diff --git a/packages/web/src/features/company/org-dialogs.tsx b/packages/web/src/features/company/org-dialogs.tsx
index 8cd4f976..8cd6d5d9 100644
--- a/packages/web/src/features/company/org-dialogs.tsx
+++ b/packages/web/src/features/company/org-dialogs.tsx
@@ -20,7 +20,9 @@
*
* Failures stay inside the dialog: a rejected id lands under the id field, anything else in
* a strip above the footer, and a settings load that fails offers its retry in place — the
- * fields never sit disabled behind a toast that has already gone.
+ * fields never sit disabled behind a toast that has already gone. A deletion is asked in a
+ * confirmation card that closes only once its own write landed: a refusal keeps the card
+ * standing with the server's words inside it, where the retry button is.
*
* `useOrganizationCreated` is the other half of creating one: what every host of the create
* dialog does once it succeeds — adopt the organization as the shell's current one, then open
@@ -606,18 +608,26 @@ export function OrganizationSettingsDialog({
/** The delete confirmation, and what has been typed into it (the id, to mean it). */
const [confirmDelete, setConfirmDelete] = useState(false);
const [typedId, setTypedId] = useState("");
+ /** The words of a deletion the server refused, kept in the card that asked for it. */
+ const [deleteRefusal, setDeleteRefusal] = useState<string | null>(null);
const { models, error: modelsError } = useProjectModels(projectId, open);
const doDelete = async () => {
+ // The card's two buttons are already disabled while the write is out; this is the same
+ // promise for a second press that slips through (a key handler, a double click).
+ if (busy) return;
setBusy(true);
try {
await api.deleteOrganization(projectId, orgId);
+ // The card goes with its own write landing, never before: a refusal has to stay readable
+ // next to the button that retries it.
setConfirmDelete(false);
+ setDeleteRefusal(null);
toastSuccess(S.company.deleted(orgId));
onClose();
onDeleted?.();
} catch (e) {
- toastError(apiErrorText(e));
+ setDeleteRefusal(apiErrorText(e));
} finally {
setBusy(false);
}
@@ -828,6 +838,7 @@ export function OrganizationSettingsDialog({
disabled={!hydrated || busy}
onClick={() => {
setTypedId("");
+ setDeleteRefusal(null);
setConfirmDelete(true);
}}
>
@@ -842,8 +853,9 @@ export function OrganizationSettingsDialog({
confirmDisabled={typedId.trim() !== orgId}
confirmLabel={S.common.confirm}
cancelLabel={S.common.cancel}
- onClose={() => setConfirmDelete(false)}
+ onClose={() => (busy ? undefined : setConfirmDelete(false))}
onConfirm={() => void doDelete()}
+ refusal={deleteRefusal === null ? undefined : S.common.refused(deleteRefusal)}
>
<p className="text-sm text-gray-600 dark:text-gray-300">{S.company.deleteOrgConfirm}</p>
<Input