Skip to content
Merged
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
4 changes: 4 additions & 0 deletions changes/fix-delete-dry-run.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const API_KEYS: Readonly<Record<string, string>> = {
"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
Expand Down
10 changes: 10 additions & 0 deletions src/content-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
})
Loading