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"])) })