From 3e0d14729a9e06dcb229cbc979a06c2b90ad1c9d Mon Sep 17 00:00:00 2001 From: leemour Date: Thu, 19 Nov 2026 11:34:16 +0100 Subject: [PATCH] fix(permissions): posts delete --dry-run names api.posts-delete The delete sends through the api group's delete, whose own key the run checks. With posts.delete set to allow, the preview said allow while the run still asked. Found by the review of the same wiring in cli-template. Co-Authored-By: Claude Opus 5.5 --- changes/fix-delete-dry-run.md | 4 ++++ src/config.ts | 1 + src/content-options.test.ts | 10 ++++++++++ 3 files changed, 15 insertions(+) create mode 100644 changes/fix-delete-dry-run.md diff --git a/changes/fix-delete-dry-run.md b/changes/fix-delete-dry-run.md new file mode 100644 index 0000000..d91afd7 --- /dev/null +++ b/changes/fix-delete-dry-run.md @@ -0,0 +1,4 @@ +### Fixed + +- **`posts delete --dry-run` names `api.posts-delete` too.** The delete sends through the `api` group's delete, whose + own key the run checks. With `posts.delete` set to `allow`, the preview said `allow` while the run still asked. diff --git a/src/config.ts b/src/config.ts index 2cdaf18..117967b 100644 --- a/src/config.ts +++ b/src/config.ts @@ -44,6 +44,7 @@ const API_KEYS: Readonly> = { "posts.update": "api.posts-update", "posts.publish": "api.posts-update", "posts.unpublish": "api.posts-update", + "posts.delete": "api.posts-delete", } // cli-core lets every api write but a delete run unasked. These install code, give a user a role, or change what diff --git a/src/content-options.test.ts b/src/content-options.test.ts index a00e49f..cb7c06c 100644 --- a/src/content-options.test.ts +++ b/src/content-options.test.ts @@ -118,4 +118,14 @@ it("every option of the content commands runs over a synced copy", async () => { await ok(["posts", "delete", second, "--allow-delete", "--yes"]) expect(post(second)).toBeUndefined() expect(service.refusals).toEqual([]) + + // --dry-run names what each write checks: the content key at its level, and the api key it sends through. + type Preview = { item: { permission: { key: string; level: string; also?: { key: string }[] } } } + const preview = async (argv: string[]) => ((await ran([...argv, "--dry-run"])).json() as Preview).item.permission + const drafted = await preview(["posts", "create", "--title", "Notes"]) + expect(drafted).toMatchObject({ key: "posts.create", level: "ask" }) + expect(drafted.also?.map(({ key }) => key)).toContain("api.posts-create") + const erased = await preview(["posts", "delete", first, "--allow-delete"]) + expect(erased).toMatchObject({ key: "posts.delete", level: "ask" }) + expect(erased.also?.map(({ key }) => key)).toEqual(expect.arrayContaining(["posts.delete.force", "api.posts-delete"])) })